SoapValidationRequestToProxyDocumentTransformer { public ProxyDocument transform(SoapValidationRequest validationRequest) { ProxyDocument proxyDocument = new ProxyDocument(); proxyDocument.setName(validationRequest.getFilename()); if (validationRequest.getDocumentType() != null) proxyDocument.setDocumentType(DocumentTypeResolver.documentTypeFromString(validationRequest.getDocumentType().name())); if (validationRequest.getReportType() != null) proxyDocument.setReportType(ReportType.reportTypeFromString(validationRequest.getReportType())); proxyDocument.setBytes(Base64.decodeBase64(validationRequest.getDocument())); proxyDocument.setSignaturePolicy(validationRequest.getSignaturePolicy()); return proxyDocument; }  ProxyDocument transform(SoapValidationRequest validationRequest);  }
@Test public void contentIsCorrectlyTransformedToBytes() { String documentContent = "ZmlsZWNvbnRlbnQ="; SoapValidationRequest validationRequest = createSoapValidationRequest(documentContent, DocumentType.XROAD, "file.bdoc", "some policy"); assertEquals(validationRequest.getDocument(), Base64.encodeBase64String(transformer.transform(validationRequest).getBytes())); }
@Test public void reportTypeIsCorrectlyTransformed() { for (ReportType reportType : ReportType.values()) { SoapValidationRequest validationRequest = createSoapValidationRequest("ZmlsZWNvbnRlbnQ=", DocumentType.XROAD, "file.bdoc", "some policy"); validationRequest.setReportType(reportType.getValue()); assertEquals(validationRequest.getReportType(), transformer.transform(validationRequest).getReportType().getValue()); } }
@Test public void reportTypeNullIsNotOverAssigned() { SoapValidationRequest validationRequest = createSoapValidationRequest("ZmlsZWNvbnRlbnQ=", DocumentType.XROAD, "file.bdoc", "some policy"); validationRequest.setReportType(null); assertEquals(null, transformer.transform(validationRequest).getReportType()); }
@Test public void invalidReportTypeThrowsUnsupportedTypeException() { String reportType = "INVALID_REPORT_TYPE"; exception.expect(UnsupportedTypeException.class); exception.expectMessage("ReportType of type '" + reportType + "' is not supported"); SoapValidationRequest validationRequest = createSoapValidationRequest("ZmlsZWNvbnRlbnQ=", DocumentType.XROAD, "file.bdoc", "some policy"); validationRequest.setReportType(reportType); transformer.transform(validationRequest); }
@Test public void xroadTypeIsCorrectlyTransformedToDocumentType() { DocumentType docType = DocumentType.XROAD; SoapValidationRequest validationRequest = createSoapValidationRequest("Ymxh", docType, "file.asice", "some policy"); assertEquals(validationRequest.getDocumentType().name(), transformer.transform(validationRequest).getDocumentType().name()); }
@Test public void filenameRemainsUnchanged() { String filename = "random file name.bdoc"; SoapValidationRequest validationRequest = createSoapValidationRequest("Ymxh", DocumentType.XROAD, filename, "some policy"); assertEquals(validationRequest.getFilename(), transformer.transform(validationRequest).getName()); }
@Test public void signaturePolicyRemainsUnchanged() { String policy = "policy"; SoapValidationRequest validationRequest = createSoapValidationRequest("Ymxh", DocumentType.XROAD, "file.bdoc", policy); assertEquals(validationRequest.getSignaturePolicy(), transformer.transform(validationRequest).getSignaturePolicy()); }