ValidationProxy { public SimpleReport validate(ProxyRequest proxyRequest) { long validationStartTime = System.nanoTime(); SimpleReport report = validateRequest(proxyRequest); long validationDuration = System.nanoTime() - validationStartTime; publishStatistics(proxyRequest, report, validationDuration); addWarningForTestEnvironment(report); return report; } @Autowired  ValidationProxy(StatisticsService statisticsService, ApplicationContext applicationContext, Environment environment); SimpleReport validate(ProxyRequest proxyRequest);  }
@Test public void givenXroadValidationWillReturnValidatedDocument() throws Exception { ValidationConclusion validationConclusion = new ValidationConclusion(); validationConclusion.setSignaturesCount(1); validationConclusion.setValidSignaturesCount(1); Reports reports = new Reports(new SimpleReport(validationConclusion), null, null); BDDMockito.given(restProxyService.validate(any(ValidationDocument.class))).willReturn(reports); ProxyDocument proxyDocument = mockProxyDocumentWithDocument(DocumentType.XROAD); SimpleReport validationReport = validationProxy.validate(proxyDocument); verify(restProxyService).validate(any(ValidationDocument.class)); Assertions.assertThat(validationReport.getValidationConclusion().getValidSignaturesCount()).isEqualTo(1); Assertions.assertThat(validationReport.getValidationConclusion().getSignaturesCount()).isEqualTo(1); }
@Test public void applicationContextHasNoBeanWithGivenNameThrowsException() throws Exception { BDDMockito.given(applicationContext.getBean(anyString())).willThrow(new NoSuchBeanDefinitionException("Bean not loaded")); exception.expect(ValidatonServiceNotFoundException.class); exception.expectMessage("genericValidationService not found"); ProxyDocument proxyDocument = mockProxyDocumentWithDocument(DocumentType.PDF); validationProxy.validate(proxyDocument); verify(applicationContext).getBean(anyString()); }
@Test public void proxyDocumentWithBDOCDocumentTypeShouldReturnValidationReport() throws Exception { when(applicationContext.getBean(TIMEMARK_CONTAINER_VALIDATION_SERVICE_BEAN)).thenReturn(validationServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithDocument(DocumentType.BDOC); SimpleReport report = validationProxy.validate(proxyDocument); assertSimpleReport(report); }
@Test public void proxyDocumentWithPDFDocumentTypeShouldReturnValidationReport() throws Exception { when(applicationContext.getBean(GENERIC_VALIDATION_SERVICE_BEAN)).thenReturn(validationServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithDocument(DocumentType.PDF); SimpleReport report = validationProxy.validate(proxyDocument); assertSimpleReport(report); }
@Test public void proxyDocumentWithDDOCDocumentTypeShouldReturnValidationReport() throws Exception { when(applicationContext.getBean(TIMEMARK_CONTAINER_VALIDATION_SERVICE_BEAN)).thenReturn(validationServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithDocument(DocumentType.DDOC); SimpleReport report = validationProxy.validate(proxyDocument); assertSimpleReport(report); }
@Test public void proxyDocumentWithAsicsExtensionShouldReturnValidationReport() throws Exception { when(applicationContext.getBean(TIMESTAMP_TOKEN_VALIDATION_SERVICE_BEAN)).thenReturn(getTimeStampValidationService()); when(applicationContext.getBean(TIMEMARK_CONTAINER_VALIDATION_SERVICE_BEAN)).thenReturn(validationServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithExtension("asics"); proxyDocument.setBytes(buildValidationDocument("timestamptoken-ddoc.asics")); SimpleReport report = validationProxy.validate(proxyDocument); TimeStampTokenValidationData timeStampTokenValidationData = report.getValidationConclusion().getTimeStampTokens().get(0); assertEquals(TimeStampTokenValidationData.Indication.TOTAL_PASSED, timeStampTokenValidationData.getIndication()); assertSimpleReport(report); }
@Test public void proxyDocumentWithZipExtensionShouldReturnValidationReport() throws Exception { when(applicationContext.getBean(TIMESTAMP_TOKEN_VALIDATION_SERVICE_BEAN)).thenReturn(getTimeStampValidationService()); when(applicationContext.getBean(TIMEMARK_CONTAINER_VALIDATION_SERVICE_BEAN)).thenReturn(validationServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithExtension("zip"); proxyDocument.setBytes(buildValidationDocument("timestamptoken-ddoc.zip")); SimpleReport report = validationProxy.validate(proxyDocument); TimeStampTokenValidationData timeStampTokenValidationData = report.getValidationConclusion().getTimeStampTokens().get(0); assertEquals(TimeStampTokenValidationData.Indication.TOTAL_PASSED, timeStampTokenValidationData.getIndication()); assertSimpleReport(report); }
@Test public void proxyDocumentWithScsExtensionShouldReturnValidationReport() throws Exception { when(applicationContext.getBean(TIMESTAMP_TOKEN_VALIDATION_SERVICE_BEAN)).thenReturn(getTimeStampValidationService()); when(applicationContext.getBean(TIMEMARK_CONTAINER_VALIDATION_SERVICE_BEAN)).thenReturn(validationServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithExtension("scs"); proxyDocument.setBytes(buildValidationDocument("timestamptoken-ddoc.asics")); SimpleReport report = validationProxy.validate(proxyDocument); TimeStampTokenValidationData timeStampTokenValidationData = report.getValidationConclusion().getTimeStampTokens().get(0); assertEquals(TimeStampTokenValidationData.Indication.TOTAL_PASSED, timeStampTokenValidationData.getIndication()); assertSimpleReport(report); }
@Test public void proxyDocumentAsicsWithRandomDataFile() throws Exception { when(applicationContext.getBean(TIMESTAMP_TOKEN_VALIDATION_SERVICE_BEAN)).thenReturn(getTimeStampValidationService()); when(applicationContext.getBean(GENERIC_VALIDATION_SERVICE_BEAN)).thenReturn(getGenericValidationService()); ProxyDocument proxyDocument = mockProxyDocumentWithExtension("asics"); proxyDocument.setBytes(buildValidationDocument("TXTinsideAsics.asics")); SimpleReport report = validationProxy.validate(proxyDocument); TimeStampTokenValidationData timeStampTokenValidationData = report.getValidationConclusion().getTimeStampTokens().get(0); assertEquals(TimeStampTokenValidationData.Indication.TOTAL_PASSED, timeStampTokenValidationData.getIndication()); }
@Test public void proxyDocumentAsicsWithTwoDataFiles() throws Exception { exception.expect(DocumentRequirementsException.class); when(applicationContext.getBean(TIMESTAMP_TOKEN_VALIDATION_SERVICE_BEAN)).thenReturn(getTimeStampValidationService()); ProxyDocument proxyDocument = mockProxyDocumentWithExtension("asics"); proxyDocument.setBytes(buildValidationDocument("TwoDataFilesAsics.asics")); validationProxy.validate(proxyDocument); }
@Test public void proxyDocumentAsicsWithDifferentMimeType() throws Exception { when(applicationContext.getBean(TIMESTAMP_TOKEN_VALIDATION_SERVICE_BEAN)).thenReturn(getTimeStampValidationService()); when(applicationContext.getBean(GENERIC_VALIDATION_SERVICE_BEAN)).thenReturn(validationServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithExtension("zip"); proxyDocument.setBytes(buildValidationDocument("timestamptoken-different-mimetype.zip")); SimpleReport report = validationProxy.validate(proxyDocument); assertSimpleReport(report); }
@Test public void proxyDocumentAsicsNoTeraWarning() throws Exception { when(applicationContext.getBean(TIMESTAMP_TOKEN_VALIDATION_SERVICE_BEAN)).thenReturn(getTimeStampValidationService()); when(applicationContext.getBean(TIMEMARK_CONTAINER_VALIDATION_SERVICE_BEAN)).thenReturn(validationServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithExtension("asics"); proxyDocument.setBytes(buildValidationDocument("timestamptoken-ddoc.asics")); SimpleReport report = validationProxy.validate(proxyDocument); assertSimpleReport(report); }
@Test public void addsTestEnvironmentWarningForTestProfile() { environment.setActiveProfiles("test"); SimpleReport report = getValidationProxySpy().validate(new ProxyDocument()); Assert.assertThat(report.getValidationConclusion().getValidationWarnings(), contains(TEST_ENV_WARNING)); }
@Test public void doesNotAddTestEnvironmentWarningWhenTestProfileNotSet() { SimpleReport report = getValidationProxySpy().validate(new ProxyDocument()); Assert.assertNull(report.getValidationConclusion().getValidationWarnings()); }
@Test public void addsTestEnvironmentWarningForTestProfile_constructsANewListWhenWarningsPresentInReport() { environment.setActiveProfiles("test"); ValidationWarning warning1 = new ValidationWarning(); warning1.setContent("warning1"); ValidationWarning warning2 = new ValidationWarning(); warning1.setContent("warning2"); SimpleReport report = getValidationProxySpyWithValidationWarningsInReport(Arrays.asList(warning1, warning2)) .validate(new ProxyDocument()); Assert.assertThat(report.getValidationConclusion().getValidationWarnings(), contains(TEST_ENV_WARNING, warning1, warning2)); }