NgsiValidation { public void checkUpdateContext(UpdateContext updateContext) throws MissingRequestParameterException { if (updateContext.getUpdateAction() == null) { throw new MissingRequestParameterException("updateAction", "string"); } if (nullOrEmpty(updateContext.getContextElements())) { throw new MissingRequestParameterException("contextElements", "List<ContextElement>"); } for (ContextElement contextElement : updateContext.getContextElements()) { checkContextElement(contextElement); } }  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 missingUpdateActionInUpdateContext() throws MissingRequestParameterException { UpdateContext updateContext = new UpdateContext(); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("updateAction"); ngsiValidation.checkUpdateContext(updateContext); }
@Test public void emptyContextElementInUpdateContext() throws MissingRequestParameterException { UpdateContext updateContext = new UpdateContext(); updateContext.setUpdateAction(UpdateAction.DELETE); List<ContextElement> contextElements = new ArrayList<>(); updateContext.setContextElements(contextElements); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("contextElements"); ngsiValidation.checkUpdateContext(updateContext); }
@Test public void nullContextElementInUpdateContext() throws MissingRequestParameterException { UpdateContext updateContext = new UpdateContext(); updateContext.setUpdateAction(UpdateAction.UPDATE); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("contextElements"); ngsiValidation.checkUpdateContext(updateContext); }
@Test public void emptyEntityIdUpdateContext() throws MissingRequestParameterException { UpdateContext updateContext = new UpdateContext(); updateContext.setUpdateAction(UpdateAction.UPDATE); ContextElement contextElement = new ContextElement(); EntityId entityId = new EntityId("", "type", false); contextElement.setEntityId(entityId); List<ContextElement> contextElements = new ArrayList<>(); contextElements.add(contextElement); updateContext.setContextElements(contextElements); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("id"); ngsiValidation.checkUpdateContext(updateContext); }
@Test public void nullEntityIdUpdateContext() throws MissingRequestParameterException { UpdateContext updateContext = new UpdateContext(); updateContext.setUpdateAction(UpdateAction.UPDATE); ContextElement contextElement = new ContextElement(); EntityId entityId = new EntityId(); contextElement.setEntityId(entityId); List<ContextElement> contextElements = new ArrayList<>(); contextElements.add(contextElement); updateContext.setContextElements(contextElements); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("id"); ngsiValidation.checkUpdateContext(updateContext); }
@Test public void emptyEntityTypeUpdateContext() throws MissingRequestParameterException { UpdateContext updateContext = new UpdateContext(); updateContext.setUpdateAction(UpdateAction.UPDATE); ContextElement contextElement = new ContextElement(); EntityId entityId = new EntityId("id", "", false); contextElement.setEntityId(entityId); List<ContextElement> contextElements = new ArrayList<>(); contextElements.add(contextElement); updateContext.setContextElements(contextElements); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("type"); ngsiValidation.checkUpdateContext(updateContext); }
@Test public void nullEntityTypeUpdateContext() throws MissingRequestParameterException { UpdateContext updateContext = new UpdateContext(); updateContext.setUpdateAction(UpdateAction.UPDATE); ContextElement contextElement = new ContextElement(); EntityId entityId = new EntityId(); entityId.setId("id"); contextElement.setEntityId(entityId); List<ContextElement> contextElements = new ArrayList<>(); contextElements.add(contextElement); updateContext.setContextElements(contextElements); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("type"); ngsiValidation.checkUpdateContext(updateContext); }