NgsiValidation { public void checkUpdateContextSubscription(UpdateContextSubscription updateContextSubscription) throws MissingRequestParameterException { if (nullOrEmpty(updateContextSubscription.getSubscriptionId())){ throw new MissingRequestParameterException("subscriptionId", "String"); } if (updateContextSubscription.getRestriction() != null) { if (nullOrEmpty(updateContextSubscription.getRestriction().getAttributeExpression()) && nullOrEmpty(updateContextSubscription.getRestriction().getScopes())) { throw new MissingRequestParameterException("attributeExpression or scopes", "string"); } } }  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 nullSubscriptionIdInUpdateContextSubscription() throws MissingRequestParameterException { UpdateContextSubscription updateContextSubscription = new UpdateContextSubscription(); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("subscriptionId"); ngsiValidation.checkUpdateContextSubscription(updateContextSubscription); }
@Test public void emptySubscriptionIdInUpdateContextSubscription() throws MissingRequestParameterException { UpdateContextSubscription updateContextSubscription = new UpdateContextSubscription(); updateContextSubscription.setSubscriptionId(""); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("subscriptionId"); ngsiValidation.checkUpdateContextSubscription(updateContextSubscription); }
@Test public void nullAttributeExpressionOfRestrictionInUpdateContextSubscription() throws MissingRequestParameterException, URISyntaxException { UpdateContextSubscription updateContextSubscription = new UpdateContextSubscription(); EntityId entityId = new EntityId("Room1","Room",false); updateContextSubscription.setSubscriptionId("12345"); updateContextSubscription.setRestriction(new Restriction()); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attributeExpression"); ngsiValidation.checkUpdateContextSubscription(updateContextSubscription); }
@Test public void emptyAttributeExpressionOfRestrictionInUpdateContextSubscription() throws MissingRequestParameterException, URISyntaxException { UpdateContextSubscription updateContextSubscription = new UpdateContextSubscription(); EntityId entityId = new EntityId("Room1","Room",false); updateContextSubscription.setSubscriptionId("12345"); Restriction restriction = new Restriction(); restriction.setAttributeExpression(""); updateContextSubscription.setRestriction(restriction); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attributeExpression"); ngsiValidation.checkUpdateContextSubscription(updateContextSubscription); }