NgsiValidation { public void checkUpdateContextAttribute(String entityID, String attributeName, String valueID, UpdateContextAttribute updateContextAttribute) throws MissingRequestParameterException, MismatchIdException { if (nullOrEmpty(entityID)) { throw new MissingRequestParameterException("entityID", "string"); } if (nullOrEmpty(attributeName)) { throw new MissingRequestParameterException("attributeName", "string"); } if (updateContextAttribute == null || updateContextAttribute.getAttribute() == null) { throw new MissingRequestParameterException("attribute", "ContextAttribute"); } if (!attributeName.equals(updateContextAttribute.getAttribute().getName())) { throw new MismatchIdException(attributeName, updateContextAttribute.getAttribute().getName()); } if (valueID != null) { if (nullOrEmpty(valueID)) { throw new MissingRequestParameterException("valueID", "string"); } if (updateContextAttribute.getAttribute().getMetadata() == null) { throw new MissingRequestParameterException("metadata", "Metadata"); } for (ContextMetadata metadata : updateContextAttribute.getAttribute().getMetadata()) { if ("ID".equals(metadata.getName())) { if (valueID.equals(metadata.getValue())) { return; } throw new MismatchIdException(valueID, String.valueOf(metadata.getValue())); } } throw new MissingRequestParameterException("ID", "Metadata ID"); } }  void checkUpdateContext(UpdateContext updateContext); void checkNotifyContext(NotifyContext notifyContext); void checkRegisterContext(RegisterContext registerContext); void checkSubscribeContext(SubscribeContext subscribeContext); void checkUpdateContextSubscription(UpdateContextSubscription updateContextSubscription); void checkUnsubscribeContext(UnsubscribeContext unsubscribeContext); void checkQueryContext(QueryContext queryContext); void checkAppendContextElement(AppendContextElement appendContextElement); void checkUpdateContextElement(UpdateContextElement updateContextElement); void checkUpdateContextAttribute(String entityID, String attributeName, String valueID, UpdateContextAttribute updateContextAttribute); void checkUpdateSubscription(String subscriptionID, UpdateContextSubscription updateContextSubscription);  }
@Test public void testUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { UpdateContextAttribute updateContextAttribute = new UpdateContextAttribute(); updateContextAttribute.setAttribute(new ContextAttribute("temp", "float", "15.5")); ngsiValidation.checkUpdateContextAttribute("12345678", "temp", null, updateContextAttribute); }
@Test public void testUpdateContextAttributeWithValueID() throws MissingRequestParameterException, MismatchIdException { ContextAttribute contextAttribute = new ContextAttribute("temp", "float", "15.5"); contextAttribute.setMetadata(Collections.singletonList(new ContextMetadata("ID", "string", "DEADBEEF"))); UpdateContextAttribute updateContextAttribute = new UpdateContextAttribute(); updateContextAttribute.setAttribute(contextAttribute); ngsiValidation.checkUpdateContextAttribute("12345678", "temp", "DEADBEEF", updateContextAttribute); }
@Test public void nullEntityIDInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("entityID"); ngsiValidation.checkUpdateContextAttribute(null, "temp", null, new UpdateContextAttribute()); }
@Test public void emptyEntityIDInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("entityID"); ngsiValidation.checkUpdateContextAttribute("", "temp", null, new UpdateContextAttribute()); }
@Test public void nullAttributeNameInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attributeName"); ngsiValidation.checkUpdateContextAttribute("12345678", null, null, new UpdateContextAttribute()); }
@Test public void emptyAttributeNameInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attributeName"); ngsiValidation.checkUpdateContextAttribute("12345678", "", null, new UpdateContextAttribute()); }
@Test public void nullUpdateContextAttributeInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attribute"); ngsiValidation.checkUpdateContextAttribute("12345678", "temp", null, null); }
@Test public void nullContextAttributeInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attribute"); ngsiValidation.checkUpdateContextAttribute("12345678", "temp", null, new UpdateContextAttribute()); }
@Test public void attributeNameMismatchInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { ContextAttribute contextAttribute = new ContextAttribute("BADATTR", "float", "15.5"); UpdateContextAttribute updateContextAttribute = new UpdateContextAttribute(); updateContextAttribute.setAttribute(contextAttribute); thrown.expect(MismatchIdException.class); thrown.expectMessage("BADATTR"); ngsiValidation.checkUpdateContextAttribute("12345678", "temp", null, updateContextAttribute); }
@Test public void nullMetadataInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { ContextAttribute contextAttribute = new ContextAttribute("temp", "float", "15.5"); UpdateContextAttribute updateContextAttribute = new UpdateContextAttribute(); updateContextAttribute.setAttribute(contextAttribute); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("Metadata ID"); ngsiValidation.checkUpdateContextAttribute("12345678", "temp", "DEADBEEF", updateContextAttribute); }
@Test public void emptyMetadataInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { ContextAttribute contextAttribute = new ContextAttribute("temp", "float", "15.5"); contextAttribute.setMetadata(Collections.emptyList()); UpdateContextAttribute updateContextAttribute = new UpdateContextAttribute(); updateContextAttribute.setAttribute(contextAttribute); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("Metadata ID"); ngsiValidation.checkUpdateContextAttribute("12345678", "temp", "DEADBEEF", updateContextAttribute); }
@Test public void mismatchMetadataIDInUpdateContextAttribute() throws MissingRequestParameterException, MismatchIdException { ContextAttribute contextAttribute = new ContextAttribute("temp", "float", "15.5"); contextAttribute.setMetadata(Collections.singletonList(new ContextMetadata("ID", "string", "CAFEBABE"))); UpdateContextAttribute updateContextAttribute = new UpdateContextAttribute(); updateContextAttribute.setAttribute(contextAttribute); thrown.expect(MismatchIdException.class); thrown.expectMessage("DEADBEEF"); ngsiValidation.checkUpdateContextAttribute("12345678", "temp", "DEADBEEF", updateContextAttribute); }