NgsiValidation { public void checkSubscribeContext(SubscribeContext subscribeContext) throws MissingRequestParameterException { if (nullOrEmpty(subscribeContext.getEntityIdList())) { throw new MissingRequestParameterException("entities", "List<EntityId>"); } for(EntityId entityId: subscribeContext.getEntityIdList()) { checkEntityId(entityId); } if (nullOrEmpty(subscribeContext.getReference())){ throw new MissingRequestParameterException("reference", "URI"); } if (subscribeContext.getRestriction() != null) { if (nullOrEmpty(subscribeContext.getRestriction().getAttributeExpression()) && nullOrEmpty(subscribeContext.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 nullEntityIdListInSubscribeContext() throws MissingRequestParameterException { SubscribeContext subscribeContext = new SubscribeContext(); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("entities"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void emptyEntityIdListInSubscribeContext() throws MissingRequestParameterException { SubscribeContext subscribeContext = new SubscribeContext(); List<EntityId> entityIdList = new ArrayList<>(); subscribeContext.setEntityIdList(entityIdList); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("entities"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void nullIdOfEntityIdInSubscribeContext() throws MissingRequestParameterException, URISyntaxException { SubscribeContext subscribeContext = new SubscribeContext(); EntityId entityId = new EntityId(); subscribeContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("id"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void emptyIdOfEntityIdInSubscribeContext() throws MissingRequestParameterException { SubscribeContext subscribeContext = new SubscribeContext(); EntityId entityId = new EntityId("","Room",false); subscribeContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("id"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void nullTypeOfEntityIdInSubscribeContext() throws MissingRequestParameterException { SubscribeContext subscribeContext = new SubscribeContext(); EntityId entityId = new EntityId("Room1","Room",false); entityId.setType(null); subscribeContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("type"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void emptyTypeOfEntityIdInSubscribeContext() throws MissingRequestParameterException { SubscribeContext subscribeContext = new SubscribeContext(); EntityId entityId = new EntityId("Room1","",false); subscribeContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("type"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void nullReferenceInSubscribeContext() throws MissingRequestParameterException { SubscribeContext subscribeContext = new SubscribeContext(); EntityId entityId = new EntityId("Room1","Room",false); subscribeContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("reference"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void emptyReferenceInSubscribeContext() throws MissingRequestParameterException, URISyntaxException { SubscribeContext subscribeContext = new SubscribeContext(); EntityId entityId = new EntityId("Room1","Room",false); subscribeContext.setEntityIdList(Collections.singletonList(entityId)); subscribeContext.setReference(new URI("")); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("reference"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void nullAttributeExpressionOfRestrictionInSubscribeContext() throws MissingRequestParameterException, URISyntaxException { SubscribeContext subscribeContext = new SubscribeContext(); EntityId entityId = new EntityId("Room1","Room",false); subscribeContext.setEntityIdList(Collections.singletonList(entityId)); subscribeContext.setReference(new URI("http: subscribeContext.setRestriction(new Restriction()); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attributeExpression"); ngsiValidation.checkSubscribeContext(subscribeContext); }
@Test public void emptyAttributeExpressionOfRestrictionInSubscribeContext() throws MissingRequestParameterException, URISyntaxException { SubscribeContext subscribeContext = new SubscribeContext(); EntityId entityId = new EntityId("Room1","Room",false); subscribeContext.setEntityIdList(Collections.singletonList(entityId)); subscribeContext.setReference(new URI("http: Restriction restriction = new Restriction(); restriction.setAttributeExpression(""); subscribeContext.setRestriction(restriction); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attributeExpression"); ngsiValidation.checkSubscribeContext(subscribeContext); }