TermResourceDefinition extends BaseResourceDefinition { @Override public void validateCreatePayload(Request request) throws InvalidPayloadException { super.validateCreatePayload(request); String name = request.getProperty("name"); if (! name.contains(".")) { throw new InvalidPayloadException("Term name must be in the form 'taxonomyName.termName.subTermName'"); } if (! request.getQueryProperties().containsKey("available_as_tag")) { request.getQueryProperties().put("available_as_tag", true); } } TermResourceDefinition(); @Override void validateCreatePayload(Request request); @Override String getTypeName(); @Override String getIdPropertyName(); @Override String resolveHref(Map<String, Object> properties);  }
@Test public void testValidate() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put("name", "taxonomy1.termName"); properties.put("description", "foo"); properties.put("available_as_tag", true); properties.put("acceptable_use", "something"); Request request = new InstanceRequest(properties); ResourceDefinition termDefinition = new TermResourceDefinition(); termDefinition.validateCreatePayload(request); }
@Test public void testValidate_nameOnly() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put("name", "taxonomy1.termName"); Request request = new InstanceRequest(properties); ResourceDefinition termDefinition = new TermResourceDefinition(); termDefinition.validateCreatePayload(request); }
@Test(expectedExceptions = InvalidPayloadException.class) public void testValidate_invalidTermName() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put("name", "NotQualifiedTermName"); properties.put("description", "foo"); properties.put("available_as_tag", true); Request request = new InstanceRequest(properties); ResourceDefinition termDefinition = new TermResourceDefinition(); termDefinition.validateCreatePayload(request); }
@Test(expectedExceptions = InvalidPayloadException.class) public void testValidate_missingName() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put("description", "foo"); Request request = new InstanceRequest(properties); ResourceDefinition termDefinition = new TermResourceDefinition(); termDefinition.validateCreatePayload(request); }
@Test(expectedExceptions = InvalidPayloadException.class) public void testValidate_invalidProperty() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put("name", "foo"); properties.put("unknownProperty", "value"); Request request = new InstanceRequest(properties); ResourceDefinition termDefinition = new TermResourceDefinition(); termDefinition.validateCreatePayload(request); }