StartupListener { @EventListener public void onApplicationEvent(WebServerInitializedEvent event) { initCRL(); cvcTlsCheck.check(); } StartupListener(TerminalPermissionAO facade, ApplicationTimer timer, CvcTlsCheck cvcTlsCheck); @EventListener void onApplicationEvent(WebServerInitializedEvent event);  }
@Test void testWhenTerminalPermissionIsNullThenCRLNotInitialized() throws Exception { tempDirectory = JAVA_IO_TMPDIR + "-" + (int)(Math.random() * 1000000); Files.createDirectory(Paths.get(tempDirectory)); log.trace("Generated random temp dir: {}", tempDirectory); Path resourceDirectory = Paths.get("src", "test", "resources"); File source = new File(resourceDirectory + "/POSeIDAS.xml"); File dest = new File(tempDirectory + "/POSeIDAS.xml"); Files.copy(source.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); System.setProperty("spring.config.additional-location", Paths.get(tempDirectory).toString()); startupListener = new StartupListener(facade, timer, cvcTlsCheck); startupListener.onApplicationEvent(webServerInitializedEvent); Mockito.verify(timer, Mockito.times(1)).renewMasterDefectList(); Assertions.assertThrows(IllegalStateException.class, CertificationRevocationListImpl::getInstance); Mockito.verify(cvcTlsCheck, Mockito.times(1)).check(); }
@Test void testWhenMasterlistPresentThenCRLInitialized() throws Exception { tempDirectory = JAVA_IO_TMPDIR + "-" + (int)(Math.random() * 1000000); Files.createDirectory(Paths.get(tempDirectory)); log.trace("Generated random temp dir: {}", tempDirectory); Path resourceDirectory = Paths.get("src", "test", "resources"); File source = new File(resourceDirectory + "/POSeIDAS.xml"); File dest = new File(tempDirectory + "/POSeIDAS.xml"); Files.copy(source.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); System.setProperty("spring.config.additional-location", Paths.get(tempDirectory).toString()); startupListener = new StartupListener(facade, timer, cvcTlsCheck); TerminalPermission terminalPermission = Mockito.mock(TerminalPermission.class); Mockito.when(facade.getTerminalPermission(Mockito.anyString())).thenReturn(terminalPermission); Mockito.when(terminalPermission.getMasterList()) .thenReturn(Base64.getDecoder().decode(MASTERLIST_BASE64)); startupListener.onApplicationEvent(webServerInitializedEvent); Mockito.verify(timer, Mockito.times(1)).renewMasterDefectList(); Assertions.assertNotNull(CertificationRevocationListImpl.getInstance()); Mockito.verify(cvcTlsCheck, Mockito.times(1)).check(); }