Search in sources :

Example 36 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class RegisterUserServiceITest method serviceRegisterUserRequestUserAlreadyExistFailureTest.

/**
 * Service register user request user already exist failure test.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void serviceRegisterUserRequestUserAlreadyExistFailureTest() throws Exception {
    final CreateApplicationSessionRequest createApplicationSesstion = createApplicationSesstionWithRoleAnonymous();
    final RegisterUserRequest serviceRequest = new RegisterUserRequest();
    serviceRequest.setCountry("Sweden");
    serviceRequest.setUsername(UUID.randomUUID().toString());
    serviceRequest.setEmail(serviceRequest.getUsername() + "@email.com");
    serviceRequest.setUserpassword("Userpassword1!");
    serviceRequest.setUserType(UserType.PRIVATE);
    serviceRequest.setSessionId(createApplicationSesstion.getSessionId());
    final RegisterUserResponse response = (RegisterUserResponse) applicationManager.service(serviceRequest);
    assertNotNull(EXPECT_A_RESULT, response);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, response.getResult());
    createApplicationSesstionWithRoleAnonymous();
    final DataContainer<UserAccount, Long> dataContainer = applicationManager.getDataContainer(UserAccount.class);
    final List<UserAccount> allBy = dataContainer.getAllBy(UserAccount_.username, serviceRequest.getUsername());
    assertEquals(1, allBy.size());
    final RegisterUserResponse errorResponse = (RegisterUserResponse) applicationManager.service(serviceRequest);
    assertNotNull(EXPECT_A_RESULT, errorResponse);
    assertEquals(EXPECT_SUCCESS, ServiceResult.FAILURE, errorResponse.getResult());
    assertEquals(RegisterUserResponse.ErrorMessage.USER_ALREADY_EXIST.toString(), errorResponse.getErrorMessage());
}
Also used : CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) RegisterUserRequest(com.hack23.cia.service.api.action.application.RegisterUserRequest) RegisterUserResponse(com.hack23.cia.service.api.action.application.RegisterUserResponse) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) PerfTest(org.databene.contiperf.PerfTest) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)

Example 37 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class SetGoogleAuthenticatorCredentialServiceITest method servicesetGoogleAuthenticatorCredentialRequestSuccessTest.

/**
 * Serviceset google authenticator credential request success test.
 *
 * @throws Exception
 *             the exception
 */
@Test
@PerfTest(threads = 2, duration = 4000, warmUp = 1500)
@Required(max = 3000, average = 2500, percentile95 = 2700, throughput = 1)
public void servicesetGoogleAuthenticatorCredentialRequestSuccessTest() throws Exception {
    final CreateApplicationSessionRequest createApplicationSesstion = createApplicationSesstionWithRoleAnonymous();
    final RegisterUserRequest serviceRequest = new RegisterUserRequest();
    serviceRequest.setCountry("Sweden");
    serviceRequest.setUsername(UUID.randomUUID().toString());
    serviceRequest.setEmail(serviceRequest.getUsername() + "@email.com");
    serviceRequest.setUserpassword("Userpassword1!");
    serviceRequest.setUserType(UserType.PRIVATE);
    serviceRequest.setSessionId(createApplicationSesstion.getSessionId());
    final RegisterUserResponse response = (RegisterUserResponse) applicationManager.service(serviceRequest);
    assertNotNull(EXPECT_A_RESULT, response);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, response.getResult());
    final DataContainer<UserAccount, Long> dataContainer = applicationManager.getDataContainer(UserAccount.class);
    final List<UserAccount> allBy = dataContainer.getAllBy(UserAccount_.username, serviceRequest.getUsername());
    assertEquals(1, allBy.size());
    final LoginRequest loginRequest = new LoginRequest();
    loginRequest.setEmail(serviceRequest.getEmail());
    loginRequest.setSessionId(serviceRequest.getSessionId());
    loginRequest.setUserpassword(serviceRequest.getUserpassword());
    final LoginResponse loginResponse = (LoginResponse) applicationManager.service(loginRequest);
    assertNotNull(EXPECT_A_RESULT, loginResponse);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, loginResponse.getResult());
    final SetGoogleAuthenticatorCredentialRequest setGoogleAuthenticatorCredentialRequest = new SetGoogleAuthenticatorCredentialRequest();
    setGoogleAuthenticatorCredentialRequest.setSessionId(serviceRequest.getSessionId());
    final ServiceResponse setGoogleAuthenticatorCredentialResponse = applicationManager.service(setGoogleAuthenticatorCredentialRequest);
    assertNotNull(EXPECT_A_RESULT, setGoogleAuthenticatorCredentialResponse);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, setGoogleAuthenticatorCredentialResponse.getResult());
    final LogoutRequest logoutRequest = new LogoutRequest();
    logoutRequest.setSessionId(serviceRequest.getSessionId());
    final ServiceResponse logoutResponse = applicationManager.service(logoutRequest);
    assertNotNull(EXPECT_A_RESULT, logoutResponse);
    assertEquals(EXPECT_SUCCESS, ServiceResult.SUCCESS, logoutResponse.getResult());
}
Also used : ServiceResponse(com.hack23.cia.service.api.action.common.ServiceResponse) LoginResponse(com.hack23.cia.service.api.action.application.LoginResponse) CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) RegisterUserRequest(com.hack23.cia.service.api.action.application.RegisterUserRequest) RegisterUserResponse(com.hack23.cia.service.api.action.application.RegisterUserResponse) SetGoogleAuthenticatorCredentialRequest(com.hack23.cia.service.api.action.user.SetGoogleAuthenticatorCredentialRequest) LogoutRequest(com.hack23.cia.service.api.action.application.LogoutRequest) LoginRequest(com.hack23.cia.service.api.action.application.LoginRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Required(org.databene.contiperf.Required) PerfTest(org.databene.contiperf.PerfTest) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest) PerfTest(org.databene.contiperf.PerfTest)

Example 38 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class DisableGoogleAuthenticatorCredentialService method processService.

@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
public DisableGoogleAuthenticatorCredentialResponse processService(final DisableGoogleAuthenticatorCredentialRequest serviceRequest) {
    final DisableGoogleAuthenticatorCredentialResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSessionId());
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    final DisableGoogleAuthenticatorCredentialResponse response = new DisableGoogleAuthenticatorCredentialResponse(ServiceResult.SUCCESS);
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
        final UserAccount updateUserAccount = userDAO.load(userAccount.getHjid());
        updateUserAccount.setGoogleAuthKey(null);
        updateUserAccount.setGoogleAuthVerificationCode(null);
        updateUserAccount.setGoogleAuthScratchCodes(null);
        userDAO.merge(updateUserAccount);
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : DisableGoogleAuthenticatorCredentialResponse(com.hack23.cia.service.api.action.user.DisableGoogleAuthenticatorCredentialResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 39 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class DocumentWordCountService method processService.

@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public DocumentWordCountResponse processService(final DocumentWordCountRequest serviceRequest) {
    final DocumentWordCountResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getDocumentId());
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
    }
    final DocumentWordCountResponse response = new DocumentWordCountResponse(ServiceResult.SUCCESS);
    final DocumentContentData documentContentData = documentContentDataDAO.findFirstByProperty(DocumentContentData_.id, serviceRequest.getDocumentId());
    if (documentContentData == null) {
        response.setWordCountMap(new HashMap<>());
    } else {
        response.setWordCountMap(wordCounter.calculateWordCount(documentContentData, serviceRequest.getMaxResults()));
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : DocumentWordCountResponse(com.hack23.cia.service.api.action.user.DocumentWordCountResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) DocumentContentData(com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData) Secured(org.springframework.security.access.annotation.Secured)

Example 40 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class SearchDocumentService method processService.

@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN", "ROLE_ANONYMOUS" })
public SearchDocumentResponse processService(final SearchDocumentRequest serviceRequest) {
    final SearchDocumentResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSearchExpression());
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
    }
    final SearchDocumentResponse response = new SearchDocumentResponse(ServiceResult.SUCCESS);
    final List<DocumentElement> searchResultTitles = documentElementDAO.search(serviceRequest.getSearchExpression(), serviceRequest.getMaxResults(), "id", "title", "subTitle");
    if (!searchResultTitles.isEmpty()) {
        response.setResultElement(searchResultTitles);
    } else {
        final List<DocumentContentData> searchResultContent = documentContentDataDAO.search(serviceRequest.getSearchExpression(), serviceRequest.getMaxResults(), "id", "content");
        if (!searchResultContent.isEmpty()) {
            final List<DocumentElement> searchResultTitlesForContent = new ArrayList<>();
            for (final DocumentContentData documentContent : searchResultContent) {
                searchResultTitlesForContent.add(documentElementDAO.load(documentContent.getId()));
            }
            response.setResultElement(searchResultTitlesForContent);
        }
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : DocumentElement(com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement) SearchDocumentResponse(com.hack23.cia.service.api.action.user.SearchDocumentResponse) ArrayList(java.util.ArrayList) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) DocumentContentData(com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)37 Test (org.junit.Test)19 Secured (org.springframework.security.access.annotation.Secured)18 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)14 RegisterUserResponse (com.hack23.cia.service.api.action.application.RegisterUserResponse)14 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)13 RegisterUserRequest (com.hack23.cia.service.api.action.application.RegisterUserRequest)13 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)13 PerfTest (org.databene.contiperf.PerfTest)10 LoginResponse (com.hack23.cia.service.api.action.application.LoginResponse)8 LoginRequest (com.hack23.cia.service.api.action.application.LoginRequest)7 PageModeMenuCommand (com.hack23.cia.web.impl.ui.application.views.common.pagelinks.api.PageModeMenuCommand)7 ManageUserAccountResponse (com.hack23.cia.service.api.action.admin.ManageUserAccountResponse)6 ArrayList (java.util.ArrayList)6 WebDriver (org.openqa.selenium.WebDriver)6 ManageUserAccountRequest (com.hack23.cia.service.api.action.admin.ManageUserAccountRequest)5 Required (org.databene.contiperf.Required)5 LogoutRequest (com.hack23.cia.service.api.action.application.LogoutRequest)4 VerticalLayout (com.vaadin.ui.VerticalLayout)4 WebElement (org.openqa.selenium.WebElement)4