EncassEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { if (bundle instanceof AnnotatedBundle) { AnnotatedBundle annotatedBundle = ((AnnotatedBundle) bundle); Map<String, Encass> map = Optional.ofNullable(annotatedBundle.getEncasses()).orElse(Collections.emptyMap()); return buildEntities(map, annotatedBundle, annotatedBundle.getFullBundle(), bundleType, document); } else { return buildEntities(bundle.getEncasses(), null, bundle, bundleType, document); } } @Inject  EncassEntityBuilder(IdGenerator idGenerator); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @NotNull @Override Integer getOrder();  }
@Test void buildFromEmptyBundle_noEncass() { EncassEntityBuilder builder = new EncassEntityBuilder(ID_GENERATOR); final List<Entity> entities = builder.build(new Bundle(), BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertTrue(entities.isEmpty()); }
@Test void buildEncassDeploymentWithWrongGuidAndId() { final Bundle bundle = new Bundle(); EncassEntityBuilder builder = new EncassEntityBuilder(ID_GENERATOR); Encass encass = buildTestEncass(TEST_GUID, TEST_GOID, TEST_POLICY_PATH); encass.setName(TEST_ENCASS); Set<Annotation> annotations = new HashSet<>(); Annotation annotation = new Annotation(AnnotationType.BUNDLE_HINTS); annotation.setGuid(""); annotation.setId(""); annotations.add(annotation); annotations.add(new Annotation(AnnotationType.SHARED)); encass.setAnnotations(annotations); encass.setParentEntityShared(encass.getAnnotations().contains(new Annotation(AnnotationType.SHARED))); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); Policy policy = new Policy(); policy.setName(TEST_POLICY_PATH); policy.setId(TEST_POLICY_ID); bundle.getPolicies().put(TEST_POLICY_PATH, policy); AnnotatedEntity annotatedEntity = encass.getAnnotatedEntity(); AnnotatedBundle annotatedBundle = new AnnotatedBundle(bundle, annotatedEntity, projectInfo); annotatedBundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); annotatedBundle.getPolicies().put(TEST_POLICY_PATH, policy); List<Entity> entities = builder.build(annotatedBundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertFalse(entities.isEmpty()); assertEquals(1, entities.size()); Entity entity = entities.get(0); String name = annotatedBundle.applyUniqueName(TEST_ENCASS, BundleType.DEPLOYMENT, true); assertEquals(name, entity.getName()); assertNotNull(entity.getId(), TEST_GOID); assertEquals(entity.getGuid(), TEST_GUID); annotations = new HashSet<>(); annotation = new Annotation(AnnotationType.BUNDLE_HINTS); annotation.setGuid("wrongGuid"); annotation.setId("wrongId"); annotations.add(annotation); annotations.add(new Annotation(AnnotationType.SHARED)); encass.setAnnotations(annotations); encass.setParentEntityShared(encass.getAnnotations().contains(new Annotation(AnnotationType.SHARED))); encass.setAnnotatedEntity(null); annotatedEntity = encass.getAnnotatedEntity(); annotatedBundle = new AnnotatedBundle(bundle, annotatedEntity, projectInfo); annotatedBundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); annotatedBundle.getPolicies().put(TEST_POLICY_PATH, policy); entities = builder.build(annotatedBundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); entity = entities.get(0); name = annotatedBundle.applyUniqueName(TEST_ENCASS, BundleType.DEPLOYMENT, true); assertEquals(name, entity.getName()); assertNotNull(entity.getId(), TEST_GOID); assertEquals(entity.getGuid(), TEST_GUID); }
@Test void buildEnvironmentWithEncass() { final Bundle bundle = new Bundle(); putPolicy(bundle, TEST_POLICY_PATH, TEST_POLICY_ID, TEST_POLICY_PATH); EncassEntityBuilder builder = new EncassEntityBuilder(ID_GENERATOR); Encass encass = buildTestEncass(TEST_GUID, "testGoid", TEST_POLICY_PATH); bundle.putAllEncasses(ImmutableMap.of(TEST_ENCASS, encass)); final List<Entity> entities = builder.build(bundle, BundleType.ENVIRONMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertTrue(entities.isEmpty()); }