Search in sources :

Example 1 with CreateUserResult

use of org.haiku.haikudepotserver.api1.model.user.CreateUserResult in project haikudepotserver by haiku.

the class UserApiIT method testCreateUser.

@Test
public void testCreateUser() {
    Captcha captcha = captchaService.generate();
    CreateUserRequest request = new CreateUserRequest();
    request.captchaToken = captcha.getToken();
    request.captchaResponse = captcha.getResponse();
    request.nickname = "testuser";
    request.passwordClear = "Ue4nI92Rw";
    request.naturalLanguageCode = "en";
    request.userUsageConditionsCode = "UUC2021V01";
    // ------------------------------------
    CreateUserResult result = userApi.createUser(request);
    // ------------------------------------
    Assertions.assertThat(result).isNotNull();
    ObjectContext context = serverRuntime.newContext();
    Optional<User> userOptional = User.tryGetByNickname(context, "testuser");
    Assertions.assertThat(userOptional.isPresent()).isTrue();
    User user = userOptional.get();
    Assertions.assertThat(user.getActive()).isTrue();
    Assertions.assertThat(user.getIsRoot()).isFalse();
    Assertions.assertThat(user.getNickname()).isEqualTo("testuser");
    Assertions.assertThat(user.getNaturalLanguage().getCode()).isEqualTo("en");
    Assertions.assertThat(user.getLastAuthenticationTimestamp()).isNull();
    Assertions.assertThat(user.tryGetUserUsageConditionsAgreement().get().getUserUsageConditions().getCode()).isEqualTo("UUC2021V01");
    Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "Ue4nI92Rw").get()).isEqualTo(userOptional.get().getObjectId());
}
Also used : Captcha(org.haiku.haikudepotserver.captcha.model.Captcha) User(org.haiku.haikudepotserver.dataobjects.User) CreateUserResult(org.haiku.haikudepotserver.api1.model.user.CreateUserResult) CreateUserRequest(org.haiku.haikudepotserver.api1.model.user.CreateUserRequest) ObjectContext(org.apache.cayenne.ObjectContext) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 CreateUserRequest (org.haiku.haikudepotserver.api1.model.user.CreateUserRequest)1 CreateUserResult (org.haiku.haikudepotserver.api1.model.user.CreateUserResult)1 Captcha (org.haiku.haikudepotserver.captcha.model.Captcha)1 User (org.haiku.haikudepotserver.dataobjects.User)1 Test (org.junit.jupiter.api.Test)1