ServiceEntityBuilder implements EntityBuilder { public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { return buildEntities(bundle.getServices(), bundle, bundleType, document); } @Inject  ServiceEntityBuilder(DocumentTools documentTools, IdGenerator idGenerator); List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @NotNull @Override Integer getOrder();  }
@Test void buildNoServices() { ServiceEntityBuilder builder = new ServiceEntityBuilder(DocumentTools.INSTANCE, new IdGenerator()); Bundle bundle = new Bundle(projectInfo); List<Entity> serviceEntities = builder.build(bundle, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertEquals(0, serviceEntities.size()); }
@Test void buildServicesWithoutPolicy() { ServiceEntityBuilder builder = new ServiceEntityBuilder(DocumentTools.INSTANCE, new IdGenerator()); Bundle bundle = new Bundle(projectInfo); Folder parentFolder = new Folder(); parentFolder.setId("asd"); parentFolder.setName("my"); parentFolder.setPath("my"); parentFolder.setParentFolder(Folder.ROOT_FOLDER); Folder serviceParentFolder = new Folder(); serviceParentFolder.setId("test"); serviceParentFolder.setName("policy"); serviceParentFolder.setPath("my/v1"); serviceParentFolder.setParentFolder(parentFolder); bundle.putAllFolders(new HashMap<String, Folder>() {{ put(parentFolder.getPath(), parentFolder); put(serviceParentFolder.getPath(), serviceParentFolder); put(Folder.ROOT_FOLDER.getPath(), Folder.ROOT_FOLDER); }}); Service service = new Service(); service.setHttpMethods(Stream.of("POST", "GET").collect(Collectors.toSet())); service.setUrl("/my/service/url"); service.setProperties(new HashMap<String, Object>() {{ put("key1", "value1"); put("key2", "value2"); }}); service.setName("path"); service.setParentFolder(serviceParentFolder); bundle.putAllServices(new HashMap<String, Service>() {{ put("/my/policy/path", service); }}); assertThrows(EntityBuilderException.class, () -> builder.build(bundle, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument())); }
@Test void buildOneServices() throws DocumentParseException { ServiceEntityBuilder builder = new ServiceEntityBuilder(DocumentTools.INSTANCE, new IdGenerator()); Bundle bundle = new Bundle(projectInfo); Folder serviceParentFolder = setUpFolderAndPolicy(bundle, "/my/policy.xml", "policy"); Service service = new Service(); service.setHttpMethods(Stream.of("POST", "GET").collect(Collectors.toSet())); service.setUrl("/my/service/url"); service.setPolicy("/my/policy.xml"); service.setParentFolder(serviceParentFolder); service.setProperties(new HashMap<String, Object>() {{ put("key1", "value1"); put("ENV.key.environment", "something"); }}); service.setName("service1"); bundle.putAllServices(new HashMap<String, Service>() {{ put("/v1/service1", service); }}); List<Entity> services = builder.build(bundle, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertEquals(1, services.size()); Entity serviceEntity = services.get(0); verifyService(service, serviceEntity, 1, "service" + 1); }
@Test void buildOneSoapServiceWithWSDLAndNoXSD() throws DocumentParseException { ServiceEntityBuilder builder = new ServiceEntityBuilder(DocumentTools.INSTANCE, new IdGenerator()); Bundle bundle = new Bundle(projectInfo); Folder serviceParentFolder = setUpFolderAndPolicy(bundle, "/soap/policy.xml", "policy"); Service service = new Service(); service.setHttpMethods(Stream.of("POST", "GET").collect(Collectors.toSet())); service.setUrl("/soap/service/url"); service.setPolicy("/soap/policy.xml"); service.setParentFolder(serviceParentFolder); service.setName("soap-service1"); service.setProperties(new HashMap<String, Object>() {{ put("key1", "value1"); put("ENV.key.environment", "something"); }}); service.setWssProcessingEnabled(true); service.setSoapVersion("1.1"); SoapResource wsdlBean = new SoapResource(); wsdlBean.setRootUrl("/test/rooturl/for/soap.wsdl"); wsdlBean.setPath(PathUtils.unixPath(serviceParentFolder.getPath(), service.getName(), "soap.wsdl")); wsdlBean.setContent("wsdl xml content"); wsdlBean.setType(SoapResourceType.WSDL.getType()); service.setWsdlRootUrl(wsdlBean.getRootUrl()); service.addSoapResource(wsdlBean); bundle.putAllServices(new HashMap<String, Service>() {{ put(service.getName(), service); }}); bundle.putAllSoapResources(ImmutableMap.of(wsdlBean.getPath(), wsdlBean)); bundle.buildFolderTree(); List<Entity> services = builder.build(bundle, EntityBuilder.BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertEquals(1, services.size()); Entity serviceEntity = services.get(0); verifyService(service, serviceEntity, 1, "soap-service" + 1); }