SivaSOAPValidationServiceClient implements ValidationService { @Override public String validateDocument(String policy, String report, UploadedFile file) throws IOException { if (file == null) { throw new IOException("File not found"); } FileType serviceType = ValidationRequestUtils.getValidationServiceType(file); String requestBody = createXMLValidationRequest(file.getEncodedFile(), serviceType, file.getFilename(), report, policy); String fullUrl = properties.getServiceHost() + properties.getSoapServicePath(); return XMLTransformer.formatXML(restTemplate.postForObject(fullUrl, requestBody, String.class)); }  @Override String validateDocument(String policy, String report, UploadedFile file); @Autowired void setProperties(SivaRESTWebServiceConfigurationProperties properties); @Autowired void setRestTemplate(RestTemplate restTemplate);  }
@Test public void givenValidRequestWillReturnSOAPValidationReport() throws Exception { String response = FileUtils.readFileToString(TestFileUtils.loadTestFile("/soap_response.xml")).replaceAll("\\n", System.lineSeparator()); response = response.replaceAll("\\r\\r\\n", System.lineSeparator()); serverMockResponse(response); UploadedFile uploadedFile = TestFileUtils.generateUploadFile(testingFolder, "hello.bdoc", "Valid document"); String validatedDocument = validationService.validateDocument("", "", uploadedFile); assertThat(validatedDocument).isEqualTo(response); verify(restTemplate).postForObject(Mockito.anyString(), validationRequestCaptor.capture(), Mockito.any()); assertThat(validationRequestCaptor.getValue()).contains("<Filename>hello.bdoc</Filename>"); }
@Test public void givenValidRequestReturnsInvalidXMLReturnsEmptyString() throws Exception { serverMockResponse(StringUtils.EMPTY); UploadedFile uploadedFile = TestFileUtils.generateUploadFile(testingFolder, "hello.bdoc", "Valid document"); String validatedDocument = validationService.validateDocument("", "", uploadedFile); assertThat(validatedDocument).isEqualTo(StringUtils.EMPTY); verify(mockAppender).doAppend(captorLoggingEvent.capture()); final LoggingEvent loggingEvent = captorLoggingEvent.getValue(); assertThat(loggingEvent.getLevel()).isEqualTo(Level.WARN); assertThat(loggingEvent.getMessage()).contains("XML Parsing error:"); }
@Test public void givenNullUploadFileWillThrowException() throws Exception { expectedException.expect(IOException.class); expectedException.expectMessage("File not found"); validationService.validateDocument(null, null, null); }