@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; } }); }
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); } }
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); } } }
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); }
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); }
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);  }