PolicyBackedServiceEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { if (bundle instanceof AnnotatedBundle) { Map<String, PolicyBackedService> policyBackedServiceMap = Optional.ofNullable(bundle.getPolicyBackedServices()).orElse(Collections.emptyMap()); return buildEntities(policyBackedServiceMap, ((AnnotatedBundle)bundle).getFullBundle(), bundleType, document); } else { return buildEntities(bundle.getPolicyBackedServices(), bundle, bundleType, document); } } @Inject  PolicyBackedServiceEntityBuilder(IdGenerator idGenerator); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @Override @NotNull Integer getOrder();  }
@Test void buildFromEmptyBundle_noPBS() { PolicyBackedServiceEntityBuilder builder = new PolicyBackedServiceEntityBuilder(ID_GENERATOR); final List<Entity> entities = builder.build(new Bundle(), BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertTrue(entities.isEmpty()); }
@Test void buildEnvironmentWithPBS() { final Bundle bundle = new Bundle(); putPolicy(bundle); PolicyBackedServiceEntityBuilder builder = new PolicyBackedServiceEntityBuilder(ID_GENERATOR); bundle.putAllPolicyBackedServices(ImmutableMap.of(TEST_PBS, buildTestPBS())); final List<Entity> entities = builder.build(bundle, BundleType.ENVIRONMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertTrue(entities.isEmpty()); }