//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testChangeCredentials() public virtual void testChangeCredentials() { User initialUser = MockProvider.createMockUser(); UserQuery sampleUserQuery = mock(typeof(UserQuery)); when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery); when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery); when(sampleUserQuery.singleResult()).thenReturn(initialUser); Authentication authentication = MockProvider.createMockAuthentication(); when(identityServiceMock.CurrentAuthentication).thenReturn(authentication); when(identityServiceMock.checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD)).thenReturn(true); UserCredentialsDto dto = new UserCredentialsDto(); dto.Password = "******"; dto.AuthenticatedUserPassword = MockProvider.EXAMPLE_USER_PASSWORD; given().pathParam("id", MockProvider.EXAMPLE_USER_ID).contentType(ContentType.JSON).body(dto).then().statusCode(Status.NO_CONTENT.StatusCode).when().put(USER_CREDENTIALS_URL); verify(identityServiceMock).CurrentAuthentication; verify(identityServiceMock).checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD); // password was updated verify(initialUser).Password = dto.Password; // and then saved verify(identityServiceMock).saveUser(initialUser); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testUserResourceOptionsDeleteAuthorized() public virtual void testUserResourceOptionsDeleteAuthorized() { string fullUserUrl = "http://localhost:" + PORT + TEST_RESOURCE_ROOT_PATH + "/user/" + MockProvider.EXAMPLE_USER_ID; User sampleUser = MockProvider.createMockUser(); UserQuery sampleUserQuery = mock(typeof(UserQuery)); when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery); when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery); when(sampleUserQuery.singleResult()).thenReturn(sampleUser); Authentication authentication = new Authentication(MockProvider.EXAMPLE_USER_ID, null); when(identityServiceMock.CurrentAuthentication).thenReturn(authentication); when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, USER, MockProvider.EXAMPLE_USER_ID)).thenReturn(true); when(authorizationServiceMock.isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, USER, MockProvider.EXAMPLE_USER_ID)).thenReturn(false); when(processEngineConfigurationMock.AuthorizationEnabled).thenReturn(true); given().pathParam("id", MockProvider.EXAMPLE_USER_ID).then().statusCode(Status.OK.StatusCode).body("links[0].href", equalTo(fullUserUrl + "/profile")).body("links[0].method", equalTo(HttpMethod.GET)).body("links[0].rel", equalTo("self")).body("links[1].href", equalTo(fullUserUrl)).body("links[1].method", equalTo(HttpMethod.DELETE)).body("links[1].rel", equalTo("delete")).body("links[2]", nullValue()).when().options(USER_URL); verify(identityServiceMock, times(2)).CurrentAuthentication; verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, DELETE, USER, MockProvider.EXAMPLE_USER_ID); verify(authorizationServiceMock, times(1)).isUserAuthorized(MockProvider.EXAMPLE_USER_ID, null, UPDATE, USER, MockProvider.EXAMPLE_USER_ID); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testGetNonExistingUserProfile() public virtual void testGetNonExistingUserProfile() { UserQuery sampleUserQuery = mock(typeof(UserQuery)); when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery); when(sampleUserQuery.userId(anyString())).thenReturn(sampleUserQuery); when(sampleUserQuery.singleResult()).thenReturn(null); given().pathParam("id", "aNonExistingUser").then().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().get(USER_PROFILE_URL); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testGetSingleUserProfile() public virtual void testGetSingleUserProfile() { User sampleUser = MockProvider.createMockUser(); UserQuery sampleUserQuery = mock(typeof(UserQuery)); when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery); when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery); when(sampleUserQuery.singleResult()).thenReturn(sampleUser); given().pathParam("id", MockProvider.EXAMPLE_USER_ID).then().statusCode(Status.OK.StatusCode).body("id", equalTo(MockProvider.EXAMPLE_USER_ID)).body("firstName", equalTo(MockProvider.EXAMPLE_USER_FIRST_NAME)).body("lastName", equalTo(MockProvider.EXAMPLE_USER_LAST_NAME)).body("email", equalTo(MockProvider.EXAMPLE_USER_EMAIL)).when().get(USER_PROFILE_URL); }
//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))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testPutCredentialsNonExistingUserFails() public virtual void testPutCredentialsNonExistingUserFails() { UserQuery sampleUserQuery = mock(typeof(UserQuery)); when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery); when(sampleUserQuery.userId("aNonExistingUser")).thenReturn(sampleUserQuery); when(sampleUserQuery.singleResult()).thenReturn(null); UserCredentialsDto dto = new UserCredentialsDto(); dto.Password = "******"; given().pathParam("id", "aNonExistingUser").body(dto).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_CREDENTIALS_URL); // user was not updated verify(identityServiceMock, never()).saveUser(any(typeof(User))); }
//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); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testPutCredentialsThrowsAuthorizationException() public virtual void testPutCredentialsThrowsAuthorizationException() { User initialUser = MockProvider.createMockUser(); 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))); UserCredentialsDto dto = new UserCredentialsDto(); dto.Password = "******"; given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(dto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.StatusCode).contentType(ContentType.JSON).body("type", equalTo(typeof(AuthorizationException).Name)).body("message", equalTo(message)).when().put(USER_CREDENTIALS_URL); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testChangeCredentialsWithWrongAuthenticatedUserPassword() public virtual void testChangeCredentialsWithWrongAuthenticatedUserPassword() { User initialUser = MockProvider.createMockUser(); UserQuery sampleUserQuery = mock(typeof(UserQuery)); when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery); when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery); when(sampleUserQuery.singleResult()).thenReturn(initialUser); Authentication authentication = MockProvider.createMockAuthentication(); when(identityServiceMock.CurrentAuthentication).thenReturn(authentication); when(identityServiceMock.checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD)).thenReturn(false); UserCredentialsDto dto = new UserCredentialsDto(); dto.Password = "******"; dto.AuthenticatedUserPassword = MockProvider.EXAMPLE_USER_PASSWORD; given().pathParam("id", MockProvider.EXAMPLE_USER_ID).contentType(ContentType.JSON).body(dto).then().statusCode(Status.BAD_REQUEST.StatusCode).contentType(ContentType.JSON).body("type", equalTo("InvalidRequestException")).body("message", equalTo("The given authenticated user password is not valid.")).when().put(USER_CREDENTIALS_URL); }
//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); }