use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class UserServiceTest method testEnsureAdminUserShouldNotCreateUser.
@Test
public void testEnsureAdminUserShouldNotCreateUser() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
Mockito.reset(alienUserDao);
enableEnsure();
GetMultipleDataResult searchResult = new GetMultipleDataResult(null, null, 0, 1, 0, 1);
Mockito.when(alienUserDao.find(Mockito.anyMap(), Mockito.eq(1))).thenReturn(searchResult);
userService.ensureAdminUser();
Mockito.verify(alienUserDao, Mockito.never()).save(Mockito.any(User.class));
}
use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class UserServiceTest method testEnsureAdminUserShouldCreateUser.
@Test
public void testEnsureAdminUserShouldCreateUser() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
Mockito.reset(alienUserDao);
enableEnsure();
GetMultipleDataResult searchResult = new GetMultipleDataResult(null, null, 0, 0, 0, 0);
Mockito.when(alienUserDao.find(Mockito.anyMap(), Mockito.eq(1))).thenReturn(searchResult);
userService.ensureAdminUser();
Mockito.verify(alienUserDao, Mockito.times(1)).save(Mockito.any(User.class));
}
use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class UserService method ensureAdminUser.
/**
* Ensure that there is at least one user with admin role.
*/
@PostConstruct
public void ensureAdminUser() {
if (!ensure) {
return;
}
// we should have one at least one user with role ADMIN
Map<String, String[]> filters = new HashMap<String, String[]>();
filters.put("roles", new String[] { Role.ADMIN.toString() });
GetMultipleDataResult searchResult = alienUserDao.find(filters, 1);
// if no user with admin role can be found, then creates a new one.
if (searchResult != null && searchResult.getTotalResults() == 0) {
adminUserName = (adminUserName == null) ? "admin" : adminUserName;
adminPassword = (adminPassword == null) ? "admin" : adminPassword;
String[] roles = new String[] { Role.ADMIN.toString() };
createUser(adminUserName, email, null, null, roles, adminPassword);
}
}
use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class QuickSearchDefinitionsSteps method The_quickSearch_response_should_contains.
@Then("^The quickSearch response should contains (\\d+) \"([^\"]*)\"$")
public void The_quickSearch_response_should_contains(int expectedSize, String searchedType) throws Throwable {
RestResponse<GetMultipleDataResult> restResponse = JsonUtil.read(Context.getInstance().getRestResponse(), GetMultipleDataResult.class);
GetMultipleDataResult searchResp = restResponse.getData();
assertNotNull(searchResp);
assertNotNull(searchResp.getTypes());
assertNotNull(searchResp.getData());
assertTrue(searchResp.getTypes().length >= expectedSize);
assertTrue(searchResp.getData().length >= expectedSize);
// check result types
List<String> resultTypes = Lists.newArrayList(searchResp.getTypes());
String esType = indexedTypes.get(searchedType);
int count = Collections.frequency(Lists.newArrayList(searchResp.getTypes()), esType);
assertEquals("There should be " + expectedSize + " " + searchedType + " in the quicksearch result.", expectedSize, count);
}
use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.
the class QuickSearchDefinitionsSteps method The_quickSearch_response_should_contains_elements.
@Then("^The quickSearch response should contains (\\d+) elements$")
public void The_quickSearch_response_should_contains_elements(int expectedSize) throws Throwable {
RestResponse<GetMultipleDataResult> restResponse = JsonUtil.read(Context.getInstance().takeRestResponse(), GetMultipleDataResult.class);
GetMultipleDataResult searchResp = restResponse.getData();
assertNotNull(searchResp);
assertNotNull(searchResp.getTypes());
assertNotNull(searchResp.getData());
assertEquals(expectedSize, searchResp.getTypes().length);
assertEquals(expectedSize, searchResp.getData().length);
}
Aggregations