ScheduledTaskLinker implements EntityLinker<ScheduledTask> { @Override public void link(ScheduledTask scheduledTaskEntity, Bundle bundle, Bundle targetBundle) { Policy policy = bundle.getPolicies().values().stream().filter(p -> scheduledTaskEntity.getPolicy().equals(p.getId())).findFirst().orElse(null); if (policy == null) { throw new LinkerException("Could not find policy for Scheduled Task: " + scheduledTaskEntity.getName() + ". Policy ID: " + scheduledTaskEntity.getPolicy()); } scheduledTaskEntity.setPolicy(getPolicyPath(policy, bundle, scheduledTaskEntity)); }  @Override Class<ScheduledTask> getEntityClass(); @Override void link(ScheduledTask scheduledTaskEntity, Bundle bundle, Bundle targetBundle);  }
@Test void link() { Bundle fullBundle = new Bundle(); fullBundle.addEntity(mySTask); fullBundle.addEntity(createPolicy("myScheduledPolicy", "1", "1", "1", null, "")); fullBundle.addEntity(createFolder("myFolder", "1", null)); FolderTree folderTree = new FolderTree(fullBundle.getEntities(Folder.class).values()); fullBundle.setFolderTree(folderTree); scheduledTaskLinker.link(bundle, fullBundle); assertEquals("myScheduledPolicy", bundle.getEntities(ScheduledTask.class).get("1").getPolicy()); }
@Test void linkMissingPolicy() { Bundle fullBundle = new Bundle(); fullBundle.addEntity(mySTask); fullBundle.addEntity(createFolder("folder", "1", null)); FolderTree folderTree = new FolderTree(fullBundle.getEntities(Folder.class).values()); fullBundle.setFolderTree(folderTree); assertThrows(LinkerException.class, () -> scheduledTaskLinker.link(bundle, fullBundle)); }
@Test void linkFolderIsMissing() { Bundle fullBundle = new Bundle(); fullBundle.addEntity(mySTask); fullBundle.addEntity(createPolicy("myScheduledPolicy", "1", "1", "1", null, "")); fullBundle.addEntity(createFolder("myFolder", "2", null)); FolderTree folderTree = new FolderTree(fullBundle.getEntities(Folder.class).values()); fullBundle.setFolderTree(folderTree); assertThrows(LinkerException.class, () -> scheduledTaskLinker.link(bundle, fullBundle)); }