FolderEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { Map<String, Folder> folderMap = Optional.ofNullable(bundle.getFolders()).orElse(Collections.emptyMap()); return buildEntities(folderMap, bundleType, document, bundle.getTargetFolderPath()); } @Inject  FolderEntityBuilder(IdGenerator idGenerator); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @Override @NotNull Integer getOrder();  }
@Test void buildFromEmptyBundle_noFolders() { FolderEntityBuilder builder = new FolderEntityBuilder(ID_GENERATOR); final List<Entity> entities = builder.build(new Bundle(projectInfo), DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertTrue(entities.isEmpty()); }
@Test void buildMissingRoot() { FolderEntityBuilder builder = new FolderEntityBuilder(ID_GENERATOR); Bundle bundle = new Bundle(projectInfo); bundle.putAllFolders(createTestFolders(null)); assertThrows(EntityBuilderException.class, () -> builder.build(bundle, DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument())); }
@Test void buildEnvironment() { FolderEntityBuilder builder = new FolderEntityBuilder(ID_GENERATOR); Bundle bundle = new Bundle(projectInfo); Folder root = createRoot(); bundle.getFolders().put(EMPTY, root); bundle.putAllFolders(createTestFolders(root)); final List<Entity> entities = builder.build(bundle, BundleType.ENVIRONMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertNotNull(entities); assertTrue(entities.isEmpty()); }
@Test void buildDeployment() { FolderEntityBuilder builder = new FolderEntityBuilder(ID_GENERATOR); Bundle bundle = new Bundle(projectInfo); Folder root = createRoot(); bundle.getFolders().put(EMPTY, root); bundle.putAllFolders(createTestFolders(root)); final List<Entity> entities = builder.build(bundle, DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertNotNull(entities); assertFalse(entities.isEmpty()); assertEquals(4, entities.size()); final Map<String, Entity> entitiesMap = entities.stream().collect(toMap(Entity::getName, identity())); entitiesMap.forEach((k, entity) -> { k = Folder.ROOT_FOLDER_NAME.equals(k) ? EMPTY : k; Folder folder = bundle.getFolders().get(k); assertNotNull(folder); if (k.equals(EMPTY)) { assertEquals(Folder.ROOT_FOLDER_NAME, folder.getName()); } else { assertEquals(folder.getName(), CharacterBlacklistUtil.filterAndReplace(k.substring(k.lastIndexOf('/') + 1))); } assertNotNull(entity.getId()); assertNotNull(entity.getXml()); assertEquals(EntityTypes.FOLDER_TYPE, entity.getType()); Element xml = entity.getXml(); assertEquals(FOLDER, xml.getTagName()); assertNotNull(getSingleChildElement(xml, NAME)); assertEquals(folder.getId(), trimToNull(xml.getAttribute(ATTRIBUTE_ID))); assertEquals(ofNullable(folder.getParentFolder()).orElse(new Folder()).getId(), trimToNull(xml.getAttribute(ATTRIBUTE_FOLDER_ID))); }); }