@Test @SuppressWarnings("unchecked") public void testValidate() { String testLookupName = "testLookup"; List<StandardLookupEntry> validStandardLookupEntries1 = new ArrayList<>(); validStandardLookupEntries1.add(new StandardLookupEntry("sub1key1", "sub1value1")); validStandardLookupEntries1.add(new StandardLookupEntry("sub1key2", "sub1value2")); List<StandardLookupEntry> validStandardLookupEntries2 = new ArrayList<>(); validStandardLookupEntries2.add(new StandardLookupEntry("sub2key1", "sub2value1")); validStandardLookupEntries2.add(new StandardLookupEntry("sub2key2", "sub2value2")); List<NestedLookupEntry> validEntries = new ArrayList<>(); validEntries.add(new NestedLookupEntry("key1", "value1", validStandardLookupEntries1)); validEntries.add(new NestedLookupEntry("key2", "value2", validStandardLookupEntries2)); List<NestedLookupEntry> emptyValueEntries = new ArrayList<>(); emptyValueEntries.add(new NestedLookupEntry("key1", "value1", validStandardLookupEntries1)); emptyValueEntries.add(new NestedLookupEntry("key2", "", validStandardLookupEntries2)); List<StandardLookupEntry> emptyValueInSubLookupEntries = new ArrayList<>(); emptyValueInSubLookupEntries.add(new StandardLookupEntry("sub2key1", "sub2value1")); emptyValueInSubLookupEntries.add(new StandardLookupEntry("sub2key2", "")); List<NestedLookupEntry> emptyValueInSubLookupEntriesLookupNestedLookupEntries = new ArrayList<>(); emptyValueInSubLookupEntriesLookupNestedLookupEntries.add(new NestedLookupEntry("key1", "value1", validStandardLookupEntries2)); emptyValueInSubLookupEntriesLookupNestedLookupEntries.add(new NestedLookupEntry("key2", "value2", emptyValueInSubLookupEntries)); List<NestedLookupEntry> duplicateKeysEntries = new ArrayList<>(); duplicateKeysEntries.add(new NestedLookupEntry("key1", "value1", validStandardLookupEntries1)); duplicateKeysEntries.add(new NestedLookupEntry("key1", "value2", validStandardLookupEntries2)); List<NestedLookupEntry> duplicateValuesEntries = new ArrayList<>(); duplicateValuesEntries.add(new NestedLookupEntry("key1", "value1", validStandardLookupEntries1)); duplicateValuesEntries.add(new NestedLookupEntry("key2", "value1", validStandardLookupEntries2)); List<StandardLookupEntry> duplicateKeysInSubLookupEntries = new ArrayList<>(); duplicateKeysInSubLookupEntries.add(new StandardLookupEntry("sub1key1", "sub1value1")); duplicateKeysInSubLookupEntries.add(new StandardLookupEntry("sub1key1", "sub1value2")); List<NestedLookupEntry> duplicateKeysInSubLookupEntriesNestedLookupEntries = new ArrayList<>(); duplicateKeysInSubLookupEntriesNestedLookupEntries.add(new NestedLookupEntry("key1", "value1", validStandardLookupEntries1)); duplicateKeysInSubLookupEntriesNestedLookupEntries.add(new NestedLookupEntry("key2", "value2", duplicateKeysInSubLookupEntries)); List<StandardLookupEntry> duplicateValuesInSubLookupEntries = new ArrayList<>(); duplicateValuesInSubLookupEntries.add(new StandardLookupEntry("sub1key1", "sub1value1")); duplicateValuesInSubLookupEntries.add(new StandardLookupEntry("sub1key2", "sub1value1")); List<NestedLookupEntry> duplicateValuesInSubLookupEntriesNestedLookupEntries = new ArrayList<>(); duplicateValuesInSubLookupEntriesNestedLookupEntries.add(new NestedLookupEntry("key1", "value1", validStandardLookupEntries1)); duplicateValuesInSubLookupEntriesNestedLookupEntries .add(new NestedLookupEntry("key2", "value2", duplicateValuesInSubLookupEntries)); Object[][] testData = { { validEntries, true, null }, { emptyValueEntries, false, "Empty value found in '" + testLookupName + "' lookup!" }, { emptyValueInSubLookupEntriesLookupNestedLookupEntries, false, "Empty value found in '" + testLookupName + "' lookup!" }, { duplicateKeysEntries, false, "Duplicate key found in '" + testLookupName + "' lookup! [key : key1]" }, { duplicateValuesEntries, false, "Duplicate value found in '" + testLookupName + "' lookup! [values : value1]" }, { duplicateKeysInSubLookupEntriesNestedLookupEntries, false, "Duplicate key found in '" + testLookupName + "' lookup! [key : sub1key1]" }, { duplicateValuesInSubLookupEntriesNestedLookupEntries, false, "Duplicate value found in '" + testLookupName + "' lookup! [values : sub1value1]" } }; for (Object[] testDatum : testData) { List<NestedLookupEntry> entries = (List<NestedLookupEntry>) testDatum[0]; nestedLookup.setEntries(entries); nestedLookup.setName(testLookupName); LookupValidationResult res = nestedLookup.validate(); assertEquals(testDatum[1], res.isValid()); assertEquals(testDatum[2], res.getErrorMessage()); } }
@Override @JsonIgnore public LookupValidationResult validate() { for (NestedLookupEntry entry : entries) { if (entry.getKey() == null) { return new LookupValidationResult(false, "Key not found or have [null] value in '" + getName() + "' lookup!"); } if (entry.getValue() == null || entry.getValue().isEmpty()) { return new LookupValidationResult(false, "Empty value found in '" + getName() + "' lookup!"); } } for (int i = 0; i < entries.size(); i++) { for (int j = i + 1; j < entries.size(); j++) { if (Objects.equals(entries.get(i).getKey(), entries.get(j).getKey())) { return new LookupValidationResult(false, "Duplicate key found in '" + getName() + "' lookup! [key : " + entries.get(i).getKey() + "]"); } if (Objects.equals(entries.get(i).getValue(), entries.get(j).getValue())) { return new LookupValidationResult(false, "Duplicate value found in '" + getName() + "' lookup! [values : " + entries.get(i).getValue() + "]"); } } } LookupValidationResult lookupValidationResult = null; for (NestedLookupEntry nestedLookupEntry : entries) { StandardLookup standardLookup = new StandardLookup(); standardLookup.setEntries(nestedLookupEntry.getSubLookup()); lookupValidationResult = standardLookup.validate(this); if (!lookupValidationResult.isValid()) { return lookupValidationResult; } } return new LookupValidationResult(true, null); }
NestedLookup extends AcmLookup<NestedLookupEntry> { @Override @JsonIgnore public LookupValidationResult validate() { for (NestedLookupEntry entry : entries) { if (entry.getKey() == null) { return new LookupValidationResult(false, "Key not found or have [null] value in '" + getName() + "' lookup!"); } if (entry.getValue() == null || entry.getValue().isEmpty()) { return new LookupValidationResult(false, "Empty value found in '" + getName() + "' lookup!"); } } for (int i = 0; i < entries.size(); i++) { for (int j = i + 1; j < entries.size(); j++) { if (Objects.equals(entries.get(i).getKey(), entries.get(j).getKey())) { return new LookupValidationResult(false, "Duplicate key found in '" + getName() + "' lookup! [key : " + entries.get(i).getKey() + "]"); } if (Objects.equals(entries.get(i).getValue(), entries.get(j).getValue())) { return new LookupValidationResult(false, "Duplicate value found in '" + getName() + "' lookup! [values : " + entries.get(i).getValue() + "]"); } } } LookupValidationResult lookupValidationResult = null; for (NestedLookupEntry nestedLookupEntry : entries) { StandardLookup standardLookup = new StandardLookup(); standardLookup.setEntries(nestedLookupEntry.getSubLookup()); lookupValidationResult = standardLookup.validate(this); if (!lookupValidationResult.isValid()) { return lookupValidationResult; } } return new LookupValidationResult(true, null); } }
NestedLookup extends AcmLookup<NestedLookupEntry> { @Override @JsonIgnore public LookupValidationResult validate() { for (NestedLookupEntry entry : entries) { if (entry.getKey() == null) { return new LookupValidationResult(false, "Key not found or have [null] value in '" + getName() + "' lookup!"); } if (entry.getValue() == null || entry.getValue().isEmpty()) { return new LookupValidationResult(false, "Empty value found in '" + getName() + "' lookup!"); } } for (int i = 0; i < entries.size(); i++) { for (int j = i + 1; j < entries.size(); j++) { if (Objects.equals(entries.get(i).getKey(), entries.get(j).getKey())) { return new LookupValidationResult(false, "Duplicate key found in '" + getName() + "' lookup! [key : " + entries.get(i).getKey() + "]"); } if (Objects.equals(entries.get(i).getValue(), entries.get(j).getValue())) { return new LookupValidationResult(false, "Duplicate value found in '" + getName() + "' lookup! [values : " + entries.get(i).getValue() + "]"); } } } LookupValidationResult lookupValidationResult = null; for (NestedLookupEntry nestedLookupEntry : entries) { StandardLookup standardLookup = new StandardLookup(); standardLookup.setEntries(nestedLookupEntry.getSubLookup()); lookupValidationResult = standardLookup.validate(this); if (!lookupValidationResult.isValid()) { return lookupValidationResult; } } return new LookupValidationResult(true, null); }  }
NestedLookup extends AcmLookup<NestedLookupEntry> { @Override @JsonIgnore public LookupValidationResult validate() { for (NestedLookupEntry entry : entries) { if (entry.getKey() == null) { return new LookupValidationResult(false, "Key not found or have [null] value in '" + getName() + "' lookup!"); } if (entry.getValue() == null || entry.getValue().isEmpty()) { return new LookupValidationResult(false, "Empty value found in '" + getName() + "' lookup!"); } } for (int i = 0; i < entries.size(); i++) { for (int j = i + 1; j < entries.size(); j++) { if (Objects.equals(entries.get(i).getKey(), entries.get(j).getKey())) { return new LookupValidationResult(false, "Duplicate key found in '" + getName() + "' lookup! [key : " + entries.get(i).getKey() + "]"); } if (Objects.equals(entries.get(i).getValue(), entries.get(j).getValue())) { return new LookupValidationResult(false, "Duplicate value found in '" + getName() + "' lookup! [values : " + entries.get(i).getValue() + "]"); } } } LookupValidationResult lookupValidationResult = null; for (NestedLookupEntry nestedLookupEntry : entries) { StandardLookup standardLookup = new StandardLookup(); standardLookup.setEntries(nestedLookupEntry.getSubLookup()); lookupValidationResult = standardLookup.validate(this); if (!lookupValidationResult.isValid()) { return lookupValidationResult; } } return new LookupValidationResult(true, null); }  @Override @JsonIgnore LookupValidationResult validate(); }
NestedLookup extends AcmLookup<NestedLookupEntry> { @Override @JsonIgnore public LookupValidationResult validate() { for (NestedLookupEntry entry : entries) { if (entry.getKey() == null) { return new LookupValidationResult(false, "Key not found or have [null] value in '" + getName() + "' lookup!"); } if (entry.getValue() == null || entry.getValue().isEmpty()) { return new LookupValidationResult(false, "Empty value found in '" + getName() + "' lookup!"); } } for (int i = 0; i < entries.size(); i++) { for (int j = i + 1; j < entries.size(); j++) { if (Objects.equals(entries.get(i).getKey(), entries.get(j).getKey())) { return new LookupValidationResult(false, "Duplicate key found in '" + getName() + "' lookup! [key : " + entries.get(i).getKey() + "]"); } if (Objects.equals(entries.get(i).getValue(), entries.get(j).getValue())) { return new LookupValidationResult(false, "Duplicate value found in '" + getName() + "' lookup! [values : " + entries.get(i).getValue() + "]"); } } } LookupValidationResult lookupValidationResult = null; for (NestedLookupEntry nestedLookupEntry : entries) { StandardLookup standardLookup = new StandardLookup(); standardLookup.setEntries(nestedLookupEntry.getSubLookup()); lookupValidationResult = standardLookup.validate(this); if (!lookupValidationResult.isValid()) { return lookupValidationResult; } } return new LookupValidationResult(true, null); }  @Override @JsonIgnore LookupValidationResult validate();  }