@Parameters({ "required1", "required2", "required3", "required3;required1", "required2;required3", "required1;required3" }) @Test public void shouldNotPassValidationManyRequired(String required) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); rule.addMandatoryElements("required1"); rule.addMandatoryElements("required2"); rule.addMandatoryElements("required3"); sut = new CommandSchemaValidator(rule); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", "some value doesn't matter what"); String[] requiredParams = required.split(";"); for (String param : requiredParams) { if (!param.isEmpty()) { params.put(param, "some value doesn't matter what"); } } // then expectValidationException("[required1, required2, required3]", "[]"); sut.validateCommandSchema(params); }
@Test public void shouldPassValidationOneTopOneRequiredNoOptional() { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); rule.addMandatoryElements("additionalRequired"); sut = new CommandSchemaValidator(rule); Map<String, String> someMap = new HashMap<String, String>(); // and someMap.put("topElem", "some value doesn't matter what"); someMap.put("additionalRequired", "some value doesn't matter what"); // when sut.validateCommandSchema(someMap); // then no exception expected }
@Test public void shouldNotPassValidationOneTopOneRequiredNoOptional1() { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); rule.addMandatoryElements("required"); sut = new CommandSchemaValidator(rule); Map<String, String> someMap = new HashMap<String, String>(); // and someMap.put("topElem", "some value doesn't matter what"); someMap.put("notExpectedElem", "some value doesn't matter what"); // then expectValidationException("[required]", "[]"); sut.validateCommandSchema(someMap); }
@Parameters({ "", "optional1;optional2;optional3", "optional1", "optional2", "optional3", "optional3;optional1", "optional2;optional3", "optional1;optional3" }) @Test public void shouldPassValidationManyRequired(String optionals) { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); rule.addMandatoryElements("required1"); rule.addMandatoryElements("required2"); rule.addMandatoryElements("required3"); rule.addOptionalElements("optional1"); rule.addOptionalElements("optional2"); rule.addOptionalElements("optional3"); sut = new CommandSchemaValidator(rule); // and Map<String, String> params = new HashMap<String, String>(); params.put("topElem", "some value doesn't matter what"); params.put("required1", "some value doesn't matter what"); params.put("required2", "some value doesn't matter what"); params.put("required3", "some value doesn't matter what"); String[] options = optionals.split(";"); for (String optional : options) { if (!optional.isEmpty()) { params.put(optional, "some value doesn't matter what"); } } // then sut.validateCommandSchema(params); }
@Test public void shouldNotPassValidationOneRequiredOneOptional1() { // given SchemaValidationRule rule = new SchemaValidationRule("topElem"); rule.addMandatoryElements("required"); rule.addOptionalElements("optional"); sut = new CommandSchemaValidator(rule); Map<String, String> params = new HashMap<String, String>(); // and params.put("topElem", "some value doesn't matter what"); params.put("optional", "some value doesn't matter what"); // then expectValidationException("[required]", "[optional]"); sut.validateCommandSchema(params); }