UnsupportedEntityBuilder implements EntityBuilder { @Override public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { List<Entity> unsupportedEntities = new ArrayList<>(); Map<String, UnsupportedGatewayEntity> unsupportedGatewayEntityMap = bundle.getUnsupportedEntities(); unsupportedGatewayEntityMap.forEach((key, value) -> { if (bundleType != ENVIRONMENT || value.isExcluded()) { unsupportedEntities.add(EntityBuilderHelper.getEntityWithOnlyMapping(value.getType(), value.getName() , value.getId())); } else { Element resourceElement = (Element) document.adoptNode(value.getElement()); unsupportedEntities.add(EntityBuilderHelper.getEntityWithNameMapping(value.getType(), value.getName() , value.getId(), resourceElement)); } }); return unsupportedEntities; }  @Override List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @Override @NotNull Integer getOrder();  }
@Test public void testEnvironmentBuildForEmptyEntities() { UnsupportedEntityBuilder unsupportedEntityBuilder = new UnsupportedEntityBuilder(); List<Entity> entities = unsupportedEntityBuilder.build(new Bundle(), EntityBuilder.BundleType.ENVIRONMENT, null); Assert.assertTrue(entities.isEmpty()); entities = unsupportedEntityBuilder.build(new AnnotatedBundle(null, null, null), EntityBuilder.BundleType.DEPLOYMENT, null); Assert.assertTrue(entities.isEmpty()); }
@Test public void testDeploymentBuildForEmptyEntities() { UnsupportedEntityBuilder unsupportedEntityBuilder = new UnsupportedEntityBuilder(); List<Entity> entities = unsupportedEntityBuilder.build(new Bundle(), EntityBuilder.BundleType.DEPLOYMENT, null); Assert.assertTrue(entities.isEmpty()); entities = unsupportedEntityBuilder.build(new AnnotatedBundle(null, null, null), EntityBuilder.BundleType.DEPLOYMENT, null); Assert.assertTrue(entities.isEmpty()); }
@Test public void testDeployementBuild(){ UnsupportedEntityBuilder unsupportedEntityBuilder = new UnsupportedEntityBuilder(); Bundle bundle = new Bundle(); String entityName = "TestEntity"; Map<String, UnsupportedGatewayEntity> unsupportedGatewayEntityMap = bundle.getUnsupportedEntities(); UnsupportedGatewayEntity unsupportedGatewayEntity = new UnsupportedGatewayEntity(); unsupportedGatewayEntity.setName(entityName); unsupportedGatewayEntity.setType("SSG_ACTIVE_CONNECTOR"); unsupportedGatewayEntity.setId("testId"); unsupportedGatewayEntityMap.put(entityName, unsupportedGatewayEntity); List<Entity> entities = unsupportedEntityBuilder.build(bundle, EntityBuilder.BundleType.DEPLOYMENT, null); Assert.assertEquals(1, entities.size()); Entity entity = entities.get(0); Assert.assertNull(entity.getXml()); Assert.assertEquals(entityName, entity.getName()); AnnotatedBundle annotatedBundle = new AnnotatedBundle(null, null, null); unsupportedGatewayEntityMap = annotatedBundle.getUnsupportedEntities(); unsupportedGatewayEntityMap.put("TestEntity", unsupportedGatewayEntity); entities = unsupportedEntityBuilder.build(annotatedBundle, EntityBuilder.BundleType.DEPLOYMENT, null); Assert.assertEquals(1, entities.size()); entity = entities.get(0); Assert.assertNull(entity.getXml()); Assert.assertEquals(entityName, entity.getName()); }
@Test public void testEnvironmentBuild(){ UnsupportedEntityBuilder unsupportedEntityBuilder = new UnsupportedEntityBuilder(); Bundle bundle = new Bundle(); String entityName = "TestEntity"; String elementName = "TestElement"; Document document = DocumentTools.INSTANCE.getDocumentBuilder().newDocument(); Element element = document.createElement(elementName); Map<String, UnsupportedGatewayEntity> unsupportedGatewayEntityMap = bundle.getUnsupportedEntities(); UnsupportedGatewayEntity unsupportedGatewayEntity = new UnsupportedGatewayEntity(); unsupportedGatewayEntity.setName(entityName); unsupportedGatewayEntity.setType("SSG_ACTIVE_CONNECTOR"); unsupportedGatewayEntity.setId("testId"); unsupportedGatewayEntity.setElement(element); unsupportedGatewayEntityMap.put(entityName, unsupportedGatewayEntity); List<Entity> entities = unsupportedEntityBuilder.build(bundle, EntityBuilder.BundleType.ENVIRONMENT, document); Assert.assertEquals(1, entities.size()); Entity entity = entities.get(0); Assert.assertNotNull(entity.getXml()); Assert.assertEquals(entityName, entity.getName()); Assert.assertEquals("SSG_ACTIVE_CONNECTOR", entity.getType()); Assert.assertEquals(elementName, entity.getXml().getTagName()); AnnotatedBundle annotatedBundle = new AnnotatedBundle(null, null, null); unsupportedGatewayEntityMap = annotatedBundle.getUnsupportedEntities(); unsupportedGatewayEntityMap.put("TestEntity", unsupportedGatewayEntity); entities = unsupportedEntityBuilder.build(annotatedBundle, EntityBuilder.BundleType.ENVIRONMENT, document); Assert.assertEquals(1, entities.size()); entity = entities.get(0); Assert.assertNotNull(entity.getXml()); Assert.assertEquals(entityName, entity.getName()); Assert.assertEquals("SSG_ACTIVE_CONNECTOR", entity.getType()); Assert.assertEquals(elementName, entity.getXml().getTagName()); }