@Test public void testEraseAttributes() { MockitoAnnotations.initMocks(this); Attribute attribute = new Attribute.Builder().name(ATTRIBUTE1).type(COMPLEX.toString()).mutability("readWrite") .addSubAttribute(new Attribute.Builder().name(ATTRIBUTE1).type(STRING.toString()).mutability("readWrite").build()) .addSubAttribute(new Attribute.Builder().name(ATTRIBUTE2).type(STRING.toString()).mutability("readOnly").build()).build(); Mockito.when(schemaAPI.getSchema(TEST_SCHEMA_NAME)).thenReturn(new Schema.Builder().setId(TEST_SCHEMA_NAME).addAttribute(attribute).build()); Map<String, Object> attributes = new HashMap<>(); Map<String, Object> attributeValue = new HashMap<>(); attributeValue.put(ATTRIBUTE1, TEXT_VALUE); attributeValue.put(ATTRIBUTE2, TEXT_VALUE); attributes.put(ATTRIBUTE1, attributeValue); Extension extension = new Extension.Builder(TEST_SCHEMA_NAME).setAttributes(attributes).build(); User user = new User.Builder("vladi").addExtension(extension).build(); Map<String, Object> expectedAttributes = new HashMap<>(); Map<String, Object> expectedAttributeValue = new HashMap<>(); expectedAttributeValue.put(ATTRIBUTE1, TEXT_VALUE); expectedAttributes.put(ATTRIBUTE1, expectedAttributeValue); Extension expectedExtension = new Extension.Builder(TEST_SCHEMA_NAME).setAttributes(expectedAttributes).build(); User expectedUser = new User.Builder("vladi").addExtension(expectedExtension).build(); ReadOnlyAttributesEraser<User> readOnlyAttributesEraser = new ReadOnlyAttributesEraser<>(schemaAPI); User actualUser = readOnlyAttributesEraser.eraseAllFormCustomExtensions(user); assertEquals(expectedUser, actualUser); }
public T eraseAllFormCustomExtensions(final T resource) { List<Extension> extensions = resource.getExtensions().values().stream().map(extension -> { if (extension instanceof EnterpriseExtension) { return extension; } Map<String, Object> attributes = extension.getAttributes(); Schema customSchema = schemaAPI.getSchema(extension.getUrn()); if (customSchema == null) { throw new SCIMException(SCIMException.Type.INVALID_SYNTAX, String.format("Schema '%s' does not exist.", extension.getUrn()), Response.Status.BAD_REQUEST); } removeReadOnlyAttributes(customSchema.toAttribute(), attributes); return new Extension.Builder(extension).setAttributes(attributes).build(); }).collect(Collectors.toList()); return resource.builder().removeExtensions().addExtensions(extensions).build(); }
ReadOnlyAttributesEraser { public T eraseAllFormCustomExtensions(final T resource) { List<Extension> extensions = resource.getExtensions().values().stream().map(extension -> { if (extension instanceof EnterpriseExtension) { return extension; } Map<String, Object> attributes = extension.getAttributes(); Schema customSchema = schemaAPI.getSchema(extension.getUrn()); if (customSchema == null) { throw new SCIMException(SCIMException.Type.INVALID_SYNTAX, String.format("Schema '%s' does not exist.", extension.getUrn()), Response.Status.BAD_REQUEST); } removeReadOnlyAttributes(customSchema.toAttribute(), attributes); return new Extension.Builder(extension).setAttributes(attributes).build(); }).collect(Collectors.toList()); return resource.builder().removeExtensions().addExtensions(extensions).build(); } }
ReadOnlyAttributesEraser { public T eraseAllFormCustomExtensions(final T resource) { List<Extension> extensions = resource.getExtensions().values().stream().map(extension -> { if (extension instanceof EnterpriseExtension) { return extension; } Map<String, Object> attributes = extension.getAttributes(); Schema customSchema = schemaAPI.getSchema(extension.getUrn()); if (customSchema == null) { throw new SCIMException(SCIMException.Type.INVALID_SYNTAX, String.format("Schema '%s' does not exist.", extension.getUrn()), Response.Status.BAD_REQUEST); } removeReadOnlyAttributes(customSchema.toAttribute(), attributes); return new Extension.Builder(extension).setAttributes(attributes).build(); }).collect(Collectors.toList()); return resource.builder().removeExtensions().addExtensions(extensions).build(); } ReadOnlyAttributesEraser(final SchemasCallback schemaAPI); }
ReadOnlyAttributesEraser { public T eraseAllFormCustomExtensions(final T resource) { List<Extension> extensions = resource.getExtensions().values().stream().map(extension -> { if (extension instanceof EnterpriseExtension) { return extension; } Map<String, Object> attributes = extension.getAttributes(); Schema customSchema = schemaAPI.getSchema(extension.getUrn()); if (customSchema == null) { throw new SCIMException(SCIMException.Type.INVALID_SYNTAX, String.format("Schema '%s' does not exist.", extension.getUrn()), Response.Status.BAD_REQUEST); } removeReadOnlyAttributes(customSchema.toAttribute(), attributes); return new Extension.Builder(extension).setAttributes(attributes).build(); }).collect(Collectors.toList()); return resource.builder().removeExtensions().addExtensions(extensions).build(); } ReadOnlyAttributesEraser(final SchemasCallback schemaAPI); T eraseAllFormCustomExtensions(final T resource); }
ReadOnlyAttributesEraser { public T eraseAllFormCustomExtensions(final T resource) { List<Extension> extensions = resource.getExtensions().values().stream().map(extension -> { if (extension instanceof EnterpriseExtension) { return extension; } Map<String, Object> attributes = extension.getAttributes(); Schema customSchema = schemaAPI.getSchema(extension.getUrn()); if (customSchema == null) { throw new SCIMException(SCIMException.Type.INVALID_SYNTAX, String.format("Schema '%s' does not exist.", extension.getUrn()), Response.Status.BAD_REQUEST); } removeReadOnlyAttributes(customSchema.toAttribute(), attributes); return new Extension.Builder(extension).setAttributes(attributes).build(); }).collect(Collectors.toList()); return resource.builder().removeExtensions().addExtensions(extensions).build(); } ReadOnlyAttributesEraser(final SchemasCallback schemaAPI); T eraseAllFormCustomExtensions(final T resource);  }