EncassLinker implements EntityLinker<Encass> { @Override public void link(Encass encass, Bundle bundle, Bundle targetBundle) { Policy policy = bundle.getPolicies().values().stream().filter(p -> encass.getPolicyId().equals(p.getId())).findFirst().orElse(null); if (policy == null) { throw new LinkerException("Could not find policy for Encapsulated Assertion: " + encass.getName() + ". Policy ID: " + encass.getPolicyId()); } encass.getProperties().put(L7_TEMPLATE, encassPolicyXMLSimplifier.simplifyEncassPolicyXML(policy)); encass.setPolicy(policy.getPath()); encass.setPath(getPolicyPath(policy, bundle, encass)); } @Inject  EncassLinker(EncassPolicyXMLSimplifier encassPolicyXMLSimplifier); @Override Class<Encass> getEntityClass(); @Override void link(Encass encass, Bundle bundle, Bundle targetBundle);  }
@Test void link() throws DocumentParseException { Bundle fullBundle = new Bundle(); myEncass.setProperties(new HashMap<String, Object>() {{ put(PALETTE_FOLDER, DEFAULT_PALETTE_FOLDER_LOCATION); }}); fullBundle.addEntity(myEncass); fullBundle.addEntity(createPolicy("myEncassPolicy", "1", "1", "1", DocumentUtils.stringToXML(DocumentTools.INSTANCE, ENCASS_POLICY_WITH_PORTAL_INTEGRATION), EMPTY)); fullBundle.addEntity(createFolder("myFolder", "1", null)); FolderTree folderTree = new FolderTree(fullBundle.getEntities(Folder.class).values()); fullBundle.setFolderTree(folderTree); encassLinker.link(bundle, fullBundle); assertEquals("myEncassPolicy", bundle.getEntities(Encass.class).get("1").getPath()); }
@Test void linkMissingPolicy() { Bundle fullBundle = new Bundle(); fullBundle.addEntity(myEncass); fullBundle.addEntity(createFolder("myFolder", "1", null)); FolderTree folderTree = new FolderTree(fullBundle.getEntities(Folder.class).values()); fullBundle.setFolderTree(folderTree); assertThrows(LinkerException.class, () -> encassLinker.link(bundle, fullBundle)); }
@Test void linkFolderIsMissing() throws DocumentParseException { Bundle fullBundle = new Bundle(); myEncass.setProperties(new HashMap<String, Object>() {{ put(PALETTE_FOLDER, DEFAULT_PALETTE_FOLDER_LOCATION); }}); fullBundle.addEntity(myEncass); fullBundle.addEntity(createPolicy("myEncassPolicy", "1","1", "1", DocumentUtils.stringToXML(DocumentTools.INSTANCE, ENCASS_POLICY_WITH_PORTAL_INTEGRATION), "")); fullBundle.addEntity(createFolder("myFolder", "2", null)); FolderTree folderTree = new FolderTree(fullBundle.getEntities(Folder.class).values()); fullBundle.setFolderTree(folderTree); assertThrows(LinkerException.class, () -> encassLinker.link(bundle, fullBundle)); }
@Test void linkPortalTemplateFlag() throws DocumentParseException { Bundle fullBundle = new Bundle(); myEncass.setProperties(new HashMap<String, Object>() {{ put(PALETTE_FOLDER, DEFAULT_PALETTE_FOLDER_LOCATION); }}); fullBundle.addEntity(myEncass); fullBundle.addEntity(createPolicy("myEncassPolicy", "1","1", "1", DocumentUtils.stringToXML(DocumentTools.INSTANCE, ENCASS_POLICY_WITH_PORTAL_INTEGRATION), EMPTY)); fullBundle.addEntity(createFolder("myFolder", "1", null)); FolderTree folderTree = new FolderTree(fullBundle.getEntities(Folder.class).values()); fullBundle.setFolderTree(folderTree); encassLinker.link(bundle, fullBundle); Encass linkedEncass = bundle.getEntities(Encass.class).get("1"); assertEquals("myEncassPolicy", linkedEncass.getPath()); assertEquals(2, linkedEncass.getProperties().size()); assertTrue(Boolean.valueOf(linkedEncass.getProperties().get(L7_TEMPLATE).toString())); Policy updatedPolicy = fullBundle.getEntities(Policy.class).get("1"); assertThrows(DocumentParseException.class, () -> getSingleElement(updatedPolicy.getPolicyDocument(), API_PORTAL_ENCASS_INTEGRATION)); }
@Test void linkPortalTemplateDisabledFlag() throws DocumentParseException { Bundle fullBundle = new Bundle(); myEncass.setProperties(new HashMap<String, Object>() {{ put(PALETTE_FOLDER, DEFAULT_PALETTE_FOLDER_LOCATION); }}); fullBundle.addEntity(myEncass); fullBundle.addEntity(createPolicy("myEncassPolicy", "1","1", "1", DocumentUtils.stringToXML(DocumentTools.INSTANCE, ENCASS_POLICY_WITH_PORTAL_INTEGRATION_DISABLED), EMPTY)); fullBundle.addEntity(createFolder("myFolder", "1", null)); FolderTree folderTree = new FolderTree(fullBundle.getEntities(Folder.class).values()); fullBundle.setFolderTree(folderTree); encassLinker.link(bundle, fullBundle); Encass linkedEncass = bundle.getEntities(Encass.class).get("1"); assertEquals("myEncassPolicy", linkedEncass.getPath()); assertEquals(2, linkedEncass.getProperties().size()); assertFalse(Boolean.valueOf(linkedEncass.getProperties().get(L7_TEMPLATE).toString())); Policy updatedPolicy = fullBundle.getEntities(Policy.class).get("1"); assertThrows(DocumentParseException.class, () -> getSingleElement(updatedPolicy.getPolicyDocument(), API_PORTAL_ENCASS_INTEGRATION)); }