@Parameters({"-12,0,-3", "-1,3,2", "100,200,199", "100,200,200", "100,200,100"}) @Test public void shouldPassValidationParamNumericValueBetween(int a, int b, int value) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); sut = new CommandSchemaValidator(rule); sut.addParameterValueValidator(new IntegerNumberParamValidator("topElem", a, b)); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", value + ""); // then sut.validateCommandSchema(params); }
@Parameters({"12", "0", "3", "2135323233", "24324234"}) @Test public void shouldPassValidationParamNumericValue(String paramValue) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); sut = new CommandSchemaValidator(rule); sut.addParameterValueValidator(new IntegerNumberParamValidator("topElem")); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", paramValue); // then sut.validateCommandSchema(params); }
@Parameters({"-12", "-0", "-3", "-200", "-300"}) @Test public void shouldPassValidationParamNumericNegativeValue(String paramValue) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); sut = new CommandSchemaValidator(rule); sut.addParameterValueValidator(new IntegerNumberParamValidator("topElem", -500, 1)); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", paramValue); // then sut.validateCommandSchema(params); }
@Parameters({"-12,0,-13", "-1,3,4", "100,200,2000000", "100,200,99", "100,200,-100"}) @Test public void shouldNotPassValidationParamNumericValueBetween(int a, int b, int value) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); sut = new CommandSchemaValidator(rule); sut.addParameterValueValidator(new IntegerNumberParamValidator("topElem", a, b)); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", value + ""); // and expectedException .expect(WebSuitesException.class) .hasMessage("Integer value for param topElem must be between " + a + " and " + b); // then sut.validateCommandSchema(params); }
@Parameters({"", "not numeric", "--2", "dd2", "34sfe"}) @Test public void shouldNotPassValidationInvalidParamNumericValueNotNumber(String paramValue) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); sut = new CommandSchemaValidator(rule); sut.addParameterValueValidator(new IntegerNumberParamValidator("topElem")); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", paramValue); // and expectedException .expect(WebSuitesException.class) .hasMessageStartingWith("Parameter topElem") .hasMessageContaining("must be proper integer value"); // then sut.validateCommandSchema(params); }