NgsiValidation { public void checkNotifyContext(NotifyContext notifyContext) throws MissingRequestParameterException { if (nullOrEmpty(notifyContext.getSubscriptionId())) { throw new MissingRequestParameterException("subscriptionId", "string"); } if (nullOrEmpty(notifyContext.getOriginator())){ throw new MissingRequestParameterException("originator", "URI"); } if (nullOrEmpty(notifyContext.getContextElementResponseList())) { throw new MissingRequestParameterException("contextElementResponse", "List<ContextElementResponse>"); } for (ContextElementResponse contextElementResponse : notifyContext.getContextElementResponseList()) { checkContextElementResponse(contextElementResponse); } }  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 emptyOriginatorInNotifyContext() throws MissingRequestParameterException, URISyntaxException { NotifyContext notifyContext = new NotifyContext(); notifyContext.setSubscriptionId("subscriptionId"); notifyContext.setOriginator(new URI("")); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("originator"); ngsiValidation.checkNotifyContext(notifyContext); }
@Test public void nullContextElementResponseListInNotifyContext() throws MissingRequestParameterException, URISyntaxException { NotifyContext notifyContext = new NotifyContext(); notifyContext.setSubscriptionId("subscriptionId"); notifyContext.setOriginator(new URI("http: thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("contextElementResponse"); ngsiValidation.checkNotifyContext(notifyContext); }
@Test public void emptyContextElementResponseListInNotifyContext() throws MissingRequestParameterException, URISyntaxException { NotifyContext notifyContext = new NotifyContext(); notifyContext.setSubscriptionId("subscriptionId"); notifyContext.setOriginator(new URI("http: List<ContextElementResponse> contextElementResponseList = new ArrayList<>(); notifyContext.setContextElementResponseList(contextElementResponseList); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("contextElementResponse"); ngsiValidation.checkNotifyContext(notifyContext); }
@Test public void nullStatusCodeInNotifyContext() throws MissingRequestParameterException, URISyntaxException { NotifyContext notifyContext = new NotifyContext(); notifyContext.setSubscriptionId("subscriptionId"); notifyContext.setOriginator(new URI("http: ContextElementResponse contextElementResponse = new ContextElementResponse(); notifyContext.setContextElementResponseList(Collections.singletonList(contextElementResponse)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("statusCode"); ngsiValidation.checkNotifyContext(notifyContext); }
@Test public void nullContextElementInNotifyContext() throws MissingRequestParameterException, URISyntaxException { NotifyContext notifyContext = new NotifyContext(); notifyContext.setSubscriptionId("subscriptionId"); notifyContext.setOriginator(new URI("http: ContextElementResponse contextElementResponse = new ContextElementResponse(); contextElementResponse.setStatusCode(new StatusCode(CODE_200)); notifyContext.setContextElementResponseList(Collections.singletonList(contextElementResponse)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("contextElement"); ngsiValidation.checkNotifyContext(notifyContext); }
@Test public void nullSubscriptionIdInNotifyContext() throws MissingRequestParameterException { NotifyContext notifyContext = new NotifyContext(); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("subscriptionId"); ngsiValidation.checkNotifyContext(notifyContext); }
@Test public void emptySubscriptionIdInNotifyContext() throws MissingRequestParameterException { NotifyContext notifyContext = new NotifyContext(); notifyContext.setSubscriptionId(""); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("subscriptionId"); ngsiValidation.checkNotifyContext(notifyContext); }
@Test public void nullOriginatorInNotifyContext() throws MissingRequestParameterException { NotifyContext notifyContext = new NotifyContext(); notifyContext.setSubscriptionId("subscriptionId"); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("originator"); ngsiValidation.checkNotifyContext(notifyContext); }