public static SoapResource generateSoapResource(){ final SoapResource soapResource = new SoapResource(); soapResource.setId("SOAP RESOURCE"); soapResource.setName("Soap resource name"); soapResource.setProjectId("Project id"); soapResource.setType(SoapResourceType.WSDL); soapResource.setContent(""); return soapResource; } }
@Test public void testSaveAndLoadSoapResource() { SoapResource soapResource = new SoapResource(); SoapResource fromDb = soapResourceMongoRepository.saveSoapResource(soapResource, "Very large content"); String content = soapResourceMongoRepository.loadSoapResource(fromDb.getId()); assertThat(content).isEqualTo("Very large content"); }
final SoapResource resource = new SoapResource(); resource.setId(resourceId); resource.setType(resourceType); ImportSoapResourceInput input = ImportSoapResourceInput.builder() .projectId(projectId)
final String raw = input.getRaw(); if(soapResource.getName() == null){ final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); final Date now = new Date(); final String soapResourceName = soapResource.getType().name() + "-" + formatter.format(now); soapResource.setName(soapResourceName); if(projectId.isPresent()){ if(SoapResourceType.WSDL.equals(soapResource.getType())){ .forEach(this.resourceRepository::deleteWithProjectId); soapResource.setProjectId(projectId.get()); result = this.resourceRepository.saveSoapResource(soapResource, raw); } else {
this.resourceRepository.delete(wsdlSoapResource.getId()); SoapResource soapResource = new SoapResource(); soapResource.setProjectId(soapProjectId); soapResource.setName(result.getName()); soapResource.setType(result.getResourceType()); this.resourceRepository.saveSoapResource(soapResource, result.getDefinition());
protected SoapProject deleteProject(final String projectId){ final List<SoapPort> ports = this.portRepository.findWithProjectId(projectId); final List<SoapResource> resources = this.resourceRepository.findWithProjectId(projectId); ports.forEach(port -> this.deletePort(port.getId())); resources.forEach(resource -> this.deleteResource(resource.getId())); return this.repository.delete(projectId); }
@Test public void testGetServiceValid() throws Exception { final String projectId = "ProjectId"; final String resourceId = "ResourceId"; final SoapResource soapResource = new SoapResource(); soapResource.setName("SOAP resource name"); final ReadSoapResourceOutput readSoapResourceOutput = ReadSoapResourceOutput.builder() .resource(soapResource).build(); final String resource = "Resource"; final LoadSoapResourceOutput loadSoapResourceOutput = LoadSoapResourceOutput.builder() .resource(resource) .build(); when(serviceProcessor.process(isA(ReadSoapResourceInput.class))).thenReturn(readSoapResourceOutput); when(serviceProcessor.process(isA(LoadSoapResourceInput.class))).thenReturn(loadSoapResourceOutput); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + projectId + SLASH + RESOURCE + SLASH + resourceId); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.model().size(3 + GLOBAL_VIEW_MODEL_COUNT)) .andExpect(MockMvcResultMatchers.forwardedUrl(INDEX)) .andExpect(MockMvcResultMatchers.model().attribute(PARTIAL, PAGE)) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_PROJECT_ID, projectId)) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_RESOURCE, soapResource)) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_RESOURCE_DATA, resource)); }
String content = this.resourceRepository.loadSoapResource(resource.getId()); resource.setContent(content);
searchResult.setTitle(resource.getName()); searchResult.setLink(SOAP + SLASH + PROJECT + SLASH + resource.getProjectId() + SLASH + RESOURCE + SLASH + resource.getId()); searchResult.setDescription(SOAP_TYPE + COMMA + resourceType); searchResults.add(searchResult);
private String getWsdl(final String projectId){ final ReadSoapProjectOutput projectOutput = this.serviceProcessor.process(ReadSoapProjectInput.builder() .projectId(projectId) .build()); final SoapProject soapProject = projectOutput.getProject(); return soapProject.getResources().stream() .filter(soapResource -> SoapResourceType.WSDL.equals(soapResource.getType())) .findFirst() .map(soapResource -> { final LoadSoapResourceOutput loadOutput = this.serviceProcessor.process(LoadSoapResourceInput.builder() .projectId(projectId) .resourceId(soapResource.getId()) .build()); return loadOutput.getResource(); }) .orElseThrow(() -> new IllegalArgumentException("Unable to find a WSDL file for the following project: " + projectId)); }
if(this.resourceRepository.exists(resource.getId())){ throw new IllegalArgumentException("A resource with the following key already exists: " + resource.getId()); this.resourceRepository.saveSoapResource(resource, resource.getContent());
/** * The method adds a new {@link SoapResource}. * * @param soapResource The instance of {@link SoapResource} that will be saved. * @param resource The raw resource * @return The saved {@link SoapResource} * @see SoapResource */ @Override public SoapResource saveSoapResource(SoapResource soapResource, String resource) { soapResource.setContent(resource); return save(soapResource); }
/** * The method adds a new {@link SoapResource}. * * @param soapResource The instance of {@link SoapResource} that will be saved. * @param resource The raw resource * @return The saved {@link SoapResource} * @see SoapResource */ @Override public SoapResource saveSoapResource(SoapResource soapResource, String resource) { SoapResourceFile resourceFile = mapper.map(soapResource, SoapResourceFile.class); SoapResource saveSoapResource = save(soapResource); String path = this.fileDirectory + File.separator; if(SoapResourceType.WSDL.equals(resourceFile.getType())){ path += WSDL_DIRECTORY; } else if(SoapResourceType.WSDL.equals(resourceFile.getType())){ path += SCHEMA_DIRECTORY; } try { this.fileRepositorySupport.save(path, saveSoapResource.getId() + this.fileExtension, resource); } catch (Exception e){ LOGGER.error("Unable to upload SOAP resource", e); } return saveSoapResource; }
private SoapProject getSoapProject(){ final SoapProject soapProject = new SoapProject(); final SoapResource soapResource = new SoapResource(); soapResource.setId("Resource id"); soapResource.setName("wsdl"); soapResource.setType(SoapResourceType.WSDL); soapProject.setResources(Arrays.asList(soapResource)); return soapProject; }
@Test public void testProcess(){ final SoapResource resource = SoapResourceGenerator.generateSoapResource(); final String projectId = "SOAP PROJECT"; final ReadSoapResourceInput input = ReadSoapResourceInput.builder() .projectId(projectId) .resourceId(resource.getId()) .build(); final ServiceTask<ReadSoapResourceInput> serviceTask = new ServiceTask<ReadSoapResourceInput>(input); Mockito.when(resourceRepository.findOne(resource.getId())).thenReturn(resource); final ServiceResult<ReadSoapResourceOutput> result = service.process(serviceTask); Mockito.verify(resourceRepository, Mockito.times(1)).findOne(resource.getId()); Assert.assertNotNull(result.getOutput()); Assert.assertEquals(resource, result.getOutput().getResource()); }
SoapResource resource = new SoapResource(); resource.setName(soapResourceV1.getName()); resource.setId(soapResourceV1.getId()); resource.setType(soapResourceV1.getType()); resource.setProjectId(project.getId()); project.getResources().add(resource);
@Test public void testProcess(){ final SoapResource soapResource = SoapResourceGenerator.generateSoapResource(); final String resourceContent = "Resource content"; Mockito.when(resourceRepository.loadSoapResource(soapResource.getId())).thenReturn(resourceContent); final LoadSoapResourceInput input = LoadSoapResourceInput.builder() .projectId("Project id") .resourceId(soapResource.getId()) .build(); final ServiceTask<LoadSoapResourceInput> serviceTask = new ServiceTask<LoadSoapResourceInput>(input); final ServiceResult<LoadSoapResourceOutput> serviceResult = service.process(serviceTask); Assert.assertNotNull(serviceResult.getOutput()); Assert.assertEquals(resourceContent, serviceResult.getOutput().getResource()); Mockito.verify(resourceRepository, Mockito.times(1)).loadSoapResource(soapResource.getId()); } }
Mockito.verify(resourceRepository, Mockito.times(1)).delete(soapResource.getId()); Mockito.verify(operationRepository, Mockito.times(1)).delete(soapOperation.getId()); Mockito.verify(mockResponseRepository, Mockito.times(1)).delete(soapMockResponse.getId());