ChecklistPlanner { public List<CheckSpec> getEffectiveCheckSpecs(final List<CheckSpec> checkOverrides) { Map<String, CheckSpec> overlaid = new LinkedHashMap<>(); List<CheckSpec> overrides = new ArrayList<>(); if (checkOverrides != null) { overrides.addAll(checkOverrides); } LOGGER.trace("[getEffectiveCheckSpecs] checkOverrides: {}", checkOverrides); getSelectedChecklists() .filter(Util.traceFilter(LOGGER, "[getEffectiveCheckSpecs] selected checklist: {}")) .flatMap(checklist -> checklist.getChecks().stream()) .map(base -> applyOverrides(overrides, base)) .filter(CheckSpec::notSkipped) .forEachOrdered(checkSpec -> { if (!overlaid.containsKey(checkSpec.getName())) { overlaid.put(checkSpec.getName(), checkSpec); } }); List<CheckSpec> toReturn = new ArrayList<>(overlaid.values()); LOGGER.trace("[getEffectiveCheckSpecs] selectedChecklistChecks: {}", toReturn); overrides.stream() .filter(CheckSpec::notSkipped) .filter(spec -> overlaid.values().stream().noneMatch(spec::overrides)) .forEachOrdered(spec -> { CheckSpec merged = inactiveChecklists.stream() .flatMap(checklist -> checklist.getChecks().stream()) .filter(spec::overrides) .findFirst() .map(spec::overlay) .filter(CheckSpec::notSkipped) .orElse(spec); if (merged.mustInherit()) { CheckSpec extended = getAllChecklists() .flatMap(checklist -> checklist.getChecks().stream()) .filter(merged::inherits) .findFirst().map(merged::inherit).orElse(merged); if (extended.notAbstract()) { toReturn.add(extended); } } else { if (merged.notAbstract()) { toReturn.add(merged); } } }); LOGGER.trace("[getEffectiveCheckSpecs] effective check specs: {}", toReturn); return toReturn; } ChecklistPlanner(final List<String> activeChecklistIds); void provideChecklists(final List<Checklist> constructed); void discoverChecklists(); void discoverChecklists(final ClassLoader classLoader); void discoverChecklists(final List<File> files); List<InitStage> getInitStages(); List<CheckSpec> getEffectiveCheckSpecs(final List<CheckSpec> checkOverrides); static List<Checklist> constructChecklists(final Map<URL, List<JsonObject>> parsed); static Map<URL, List<JsonObject>> parseChecklists(final URL manifestUrl); static Map<URL, List<JsonObject>> parseChecklists(final ClassLoader classLoader); static Map<URL, List<JsonObject>> parseChecklists(final List<File> files); static final String OAKPAL_CHECKLIST; static final String OAKPAL_MODULENAME; static final String BUNDLE_SYMBOLICNAME; static final String AUTOMATIC_MODULE_NAME; }
@Test public void testGetEffectiveCheckSpecs() throws Exception { ChecklistPlanner planner = new ChecklistPlanner(Arrays.asList(CKL_NAME_ALPHA, CKL_NAME_BRAVO_1)); planner.provideChecklists(constructIndivChecklists()); List<CheckSpec> effNoOverrides = planner.getEffectiveCheckSpecs(null); assertEquals("effective checks size should be", 2, effNoOverrides.size()); assertEquals("first should be alpha", CKL_NAME_ALPHA + "/pathy", effNoOverrides.get(0).getName()); assertEquals("second should be bravo/bravo-1", CKL_ID_BRAVO_1 + "/pathy", effNoOverrides.get(1).getName()); final CheckSpec pathyOverride = new CheckSpec(); pathyOverride.setName("pathy"); pathyOverride.setSkip(true); List<CheckSpec> effOneOverride = planner.getEffectiveCheckSpecs(Collections.singletonList(pathyOverride)); assertEquals("effective checks size should be", 0, effOneOverride.size()); final CheckSpec alphaPathyOverride = new CheckSpec(); alphaPathyOverride.setName("alpha/pathy"); alphaPathyOverride.setSkip(true); List<CheckSpec> effOneAlphaOverride = planner.getEffectiveCheckSpecs(Collections.singletonList(alphaPathyOverride)); assertEquals("effective checks size should be", 1, effOneAlphaOverride.size()); final CheckSpec alphaPathy2Override = new CheckSpec(); alphaPathy2Override.setName("pathy2"); alphaPathy2Override.setTemplate("alpha/pathy"); List<CheckSpec> effOneAlphaInherit = planner.getEffectiveCheckSpecs(Arrays.asList(alphaPathyOverride, alphaPathy2Override)); assertEquals("effective checks size should be", 2, effOneAlphaInherit.size()); final CheckSpec implSpec = new CheckSpec(); implSpec.setImpl("foo"); List<CheckSpec> effWithImplSpec = planner.getEffectiveCheckSpecs(Arrays.asList(alphaPathyOverride, alphaPathy2Override, implSpec)); assertEquals("effective checks size should be", 3, effWithImplSpec.size()); }