HashcodeValidationRequestToProxyDocumentTransformer { public ProxyHashcodeDataSet transform(HashcodeValidationRequest hashcodeValidationRequest) { ProxyHashcodeDataSet proxyHashcodeDataSet = new ProxyHashcodeDataSet(); setReportType(hashcodeValidationRequest, proxyHashcodeDataSet); proxyHashcodeDataSet.setSignaturePolicy(hashcodeValidationRequest.getSignaturePolicy()); proxyHashcodeDataSet.setSignatureFiles(mapSignatureFiles(hashcodeValidationRequest.getSignatureFiles())); return proxyHashcodeDataSet; }  ProxyHashcodeDataSet transform(HashcodeValidationRequest hashcodeValidationRequest);  }
@Test public void contentIsCorrectlyTransformedToBytes() throws IOException, URISyntaxException { SignatureFile signatureFile = createSignatureFile(getSignature(), Collections.emptyList()); MockHashcodeValidationRequest validationRequest = createHashcodeValidationRequest(null, Collections.singletonList(signatureFile)); ProxyHashcodeDataSet proxyDocument = transformer.transform(validationRequest); assertEquals(validationRequest.getSignatureFiles().get(0).getSignature(), Base64.encodeBase64String(proxyDocument.getSignatureFiles().get(0).getSignature())); }
@Test public void reportTypeDefaultsToSimple() throws URISyntaxException, IOException { SignatureFile signatureFile = createSignatureFile(getSignature(), Collections.emptyList()); MockHashcodeValidationRequest validationRequest = createHashcodeValidationRequest(null, Collections.singletonList(signatureFile)); assertNull(validationRequest.getReportType()); ProxyRequest proxyRequest = transformer.transform(validationRequest); assertSame(proxyRequest.getReportType(), ReportType.SIMPLE); }
@Test public void reportTypeRemainsUnchangedIfNotNull() throws URISyntaxException, IOException { SignatureFile signatureFile = createSignatureFile(getSignature(), Collections.emptyList()); MockHashcodeValidationRequest validationRequest = createHashcodeValidationRequest("Detailed", Collections.singletonList(signatureFile)); ProxyRequest proxyRequest = transformer.transform(validationRequest); assertSame(proxyRequest.getReportType(), ReportType.DETAILED); }
@Test public void reportTypeIsCaseInsensitive() throws URISyntaxException, IOException { SignatureFile signatureFile = createSignatureFile(getSignature(), Collections.emptyList()); MockHashcodeValidationRequest validationRequest = createHashcodeValidationRequest("simple", Collections.singletonList(signatureFile)); ProxyRequest proxyRequest = transformer.transform(validationRequest); assertSame(proxyRequest.getReportType(), ReportType.SIMPLE); SignatureFile signatureFile2 = createSignatureFile(getSignature(), Collections.emptyList()); MockHashcodeValidationRequest validationRequest2 = createHashcodeValidationRequest("SIMPLE", Collections.singletonList(signatureFile2)); ProxyRequest proxyRequest2 = transformer.transform(validationRequest2); assertSame(proxyRequest2.getReportType(), ReportType.SIMPLE); }
@Test public void signaturePolicyRemainsUnchanged() throws IOException, URISyntaxException { SignatureFile signatureFile = createSignatureFile(getSignature(), Collections.emptyList()); MockHashcodeValidationRequest validationRequest = createHashcodeValidationRequest(null, Collections.singletonList(signatureFile)); ProxyRequest proxyRequest = transformer.transform(validationRequest); assertEquals(validationRequest.getSignaturePolicy(), proxyRequest.getSignaturePolicy()); }
@Test public void dataFilesTransformedCorrectlyWhileValuesRemainingUnchanged() throws URISyntaxException, IOException { Datafile datafile1 = new Datafile(); datafile1.setFilename("test.pdf"); datafile1.setHashAlgo("SHA256"); datafile1.setHash("IucjUcbRo9Rke0bZLiHcwiIiplP9pSrSPr7LKln1EiI="); Datafile datafile2 = new Datafile(); datafile2.setFilename("test2.pdf"); datafile2.setHashAlgo("SHA512"); datafile2.setHash("AucjUcbRo9Rke0bZLiHcwiIiplP9pSrSPr7LKln1EiI="); List<Datafile> datafiles = new ArrayList<>(); datafiles.add(datafile1); datafiles.add(datafile2); SignatureFile signatureFile = createSignatureFile(getSignature(), datafiles); MockHashcodeValidationRequest validationRequest = createHashcodeValidationRequest("Simple", Collections.singletonList(signatureFile)); ProxyHashcodeDataSet proxyDocument = transformer.transform(validationRequest); List<ee.openeid.siva.validation.document.Datafile> dataFiles = proxyDocument.getSignatureFiles().get(0).getDatafiles(); assertFalse(dataFiles.isEmpty()); assertSame(validationRequest.getSignatureFiles().get(0).getDatafiles().size(), dataFiles.size()); assertDataFileValues(dataFiles.get(0), datafile1); assertDataFileValues(dataFiles.get(1), datafile2); }