Mod aaa-12 add domain handler test and role handler test
RCA: SOL: 修改人:maxiaonan 检视人:maxiaonan
This commit is contained in:
parent
5ec7a37bd9
commit
a3ef648b3b
|
@ -37,12 +37,12 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
Domains domains = target("/v1/domains").request().get(Domains.class);
|
||||
assertNotNull(domains);
|
||||
assertEquals(1, domains.getDomains().size());
|
||||
assertTrue(domains.getDomains().get(0).getName().equals("sdn"));
|
||||
assertEquals("sdn", domains.getDomains().get(0).getName());
|
||||
|
||||
// check existing domain
|
||||
Domain domain = target("/v1/domains/0").request().get(Domain.class);
|
||||
assertNotNull(domain);
|
||||
assertTrue(domain.getName().equals("sdn"));
|
||||
assertEquals("sdn", domain.getName());
|
||||
|
||||
// check not exist domain
|
||||
try {
|
||||
|
@ -54,19 +54,27 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
|
||||
// check create domain
|
||||
Map<String, String> domainData = new HashMap<>();
|
||||
Response clientResponse = target("/v1/domains").request().post(entity(domainData));
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
|
||||
domainData.put("name", "dom1");
|
||||
domainData.put("description", "test dom");
|
||||
domainData.put("enabled", "true");
|
||||
Response clientResponse = target("/v1/domains").request().post(entity(domainData));
|
||||
clientResponse = target("/v1/domains").request().post(entity(domainData));
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
|
||||
|
||||
// check update domain data
|
||||
domainData.put("name", "dom1Update");
|
||||
clientResponse = target("/v1/domains/1").request().put(entity(domainData));
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
|
||||
clientResponse = target("/v1/domains/101").request().put(entity(domainData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
domain = target("/v1/domains/1").request().get(Domain.class);
|
||||
assertNotNull(domain);
|
||||
assertTrue(domain.getName().equals("dom1Update"));
|
||||
assertEquals("dom1Update", domain.getName());
|
||||
|
||||
// check create grant
|
||||
Map<String, String> grantData = new HashMap<>();
|
||||
|
@ -74,6 +82,18 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData));
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
|
||||
clientResponse = target("/v1/domains/1/users/100/roles").request().post(entity(grantData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
grantData.put("roleid", "10ywre");
|
||||
clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
grantData.put("roleid", "52");
|
||||
clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
grantData.put("roleid", "1");
|
||||
// check create existing grant
|
||||
clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData));
|
||||
assertEquals(403, clientResponse.getStatus());
|
||||
|
@ -96,6 +116,28 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData));
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
|
||||
//check domain is null
|
||||
clientResponse = target("/v1/domains/12/users/roles").request().post(entity(usrPwdData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
//check user pwd with null parameter
|
||||
//check domain is null
|
||||
usrPwdData.remove("username");
|
||||
clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
usrPwdData.put("username", "admin");
|
||||
|
||||
usrPwdData.remove("userpwd");
|
||||
clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
usrPwdData.put("userpwd", "admin");
|
||||
|
||||
//check user is null
|
||||
usrPwdData.put("username","12321421");
|
||||
clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
usrPwdData.put("username", "admin");
|
||||
|
||||
// check validate user (admin) with wrong password
|
||||
usrPwdData.put("userpwd", "1234");
|
||||
clientResponse = target("/v1/domains/0/users/roles").request().post(entity(usrPwdData));
|
||||
|
@ -114,6 +156,12 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
target("/v1/domains/19/users/0/roles").request().get(IDMError.class);
|
||||
fail("Should fail with 404!");
|
||||
} catch (NotFoundException e) {
|
||||
// expected
|
||||
}
|
||||
// check delete grant
|
||||
clientResponse = target("/v1/domains/0/users/0/roles/0").request().delete();
|
||||
assertEquals(204, clientResponse.getStatus());
|
||||
|
|
|
@ -69,9 +69,32 @@ public class RoleHandlerTest extends HandlerTest {
|
|||
try {
|
||||
clientResponse = target("/v1/roles").request().post(entity(roleData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
roleData.put("name", getMaxLengthName());
|
||||
target("/v1/roles").request().post(entity(roleData));
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
roleData.put("name", "role1");
|
||||
//POST ERROR
|
||||
roleData.remove("domainid");
|
||||
try {
|
||||
clientResponse = target("/v1/roles").request().post(entity(roleData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
roleData.put("domainid", getMaxLengthName());
|
||||
target("/v1/roles").request().post(entity(roleData));
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
roleData.put("domainid", "0");
|
||||
roleData.remove("description");
|
||||
try {
|
||||
target("/v1/roles").request().post(entity(roleData));
|
||||
roleData.put("description", getMaxLengthName());
|
||||
target("/v1/roles").request().post(entity(roleData));
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
roleData.put("description", "test Role");
|
||||
|
||||
// check update Role data
|
||||
roleData.put("name", "role1Update");
|
||||
|
@ -81,6 +104,25 @@ public class RoleHandlerTest extends HandlerTest {
|
|||
assertNotNull(role);
|
||||
assertTrue(role.getName().equals("role1Update"));
|
||||
|
||||
//PUT Error
|
||||
roleData.put("name", getMaxLengthName());
|
||||
clientResponse = target("/v1/roles/2").request().put(entity(roleData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
roleData.put("name", "role1Update");
|
||||
|
||||
roleData.put("description", getMaxLengthName());
|
||||
clientResponse = target("/v1/roles/2").request().put(entity(roleData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
roleData.put("description", "test Role");
|
||||
|
||||
HashMap<String,String> newRole = new HashMap<>();
|
||||
newRole.put("name", "role1Update");
|
||||
newRole.put("domainid", "0");
|
||||
newRole.put("description", "test Role");
|
||||
clientResponse = target("/v1/roles/111111").request().put(entity(newRole));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
|
||||
// check delete Role
|
||||
clientResponse = target("/v1/roles/2").request().delete();
|
||||
assertEquals(204, clientResponse.getStatus());
|
||||
|
@ -102,6 +144,16 @@ public class RoleHandlerTest extends HandlerTest {
|
|||
clientResponse = target("/v1/roles").request().post(entity(roleData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
}
|
||||
|
||||
private String getMaxLengthName() {
|
||||
return "abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
|
|
Loading…
Reference in New Issue