@Test void build() { Element policyElement = createElementWithAttributesAndChildren( document, "wsp:Policy", ImmutableMap.of("xmlns:L7p", "http: createSetVariableAssertion(document, "var", "value"), createIncludeAssertionElement(document, "include"), createHardcodedAssertionElement(document, "response") ); Element encassElement = createEncapsulatedAssertionElement(document, TEST_ENCASS, "encass"); encassElement.setAttribute(EncapsulatedAssertionBuilder.ENCASS_NAME, TEST_ENCASS); policyElement.appendChild(encassElement); document.appendChild(policyElement); policy.setPolicyXML(DocumentTools.INSTANCE.elementToString(document.getDocumentElement())); policy.setParentFolder(Folder.ROOT_FOLDER); policy.setGuid("policyGuid"); policy.setId("policyID"); policy.setName(policy.getPath()); Encass encass = new Encass(); encass.setGuid("encass"); encass.setName(TEST_ENCASS); Set<Annotation> annotations = new HashSet<>(); Annotation annotation = new Annotation(AnnotationType.SHARED); annotations.add(annotation); policy.setAnnotations(annotations); bundle.getEncasses().put(TEST_ENCASS, encass); bundle.getPolicies().put("Policy", policy); Policy include = new Policy(); include.setParentFolder(Folder.ROOT_FOLDER); include.setPath("test/policy/include"); include.setName(include.getPath()); include.setId("includeID"); include.setGuid("includeGuid"); annotations = new HashSet<>(); annotation = new Annotation(AnnotationType.SHARED); annotations.add(annotation); include.setAnnotations(annotations); include.setPolicyXML("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<wsp:Policy xmlns:L7p=\"http: " <wsp:All wsp:Usage=\"Required\">\n" + " <L7p:CommentAssertion>\n" + " <L7p:Comment stringValue=\"Policy Fragment: includedPolicy\"/>\n" + " </L7p:CommentAssertion>\n" + " </wsp:All>\n" + "</wsp:Policy>"); bundle.getPolicies().put("include", include); PolicyEntityBuilder builder = new PolicyEntityBuilder(DocumentTools.INSTANCE, new IdGenerator(), policyXMLBuilder); final List<Entity> entities = builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertFalse(entities.isEmpty()); assertEquals(2, entities.size()); entities.stream().collect(toMap(Entity::getId, identity())).forEach((i, e) -> { assertEquals(EntityTypes.POLICY_TYPE, e.getType()); assertNotNull(e.getXml()); assertTrue(e.getMappingProperties().containsKey(MAP_BY)); assertEquals(MappingProperties.PATH, e.getMappingProperties().get(MAP_BY)); assertTrue(e.getMappingProperties().containsKey(MAP_TO)); assertEquals(e.getName(), e.getMappingProperties().get(MAP_TO)); assertTrue("test/policy/include".equals(e.getName()) || "test/policy/path.xml".equals(e.getName())); assertTrue("includeID".equals(e.getId()) || "policyID".equals(e.getId())); }); }
public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { if (bundle instanceof AnnotatedBundle) { AnnotatedBundle annotatedBundle = (AnnotatedBundle) bundle; Map<String, Policy> map = Optional.ofNullable(bundle.getPolicies()).orElse(Collections.emptyMap()); return buildEntities(map, annotatedBundle, annotatedBundle.getFullBundle(), bundleType, document); } else { return buildEntities(bundle.getPolicies(), null, bundle, bundleType, document); } }
PolicyEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { if (bundle instanceof AnnotatedBundle) { AnnotatedBundle annotatedBundle = (AnnotatedBundle) bundle; Map<String, Policy> map = Optional.ofNullable(bundle.getPolicies()).orElse(Collections.emptyMap()); return buildEntities(map, annotatedBundle, annotatedBundle.getFullBundle(), bundleType, document); } else { return buildEntities(bundle.getPolicies(), null, bundle, bundleType, document); } } }
PolicyEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { if (bundle instanceof AnnotatedBundle) { AnnotatedBundle annotatedBundle = (AnnotatedBundle) bundle; Map<String, Policy> map = Optional.ofNullable(bundle.getPolicies()).orElse(Collections.emptyMap()); return buildEntities(map, annotatedBundle, annotatedBundle.getFullBundle(), bundleType, document); } else { return buildEntities(bundle.getPolicies(), null, bundle, bundleType, document); } } @Inject  PolicyEntityBuilder(DocumentTools documentTools, IdGenerator idGenerator, PolicyXMLBuilder policyXMLBuilder); }
PolicyEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { if (bundle instanceof AnnotatedBundle) { AnnotatedBundle annotatedBundle = (AnnotatedBundle) bundle; Map<String, Policy> map = Optional.ofNullable(bundle.getPolicies()).orElse(Collections.emptyMap()); return buildEntities(map, annotatedBundle, annotatedBundle.getFullBundle(), bundleType, document); } else { return buildEntities(bundle.getPolicies(), null, bundle, bundleType, document); } } @Inject  PolicyEntityBuilder(DocumentTools documentTools, IdGenerator idGenerator, PolicyXMLBuilder policyXMLBuilder); List<Entity> buildEntities(Map<String, ?> policyMap, AnnotatedBundle annotatedBundle, Bundle bundle, BundleType bundleType, Document document); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @NotNull @Override Integer getOrder(); static void resolvePossibleMissingEncapsulatedAssertionDependencies(Bundle bundle, Element encapsulatedAssertionElement); }
PolicyEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { if (bundle instanceof AnnotatedBundle) { AnnotatedBundle annotatedBundle = (AnnotatedBundle) bundle; Map<String, Policy> map = Optional.ofNullable(bundle.getPolicies()).orElse(Collections.emptyMap()); return buildEntities(map, annotatedBundle, annotatedBundle.getFullBundle(), bundleType, document); } else { return buildEntities(bundle.getPolicies(), null, bundle, bundleType, document); } } @Inject  PolicyEntityBuilder(DocumentTools documentTools, IdGenerator idGenerator, PolicyXMLBuilder policyXMLBuilder); List<Entity> buildEntities(Map<String, ?> policyMap, AnnotatedBundle annotatedBundle, Bundle bundle, BundleType bundleType, Document document); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @NotNull @Override Integer getOrder(); static void resolvePossibleMissingEncapsulatedAssertionDependencies(Bundle bundle, Element encapsulatedAssertionElement); static final String POLICY; static final String ZERO_GUID; }