BundleEntityBuilder { public Map<String, BundleArtifacts> build(Bundle bundle, BundleType bundleType, Document document, ProjectInfo projectInfo) { return build(bundle, bundleType, document, projectInfo, false); } @Inject  BundleEntityBuilder(final Set<EntityBuilder> entityBuilders, final BundleDocumentBuilder bundleDocumentBuilder,
                        final BundleMetadataBuilder bundleMetadataBuilder,
                        final EntityTypeRegistry entityTypeRegistry, PrivateKeyImportContextBuilder privateKeyImportContextBuilder); Map<String, BundleArtifacts> build(Bundle bundle, BundleType bundleType,
                                              Document document, ProjectInfo projectInfo); Map<String, BundleArtifacts> build(Bundle bundle, BundleType bundleType,
                                              Document document, ProjectInfo projectInfo, boolean generateMetadata); void addPrivateKeyContexts(Bundle bundle, ProjectInfo projectInfo, BundleArtifacts bundleArtifacts,
                                      Document document); @VisibleForTesting Set<EntityBuilder> getEntityBuilders();  }
@Test void build() { BundleEntityBuilder builder = new BundleEntityBuilder(singleton(new TestEntityBuilder()), new BundleDocumentBuilder(), new BundleMetadataBuilder(ID_GENERATOR), entityTypeRegistry, new PrivateKeyImportContextBuilder()); final Map<String, BundleArtifacts> element = builder.build(new Bundle(), DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(element); }
@Test public void testAnnotatedEncassDeleteBundle() { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundle(ENCASS_POLICY_WITH_ENV_DEPENDENCIES, true, true, false, projectInfo); Encass encass = buildTestEncassWithAnnotation(TEST_GUID, TEST_ENCASS_POLICY, false); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); Map<String, BundleArtifacts> bundles = builder.build(bundle, DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(bundles); assertEquals(1, bundles.size()); Element deleteBundleElement = bundles.get(TEST_ENCASS_ANNOTATION_NAME + "-1.0").getDeleteBundle().getElement(); assertNotNull(deleteBundleElement); assertEquals(BundleDocumentBuilder.GATEWAY_MANAGEMENT, deleteBundleElement.getAttribute(BundleDocumentBuilder.L7)); assertEquals(BUNDLE, deleteBundleElement.getTagName()); final int expectedElementCountBundle = 2; final Element references = getSingleChildElement(deleteBundleElement, REFERENCES); assertNotNull(references); final List<Element> itemList = getChildElements(references, ITEM); assertNotNull(itemList); assertEquals(expectedElementCountBundle, itemList.size()); final Element item1 = itemList.get(1); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion() , getSingleChildElementTextContent(item1, NAME)); assertEquals(EntityTypes.POLICY_TYPE, getSingleChildElementTextContent(item1, TYPE)); assertNotNull(getSingleChildElement(item1, RESOURCE)); final Element item2 = itemList.get(0); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion(), getSingleChildElementTextContent(item2, NAME)); assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, getSingleChildElementTextContent(item2, TYPE)); assertNotNull(getSingleChildElement(item2, RESOURCE)); final Element mappings = getSingleChildElement(deleteBundleElement, MAPPINGS); assertNotNull(mappings); final List<Element> mappingItemList = getChildElements(mappings, MAPPING); assertEquals(expectedElementCountBundle, mappingItemList.size()); final Element mapping1 = mappingItemList.get(1); assertEquals(MappingActions.DELETE, mapping1.getAttribute("action")); assertEquals(EntityTypes.POLICY_TYPE, mapping1.getAttribute("type")); final Element mapping2 = mappingItemList.get(0); assertEquals(MappingActions.DELETE, mapping2.getAttribute("action")); assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, mapping2.getAttribute("type")); }
@Test public void testAnnotatedEncassDeleteBundle_WithPolicyFragment() { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundleWithPolicyFragment(false, projectInfo); Encass encass = buildTestEncassWithAnnotation(TEST_GUID, TEST_ENCASS_POLICY, false); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); Map<String, BundleArtifacts> bundles = builder.build(bundle, DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(bundles); assertEquals(1, bundles.size()); Element deleteBundleElement = bundles.get(TEST_ENCASS_ANNOTATION_NAME + "-1.0").getDeleteBundle().getElement(); assertNotNull(deleteBundleElement); assertEquals(BundleDocumentBuilder.GATEWAY_MANAGEMENT, deleteBundleElement.getAttribute(BundleDocumentBuilder.L7)); assertEquals(BUNDLE, deleteBundleElement.getTagName()); final int expectedElementCountBundle = 3; final Element references = getSingleChildElement(deleteBundleElement, REFERENCES); assertNotNull(references); final List<Element> itemList = getChildElements(references, ITEM); assertNotNull(itemList); assertEquals(expectedElementCountBundle, itemList.size()); final Element item1 = itemList.get(2); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_POLICY_FRAGMENT + "::" + projectInfo.getVersion() , getSingleChildElementTextContent(item1, NAME)); assertEquals(EntityTypes.POLICY_TYPE, getSingleChildElementTextContent(item1, TYPE)); assertNotNull(getSingleChildElement(item1, RESOURCE)); final Element item2 = itemList.get(1); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion() , getSingleChildElementTextContent(item2, NAME)); assertEquals(EntityTypes.POLICY_TYPE, getSingleChildElementTextContent(item2, TYPE)); assertNotNull(getSingleChildElement(item2, RESOURCE)); final Element item3 = itemList.get(0); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion(), getSingleChildElementTextContent(item3, NAME)); assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, getSingleChildElementTextContent(item3, TYPE)); assertNotNull(getSingleChildElement(item3, RESOURCE)); final Element mappings = getSingleChildElement(deleteBundleElement, MAPPINGS); assertNotNull(mappings); final List<Element> mappingItemList = getChildElements(mappings, MAPPING); assertEquals(expectedElementCountBundle, mappingItemList.size()); final Element mapping1 = mappingItemList.get(2); final Element mapping1Properties = getSingleChildElement(mapping1, PROPERTIES); Set<String> propertyValues = getChildElementsTextContents(mapping1Properties, PROPERTY); assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_POLICY_FRAGMENT + "::" + projectInfo.getVersion())); assertEquals(MappingActions.DELETE, mapping1.getAttribute("action")); assertEquals(EntityTypes.POLICY_TYPE, mapping1.getAttribute("type")); final Element mapping2 = mappingItemList.get(1); final Element mapping2Properties = getSingleChildElement(mapping2, PROPERTIES); propertyValues = getChildElementsTextContents(mapping2Properties, PROPERTY); assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion())); assertEquals(MappingActions.DELETE, mapping2.getAttribute("action")); assertEquals(EntityTypes.POLICY_TYPE, mapping2.getAttribute("type")); final Element mapping3 = mappingItemList.get(0); final Element mapping3Properties = getSingleChildElement(mapping3, PROPERTIES); propertyValues = getChildElementsTextContents(mapping3Properties, PROPERTY); assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion())); assertEquals(MappingActions.DELETE, mapping3.getAttribute("action")); assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, mapping3.getAttribute("type")); }
@Test public void testAnnotatedEncassDeleteBundle_WithSharedPolicyFragment_RedeployableBundle() { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundleWithPolicyFragment(false, projectInfo); Encass encass = buildTestEncassWithAnnotation(TEST_GUID, TEST_ENCASS_POLICY, true); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); Map<String, BundleArtifacts> bundles = builder.build(bundle, DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(bundles); assertEquals(1, bundles.size()); Element deleteBundleElement = bundles.get(TEST_ENCASS_ANNOTATION_NAME + "-1.0").getDeleteBundle().getElement(); assertNotNull(deleteBundleElement); assertEquals(BundleDocumentBuilder.GATEWAY_MANAGEMENT, deleteBundleElement.getAttribute(BundleDocumentBuilder.L7)); assertEquals(BUNDLE, deleteBundleElement.getTagName()); final int expectedElementCountBundle = 3; final Element references = getSingleChildElement(deleteBundleElement, REFERENCES); assertNotNull(references); final List<Element> itemList = getChildElements(references, ITEM); assertNotNull(itemList); assertEquals(expectedElementCountBundle, itemList.size()); final Element item1 = itemList.get(2); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_POLICY_FRAGMENT + "::" + projectInfo.getVersion(), getSingleChildElementTextContent(item1, NAME)); assertEquals(EntityTypes.POLICY_TYPE, getSingleChildElementTextContent(item1, TYPE)); assertNotNull(getSingleChildElement(item1, RESOURCE)); final Element item2 = itemList.get(1); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion(), getSingleChildElementTextContent(item2, NAME)); assertEquals(EntityTypes.POLICY_TYPE, getSingleChildElementTextContent(item2, TYPE)); assertNotNull(getSingleChildElement(item2, RESOURCE)); final Element item3 = itemList.get(0); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion(), getSingleChildElementTextContent(item3, NAME)); assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, getSingleChildElementTextContent(item3, TYPE)); assertNotNull(getSingleChildElement(item3, RESOURCE)); final Element mappings = getSingleChildElement(deleteBundleElement, MAPPINGS); assertNotNull(mappings); final List<Element> mappingItemList = getChildElements(mappings, MAPPING); assertEquals(expectedElementCountBundle, mappingItemList.size()); final Element mapping1 = mappingItemList.get(2); final Element mapping1Properties = getSingleChildElement(mapping1, PROPERTIES); Set<String> propertyValues = getChildElementsTextContents(mapping1Properties, PROPERTY); assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_POLICY_FRAGMENT + "::" + projectInfo.getVersion())); assertEquals(MappingActions.DELETE, mapping1.getAttribute("action")); assertEquals(EntityTypes.POLICY_TYPE, mapping1.getAttribute("type")); final Element mapping2 = mappingItemList.get(1); final Element mapping2Properties = getSingleChildElement(mapping2, PROPERTIES); propertyValues = getChildElementsTextContents(mapping2Properties, PROPERTY); assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion())); assertEquals(MappingActions.DELETE, mapping2.getAttribute("action")); assertEquals(EntityTypes.POLICY_TYPE, mapping2.getAttribute("type")); final Element mapping3 = mappingItemList.get(0); final Element mapping3Properties = getSingleChildElement(mapping3, PROPERTIES); propertyValues = getChildElementsTextContents(mapping3Properties, PROPERTY); assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion())); assertEquals(MappingActions.DELETE, mapping3.getAttribute("action")); assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, mapping3.getAttribute("type")); }
@Test public void testAnnotatedEncassDeleteBundle_WithSharedPolicyFragment() { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundleWithPolicyFragment(true, projectInfo); Encass encass = buildTestEncassWithAnnotation(TEST_GUID, TEST_ENCASS_POLICY, false); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); Map<String, BundleArtifacts> bundles = builder.build(bundle, DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(bundles); assertEquals(1, bundles.size()); Element deleteBundleElement = bundles.get(TEST_ENCASS_ANNOTATION_NAME + "-1.0").getDeleteBundle().getElement(); assertNotNull(deleteBundleElement); assertEquals(BundleDocumentBuilder.GATEWAY_MANAGEMENT, deleteBundleElement.getAttribute(BundleDocumentBuilder.L7)); assertEquals(BUNDLE, deleteBundleElement.getTagName()); final int expectedElementCountBundle = 2; final Element references = getSingleChildElement(deleteBundleElement, REFERENCES); assertNotNull(references); final List<Element> itemList = getChildElements(references, ITEM); assertNotNull(itemList); assertEquals(expectedElementCountBundle, itemList.size()); final Element item2 = itemList.get(1); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion() , getSingleChildElementTextContent(item2, NAME)); assertEquals(EntityTypes.POLICY_TYPE, getSingleChildElementTextContent(item2, TYPE)); assertNotNull(getSingleChildElement(item2, RESOURCE)); final Element item3 = itemList.get(0); assertEquals("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion(), getSingleChildElementTextContent(item3, NAME)); assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, getSingleChildElementTextContent(item3, TYPE)); assertNotNull(getSingleChildElement(item3, RESOURCE)); final Element mappings = getSingleChildElement(deleteBundleElement, MAPPINGS); assertNotNull(mappings); final List<Element> mappingItemList = getChildElements(mappings, MAPPING); assertEquals(expectedElementCountBundle, mappingItemList.size()); Set<String> propertyValues; final Element mapping2 = mappingItemList.get(1); final Element mapping2Properties = getSingleChildElement(mapping2, PROPERTIES); propertyValues = getChildElementsTextContents(mapping2Properties, PROPERTY); assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS_POLICY + "::" + projectInfo.getVersion())); assertEquals(MappingActions.DELETE, mapping2.getAttribute("action")); assertEquals(EntityTypes.POLICY_TYPE, mapping2.getAttribute("type")); final Element mapping3 = mappingItemList.get(0); final Element mapping3Properties = getSingleChildElement(mapping3, PROPERTIES); propertyValues = getChildElementsTextContents(mapping3Properties, PROPERTY); assertTrue(propertyValues.contains("::" + projectInfo.getGroupName() + "." + TEST_ENCASS_ANNOTATION_NAME + "::" + TEST_ENCASS + "::" + projectInfo.getVersion())); assertEquals(MappingActions.DELETE, mapping3.getAttribute("action")); assertEquals(EntityTypes.ENCAPSULATED_ASSERTION_TYPE, mapping3.getAttribute("type")); }