BundleMetadataBuilder { public BundleMetadata build(final AnnotatedBundle annotatedBundle, final Bundle bundle, final List<Entity> dependentEntities, ProjectInfo projectInfo) { if (annotatedBundle != null && annotatedBundle.getAnnotatedEntity() != null) { AnnotatedEntity<? extends GatewayEntity> annotatedEntity = annotatedBundle.getAnnotatedEntity(); final String bundleName = annotatedBundle.getBundleName(); String name = bundleName; if (StringUtils.isNotBlank(projectInfo.getVersion())) { name = bundleName.substring(0, bundleName.indexOf(projectInfo.getVersion()) - 1); } BundleMetadata.Builder builder = new BundleMetadata.Builder(annotatedEntity.getEntityType(), name, projectInfo.getName(), projectInfo.getGroupName(), projectInfo.getVersion()); builder.description(annotatedEntity.getDescription()); final Collection<Metadata> referencedEntities = getEnvironmentDependenciesMetadata(dependentEntities); builder.referencedEntities(referencedEntities); if (!referencedEntities.isEmpty()) { annotatedBundle.getDependentBundles().add(generateDependentEnvBundleFromProject(projectInfo)); } builder.dependencies(annotatedBundle.getDependentBundles()); builder.tags(annotatedEntity.getTags()); builder.redeployable(annotatedEntity.isRedeployable() || (MappingActions.NEW_OR_UPDATE.equals(EntityBuilderHelper.getDefaultEntityMappingAction()) && !isBundleContainsSharedEntity(annotatedBundle))); builder.l7Template(annotatedEntity.isL7Template()); builder.hasRouting(hasRoutingAssertion(dependentEntities)); final List<Metadata> definedEntities = new ArrayList<>(); definedEntities.add(annotatedEntity.getEntity().getMetadata()); return builder.definedEntities(definedEntities).build(); } else { return buildFullBundleMetadata(dependentEntities, bundle, projectInfo); } } @Inject  BundleMetadataBuilder(final IdGenerator idGenerator); BundleMetadata build(final AnnotatedBundle annotatedBundle, final Bundle bundle, final List<Entity> dependentEntities,
                                ProjectInfo projectInfo); BundleMetadata buildEnvironmentMetadata(final List<Entity> entities, ProjectInfo projectInfo);  }
@Test public void testAnnotatedEncassMetadata() throws JsonProcessingException { 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, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(bundles); assertEquals(1, bundles.size()); BundleMetadata metadata = bundles.get(TEST_ENCASS_ANNOTATION_NAME + "-1.0").getBundleMetadata(); assertNotNull(metadata); assertEquals(TEST_ENCASS_ANNOTATION_NAME, metadata.getName()); assertEquals(TEST_ENCASS_ANNOTATION_DESC, metadata.getDescription()); assertEquals(TEST_ENCASS_ANNOTATION_TAGS, metadata.getTags()); assertTrue(metadata.isL7Template()); verifyAnnotatedEncassBundleMetadata(bundles, bundle, encass, false, false, true); }
@Test public void testAnnotatedServiceMetadata() throws JsonProcessingException { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundleForService(true); Service service = buildTestServiceWithAnnotation(TEST_SERVICE, TEST_SERVICE_ID, TEST_SERVICE); bundle.getServices().put(TEST_SERVICE, service); Map<String, BundleArtifacts> bundles = builder.build(bundle, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(bundles); assertEquals(1, bundles.size()); BundleMetadata metadata = bundles.get(TEST_SERVICE_ANNOTATION_NAME + "-1.0").getBundleMetadata(); assertNotNull(metadata); assertTrue(metadata.isHasRouting()); assertEquals(TEST_SERVICE_ANNOTATION_NAME, metadata.getName()); assertEquals(TEST_SERVICE_ANNOTATION_DESC, metadata.getDescription()); assertEquals(TEST_SERVICE_ANNOTATION_TAGS, metadata.getTags()); assertFalse(metadata.isL7Template()); verifyAnnotatedServiceBundleMetadata(bundles, bundle, service, false, true, true); }
@Test public void testAnnotatedEncassMetadata_ExcludingOptionalAnnotationFields() throws JsonProcessingException { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundle(ENCASS_POLICY_WITH_ENV_DEPENDENCIES, true, true, true, projectInfo); Encass encass = buildTestEncassWithAnnotation(TEST_GUID, TEST_ENCASS_POLICY, true); encass.getAnnotations().forEach(a -> { a.setId(null); a.setName(null); a.setDescription(null); a.setTags(Collections.emptySet()); }); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); Map<String, BundleArtifacts> bundles = builder.build(bundle, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(bundles); assertEquals(1, bundles.size()); BundleMetadata metadata = bundles.get("my-bundle-" + encass.getName() + "-1.0").getBundleMetadata(); assertNotNull(metadata); assertNotNull(metadata.getDefinedEntities().iterator().next().getId()); assertEquals("my-bundle-" + encass.getName(), metadata.getName()); assertEquals(encass.getProperties().get("description"), metadata.getDescription()); assertEquals(0, metadata.getTags().size()); verifyAnnotatedEncassBundleMetadata(bundles, bundle, encass, true, true, true); }
@Test public void testHasRoutingInMetadata() { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundle(BASIC_ENCASS_POLICY, false, false, 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, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), new ProjectInfo("my-bundle", "my-bundle-group", "1.0")); assertNotNull(bundles); assertEquals(1, bundles.size()); BundleMetadata metadata = bundles.get(TEST_ENCASS_ANNOTATION_NAME + "-1.0").getBundleMetadata(); assertNotNull(metadata); assertEquals(TEST_ENCASS_ANNOTATION_NAME, metadata.getName()); assertFalse(metadata.isHasRouting()); }
@Test public void testEnvironmentBundleMetadata() throws JsonProcessingException { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundle(ENCASS_POLICY_WITH_ENV_DEPENDENCIES, true, true, false, projectInfo); Encass encass = buildTestEncassWithAnnotation(TEST_ENCASS, TEST_ENCASS_ID, TEST_GUID, TEST_ENCASS_POLICY, Collections.emptySet()); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); Map<String, BundleArtifacts> bundles = builder.build(bundle, EntityBuilder.BundleType.ENVIRONMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo, true); assertNotNull(bundles); assertEquals(1, bundles.size()); BundleMetadata metadata = bundles.get(projectInfo.getName() + "-" + projectInfo.getVersion()).getBundleMetadata(); assertNotNull(metadata); assertEquals(projectInfo.getName() + "-environment", metadata.getName()); assertEquals(projectInfo.getGroupName(), metadata.getGroupName()); assertEquals(projectInfo.getVersion() + "-qa", metadata.getVersion()); assertEquals(EntityBuilder.BundleType.ENVIRONMENT.name(), metadata.getType()); assertEquals(StringUtils.EMPTY, metadata.getDescription()); List<String> tags = new ArrayList<>(); tags.add("qa"); assertEquals(tags, metadata.getTags()); assertTrue(metadata.isRedeployable()); assertFalse(metadata.isL7Template()); Collection<Metadata> definedEntities = metadata.getDefinedEntities(); assertEquals(3, definedEntities.size()); definedEntities.stream().forEach(definedEntityData -> { switch (definedEntityData.getType()) { case EntityTypes.JDBC_CONNECTION: assertEquals("::" + metadata.getGroupName() + "::" + "some-jdbc" + "::1.0", definedEntityData.getName()); break; case EntityTypes.TRUSTED_CERT_TYPE: assertEquals("apim-hugh-new.lvn.broadcom.net", definedEntityData.getName()); break; case EntityTypes.STORED_PASSWORD_TYPE: assertEquals("secure-pass", definedEntityData.getName()); break; default: break; } }); }
@Test public void testUnAnnotatedBundleMetadata() throws JsonProcessingException { BundleEntityBuilder builder = createBundleEntityBuilder(); Bundle bundle = createBundle(ENCASS_POLICY_WITH_ENV_DEPENDENCIES, true, false, false, projectInfo); Encass encass = buildTestEncassWithAnnotation(TEST_ENCASS, TEST_ENCASS_ID, TEST_GUID, TEST_ENCASS_POLICY, Collections.emptySet()); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); Map<String, BundleArtifacts> bundles = builder.build(bundle, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), projectInfo); assertNotNull(bundles); assertEquals(1, bundles.size()); BundleMetadata metadata = bundles.get(projectInfo.getName() + "-1.0").getBundleMetadata(); assertNotNull(metadata); assertEquals(projectInfo.getName(), metadata.getName()); assertEquals(projectInfo.getGroupName(), metadata.getGroupName()); assertEquals(BUNDLE_TYPE_ALL, metadata.getType()); assertEquals(StringUtils.EMPTY, metadata.getDescription()); assertEquals(Collections.emptyList(), metadata.getTags()); assertTrue(metadata.isRedeployable()); assertFalse(metadata.isL7Template()); Collection<Metadata> definedEntities = metadata.getDefinedEntities(); assertEquals(2, definedEntities.size()); definedEntities.stream().forEach(definedEntityData -> { switch (definedEntityData.getType()) { case EntityTypes.ENCAPSULATED_ASSERTION_TYPE: assertEquals(TEST_ENCASS, definedEntityData.getName()); assertEquals(TEST_ENCASS_ID, definedEntityData.getId()); assertEquals(TEST_GUID, definedEntityData.getGuid()); break; case EntityTypes.POLICY_TYPE: assertEquals(TEST_ENCASS_POLICY, definedEntityData.getName()); assertEquals(TEST_POLICY_ID, definedEntityData.getId()); assertEquals(TEST_GUID, definedEntityData.getGuid()); break; default: break; } }); }