@Test public void shouldNotifyListenerOnFileAdded() throws IOException { final Path torrentFile = TorrentFileCreator.create(torrentsPath.resolve("ubuntu.torrent"), TorrentFileCreator.TorrentType.UBUNTU); final TorrentFileProvider provider = new TorrentFileProvider(resourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class)); final CountDownLatch createLock = new CountDownLatch(1); final CountDownLatch deleteLock = new CountDownLatch(1); final TorrentFileChangeAware listener = new CountDownLatchListener(createLock, deleteLock); provider.registerListener(listener); provider.start(); provider.onFileCreate(torrentFile.toFile()); assertThat(createLock.getCount()).isEqualTo(0); assertThat(deleteLock.getCount()).isEqualTo(1); provider.stop(); provider.unRegisterListener(listener); }
@Before public void setUp() throws Exception { final Map<String, List<Object>> attributes = new HashMap<>(); attributes.put("test", Arrays.asList(new Object[] {"test"})); this.repository = new StubPersonAttributeDao(); this.repository.setBackingMap(attributes); this.registeredServiceFactory = new DefaultRegisteredServiceFactory(); this.registeredServiceFactory.setFormDataPopulators(ImmutableList.of(new AttributeFormDataPopulator(this .repository))); this.registeredServiceFactory.initializeDefaults(); this.manager = new DefaultServicesManagerImpl( new InMemoryServiceRegistryDaoImpl()); this.manager.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); this.controller = new RegisteredServiceSimpleFormController(this.manager, this.registeredServiceFactory); }
@Before public void setUp() throws Exception { final InMemoryServiceRegistryDaoImpl dao = new InMemoryServiceRegistryDaoImpl(); final List<RegisteredService> list = new ArrayList<>(); final RegisteredServiceImpl r = new RegisteredServiceImpl(); r.setId(2500); r.setServiceId("serviceId"); r.setName("serviceName"); r.setEvaluationOrder(1000); list.add(r); dao.setRegisteredServices(list); this.defaultServicesManagerImpl = new DefaultServicesManagerImpl(dao); this.defaultServicesManagerImpl.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); }
@Before public void setUp() throws Exception { this.servicesManager = new DefaultServicesManagerImpl(new InMemoryServiceRegistryDaoImpl()); this.servicesManager.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); final RegisteredServiceImpl r = new RegisteredServiceImpl(); r.setTheme("myTheme"); r.setId(1000); r.setName("Test Service"); r.setServiceId("myServiceId"); this.servicesManager.save(r); final RegisteredServiceImpl r2 = new RegisteredServiceImpl(); r2.setTheme(null); r2.setId(1001); r2.setName("Test Service 2"); r2.setServiceId("myDefaultId"); this.servicesManager.save(r2); this.registeredServiceThemeBasedViewResolver = new RegisteredServiceThemeBasedViewResolver(this.servicesManager); this.registeredServiceThemeBasedViewResolver.setPrefix("/WEB-INF/view/jsp"); }
@Test public void shouldCallOnFileDeleteBeforeDeletingFileWhenArchiving() throws IOException { final Path torrentFile = TorrentFileCreator.create(torrentsPath.resolve("ubuntu.torrent"), TorrentFileCreator.TorrentType.UBUNTU); final TorrentFileProvider provider = Mockito.spy(new TorrentFileProvider(resourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class))); provider.init(); Mockito.doAnswer(invocation -> { assertThat(torrentFile.toFile()).exists(); return null; }).when(provider).onFileDelete(torrentFile.toFile()); provider.onFileCreate(torrentFile.toFile()); provider.moveToArchiveFolder(torrentFile.toFile()); Mockito.verify(provider, Mockito.times(1)).moveToArchiveFolder(torrentFile.toFile()); assertThat(torrentFile.toFile()).doesNotExist(); }
@Test public void shouldNotifyListenerOnFileRemoved() throws IOException { final Path torrentFile = TorrentFileCreator.create(torrentsPath.resolve("ubuntu.torrent"), TorrentFileCreator.TorrentType.UBUNTU); final TorrentFileProvider provider = new TorrentFileProvider(resourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class)); provider.onFileCreate(torrentFile.toFile()); final CountDownLatch createLock = new CountDownLatch(1); final CountDownLatch deleteLock = new CountDownLatch(1); final TorrentFileChangeAware listener = new CountDownLatchListener(createLock, deleteLock); provider.registerListener(listener); provider.onFileDelete(torrentFile.toFile()); provider.unRegisterListener(listener); assertThat(createLock.getCount()).isEqualTo(1); assertThat(deleteLock.getCount()).isEqualTo(0); }
@Test public void shouldUnRegisterListener() throws IOException { final Path torrentFile = TorrentFileCreator.create(torrentsPath.resolve("ubuntu.torrent"), TorrentFileCreator.TorrentType.UBUNTU); final Path torrentFile2 = TorrentFileCreator.create(torrentsPath.resolve("audio.torrent"), TorrentFileCreator.TorrentType.AUDIO); final TorrentFileProvider provider = new TorrentFileProvider(resourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class)); final CountDownLatch createLock = new CountDownLatch(2); final CountDownLatch deleteLock = new CountDownLatch(2); final TorrentFileChangeAware listener = new CountDownLatchListener(createLock, deleteLock); provider.registerListener(listener); provider.start(); provider.onFileCreate(torrentFile.toFile()); provider.unRegisterListener(listener); provider.onFileCreate(torrentFile2.toFile()); assertThat(createLock.getCount()).isEqualTo(1); assertThat(deleteLock.getCount()).isEqualTo(2); provider.stop(); provider.unRegisterListener(listener); }
@Test public void shouldWriteConfigurationFile() throws IOException { new ObjectMapper().writeValue(rewritableResourcePath.resolve("config.json").toFile(), defaultConfig); try { final JoalConfigProvider provider = new JoalConfigProvider(new ObjectMapper(), rewritableResourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class)); final Random rand = new Random(); final AppConfiguration newConf = new AppConfiguration( rand.longs(1, 200).findFirst().getAsLong(), rand.longs(201, 400).findFirst().getAsLong(), rand.ints(1, 5).findFirst().getAsInt(), RandomStringUtils.random(60), false ); provider.saveNewConf(newConf); assertThat(provider.loadConfiguration()).isEqualTo(newConf); } finally { Files.deleteIfExists(rewritableResourcePath.resolve("config.json")); } }
@Before public void onSetUp() throws Exception { this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); this.requestContext = mock(RequestContext.class); final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class); when(this.requestContext.getExternalContext()).thenReturn(servletExternalContext); when(servletExternalContext.getNativeRequest()).thenReturn(request); when(servletExternalContext.getNativeResponse()).thenReturn(response); final LocalAttributeMap flowScope = new LocalAttributeMap(); when(this.requestContext.getFlowScope()).thenReturn(flowScope); this.warnCookieGenerator = new CookieRetrievingCookieGenerator(); this.serviceRegistryDao = new InMemoryServiceRegistryDaoImpl(); this.serviceManager = new DefaultServicesManagerImpl(serviceRegistryDao); this.serviceManager.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); this.serviceManager.reload(); this.warnCookieGenerator.setCookieName("test"); this.ticketGrantingTicketCookieGenerator = new CookieRetrievingCookieGenerator(); this.ticketGrantingTicketCookieGenerator.setCookieName(COOKIE_TGC_ID); this.logoutAction = new LogoutAction(); this.logoutAction.setServicesManager(this.serviceManager); }
@Autowired public DocumentGenerator( CitizenSealedClaimPdfService citizenSealedClaimPdfService, DefendantPinLetterPdfService defendantPinLetterPdfService, LegalSealedClaimPdfService legalSealedClaimPdfService, ApplicationEventPublisher publisher ) { this.citizenSealedClaimPdfService = citizenSealedClaimPdfService; this.defendantPinLetterPdfService = defendantPinLetterPdfService; this.legalSealedClaimPdfService = legalSealedClaimPdfService; this.publisher = publisher; }
@Test public void testPublishDisconnectedEventNullClientId() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(EXCEPTION_MESSAGE_CLIENT_ID); ApplicationEventPublisher applicationEventPublisher = Mockito .mock(ApplicationEventPublisher.class); mqttClientEventPublisher.publishDisconnectedEvent(null, applicationEventPublisher, this); }
/** * This test checks that the TGT destruction happens properly for a remote registry. * It previously failed when the deletion happens before the ticket was marked expired because an update was necessary for that. * * @throws AuthenticationException * @throws AbstractTicketException */ @Test public void verifyDestroyRemoteRegistry() throws AbstractTicketException, AuthenticationException { final MockOnlyOneTicketRegistry registry = new MockOnlyOneTicketRegistry(); final TicketGrantingTicketImpl tgt = new TicketGrantingTicketImpl("TGT-1", mock(Authentication.class), mock(ExpirationPolicy.class)); final MockExpireUpdateTicketLogoutManager logoutManager = new MockExpireUpdateTicketLogoutManager(registry); registry.addTicket(tgt); final CentralAuthenticationServiceImpl cas = new CentralAuthenticationServiceImpl(registry, null, null, logoutManager); cas.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); cas.destroyTicketGrantingTicket(tgt.getId()); }
@Test public void shouldFailIfFolderDoesNotContainsTorrentFiles() throws IOException { final TorrentFileProvider provider = new TorrentFileProvider(resourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class)); assertThatThrownBy(() -> provider.getTorrentNotIn(new ArrayList<>())) .isInstanceOf(NoMoreTorrentsFileAvailableException.class) .hasMessageContaining("No more torrent file available."); }
@Test public void testPublishConnectionLostEvent() { ApplicationEventPublisher applicationEventPublisher = Mockito .mock(ApplicationEventPublisher.class); mqttClientEventPublisher.publishConnectionLostEvent(CLIENT_ID, true, applicationEventPublisher, this); Mockito.verify(applicationEventPublisher, Mockito.atLeast(1)) .publishEvent(Mockito.any(MqttClientConnectionLostEvent.class)); }
@Before public void setUp() throws Exception { this.servicesManager = new DefaultServicesManagerImpl(new InMemoryServiceRegistryDaoImpl()); this.servicesManager.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); this.serviceThemeResolver = new ServiceThemeResolver(); this.serviceThemeResolver.setDefaultThemeName("test"); this.serviceThemeResolver.setServicesManager(this.servicesManager); final Map<String, String> mobileBrowsers = new HashMap<>(); mobileBrowsers.put("Mozilla", "theme"); this.serviceThemeResolver.setMobileBrowsers(mobileBrowsers); }
@Before public void setUp() { try { this.dao = new JsonServiceRegistryDao(RESOURCE, false, mock(ApplicationEventPublisher.class)); } catch (final Exception e) { throw new IllegalArgumentException(e); } }
@Test public void verifySavingSamlService() throws Exception { final SamlRegisteredService service = new SamlRegisteredService(); service.setName(SAML_SERVICE); service.setServiceId("http://mmoayyed.unicon.net"); service.setMetadataLocation(METADATA_LOCATION); final JsonServiceRegistryDao dao = new JsonServiceRegistryDao(RESOURCE, false, mock(ApplicationEventPublisher.class)); dao.save(service); dao.load(); }
@Test public void verifySavingInCommonSamlService() throws Exception { final SamlRegisteredService service = new SamlRegisteredService(); service.setName(SAML_SERVICE); service.setServiceId("http://mmoayyed.unicon.net"); service.setMetadataLocation(METADATA_LOCATION); final InCommonRSAttributeReleasePolicy policy = new InCommonRSAttributeReleasePolicy(); final ChainingAttributeReleasePolicy chain = new ChainingAttributeReleasePolicy(); chain.setPolicies(Arrays.asList(policy, new DenyAllAttributeReleasePolicy())); service.setAttributeReleasePolicy(chain); final JsonServiceRegistryDao dao = new JsonServiceRegistryDao(RESOURCE, false, mock(ApplicationEventPublisher.class)); dao.save(service); dao.load(); }
@Test public void testPublishConnectedEventNullSubscribedTopics() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("'subscribedTopics' must be set!"); ApplicationEventPublisher applicationEventPublisher = Mockito .mock(ApplicationEventPublisher.class); mqttClientEventPublisher.publishConnectedEvent(CLIENT_ID, SERVER_URI, null, applicationEventPublisher, this); }
@Test public void shouldNotFailIfFileIsNotPresentWhenArchiving() throws IOException { final Path torrentFile = TorrentFileCreator.create(torrentsPath.resolve("ubuntu.torrent"), TorrentFileCreator.TorrentType.UBUNTU); final TorrentFileProvider provider = new TorrentFileProvider(resourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class)); try { provider.moveToArchiveFolder(torrentFile.resolve("dd.torrent").toFile()); } catch (final Throwable throwable) { fail("should not fail if file were not present."); } }
@Test public void shouldMoveTorrentFileToArchivedFolder() throws IOException { final Path torrentFile = TorrentFileCreator.create(torrentsPath.resolve("ubuntu.torrent"), TorrentFileCreator.TorrentType.UBUNTU); final TorrentFileProvider provider = new TorrentFileProvider(resourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class)); provider.init(); provider.onFileCreate(torrentFile.toFile()); assertThat(provider.getTorrentCount()).isEqualTo(1); assertThat(archivedTorrentPath.resolve("ubuntu.torrent")).doesNotExist(); provider.moveToArchiveFolder(torrentFile.toFile()); assertThat(torrentsPath.resolve("ubuntu.torrent")).doesNotExist(); assertThat(archivedTorrentPath.resolve("ubuntu.torrent")).exists(); }
@Autowired public MainFrame(@NonNull ApplicationEventPublisher publisher, @NonNull AboutFrame aboutFrame) { super(); this.publisher = publisher; this.aboutFrame = aboutFrame; initMenu(); }
/** * Instantiates a new Json service registry config watcher. * * @param serviceRegistryDao the registry to callback */ ServiceRegistryConfigWatcher(final ResourceBasedServiceRegistryDao serviceRegistryDao, final ApplicationEventPublisher eventPublisher) { try { this.serviceRegistryDao = serviceRegistryDao; this.watcher = FileSystems.getDefault().newWatchService(); final WatchEvent.Kind[] kinds = new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY}; LOGGER.debug("Created service registry watcher for events of type [{}]", (Object[]) kinds); this.serviceRegistryDao.getWatchableResource().register(this.watcher, kinds); this.applicationEventPublisher = eventPublisher; } catch (final IOException e) { throw Throwables.propagate(e); } }
@Test public void testPublishConnectedEventNullServerUri() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("'serverUri' must be set!"); ApplicationEventPublisher applicationEventPublisher = Mockito .mock(ApplicationEventPublisher.class); mqttClientEventPublisher.publishConnectedEvent(CLIENT_ID, null, SUBSCRIBED_TOPICS_EMPTY, applicationEventPublisher, this); }
@Test public void shouldNotBuildIfFolderDoesNotExists() throws FileNotFoundException { assertThatThrownBy(() -> new TorrentFileProvider(resourcePath.resolve("nop").toString(), Mockito.mock(ApplicationEventPublisher.class))) .isInstanceOf(FileNotFoundException.class) .hasMessageStartingWith("Torrent folder '") .hasMessageEndingWith("' not found."); }
/** * Instantiates a new batch processor. * * @param processName * the process name * @param retryingTransactionHelper * the retrying transaction helper * @param collection * the collection * @param workerThreads * the number of worker threads * @param batchSize * the number of entries we process at a time in a transaction * @param applicationEventPublisher * the application event publisher (may be <tt>null</tt>) * @param logger * the logger to use (may be <tt>null</tt>) * @param loggingInterval * the number of entries to process before reporting progress * * @deprecated Since 3.4, use the {@link BatchProcessWorkProvider} instead of the <tt>Collection</tt> */ public BatchProcessor( String processName, RetryingTransactionHelper retryingTransactionHelper, final Collection<T> collection, int workerThreads, int batchSize, ApplicationEventPublisher applicationEventPublisher, Log logger, int loggingInterval) { this( processName, retryingTransactionHelper, new BatchProcessWorkProvider<T>() { boolean hasMore = true; public int getTotalEstimatedWorkSize() { return collection.size(); } public Collection<T> getNextWork() { // Only return the collection once if (hasMore) { hasMore = false; return collection; } else { return Collections.emptyList(); } } }, workerThreads, batchSize, applicationEventPublisher, logger, loggingInterval); }
@Test public void shouldAddFileToListOnCreation() throws IOException { TorrentFileCreator.create(torrentsPath.resolve("ubuntu.torrent"), TorrentFileCreator.TorrentType.UBUNTU); final TorrentFileProvider provider = new TorrentFileProvider(resourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class)); assertThat(provider.getTorrentCount()).isEqualTo(0); provider.onFileCreate(torrentsPath.resolve("ubuntu.torrent").toFile()); assertThat(provider.getTorrentCount()).isEqualTo(1); }
@Autowired public GameServerService(GameServerRepository gameServerRepository, GameServerMapper gameServerMapper, GameAdminService gameAdminService, GameQueryService gameQueryService, ApplicationEventPublisher publisher, MetricRegistry metricRegistry, SettingService settingService) { this.gameServerRepository = gameServerRepository; this.gameServerMapper = gameServerMapper; this.gameAdminService = gameAdminService; this.gameQueryService = gameQueryService; this.publisher = publisher; this.metricRegistry = metricRegistry; this.settingService = settingService; }
@Autowired public StreamerService(StreamerRepository streamerRepository, StreamerMapper streamerMapper, SentryProperties sentryProperties, RestTemplate restTemplate, ApplicationEventPublisher publisher, SettingService settingService) { this.streamerRepository = streamerRepository; this.streamerMapper = streamerMapper; this.sentryProperties = sentryProperties; this.restTemplate = restTemplate; this.publisher = publisher; this.settingService = settingService; }
@Autowired public EventSourcingServiceImpl( EventStoreRepository eventStore, EventSerializer eventSerializer, ApplicationEventPublisher eventPublisher ) { this.eventStoreRepository = eventStore; this.eventSerializer = eventSerializer; }
@Test public void shouldFailIfJsonFileIsNotPresent() { final String fakePath = resourcePath.resolve("nop").toString(); assertThatThrownBy(() -> new JoalConfigProvider(new ObjectMapper(), fakePath, Mockito.mock(ApplicationEventPublisher.class))) .isInstanceOf(FileNotFoundException.class) .hasMessageContaining("App configuration file '" + fakePath + File.separator + "config.json' not found."); }
@Test public void testPublishConnectedEventNullClientId() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(EXCEPTION_MESSAGE_CLIENT_ID); ApplicationEventPublisher applicationEventPublisher = Mockito .mock(ApplicationEventPublisher.class); mqttClientEventPublisher.publishConnectedEvent(null, SERVER_URI, SUBSCRIBED_TOPICS_EMPTY, applicationEventPublisher, this); }
@Before public void setUp() throws Exception { this.servicesManager = new DefaultServicesManagerImpl(new InMemoryServiceRegistryDaoImpl()); this.servicesManager.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); this.registeredServiceFactory = new DefaultRegisteredServiceFactory(); this.registeredServiceFactory.initializeDefaults(); this.controller = new ManageRegisteredServicesMultiActionController(this.servicesManager, this .registeredServiceFactory, "foo"); }
@Test public void testPublishConnectionFailureEventNullClientId() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(EXCEPTION_MESSAGE_CLIENT_ID); ApplicationEventPublisher applicationEventPublisher = Mockito .mock(ApplicationEventPublisher.class); mqttClientEventPublisher.publishConnectionFailureEvent(null, true, new Exception(), applicationEventPublisher, this); }