@Test public void testValidateAgainstWithNameMismatch() { @SuppressWarnings("unchecked") Function<Element, DataDirectories> resourcesTypeSupplier = mock(Function.class); DataRootValidator dataRootValidator = new DataRootValidator(resourcesTypeSupplier); DataRootMapping dataRootMapping1 = new DataRootMapping(); dataRootMapping1.setName("dataRoot1"); dataRootMapping1.setValue("../data-root1"); dataRootMapping1.setUseForPlatform(true); DataRootMapping dataRootMapping2 = new DataRootMapping(); dataRootMapping2.setName("dataRoot2"); dataRootMapping2.setValue("../data-root2"); dataRootMapping1.setUseForPlatform(true); DataDirectories dataDirectories1 = new DataDirectories(); DataDirectories dataDirectories2 = new DataDirectories(); dataDirectories1.getDirectory().add(dataRootMapping1); dataDirectories2.getDirectory().add(dataRootMapping2); Element element1 = mock(Element.class); when(resourcesTypeSupplier.apply(element1)).thenReturn(dataDirectories1); Element element2 = mock(Element.class); when(resourcesTypeSupplier.apply(element2)).thenReturn(dataDirectories2); try { dataRootValidator.validateAgainst(element1, element2); } catch (ValidationException e) { assertEquals(ValidationFailureId.MISMATCHED_DATA_DIR_NAMES.getFailureId(), e.getErrorId()); } }
public void validateAgainst(Element oneFragment, Element otherFragment) throws ValidationException { DataDirectories oneDataDirs = getDataDirectoriesObject(oneFragment); DataDirectories anotherDataDirs = getDataDirectoriesObject(otherFragment); if (oneDataDirs.getDirectory().size() != anotherDataDirs.getDirectory().size()) { throw new ValidationException("Number of data-root directories are not matching." , ValidationFailureId.MISMATCHED_DATA_DIR_RESOURCE_NUMBERS.getFailureId()); } Map<String, DataRootMapping> oneDataRootDirectoryNames = oneDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); Map<String, DataRootMapping> anotherDataDirectoryNames = anotherDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); if (!oneDataRootDirectoryNames.keySet().equals(anotherDataDirectoryNames.keySet())) { throw new ValidationException("Mismatched data-root names." , ValidationFailureId.MISMATCHED_DATA_DIR_NAMES.getFailureId()); } Set<String> onePlatformMappings = oneDataRootDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); Set<String> anotherPlatformMappings = anotherDataDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); String oneDataRootMappingName = null; if (onePlatformMappings.iterator().hasNext()) { oneDataRootMappingName = onePlatformMappings.iterator().next(); } String anotherDataRootMappingName = null; if (anotherPlatformMappings.iterator().hasNext()) { anotherDataRootMappingName = anotherPlatformMappings.iterator().next(); } if ((oneDataRootMappingName == null && anotherDataRootMappingName != null) || (oneDataRootMappingName != null && anotherDataRootMappingName == null)) { throw new ValidationException("Platform data-root is missing in one." , ValidationFailureId.PLATFORM_DATA_ROOT_MISSING_IN_ONE.getFailureId()); } if (oneDataRootMappingName != null) { if (!oneDataRootMappingName.equals(anotherDataRootMappingName)) { throw new ValidationException("Different data-roots are configured for platform usage in different elements." , ValidationFailureId.DIFFERENT_PLATFORM_DATA_ROOTS.getFailureId()); } } }
DataRootValidator implements ConfigValidator { public void validateAgainst(Element oneFragment, Element otherFragment) throws ValidationException { DataDirectories oneDataDirs = getDataDirectoriesObject(oneFragment); DataDirectories anotherDataDirs = getDataDirectoriesObject(otherFragment); if (oneDataDirs.getDirectory().size() != anotherDataDirs.getDirectory().size()) { throw new ValidationException("Number of data-root directories are not matching." , ValidationFailureId.MISMATCHED_DATA_DIR_RESOURCE_NUMBERS.getFailureId()); } Map<String, DataRootMapping> oneDataRootDirectoryNames = oneDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); Map<String, DataRootMapping> anotherDataDirectoryNames = anotherDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); if (!oneDataRootDirectoryNames.keySet().equals(anotherDataDirectoryNames.keySet())) { throw new ValidationException("Mismatched data-root names." , ValidationFailureId.MISMATCHED_DATA_DIR_NAMES.getFailureId()); } Set<String> onePlatformMappings = oneDataRootDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); Set<String> anotherPlatformMappings = anotherDataDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); String oneDataRootMappingName = null; if (onePlatformMappings.iterator().hasNext()) { oneDataRootMappingName = onePlatformMappings.iterator().next(); } String anotherDataRootMappingName = null; if (anotherPlatformMappings.iterator().hasNext()) { anotherDataRootMappingName = anotherPlatformMappings.iterator().next(); } if ((oneDataRootMappingName == null && anotherDataRootMappingName != null) || (oneDataRootMappingName != null && anotherDataRootMappingName == null)) { throw new ValidationException("Platform data-root is missing in one." , ValidationFailureId.PLATFORM_DATA_ROOT_MISSING_IN_ONE.getFailureId()); } if (oneDataRootMappingName != null) { if (!oneDataRootMappingName.equals(anotherDataRootMappingName)) { throw new ValidationException("Different data-roots are configured for platform usage in different elements." , ValidationFailureId.DIFFERENT_PLATFORM_DATA_ROOTS.getFailureId()); } } } }
DataRootValidator implements ConfigValidator { public void validateAgainst(Element oneFragment, Element otherFragment) throws ValidationException { DataDirectories oneDataDirs = getDataDirectoriesObject(oneFragment); DataDirectories anotherDataDirs = getDataDirectoriesObject(otherFragment); if (oneDataDirs.getDirectory().size() != anotherDataDirs.getDirectory().size()) { throw new ValidationException("Number of data-root directories are not matching." , ValidationFailureId.MISMATCHED_DATA_DIR_RESOURCE_NUMBERS.getFailureId()); } Map<String, DataRootMapping> oneDataRootDirectoryNames = oneDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); Map<String, DataRootMapping> anotherDataDirectoryNames = anotherDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); if (!oneDataRootDirectoryNames.keySet().equals(anotherDataDirectoryNames.keySet())) { throw new ValidationException("Mismatched data-root names." , ValidationFailureId.MISMATCHED_DATA_DIR_NAMES.getFailureId()); } Set<String> onePlatformMappings = oneDataRootDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); Set<String> anotherPlatformMappings = anotherDataDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); String oneDataRootMappingName = null; if (onePlatformMappings.iterator().hasNext()) { oneDataRootMappingName = onePlatformMappings.iterator().next(); } String anotherDataRootMappingName = null; if (anotherPlatformMappings.iterator().hasNext()) { anotherDataRootMappingName = anotherPlatformMappings.iterator().next(); } if ((oneDataRootMappingName == null && anotherDataRootMappingName != null) || (oneDataRootMappingName != null && anotherDataRootMappingName == null)) { throw new ValidationException("Platform data-root is missing in one." , ValidationFailureId.PLATFORM_DATA_ROOT_MISSING_IN_ONE.getFailureId()); } if (oneDataRootMappingName != null) { if (!oneDataRootMappingName.equals(anotherDataRootMappingName)) { throw new ValidationException("Different data-roots are configured for platform usage in different elements." , ValidationFailureId.DIFFERENT_PLATFORM_DATA_ROOTS.getFailureId()); } } } DataRootValidator(Function<Element, DataDirectories> resourcesTypeSupplier); }
DataRootValidator implements ConfigValidator { public void validateAgainst(Element oneFragment, Element otherFragment) throws ValidationException { DataDirectories oneDataDirs = getDataDirectoriesObject(oneFragment); DataDirectories anotherDataDirs = getDataDirectoriesObject(otherFragment); if (oneDataDirs.getDirectory().size() != anotherDataDirs.getDirectory().size()) { throw new ValidationException("Number of data-root directories are not matching." , ValidationFailureId.MISMATCHED_DATA_DIR_RESOURCE_NUMBERS.getFailureId()); } Map<String, DataRootMapping> oneDataRootDirectoryNames = oneDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); Map<String, DataRootMapping> anotherDataDirectoryNames = anotherDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); if (!oneDataRootDirectoryNames.keySet().equals(anotherDataDirectoryNames.keySet())) { throw new ValidationException("Mismatched data-root names." , ValidationFailureId.MISMATCHED_DATA_DIR_NAMES.getFailureId()); } Set<String> onePlatformMappings = oneDataRootDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); Set<String> anotherPlatformMappings = anotherDataDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); String oneDataRootMappingName = null; if (onePlatformMappings.iterator().hasNext()) { oneDataRootMappingName = onePlatformMappings.iterator().next(); } String anotherDataRootMappingName = null; if (anotherPlatformMappings.iterator().hasNext()) { anotherDataRootMappingName = anotherPlatformMappings.iterator().next(); } if ((oneDataRootMappingName == null && anotherDataRootMappingName != null) || (oneDataRootMappingName != null && anotherDataRootMappingName == null)) { throw new ValidationException("Platform data-root is missing in one." , ValidationFailureId.PLATFORM_DATA_ROOT_MISSING_IN_ONE.getFailureId()); } if (oneDataRootMappingName != null) { if (!oneDataRootMappingName.equals(anotherDataRootMappingName)) { throw new ValidationException("Different data-roots are configured for platform usage in different elements." , ValidationFailureId.DIFFERENT_PLATFORM_DATA_ROOTS.getFailureId()); } } } DataRootValidator(Function<Element, DataDirectories> resourcesTypeSupplier); void validate(Element fragment); void validateAgainst(Element oneFragment, Element otherFragment); }
DataRootValidator implements ConfigValidator { public void validateAgainst(Element oneFragment, Element otherFragment) throws ValidationException { DataDirectories oneDataDirs = getDataDirectoriesObject(oneFragment); DataDirectories anotherDataDirs = getDataDirectoriesObject(otherFragment); if (oneDataDirs.getDirectory().size() != anotherDataDirs.getDirectory().size()) { throw new ValidationException("Number of data-root directories are not matching." , ValidationFailureId.MISMATCHED_DATA_DIR_RESOURCE_NUMBERS.getFailureId()); } Map<String, DataRootMapping> oneDataRootDirectoryNames = oneDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); Map<String, DataRootMapping> anotherDataDirectoryNames = anotherDataDirs.getDirectory() .stream() .collect(Collectors.toMap(DataRootMapping::getName, Function.identity())); if (!oneDataRootDirectoryNames.keySet().equals(anotherDataDirectoryNames.keySet())) { throw new ValidationException("Mismatched data-root names." , ValidationFailureId.MISMATCHED_DATA_DIR_NAMES.getFailureId()); } Set<String> onePlatformMappings = oneDataRootDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); Set<String> anotherPlatformMappings = anotherDataDirectoryNames.entrySet() .stream() .filter(entry -> entry.getValue().isUseForPlatform()) .map(drm -> drm.getValue().getName()) .collect(Collectors.toSet()); String oneDataRootMappingName = null; if (onePlatformMappings.iterator().hasNext()) { oneDataRootMappingName = onePlatformMappings.iterator().next(); } String anotherDataRootMappingName = null; if (anotherPlatformMappings.iterator().hasNext()) { anotherDataRootMappingName = anotherPlatformMappings.iterator().next(); } if ((oneDataRootMappingName == null && anotherDataRootMappingName != null) || (oneDataRootMappingName != null && anotherDataRootMappingName == null)) { throw new ValidationException("Platform data-root is missing in one." , ValidationFailureId.PLATFORM_DATA_ROOT_MISSING_IN_ONE.getFailureId()); } if (oneDataRootMappingName != null) { if (!oneDataRootMappingName.equals(anotherDataRootMappingName)) { throw new ValidationException("Different data-roots are configured for platform usage in different elements." , ValidationFailureId.DIFFERENT_PLATFORM_DATA_ROOTS.getFailureId()); } } } DataRootValidator(Function<Element, DataDirectories> resourcesTypeSupplier); void validate(Element fragment); void validateAgainst(Element oneFragment, Element otherFragment);  }