@Test void buildDeploymentBundleWithWrongGuidAndId() { Element policyElement = createElementWithAttributesAndChildren( document, "wsp:Policy", ImmutableMap.of("xmlns:L7p", "http: createSetVariableAssertion(document, "var", "value"), 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()); Set<Annotation> annotations = new HashSet<>(); Annotation annotation = new Annotation(AnnotationType.BUNDLE_HINTS); annotation.setGuid(""); annotation.setId(""); annotations.add(annotation); annotation = new Annotation(AnnotationType.SHARED); annotations.add(annotation); policy.setAnnotations(annotations); policy.setParentEntityShared(policy.isShared()); Encass encass = new Encass(); encass.setGuid("encassGuid"); encass.setName(TEST_ENCASS); Annotation encassAnnotation = new Annotation(AnnotationType.SHARED); annotations = new HashSet<>(); annotations.add(encassAnnotation); encass.setAnnotations(annotations); encass.setParentEntityShared(encass.isShared()); bundle.getEncasses().put(TEST_ENCASS, encass); bundle.getPolicies().put("Policy", policy); AnnotatedEntity annotatedEntity = encass.getAnnotatedEntity(); annotatedEntity.setEntityName(encass.getName()); AnnotatedBundle annotatedBundle = new AnnotatedBundle(bundle, annotatedEntity, new ProjectInfo("", "", "")); annotatedBundle.putAllEncasses(org.testcontainers.shaded.com.google.common.collect.ImmutableMap.of(TEST_ENCASS, encass)); annotatedBundle.getPolicies().put("Policy", policy); PolicyEntityBuilder builder = new PolicyEntityBuilder(DocumentTools.INSTANCE, new IdGenerator(), policyXMLBuilder); List<Entity> entities = builder.build(annotatedBundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertFalse(entities.isEmpty()); assertEquals(1, entities.size()); Entity e = entities.get(0); assertEquals(EntityTypes.POLICY_TYPE, e.getType()); assertEquals(e.getId(), "policyID"); annotations = new HashSet<>(); annotation = new Annotation(AnnotationType.SHARED); annotations.add(annotation); annotation = new Annotation(AnnotationType.BUNDLE_HINTS); annotation.setGuid("wrongGuid"); annotation.setId("wrongId"); annotations.add(annotation); policy.setAnnotations(annotations); policy.setAnnotatedEntity(null); builder = new PolicyEntityBuilder(DocumentTools.INSTANCE, new IdGenerator(), policyXMLBuilder); entities = builder.build(annotatedBundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertFalse(entities.isEmpty()); assertEquals(1, entities.size()); e = entities.get(0); assertEquals(EntityTypes.POLICY_TYPE, e.getType()); assertEquals(e.getId(), "policyID"); }
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; }