DeploymentManager implements ConfigurationManager<Deployment> { @Override public List<Deployment> list(Deployment filter, String groupName) { Configuration configuration = persistenceService.getConfiguration(groupName); if (configuration == null) { return emptyList(); } return configuration.getDeployments().stream() .filter(deploymentsForJarName(filter.getFileName())) .collect(toList()); } DeploymentManager(InternalConfigurationPersistenceService persistenceService); @Override void add(Deployment config, String groupName); @Override void delete(Deployment config, String groupName); @Override void update(Deployment config, String groupName); @Override List<Deployment> list(Deployment filter, String groupName);  }
@Test public void listWithNullJarNameReturnsAllDeployedJarsForGroup() { Set<Deployment> configuredDeployments = new HashSet<>(asList( new Deployment("jar1.jar", "deployedBy1", "deployedTime1"), new Deployment("jar2.jar", "deployedBy2", "deployedTime2"), new Deployment("jar3.jar", "deployedBy3", "deployedTime3"))); Configuration configuration = mock(Configuration.class); when(configuration.getDeployments()).thenReturn(configuredDeployments); InternalConfigurationPersistenceService persistenceService = mock(InternalConfigurationPersistenceService.class); when(persistenceService.getConfiguration(any())).thenReturn(configuration); DeploymentManager manager = new DeploymentManager(persistenceService); Deployment filter = new Deployment(); filter.setFileName(null); List<Deployment> result = manager.list(filter, "some-group"); assertThat(result) .containsExactlyInAnyOrderElementsOf(configuredDeployments); }
@Test public void listWithJarNameReturnsSingletonListConfiguredDeploymentForThatJar() { String requestedJarFile = "jar2.jar"; Deployment expectedDeployment = new Deployment(requestedJarFile, "deployedBy2", "deployedTime2"); Set<Deployment> configuredJarNames = new HashSet<>(asList( new Deployment("jar1.jar", "deployedBy1", "deployedTime1"), expectedDeployment, new Deployment("jar3.jar", "deployedBy3", "deployedTime3"))); Configuration configuration = mock(Configuration.class); when(configuration.getDeployments()).thenReturn(configuredJarNames); InternalConfigurationPersistenceService persistenceService = mock(InternalConfigurationPersistenceService.class); when(persistenceService.getConfiguration(any())).thenReturn(configuration); DeploymentManager manager = new DeploymentManager(persistenceService); Deployment filter = new Deployment(); filter.setFileName(requestedJarFile); List<Deployment> result = manager.list(filter, "some-group"); assertThat(result).containsExactly(expectedDeployment); }
@Test public void listWithJarNameReturnsEmptyListIfRequestedJarNotDeployed() { Configuration configuration = mock(Configuration.class); when(configuration.getDeployments()).thenReturn(emptySet()); InternalConfigurationPersistenceService persistenceService = mock(InternalConfigurationPersistenceService.class); when(persistenceService.getConfiguration(any())).thenReturn(configuration); DeploymentManager manager = new DeploymentManager(persistenceService); Deployment filter = new Deployment(); filter.setFileName("jarFileThatHasNotBeenDeployed.jar"); List<Deployment> result = manager.list(filter, "some-group"); assertThat(result).isEmpty(); }
@Test public void listNonExistentGroup() { InternalConfigurationPersistenceService persistenceService = mock(InternalConfigurationPersistenceService.class); when(persistenceService.getConfiguration("some-group")).thenReturn(null); DeploymentManager manager = new DeploymentManager(persistenceService); Deployment filter = new Deployment(); List<Deployment> result = manager.list(filter, "some-group"); assertThat(result).isEmpty(); }