Skip to content

Commit

Permalink
minor test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonfagerberg-toast committed Dec 6, 2024
1 parent 2f5c097 commit e3b8adc
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@

package org.apache.directory.scim.core.repository;

import java.util.HashMap;
import static java.util.Map.entry;
import static org.apache.directory.scim.spec.patch.PatchOperation.Type.ADD;
import static org.apache.directory.scim.spec.patch.PatchOperation.Type.REMOVE;
import static org.apache.directory.scim.spec.patch.PatchOperation.Type.REPLACE;
import static org.apache.directory.scim.test.assertj.ScimpleAssertions.scimAssertThat;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import lombok.SneakyThrows;
import org.apache.directory.scim.core.schema.SchemaRegistry;
import org.apache.directory.scim.spec.extension.EnterpriseExtension;
Expand All @@ -37,15 +46,6 @@
import org.apache.directory.scim.spec.resources.ScimUser;
import org.junit.jupiter.api.Test;

import static org.apache.directory.scim.spec.patch.PatchOperation.Type.*;
import static java.util.Map.entry;
import static org.apache.directory.scim.test.assertj.ScimpleAssertions.scimAssertThat;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public class PatchHandlerTest {

DefaultPatchHandler patchHandler;
Expand All @@ -60,12 +60,13 @@ public PatchHandlerTest() {
@Test
public void applyReplaceEntireEnterpriseExtension() {
String enterpriseExtensionUrn = "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User";
Map<String, String> enterpriseExtensionValue = new HashMap<>();
enterpriseExtensionValue.put("costCenter", "New Cost Center");
enterpriseExtensionValue.put("department", "New Department");
Map<String, String> enterpriseExtensionValue = Map.ofEntries(
entry("costCenter", "New Cost Center"),
entry("department", "New Department")
);
PatchOperation op = patchOperation(REPLACE, enterpriseExtensionUrn, enterpriseExtensionValue);
ScimUser updatedUser = patchHandler.apply(user(), List.of(op));
EnterpriseExtension actual = (EnterpriseExtension) updatedUser.getExtension("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User");
EnterpriseExtension actual = (EnterpriseExtension) updatedUser.getExtension(enterpriseExtensionUrn);
assertThat(actual).isNotNull();
assertThat(actual.getCostCenter()).isEqualTo("New Cost Center");
assertThat(actual.getDepartment()).isEqualTo("New Department");
Expand All @@ -74,13 +75,13 @@ public void applyReplaceEntireEnterpriseExtension() {
@Test
public void applyReplaceEntireEnterpriseExtensionWithNullPath() {
String enterpriseExtensionUrn = "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User";
Map<String, String> enterpriseExtensionValue = Map.of(
"costCenter", "New Cost Center",
"department", "New Department"
Map<String, String> enterpriseExtensionValue = Map.ofEntries(
entry("costCenter", "New Cost Center"),
entry("department", "New Department")
);
PatchOperation op = patchOperation(REPLACE, null, Map.of(enterpriseExtensionUrn, enterpriseExtensionValue));
ScimUser updatedUser = patchHandler.apply(user(), List.of(op));
EnterpriseExtension actual = (EnterpriseExtension) updatedUser.getExtension("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User");
EnterpriseExtension actual = (EnterpriseExtension) updatedUser.getExtension(enterpriseExtensionUrn);
assertThat(actual).isNotNull();
assertThat(actual.getCostCenter()).isEqualTo("New Cost Center");
assertThat(actual.getDepartment()).isEqualTo("New Department");
Expand All @@ -91,7 +92,7 @@ public void applyRemoveEntireEnterpriseExtension() {
String enterpriseExtensionUrn = "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User";
PatchOperation op = patchOperation(REMOVE, enterpriseExtensionUrn, null);
ScimUser updatedUser = patchHandler.apply(user(), List.of(op));
assertThat(updatedUser.getExtension("urn:ietf:params:scim:schemas:extension:enterprise:2.0:User")).isNull();
assertThat(updatedUser.getExtension(enterpriseExtensionUrn)).isNull();
}

@Test
Expand Down

0 comments on commit e3b8adc

Please sign in to comment.