Exemple #1
0
        public virtual void createInitialUser(string id, string password, string firstName, string lastName)
        {
            UserDto            user        = new UserDto();
            UserCredentialsDto credentials = new UserCredentialsDto();

            credentials.Password = password;
            user.Credentials     = credentials;
            UserProfileDto profile = new UserProfileDto();

            profile.Id        = id;
            profile.FirstName = firstName;
            profile.LastName  = lastName;
            user.Profile      = profile;

            WebResource    webResource    = client.resource(testProperties.getApplicationPath("/camunda/api/admin/setup/default/user/create"));
            ClientResponse clientResponse = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(typeof(ClientResponse), user);

            try
            {
                if (clientResponse.ResponseStatus != Response.Status.NO_CONTENT)
                {
                    throw new WebApplicationException(clientResponse.ResponseStatus);
                }
            }
            finally
            {
                clientResponse.close();
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testReadOnlyPutUserProfileFails()
        public virtual void testReadOnlyPutUserProfileFails()
        {
            User userUdpdate = MockProvider.createMockUser();

            when(identityServiceMock.ReadOnly).thenReturn(true);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(UserProfileDto.fromUser(userUdpdate)).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(InvalidRequestException).Name)).body("message", equalTo("Identity service implementation is read-only.")).when().put(USER_PROFILE_URL);

            verify(identityServiceMock, never()).saveUser(userUdpdate);
        }
Exemple #3
0
        public virtual UserProfileDto getUserProfile(UriInfo context)
        {
            User dbUser = findUserObject();

            if (dbUser == null)
            {
                throw new InvalidRequestException(Status.NOT_FOUND, "User with id " + resourceId + " does not exist");
            }

            UserProfileDto user = UserProfileDto.fromUser(dbUser);

            return(user);
        }
Exemple #4
0
        public virtual void updateProfile(UserProfileDto profile)
        {
            ensureNotReadOnly();

            User dbUser = findUserObject();

            if (dbUser == null)
            {
                throw new InvalidRequestException(Status.NOT_FOUND, "User with id " + resourceId + " does not exist");
            }

            profile.update(dbUser);

            identityService.saveUser(dbUser);
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutProfileNonexistingFails()
        public virtual void testPutProfileNonexistingFails()
        {
            User userUpdate = MockProvider.createMockUserUpdate();

            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId("aNonExistingUser")).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(null);

            UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);

            given().pathParam("id", "aNonExistingUser").body(updateDto).contentType(ContentType.JSON).then().then().expect().statusCode(Status.NOT_FOUND.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(InvalidRequestException).Name)).body("message", equalTo("User with id aNonExistingUser does not exist")).when().put(USER_PROFILE_URL);

            // nothing was saved
            verify(identityServiceMock, never()).saveUser(any(typeof(User)));
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutProfileThrowsAuthorizationException()
        public virtual void testPutProfileThrowsAuthorizationException()
        {
            User initialUser = MockProvider.createMockUser();
            User userUpdate  = MockProvider.createMockUserUpdate();

            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            string message = "exception expected";

            doThrow(new AuthorizationException(message)).when(identityServiceMock).saveUser(any(typeof(User)));

            UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(updateDto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(AuthorizationException).Name)).body("message", equalTo(message)).when().put(USER_PROFILE_URL);
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPutProfile()
        public virtual void testPutProfile()
        {
            User initialUser = MockProvider.createMockUser();
            User userUpdate  = MockProvider.createMockUserUpdate();

            UserQuery sampleUserQuery = mock(typeof(UserQuery));

            when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
            when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
            when(sampleUserQuery.singleResult()).thenReturn(initialUser);

            UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);

            given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(updateDto).contentType(ContentType.JSON).then().statusCode(Status.NO_CONTENT.StatusCode).when().put(USER_PROFILE_URL);

            // password was updated
            verify(initialUser).Email     = updateDto.Email;
            verify(initialUser).FirstName = updateDto.FirstName;
            verify(initialUser).LastName  = updateDto.LastName;

            // and then saved
            verify(identityServiceMock).saveUser(initialUser);
        }