UpdatePartIterationPSFilter implements ProductStructureFilter, Serializable { @Override public List<PartIteration> filter(PartMaster part) { if(part.getKey().equals(rootKey)){ return Collections.singletonList(partIteration); } List<PartIteration> partIterations = new ArrayList<>(); PartRevision partRevision = part.getLastRevision(); PartIteration lastIteration = partRevision.getLastIteration(); PartIteration lastCheckedInIteration = partRevision.getLastCheckedInIteration(); if(partRevision.isCheckedOut() && lastCheckedInIteration != null){ partIterations.add(lastCheckedInIteration); } partIterations.add(lastIteration); return partIterations; } UpdatePartIterationPSFilter(PartIteration partIteration); @Override List<PartIteration> filter(PartMaster part); @Override List<PartLink> filter(List<PartLink> path);  }
@Test public void filterTestWithPartMasterAsParameterTest(){ PartMaster partMaster = getPartMasterWith("PART-002"); List<PartIteration> result = updatePartIterationPSFilter.filter(partMaster); assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals(partMaster.getLastRevision().getLastIteration(), result.get(0)); generateStructureForTest(); partMaster = getPartMasterWith("PART-001"); result = updatePartIterationPSFilter.filter(partMaster); assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals(partMaster.getLastRevision().getLastIteration(), result.get(0)); partMaster.getLastRevision().setCheckOutUser(user); result = updatePartIterationPSFilter.filter(partMaster); assertFalse(result.isEmpty()); assertEquals(1, result.size()); assertEquals(partMaster.getLastRevision().getLastIteration(), result.get(0)); addIterationTo( partMaster.getNumber(), partMaster.getLastRevision().createNextIteration(user)); assertTrue(partMaster.getLastRevision().isCheckedOut()); result = updatePartIterationPSFilter.filter(partMaster); assertFalse(result.isEmpty()); assertEquals(2, result.size()); assertEquals(1, result.get(0).getIteration()); assertEquals(2, result.get(1).getIteration()); }
@Test public void filterTestWithListPartLinkAsParameterTest(){ generateSomeReleasedRevisionWithSubstitutesFor("PART-001"); PartMaster partMaster = getPartMasterWith("PART-001"); List<PartLink> links = new ArrayList<>((partMaster.getLastRevision().getLastIteration().getComponents())); List<PartLink> result = updatePartIterationPSFilter.filter(links); assertFalse(result.isEmpty()); assertEquals(5,result.size()); assertEquals("PART-016-UsageLink", result.get(0).getReferenceDescription()); assertEquals("PART-018-Substitute", result.get(1).getReferenceDescription()); assertEquals("PART-015-Substitute", result.get(2).getReferenceDescription()); assertEquals("PART-009-Substitute", result.get(3).getReferenceDescription()); assertEquals("PART-012-Substitute", result.get(4).getReferenceDescription()); }