### Question:
SchemaBasedAttributeValueValidator implements Validator<Object> { @Override public void validate(final Object value) { JsonNode jsonNodeValue = (value instanceof JsonNode) ? (JsonNode) value : new ObjectMapper().valueToTree(value); validateValueAttributes(attributeDefinition, jsonNodeValue); } SchemaBasedAttributeValueValidator(final Attribute attributeDefinition, final Map<String, Schema> permittedSchemas); @Override void validate(final Object value);  }### Answer:
@Test public void testValidate() { 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("readWrite").build()).build(); Attribute mainAttribute = new Attribute.Builder().name(PARENT_ATTRIBUTE_NAME).type(COMPLEX.toString()).mutability("readWrite") .addSubAttribute(attribute).build(); new SchemaBasedAttributeValueValidator(mainAttribute, Collections.emptyMap()).validate(value); }
@Test public void testValidateDataType() { Attribute attribute = new Attribute.Builder().name(ATTRIBUTE1).type(COMPLEX.toString()).mutability("readWrite") .addSubAttribute(new Attribute.Builder().name(ATTRIBUTE1).type(BOOLEAN.toString()).mutability("readWrite").build()) .addSubAttribute(new Attribute.Builder().name(ATTRIBUTE2).type(STRING.toString()).mutability("readWrite").build()).build(); Attribute mainAttribute = new Attribute.Builder().name(PARENT_ATTRIBUTE_NAME).type(COMPLEX.toString()).mutability("readWrite") .addSubAttribute(attribute).build(); assertThrows(SCIMException.class, () -> new SchemaBasedAttributeValueValidator(mainAttribute, Collections.emptyMap()).validate(value)); }
@Test public void testValidateWhenAttributeWithMoreSubAttributesThanValue() { 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("readWrite").build()) .addSubAttribute(new Attribute.Builder().name(ATTRIBUTE3).type(STRING.toString()).mutability("readWrite").build()).build(); Attribute mainAttribute = new Attribute.Builder().name(PARENT_ATTRIBUTE_NAME).type(COMPLEX.toString()).mutability("readWrite") .addSubAttribute(attribute).build(); new SchemaBasedAttributeValueValidator(mainAttribute, Collections.emptyMap()).validate(value); }
@Test public void testValidateWhenAttributeWithLessSubAttributesThanValue() { Attribute attribute = new Attribute.Builder().name(ATTRIBUTE1).type(COMPLEX.toString()).mutability("readWrite") .addSubAttribute(new Attribute.Builder().name(ATTRIBUTE1).type(STRING.toString()).mutability("readWrite").build()).build(); Attribute mainAttribute = new Attribute.Builder().name(PARENT_ATTRIBUTE_NAME).type(COMPLEX.toString()).mutability("readWrite") .addSubAttribute(attribute).build(); assertThrows(SCIMException.class, () -> new SchemaBasedAttributeValueValidator(mainAttribute, Collections.emptyMap()).validate(value)); }
@Test public void testValidateWhenAttributeWithMoreSubAttributesThanValueAndAreRequired() { 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("readWrite").build()) .addSubAttribute(new Attribute.Builder().name(ATTRIBUTE3).type(STRING.toString()).mutability("readWrite").required(true).build()).build(); Attribute mainAttribute = new Attribute.Builder().name(PARENT_ATTRIBUTE_NAME).type(COMPLEX.toString()).mutability("readWrite") .addSubAttribute(attribute).build(); assertThrows(SCIMException.class, () -> new SchemaBasedAttributeValueValidator(mainAttribute, Collections.emptyMap()).validate(value)); }