Search in sources :

Example 11 with GetMultipleDataResult

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));
}
Also used : User(alien4cloud.security.model.User) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Test(org.junit.Test)

Example 12 with GetMultipleDataResult

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));
}
Also used : User(alien4cloud.security.model.User) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Test(org.junit.Test)

Example 13 with GetMultipleDataResult

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);
    }
}
Also used : HashMap(java.util.HashMap) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) PostConstruct(javax.annotation.PostConstruct)

Example 14 with GetMultipleDataResult

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);
}
Also used : GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Then(cucumber.api.java.en.Then)

Example 15 with GetMultipleDataResult

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);
}
Also used : GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Then(cucumber.api.java.en.Then)

Aggregations

GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)32 Test (org.junit.Test)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ApiOperation (io.swagger.annotations.ApiOperation)7 HashMap (java.util.HashMap)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 Application (alien4cloud.model.application.Application)4 User (alien4cloud.security.model.User)4 Then (cucumber.api.java.en.Then)4 Location (alien4cloud.model.orchestrators.locations.Location)3 IdsFilterBuilder (org.elasticsearch.index.query.IdsFilterBuilder)3 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)2 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 FilteredSearchRequest (alien4cloud.rest.model.FilteredSearchRequest)2 Group (alien4cloud.security.model.Group)2 Arrays (java.util.Arrays)2 Resource (javax.annotation.Resource)2