ProductBaselineCreationConfigSpec extends ProductConfigSpec { @Override public PartLink filterPartLink(List<PartLink> path) { PartLink nominalLink = path.get(path.size() - 1); String pathAsString = Tools.getPathAsString(path); if (nominalLink.isOptional() && optionalUsageLinks.contains(pathAsString)) { retainedOptionalUsageLinks.add(pathAsString); } for (PartSubstituteLink substituteLink : nominalLink.getSubstitutes()) { List<PartLink> substitutePath = new ArrayList<>(path); substitutePath.set(substitutePath.size() - 1, substituteLink); String substitutePathAsString = Tools.getPathAsString(substitutePath); if (substituteLinks.contains(substitutePathAsString)) { retainedSubstituteLinks.add(substitutePathAsString); return substituteLink; } } return nominalLink; } ProductBaselineCreationConfigSpec(ProductBaselineType type, List<PartIteration> partIterations, List<String> substituteLinks, List<String> optionalUsageLinks); @Override PartIteration filterPartIteration(PartMaster partMaster); @Override PartLink filterPartLink(List<PartLink> path);  }
@Test public void filterPartLinkTest(){ PartMaster partMaster = getPartMasterWith("PART-001"); List<PartLink> links = new ArrayList<>((partMaster.getLastRevision().getLastIteration().getComponents())); PartLink result = pB2CS.filterPartLink(links); assertNotNull(result); assertEquals(links.get(links.size()-1),result); assertTrue(pB2CS.getRetainedOptionalUsageLinks().isEmpty()); assertTrue(pB2CS.getRetainedSubstituteLinks().isEmpty()); pB2CS = new ProductBaselineCreationConfigSpec(ProductBaselineType.LATEST, new ArrayList<>(), Collections.singletonList(""), Collections.singletonList("u0-u0-u0-u0-u0")); result = pB2CS.filterPartLink(links); assertNotNull(result); assertEquals(links.get(links.size() - 1), result); assertFalse(pB2CS.getRetainedOptionalUsageLinks().isEmpty()); assertTrue(pB2CS.getRetainedSubstituteLinks().isEmpty()); pB2CS = new ProductBaselineCreationConfigSpec(ProductBaselineType.LATEST, new ArrayList<>(), Collections.singletonList("u0-u0-u0-u0-s0"), Collections.singletonList("u0-u0-u0-u0-u0")); result = pB2CS.filterPartLink(links); assertNotNull(result); assertEquals("PART-018-Substitute", result.getReferenceDescription()); assertFalse(pB2CS.getRetainedOptionalUsageLinks().isEmpty()); assertFalse(pB2CS.getRetainedSubstituteLinks().isEmpty()); }