NgsiValidation { public void checkQueryContext(QueryContext queryContext) throws MissingRequestParameterException { if (nullOrEmpty(queryContext.getEntityIdList())) { throw new MissingRequestParameterException("entities", "List<EntityId>"); } for(EntityId entityId : queryContext.getEntityIdList()) { checkEntityId(entityId); } if (queryContext.getRestriction() != null) { if (nullOrEmpty(queryContext.getRestriction().getAttributeExpression())) { throw new MissingRequestParameterException("attributeExpression", "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 nullEntityIdListInQueryContext() throws MissingRequestParameterException { QueryContext queryContext = new QueryContext(); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("entities"); ngsiValidation.checkQueryContext(queryContext); }
@Test public void emptyEntityIdListInQueryContext() throws MissingRequestParameterException { QueryContext queryContext = new QueryContext(); List<EntityId> entityIdList = new ArrayList<>(); queryContext.setEntityIdList(entityIdList); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("entities"); ngsiValidation.checkQueryContext(queryContext); }
@Test public void nullIdOfEntityIdInQueryContext() throws MissingRequestParameterException { QueryContext queryContext = new QueryContext(); EntityId entityId = new EntityId(); queryContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("id"); ngsiValidation.checkQueryContext(queryContext); }
@Test public void emptyIdOfEntityIdInQueryContext() throws MissingRequestParameterException { QueryContext queryContext = new QueryContext(); EntityId entityId = new EntityId("","Room",false); queryContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("id"); ngsiValidation.checkQueryContext(queryContext); }
@Test public void nullTypeOfEntityIdInQueryContext() throws MissingRequestParameterException { QueryContext queryContext = new QueryContext(); EntityId entityId = new EntityId("Room1","Room",false); entityId.setType(null); queryContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("type"); ngsiValidation.checkQueryContext(queryContext); }
@Test public void emptyTypeOfEntityIdInQueryContext() throws MissingRequestParameterException { QueryContext queryContext = new QueryContext(); EntityId entityId = new EntityId("Room1","",false); queryContext.setEntityIdList(Collections.singletonList(entityId)); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("type"); ngsiValidation.checkQueryContext(queryContext); }
@Test public void nullAttributeExpressionOfRestrictionInQueryContext() throws MissingRequestParameterException { QueryContext queryContext = new QueryContext(); EntityId entityId = new EntityId("Room1","Room",false); queryContext.setEntityIdList(Collections.singletonList(entityId)); queryContext.setRestriction(new Restriction()); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attributeExpression"); ngsiValidation.checkQueryContext(queryContext); }
@Test public void emptyAttributeExpressionOfRestrictionInQueryContext() throws MissingRequestParameterException { QueryContext queryContext = new QueryContext(); EntityId entityId = new EntityId("Room1","Room",false); queryContext.setEntityIdList(Collections.singletonList(entityId)); Restriction restriction = new Restriction(); restriction.setAttributeExpression(""); queryContext.setRestriction(restriction); thrown.expect(MissingRequestParameterException.class); thrown.expectMessage("attributeExpression"); ngsiValidation.checkQueryContext(queryContext); }