-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scimono jakarta branch next dev (#238)
Co-authored-by: davidsarosap <[email protected]>
- Loading branch information
1 parent
738624d
commit 57278d0
Showing
13 changed files
with
115 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 69 additions & 10 deletions
79
scimono-server/src/test/java/com/sap/scimono/api/UsersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,95 @@ | ||
package com.sap.scimono.api; | ||
|
||
import com.sap.scimono.SCIMApplication; | ||
import com.sap.scimono.exception.InvalidInputException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mockito; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.sap.scimono.SCIMApplication; | ||
import com.sap.scimono.callback.schemas.SchemasCallback; | ||
import com.sap.scimono.callback.users.UsersCallback; | ||
import com.sap.scimono.entity.patch.PatchBody; | ||
import com.sap.scimono.entity.patch.PatchOperation; | ||
import com.sap.scimono.exception.InvalidInputException; | ||
|
||
public class UsersTest { | ||
|
||
private Users users; | ||
|
||
@BeforeEach | ||
private ObjectMapper mapper; | ||
private SchemasCallback schemasCallbackMock = Mockito.mock(SchemasCallback.class, Mockito.CALLS_REAL_METHODS); | ||
private UsersCallback usersCallbackMock = Mockito.mock(UsersCallback.class, Mockito.CALLS_REAL_METHODS); | ||
|
||
ArgumentCaptor<String> userIdCaptor = ArgumentCaptor.forClass(String.class); | ||
ArgumentCaptor<PatchBody> patchBodyCaptor = ArgumentCaptor.forClass(PatchBody.class); | ||
private final String PATCH_OP_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:PatchOp"; | ||
|
||
@Before | ||
public void setup() { | ||
mapper = new ObjectMapper(); | ||
SCIMApplication scimApplication = new SCIMApplication() { | ||
|
||
@Override | ||
public SchemasCallback getSchemasCallback() { | ||
return schemasCallbackMock; | ||
} | ||
|
||
@Override | ||
public UsersCallback getUsersCallback() { | ||
return usersCallbackMock; | ||
} | ||
}; | ||
users = new Users(scimApplication, null); | ||
} | ||
|
||
@Test | ||
@Test(expected = InvalidInputException.class) | ||
public void testUpdateUserWithEmptyBody() { | ||
String userId = String.valueOf(UUID.randomUUID()); | ||
} | ||
|
||
assertThrows(InvalidInputException.class, () -> users.updateUser(userId, null)); | ||
@Test(expected = InvalidInputException.class) | ||
public void testPatchUserWithEmptyBody() { | ||
String userId = String.valueOf(UUID.randomUUID()); | ||
} | ||
|
||
@Test | ||
public void testPatchUserWithEmptyBody() { | ||
public void testPatchUserActivate() throws JsonProcessingException { | ||
Mockito.doNothing().when(usersCallbackMock).patchUser(Mockito.any(), Mockito.any(), Mockito.any()); | ||
Mockito.doReturn(new ArrayList<>()).when(schemasCallbackMock).getCustomSchemas(); | ||
String userId = String.valueOf(UUID.randomUUID()); | ||
assertThrows(InvalidInputException.class, () -> users.patchUser(userId, null)); | ||
Set<String> schemas = new HashSet<>(); | ||
schemas.add(PATCH_OP_SCHEMA); | ||
|
||
|
||
JsonNode valueTrue = getValueTrue(); | ||
PatchOperation patchOperation1 = new PatchOperation.Builder() | ||
.setOp(PatchOperation.Type.ADD) | ||
.setPath("active") | ||
.setValue(valueTrue) | ||
.build(); | ||
PatchBody patchBody = new PatchBody.Builder() | ||
.addOperation(patchOperation1) | ||
.setSchemas(schemas) | ||
.build(); | ||
users.patchUser(userId, patchBody); | ||
|
||
Mockito.verify(usersCallbackMock).patchUser(userIdCaptor.capture(), patchBodyCaptor.capture(), Mockito.any()); | ||
Assert.assertEquals(userId, userIdCaptor.getValue()); | ||
Assert.assertEquals(patchBody, patchBodyCaptor.getValue()); | ||
} | ||
|
||
private JsonNode getValueTrue() throws JsonProcessingException { | ||
JsonNode boolValue = mapper.readTree("true"); | ||
return boolValue; | ||
} | ||
|
||
} |