use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class GroupControllerIntegrationTest method testGetGroupsPagination.
@Test
public void testGetGroupsPagination() throws Exception {
List<Group> testGroups = new ArrayList<>();
try {
for (int i = 0; i < 25; i++) {
String x = ("tmp_" + i);
Group group = new Group();
group.setDescription(x);
group.setName(x);
testGroups.add(group);
this.groupManager.addGroup(group);
}
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/groups").param("pageSize", "5").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
result.andExpect(jsonPath("$.metaData.page", is(1)));
result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
result.andExpect(jsonPath("$.payload[0].code", is("administrators")));
// -------------
result = mockMvc.perform(get("/groups").param("pageSize", "5").param("page", "1").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
result.andExpect(jsonPath("$.metaData.page", is(1)));
result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
result.andExpect(jsonPath("$.payload[0].code", is("administrators")));
// -------------
result = mockMvc.perform(get("/groups").param("pageSize", "5").param("page", "7").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
result.andExpect(jsonPath("$.metaData.page", is(7)));
result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
result.andExpect(jsonPath("$.payload[0].code", is("tmp_9")));
// -------------
result = mockMvc.perform(get("/groups").param("pageSize", "0").param("page", "7").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isNotFound());
// -------------
result = mockMvc.perform(get("/groups").param("pageSize", "7").param("page", "0").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
// -------------
result = mockMvc.perform(get("/groups").param("pageSize", "1").param("page", "7").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(jsonPath("$.metaData.pageSize", is(1)));
result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
result.andExpect(jsonPath("$.metaData.page", is(7)));
result.andExpect(jsonPath("$.metaData.lastPage", is(31)));
result.andExpect(jsonPath("$.payload[0].code", is("tmp_0")));
} finally {
for (Group group : testGroups) {
this.groupManager.removeGroup(group);
}
}
}
use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class UserControllerUnitTest method mockedGroup.
private Group mockedGroup() {
Group group = new Group();
group.setDescription("descr1");
group.setName("group1");
return group;
}
use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class OAuth2TestUtils method addAuthorization.
public static void addAuthorization(User user, String groupName, String roleName, String[] permissions) {
Group group = null;
if (StringUtils.isNotBlank(groupName)) {
group = new Group();
group.setName(groupName);
group.setDescription(groupName + " descr");
}
Role role = null;
if (StringUtils.isNotBlank(roleName)) {
role = new Role();
role.setName(roleName);
role.setDescription(roleName + " descr");
if (null != permissions) {
for (String permissionName : permissions) {
role.addPermission(permissionName);
}
}
}
Authorization auth = new Authorization(group, role);
user.addAuthorization(auth);
}
use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class TestAuthorityManager method testSetRemoveUserAuthorizations_2.
public void testSetRemoveUserAuthorizations_2() throws Throwable {
String username = "pageManagerCustomers";
String notExistentGroupName = "testgroupname";
String existentGroupName = "management";
String roleName = "pageManager";
Role roleForTest = this.getRole(roleName);
assertNotNull(roleForTest);
// existent group
Group existentGroup = this.getGroup(existentGroupName);
assertNotNull(existentGroup);
// nonexistent group
Group nonExistentGroup = this.createGroupForTest(notExistentGroupName);
List<String> usersByGroup = this._authorizationManager.getUsersByAuthority(existentGroup, false);
assertNotNull(usersByGroup);
assertEquals(0, usersByGroup.size());
usersByGroup = this._authorizationManager.getUsersByGroup(nonExistentGroup, false);
assertNull(usersByGroup);
try {
Authorization auth1 = new Authorization(existentGroup, roleForTest);
Authorization auth2 = new Authorization(nonExistentGroup, roleForTest);
List<Authorization> authorizations = new ArrayList<Authorization>();
authorizations.add(auth1);
authorizations.add(auth2);
this._authorizationManager.addUserAuthorizations(username, authorizations);
usersByGroup = this._authorizationManager.getUsersByAuthority(existentGroup, false);
assertNotNull(usersByGroup);
assertEquals(1, usersByGroup.size());
usersByGroup = this._authorizationManager.getUsersByGroup(nonExistentGroup, false);
assertNull(usersByGroup);
} catch (Throwable t) {
this._authorizationManager.deleteUserAuthorization(username, notExistentGroupName, roleName);
throw t;
} finally {
this._authorizationManager.deleteUserAuthorization(username, existentGroupName, roleName);
usersByGroup = this._authorizationManager.getUsersByAuthority(existentGroup, false);
assertNotNull(usersByGroup);
assertEquals(0, usersByGroup.size());
}
}
use of com.agiletec.aps.system.services.group.Group in project entando-core by entando.
the class TestAuthorityManager method testGetUsersByAuthority_1.
public void testGetUsersByAuthority_1() throws Throwable {
Role role = this.getRole("pageManager");
List<String> usersByRole = this._authorizationManager.getUsersByAuthority(role, false);
assertNotNull(usersByRole);
assertTrue(usersByRole.size() >= 2);
usersByRole = this._authorizationManager.getUsersByRole(role, false);
assertNotNull(usersByRole);
assertTrue(usersByRole.size() >= 2);
List<String> usersByInvalidGroup = this._authorizationManager.getUsersByGroup(role, false);
assertNull(usersByInvalidGroup);
Group group = this.getGroup("coach");
List<String> usersByGroup = this._authorizationManager.getUsersByAuthority(group, false);
assertNotNull(usersByGroup);
assertTrue(usersByGroup.size() >= 3);
List<String> usersByNullGroup = this._authorizationManager.getUsersByAuthority(null, false);
assertNull(usersByNullGroup);
Group noExistingGroup = new Group();
noExistingGroup.setName("test");
noExistingGroup.setDescription("test");
List<String> usersByInvaliGroup = this._authorizationManager.getUsersByGroup(noExistingGroup, false);
assertNull(usersByInvaliGroup);
}
Aggregations