ClusterPropertyEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { Map<String, GlobalEnvironmentProperty> globalEnvironmentProperties = Optional.ofNullable(bundle.getGlobalEnvironmentProperties()).orElse(Collections.emptyMap()); Map<String, ClusterProperty> clusterPropertyMap = Optional.ofNullable(bundle.getStaticProperties()).orElse(Collections.emptyMap()); return buildEntities(globalEnvironmentProperties, clusterPropertyMap, bundleType, document); } @Inject  ClusterPropertyEntityBuilder(IdGenerator idGenerator); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @Override @NotNull Integer getOrder();  }
@Test void buildFromEmptyBundle_noProperties() { ClusterPropertyEntityBuilder builder = new ClusterPropertyEntityBuilder(ID_GENERATOR); final List<Entity> entities = builder.build(new Bundle(), BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertTrue(entities.isEmpty()); }
@Test void buildDeploymentBundleWithStaticProps() { ClusterPropertyEntityBuilder builder = new ClusterPropertyEntityBuilder(ID_GENERATOR); Bundle bundle = new Bundle(); bundle.putAllStaticProperties(STATIC_PROPS); final List<Entity> entities = builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertExpectedProperties(entities, ImmutableMap.<String, PropertiesEntity>builder().putAll(STATIC_PROPS).build()); }
@Test void buildDeploymentBundleWithMixedProps() { ClusterPropertyEntityBuilder builder = new ClusterPropertyEntityBuilder(ID_GENERATOR); Bundle bundle = new Bundle(); bundle.putAllStaticProperties(STATIC_PROPS); bundle.putAllGlobalEnvironmentProperties(ENV_PROPS); final List<Entity> entities = builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertExpectedProperties(entities, ImmutableMap.<String, PropertiesEntity>builder().putAll(STATIC_PROPS).putAll(ENV_PROPS).build()); }
@Test void buildEnvironmentBundleWithProps_ignoringStatic() { ClusterPropertyEntityBuilder builder = new ClusterPropertyEntityBuilder(ID_GENERATOR); Bundle bundle = new Bundle(); bundle.putAllStaticProperties(STATIC_PROPS); bundle.putAllGlobalEnvironmentProperties(ENV_PROPS); final List<Entity> entities = builder.build(bundle, BundleType.ENVIRONMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertExpectedProperties(entities, ImmutableMap.<String, PropertiesEntity>builder().putAll(ENV_PROPS).build()); }
@Test void buildDeploymentBundleWithDuplicateProps() { ClusterPropertyEntityBuilder builder = new ClusterPropertyEntityBuilder(ID_GENERATOR); Bundle bundle = new Bundle(); bundle.putAllStaticProperties(STATIC_PROPS); bundle.getStaticProperties().put("envprop1", new ClusterProperty("envprop1", "some value")); bundle.putAllGlobalEnvironmentProperties(ENV_PROPS); assertThrows(EntityBuilderException.class, () -> builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument())); }