Updated Branches:
  refs/heads/master e26d4a914 -> d0fdbe3d2

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/UserApiExpectTest.java
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/UserApiExpectTest.java
 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/UserApiExpectTest.java
new file mode 100644
index 0000000..7ea10c9
--- /dev/null
+++ 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/UserApiExpectTest.java
@@ -0,0 +1,372 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.openstack.reddwarf.v1.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertFalse;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.reddwarf.v1.domain.User;
+import org.jclouds.openstack.reddwarf.v1.internal.BaseRedDwarfApiExpectTest;
+import org.testng.annotations.Test;
+import org.testng.collections.Lists;
+import org.testng.internal.annotations.Sets;
+
+import com.google.common.collect.ImmutableSortedSet;
+import com.google.common.collect.ImmutableSortedSet.Builder;
+
+/**
+ * Tests UserApi Guice wiring and parsing
+ *
+ * @author Zack Shoylev
+ */
+@Test(groups = "unit", testName = "UserApiExpectTest")
+public class UserApiExpectTest extends BaseRedDwarfApiExpectTest {
+
+   public void testCreateUserSimple() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("POST")
+            
.payload(payloadFromResourceWithContentType("/user_create_simple_request.json", 
MediaType.APPLICATION_JSON))
+            .build(),
+            HttpResponse.builder().statusCode(202).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      boolean result = api.create("dbuser1", "password", "databaseA");
+      assertTrue(result);
+   }
+
+   public void testCreateUserSimpleFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("POST")
+            
.payload(payloadFromResourceWithContentType("/user_create_simple_request.json", 
MediaType.APPLICATION_JSON))
+            .build(),
+            HttpResponse.builder().statusCode(404).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      boolean result = api.create("dbuser1", "password", "databaseA");
+      assertFalse(result);
+   }
+
+   public void testCreateUser() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("POST")
+            
.payload(payloadFromResourceWithContentType("/user_create_request.json", 
MediaType.APPLICATION_JSON))
+            .build(),
+            HttpResponse.builder().statusCode(202).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<String> databases1 = Sets.newHashSet();
+      databases1.add( "databaseA" );      
+      Builder<String> databases2builder = 
ImmutableSortedSet.<String>naturalOrder();
+      databases2builder.add( "databaseB" );
+      databases2builder.add( "databaseC" );
+      Set<String> databases2 = databases2builder.build();
+      Set<String> databases3 = Sets.newHashSet();
+      databases3.add( "databaseD" );
+      User user1 = User.builder().databases( databases1 
).name("dbuser1").password("password").build();
+      User user2 = User.builder().databases( databases2 
).name("dbuser2").password("password").build();
+      User user3 = User.builder().databases( databases3 
).name("dbuser3").password("password").build();
+      Set<User> users = Sets.newHashSet();
+      users.add(user1);
+      users.add(user2);
+      users.add(user3);
+      
+      boolean result = 
api.create(ImmutableSortedSet.<User>naturalOrder().addAll(users).build());
+      assertTrue(result);
+   }
+
+   public void testCreateUserFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("POST")
+            
.payload(payloadFromResourceWithContentType("/user_create_request.json", 
MediaType.APPLICATION_JSON))
+            .build(),
+            HttpResponse.builder().statusCode(404).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<String> databases1 = Sets.newHashSet();
+      databases1.add( "databaseA" );
+      Builder<String> databases2builder = 
ImmutableSortedSet.<String>naturalOrder();
+      databases2builder.add( "databaseB" );
+      databases2builder.add( "databaseC" );
+      Set<String> databases2 = databases2builder.build();
+      Set<String> databases3 = Sets.newHashSet();
+      databases3.add( "databaseD" );
+      User user1 = User.builder().databases( databases1 
).name("dbuser1").password("password").build();
+      User user2 = User.builder().databases( databases2 
).name("dbuser2").password("password").build();
+      User user3 = User.builder().databases( databases3 
).name("dbuser3").password("password").build();
+      Set<User> users = Sets.newHashSet();
+      users.add(user1);
+      users.add(user2);
+      users.add(user3);
+      
+      boolean result = api.create( 
ImmutableSortedSet.<User>naturalOrder().addAll(users).build());
+      assertFalse(result);
+   }
+
+   public void testGrantUserSimple() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("PUT")
+            
.payload(payloadFromResourceWithContentType("/user_grant_simple_request.json", 
MediaType.APPLICATION_JSON))
+            .build(),
+            HttpResponse.builder().statusCode(202).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      boolean result = api.grant("dbuser1", "databaseZ");
+      assertTrue(result);
+   }
+
+   public void testGrantUserSimpleFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("PUT")
+            
.payload(payloadFromResourceWithContentType("/user_grant_simple_request.json", 
MediaType.APPLICATION_JSON))
+            .build(),
+            HttpResponse.builder().statusCode(404).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      boolean result = api.grant("dbuser1", "databaseZ");
+      assertFalse(result);
+   }
+
+   public void testGrantUser() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("PUT")
+            
.payload(payloadFromResourceWithContentType("/user_grant_request.json", 
MediaType.APPLICATION_JSON))
+            .build(),
+            HttpResponse.builder().statusCode(202).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      List<String> databases = Lists.newArrayList();
+      databases.add( "databaseC" );
+      databases.add( "databaseD" );
+      
+      boolean result = api.grant("dbuser1", databases);
+      assertTrue(result);
+   }
+
+   public void testGrantUserFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("PUT")
+            
.payload(payloadFromResourceWithContentType("/user_grant_request.json", 
MediaType.APPLICATION_JSON))
+            .build(),
+            HttpResponse.builder().statusCode(404).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      List<String> databases = Lists.newArrayList();
+      databases.add( "databaseC" );
+      databases.add( "databaseD" );
+      
+      boolean result = api.grant("dbuser1", databases);
+      assertFalse(result);
+   }
+   
+   public void testRevokeUser() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases/databaseA";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("DELETE")
+            .build(),
+            HttpResponse.builder().statusCode(202).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<String> databases = Sets.newHashSet();
+      databases.add( "database" );
+      databases.add( "database" );
+      boolean result = api.revoke("dbuser1", "databaseA");
+      assertTrue(result);
+   }
+   
+   public void testRevokeUserFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases/databaseA";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("DELETE")
+            .build(),
+            HttpResponse.builder().statusCode(404).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<String> databases = Sets.newHashSet();
+      databases.add( "database" );
+      databases.add( "database" );
+      boolean result = api.revoke("dbuser1", "databaseA");
+      assertFalse(result);
+   }
+   
+   public void testDeleteUser() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("DELETE")
+            .build(),
+            HttpResponse.builder().statusCode(202).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<String> databases = Sets.newHashSet();
+      databases.add( "database" );
+      databases.add( "database" );
+      boolean result = api.delete("dbuser1");
+      assertTrue(result);
+   }
+   
+   public void testDeleteUserFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint) // bad naming convention, 
you should not be able to change the method to POST
+            .method("DELETE")
+            .build(),
+            HttpResponse.builder().statusCode(404).build() // response
+            ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<String> databases = Sets.newHashSet();
+      databases.add( "database" );
+      databases.add( "database" );
+      boolean result = api.delete("dbuser1");
+      assertFalse(result);
+   }
+   
+   public void testListUsers() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint).build(),
+            
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/reddwarf_user_list.json")).build()
+      ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<User> users = api.list("instanceId-1234-5678").toSet();
+      assertEquals(users.size(), 4);
+      assertEquals(users.iterator().next().getDatabases().size(), 0);
+      assertEquals(users.iterator().next().getName(), "dbuser1");
+   }
+   
+   public void testListUsersFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint).build(),
+            
HttpResponse.builder().statusCode(404).payload(payloadFromResource("/reddwarf_user_list.json")).build()
+      ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<User> users = api.list("instanceId-1234-5678").toSet();
+      assertEquals(users.size(), 0);
+   }
+   
+   public void testUserGetDatabaseList() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint).build(),
+            
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/user_list_access.json")).build()
+      ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      List<String> databases = api.getDatabaseList("dbuser1").toList();
+      assertEquals(databases.size(), 2);
+      assertEquals(databases.iterator().next(), "databaseA");
+   }
+   
+   public void testUserGetDatabaseListFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint).build(),
+            
HttpResponse.builder().statusCode(404).payload(payloadFromResource("/user_list_access.json")).build()
+      ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      Set<String> databases = api.getDatabaseList("dbuser1").toSet();
+      assertEquals(databases.size(), 0);
+   }
+   
+   public void testGetUser() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/exampleuser";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint).build(),
+            
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/user_get.json")).build()
+      ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      User user = api.get("exampleuser");
+      assertEquals(user.getName(), "exampleuser");
+      assertEquals(user.getDatabases().size(), 2);
+      assertEquals(user.getDatabases().iterator().next(), "databaseA");
+   }
+   
+   public void testGetUserFail() {
+      URI endpoint = 
URI.create("http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/exampleuser";);
+      UserApi api = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName,
+            responseWithKeystoneAccess,
+            authenticatedGET().endpoint(endpoint).build(),
+            
HttpResponse.builder().statusCode(404).payload(payloadFromResource("/user_get.json")).build()
+      ).getUserApiForInstanceInZone("instanceId-1234-5678","RegionOne");
+
+      User user = api.get("exampleuser");
+      assertNull(user);
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/UserApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/UserApiLiveTest.java
 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/UserApiLiveTest.java
new file mode 100644
index 0000000..75d7a04
--- /dev/null
+++ 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/UserApiLiveTest.java
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.jclouds.openstack.reddwarf.v1.features;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.jclouds.openstack.reddwarf.v1.domain.Instance;
+import org.jclouds.openstack.reddwarf.v1.domain.User;
+import org.jclouds.openstack.reddwarf.v1.internal.BaseRedDwarfApiLiveTest;
+import org.jclouds.openstack.reddwarf.v1.predicates.InstancePredicates;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * @author Zack Shoylev
+ */
+@Test(groups = "live", testName = "UserApiLiveTest", singleThreaded = true)
+public class UserApiLiveTest extends BaseRedDwarfApiLiveTest {
+
+   // zone to instance
+   private static Map<String,List<Instance>> instancesToDelete = 
Maps.newHashMap();
+   // not deleting users. they will be deleted when instances are deleted
+
+   @Override
+   @BeforeClass(groups = { "integration", "live" })
+   public void setup() {
+      super.setup();
+      for (String zone : api.getConfiguredZones()) {
+         // create instances
+         List<Instance> instanceList = Lists.newArrayList();
+         InstanceApi instanceApi = api.getInstanceApiForZone(zone);
+         Instance first = instanceApi.create("1", 1, "first_user_testing");
+         Instance second = instanceApi.create("1", 1, "second_user_testing");
+         instanceList.add(first);
+         instanceList.add(second);
+         InstancePredicates.awaitAvailable(instanceApi).apply(first);
+         InstancePredicates.awaitAvailable(instanceApi).apply(second);        
+         instancesToDelete.put(zone, instanceList);
+         // create users
+         User user1 = User.builder()
+               .name("user1")
+               .password(UUID.randomUUID().toString())
+               .databases(ImmutableSet.of(
+                     "u1db1", 
+                     "u1db1")).build();
+         User user2 = User.builder()
+               .name("user2")
+               .password(UUID.randomUUID().toString())
+               .databases(ImmutableSet.of(
+                     "u2db1", 
+                     "u2db1")).build();
+         User user3 = User.builder()
+               .name("user3")
+               .password(UUID.randomUUID().toString())
+               .databases(ImmutableSet.of(
+                     "u3db1", 
+                     "u3db1")).build();
+         UserApi userApiFirst = api.getUserApiForInstanceInZone(first.getId(), 
zone);
+         UserApi userApiSecond = 
api.getUserApiForInstanceInZone(second.getId(), zone);
+         userApiFirst.create(ImmutableSet.of(user1, user2));
+         userApiSecond.create(ImmutableSet.of(user3));
+      }
+   }
+
+   @Override
+   @AfterClass(groups = { "integration", "live" })
+   public void tearDown(){
+      for (String zone : api.getConfiguredZones()) {
+         InstanceApi instanceApi = api.getInstanceApiForZone(zone);
+         for(Instance instance : instancesToDelete.get(zone)){
+            if( !instanceApi.delete(instance.getId() ) )
+               throw new RuntimeException("Could not delete a database 
instance after tests!");
+         }
+      }
+      super.tearDown();
+   }
+
+   private void checkUser(User user) {
+      assertNotNull(user.getName(), "Name cannot be null for " + user);
+      checkArgument(user.getDatabases().size() > 0, "Number of databases must 
not be 0");
+   }
+
+   @Test
+   public void testListUsers() {
+      for (String zone : api.getConfiguredZones()) {
+         InstanceApi instanceApi = api.getInstanceApiForZone(zone);
+         assertTrue(instanceApi.list().size() >= 2);
+         for(Instance instance : instanceApi.list() ) {
+            UserApi userApi = 
api.getUserApiForInstanceInZone(instance.getId(), zone);
+            if(!instance.getName().contains("user_testing"))continue;
+            assertTrue(userApi.list(instance.getId()).size() >=1);
+            for(User user : userApi.list(instance.getId())){
+               checkUser(user);      
+            }
+         }  
+      }   
+   }    
+
+   @Test
+   public void testGetUser() {
+      for (String zone : api.getConfiguredZones()) {
+         InstanceApi instanceApi = api.getInstanceApiForZone(zone);
+         assertTrue(instanceApi.list().size() >= 2);
+         for(Instance instance : instanceApi.list() ) {
+            UserApi userApi = 
api.getUserApiForInstanceInZone(instance.getId(), zone);
+            if(!instance.getName().contains("user_testing"))continue;
+            assertTrue(userApi.list(instance.getId()).size() >=1);
+            for(User user : userApi.list(instance.getId())){
+               User userFromGet = userApi.get(user.getName());
+               assertEquals(userFromGet.getName(), user.getName());
+               assertEquals(userFromGet.getDatabases(), user.getDatabases());  
   
+            }
+         }  
+      } 
+   }
+
+   @Test
+   public void testGetDatabaseListForUser() {
+      for (String zone : api.getConfiguredZones()) {
+         InstanceApi instanceApi = api.getInstanceApiForZone(zone);
+         assertTrue(instanceApi.list().size() >= 2 );
+         for(Instance instance : instanceApi.list() ) {
+            UserApi userApi = 
api.getUserApiForInstanceInZone(instance.getId(), zone);
+            if(!instance.getName().contains("user_testing"))continue;
+            assertTrue(userApi.list(instance.getId()).size() >=1);
+            for(User user : userApi.list(instance.getId())){
+               assertTrue(userApi.getDatabaseList(user.getName()).size()>0);
+            }
+         }  
+      } 
+   }
+
+   @Test
+   public void testGrantAndRevokeAcccessForUser() {
+      for (String zone : api.getConfiguredZones()) {
+         InstanceApi instanceApi = api.getInstanceApiForZone(zone);
+         assertTrue(instanceApi.list().size() >= 2);
+         for(Instance instance : instanceApi.list() ) {
+            UserApi userApi = 
api.getUserApiForInstanceInZone(instance.getId(), zone);
+            if(!instance.getName().contains("user_testing"))continue;
+            assertTrue(userApi.list(instance.getId()).size() >=1);
+            for(User user : userApi.list(instance.getId())){
+               userApi.grant(user.getName(), "dbA");
+               userApi.grant(user.getName(), ImmutableList.of(
+                     "dbB", 
+                     "dbC"));
+
+               Set<String> databases = 
userApi.getDatabaseList(user.getName()).toSet();
+               assertTrue(databases.contains("dbA"));
+               assertTrue(databases.contains("dbB"));
+               assertTrue(databases.contains("dbC"));
+
+               userApi.revoke(user.getName(), "dbA");
+               userApi.revoke(user.getName(), "dbB");
+               userApi.revoke(user.getName(), "dbC");
+
+               databases = userApi.getDatabaseList(user.getName()).toSet();
+               assertFalse(databases.contains("dbA"));
+               assertFalse(databases.contains("dbB"));
+               assertFalse(databases.contains("dbC"));
+            }
+         }  
+      } 
+   }
+
+   @Test
+   public void testGetUserWhenNotFound() {
+      for (String zone : api.getConfiguredZones()) {
+         String instanceId = 
api.getInstanceApiForZone(zone).list().iterator().next().getId(); 
+         UserApi userApi = api.getUserApiForInstanceInZone(instanceId, zone);
+         assertNull(userApi.get("9999"));
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiExpectTest.java
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiExpectTest.java
 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiExpectTest.java
index 290946f..1cedae9 100644
--- 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiExpectTest.java
+++ 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiExpectTest.java
@@ -1,14 +1,14 @@
-/**
- * Licensed to jclouds, Inc. (jclouds) under one or more
- * contributor license agreements.  See the NOTICE file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
- * regarding copyright ownership.  jclouds licenses this file
+ * regarding copyright ownership.  The ASF licenses this file
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ * 
  *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiLiveTest.java
 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiLiveTest.java
index bc9f484..b486024 100644
--- 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiLiveTest.java
+++ 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfApiLiveTest.java
@@ -1,14 +1,14 @@
-/**
- * Licensed to jclouds, Inc. (jclouds) under one or more
- * contributor license agreements.  See the NOTICE file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
- * regarding copyright ownership.  jclouds licenses this file
+ * regarding copyright ownership.  The ASF licenses this file
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ * 
  *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfExpectTest.java
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfExpectTest.java
 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfExpectTest.java
index 17c18a0..c2078d7 100644
--- 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfExpectTest.java
+++ 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/internal/BaseRedDwarfExpectTest.java
@@ -1,14 +1,14 @@
-/**
- * Licensed to jclouds, Inc. (jclouds) under one or more
- * contributor license agreements.  See the NOTICE file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
- * regarding copyright ownership.  jclouds licenses this file
+ * regarding copyright ownership.  The ASF licenses this file
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ * 
  *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseFlavorListTest.java
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseFlavorListTest.java
 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseFlavorListTest.java
index b920c82..e00e1c3 100644
--- 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseFlavorListTest.java
+++ 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseFlavorListTest.java
@@ -1,14 +1,14 @@
-/**
- * Licensed to jclouds, Inc. (jclouds) under one or more
- * contributor license agreements.  See the NOTICE file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
- * regarding copyright ownership.  jclouds licenses this file
+ * regarding copyright ownership.  The ASF licenses this file
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ * 
  *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseInstanceListTest.java
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseInstanceListTest.java
 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseInstanceListTest.java
index ee400f4..7628e64 100644
--- 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseInstanceListTest.java
+++ 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseInstanceListTest.java
@@ -1,14 +1,14 @@
-/**
- * Licensed to jclouds, Inc. (jclouds) under one or more
- * contributor license agreements.  See the NOTICE file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
- * regarding copyright ownership.  jclouds licenses this file
+ * regarding copyright ownership.  The ASF licenses this file
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
+ * 
  *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseUserListTest.java
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseUserListTest.java
 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseUserListTest.java
new file mode 100644
index 0000000..2342b78
--- /dev/null
+++ 
b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/parse/ParseUserListTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.openstack.reddwarf.v1.parse;
+
+import java.util.Set;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.core.MediaType;
+import org.jclouds.json.BaseSetParserTest;
+import org.jclouds.openstack.reddwarf.v1.domain.User;
+import org.jclouds.rest.annotations.SelectJson;
+import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * 
+ * @author Zack Shoylev
+ */
+
+@Test(groups = "unit", testName = "ParseUserTest")
+public class ParseUserListTest extends BaseSetParserTest<User> {
+
+   @Override
+   public String resource() {
+      return "/reddwarf_user_list.json";
+   }
+
+   /*
+    * The user needs to be comparable for this test to work 
+    * */
+   @Override
+   @Consumes(MediaType.APPLICATION_JSON)
+   @SelectJson("users")
+   public Set<User> expected() {
+      return ImmutableSet
+            .of(User.builder()
+                  .name("dbuser1")
+                  .build(),
+                  User.builder()
+                  .name("dbuser2")
+                  .databases( ImmutableSet.of( 
+                          "databaseB",
+                          "databaseC") )
+                  .build(),
+                  User.builder().name("dbuser3").build(),
+                  User.builder().name("demouser").databases(
+                          ImmutableSet.of("sampledb"))
+                          .build()
+                  );
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/resources/reddwarf_user_list.json
----------------------------------------------------------------------
diff --git a/openstack-reddwarf/src/test/resources/reddwarf_user_list.json 
b/openstack-reddwarf/src/test/resources/reddwarf_user_list.json
new file mode 100644
index 0000000..55afb56
--- /dev/null
+++ b/openstack-reddwarf/src/test/resources/reddwarf_user_list.json
@@ -0,0 +1,31 @@
+{
+    "users": [
+        {
+            "databases": [], 
+            "name": "dbuser1"
+        }, 
+        {
+            "databases": [
+                {
+                    "name": "databaseB"
+                }, 
+                {
+                    "name": "databaseC"
+                }
+            ], 
+            "name": "dbuser2"
+        }, 
+        {
+            "databases": [], 
+            "name": "dbuser3"
+        }, 
+        {
+            "databases": [
+                {
+                    "name": "sampledb"
+                }
+            ], 
+            "name": "demouser"
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/resources/user_create_request.json
----------------------------------------------------------------------
diff --git a/openstack-reddwarf/src/test/resources/user_create_request.json 
b/openstack-reddwarf/src/test/resources/user_create_request.json
new file mode 100644
index 0000000..7742898
--- /dev/null
+++ b/openstack-reddwarf/src/test/resources/user_create_request.json
@@ -0,0 +1,34 @@
+{
+    "users":[
+        {
+            "databases":[
+                {
+                    "name":"databaseA"
+                }
+            ],
+            "name":"dbuser1",
+            "password":"password"
+        },
+        {
+            "databases":[
+                {
+                    "name":"databaseB"
+                },
+                {
+                    "name":"databaseC"
+                }
+            ],
+            "name":"dbuser2",
+            "password":"password"
+        },
+        {
+            "databases":[
+                {
+                    "name":"databaseD"
+                }
+            ],
+            "name":"dbuser3",
+            "password":"password"
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/resources/user_create_simple_request.json
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/resources/user_create_simple_request.json 
b/openstack-reddwarf/src/test/resources/user_create_simple_request.json
new file mode 100644
index 0000000..921f68e
--- /dev/null
+++ b/openstack-reddwarf/src/test/resources/user_create_simple_request.json
@@ -0,0 +1,13 @@
+{
+    "users":[
+        {
+            "databases":[
+                {
+                    "name":"databaseA"
+                }
+            ],
+            "name":"dbuser1",
+            "password":"password"
+        }
+    ]
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/resources/user_get.json
----------------------------------------------------------------------
diff --git a/openstack-reddwarf/src/test/resources/user_get.json 
b/openstack-reddwarf/src/test/resources/user_get.json
new file mode 100644
index 0000000..8d4169c
--- /dev/null
+++ b/openstack-reddwarf/src/test/resources/user_get.json
@@ -0,0 +1,13 @@
+{
+   "user": {
+      "name": "exampleuser",
+      "databases": [
+         {
+            "name": "databaseA"
+         },
+         {
+            "name": "databaseB"
+         }
+      ]
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/resources/user_grant_request.json
----------------------------------------------------------------------
diff --git a/openstack-reddwarf/src/test/resources/user_grant_request.json 
b/openstack-reddwarf/src/test/resources/user_grant_request.json
new file mode 100644
index 0000000..97a1239
--- /dev/null
+++ b/openstack-reddwarf/src/test/resources/user_grant_request.json
@@ -0,0 +1,10 @@
+{
+   "databases": [
+      {
+         "name": "databaseC"
+      },
+      {
+         "name": "databaseD"
+      }
+   ]
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/resources/user_grant_simple_request.json
----------------------------------------------------------------------
diff --git 
a/openstack-reddwarf/src/test/resources/user_grant_simple_request.json 
b/openstack-reddwarf/src/test/resources/user_grant_simple_request.json
new file mode 100644
index 0000000..5113e4f
--- /dev/null
+++ b/openstack-reddwarf/src/test/resources/user_grant_simple_request.json
@@ -0,0 +1,7 @@
+{
+   "databases": [
+      {
+         "name": "databaseZ"
+      }
+   ]
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/resources/user_list_access.json
----------------------------------------------------------------------
diff --git a/openstack-reddwarf/src/test/resources/user_list_access.json 
b/openstack-reddwarf/src/test/resources/user_list_access.json
new file mode 100644
index 0000000..c58e1fa
--- /dev/null
+++ b/openstack-reddwarf/src/test/resources/user_list_access.json
@@ -0,0 +1,10 @@
+{
+   "databases": [
+      {
+         "name": "databaseA"
+      },
+      {
+         "name": "databaseB"
+      }
+   ]
+}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/d0fdbe3d/openstack-reddwarf/src/test/resources/user_password_request.json
----------------------------------------------------------------------
diff --git a/openstack-reddwarf/src/test/resources/user_password_request.json 
b/openstack-reddwarf/src/test/resources/user_password_request.json
new file mode 100644
index 0000000..e42b277
--- /dev/null
+++ b/openstack-reddwarf/src/test/resources/user_password_request.json
@@ -0,0 +1,12 @@
+{
+   "users": [
+      {
+          "name": "dbuser1",
+          "password": "newpassword"
+      },
+      {
+           "name": "dbuser2",
+           "password": "anotherpassword"
+      }
+   ]
+}

Reply via email to