@Test public void testKillJob() throws Exception { List<String> expectedCommand = asList( "aurora job killall %s %s %s %d", JOB_SPEC, VERBOSE_CONFIG, BATCH_CONFIG, Integer.MAX_VALUE); // Failed Mockito.doReturn(false).when(controller).runProcess(Matchers.anyListOf(String.class)); Assert.assertFalse(controller.killJob()); Mockito.verify(controller).runProcess(Mockito.eq(expectedCommand)); // Happy path Mockito.doReturn(true).when(controller).runProcess(Matchers.anyListOf(String.class)); Assert.assertTrue(controller.killJob()); Mockito.verify(controller, Mockito.times(2)).runProcess(expectedCommand); }
@Test public void testCreateJob() throws Exception { String auroraFilename = "file.aurora"; Map<String, String> bindings = new HashMap<>(); List<String> expectedCommand = asList( "aurora job create --wait-until RUNNING %s %s %s", JOB_SPEC, auroraFilename, VERBOSE_CONFIG); // Failed Mockito.doReturn(false).when(controller).runProcess(Matchers.anyListOf(String.class)); Assert.assertFalse(controller.createJob(auroraFilename, bindings)); Mockito.verify(controller).runProcess(Mockito.eq(expectedCommand)); // Happy path Mockito.doReturn(true).when(controller).runProcess(Matchers.anyListOf(String.class)); Assert.assertTrue(controller.createJob(auroraFilename, bindings)); Mockito.verify(controller, Mockito.times(2)).runProcess(expectedCommand); }
@Test public void testAddContainers() { Integer containersToAdd = 3; List<String> expectedCommand = asList("aurora job add --wait-until RUNNING %s/0 %s", JOB_SPEC, containersToAdd.toString()); Mockito.doReturn(true).when(controller).runProcess(Matchers.anyListOf(String.class)); controller.addContainers(containersToAdd); Mockito.verify(controller).runProcess(Mockito.eq(expectedCommand)); }
@Test public void testFetchData() { // result from server is a list with at least one film -> give this film list to tableView when(filmDataModel.getAppliedFilter()).thenReturn(demoFilterWithResult); tablePresenter.fetchData(); // 1st called from constructor (no results info), 2nd called when rpc starts loading (loading // info),3rd the result from the rpc verify(tableView, times(3)).setTable(Matchers.anyListOf(Film.class)); // result from server is empty list -> tableView receives pseudo film list with information when(filmDataModel.getAppliedFilter()).thenReturn(demoFilterWithoutResult); tablePresenter.fetchData(); // 1st called from constructor (no results info), 2nd the result of the empty rpc verify(tableView, times(2)) .setTable(Matchers.eq(tablePresenter.createPseudoFilmList("No Search Results Found"))); }
@Test public void testRemoveContainers() { class ContainerPlanComparator implements Comparator<PackingPlan.ContainerPlan> { @Override public int compare(PackingPlan.ContainerPlan o1, PackingPlan.ContainerPlan o2) { return ((Integer) o1.getId()).compareTo(o2.getId()); } } SortedSet<PackingPlan.ContainerPlan> containers = new TreeSet<>(new ContainerPlanComparator()); containers.add(PackingTestUtils.testContainerPlan(3)); containers.add(PackingTestUtils.testContainerPlan(5)); List<String> expectedCommand = asList("aurora job kill %s/3,5", JOB_SPEC); Mockito.doReturn(true).when(controller).runProcess(Matchers.anyListOf(String.class)); controller.removeContainers(containers); Mockito.verify(controller).runProcess(Mockito.eq(expectedCommand)); }
@SuppressWarnings("unchecked") @Override protected void setup(TestContainer container) throws Exception { AESEncrypter.generateKey(); container.addBean(configService = Mockito.mock(APPConfigurationServiceBean.class)); container.addBean(Mockito.mock(ServiceInstanceDAO.class)); container.addBean(Mockito.mock(APPConcurrencyServiceBean.class)); container.addBean(Mockito.mock(ProductProvisioningServiceFactoryBean.class)); container.addBean(Mockito.mock(APPCommunicationServiceBean.class)); serviceMock = Mockito.mock(Service.class); besDAO = Mockito.mock(BesDAO.class); subcriptionService = Mockito.mock(SubscriptionService.class); identityService = Mockito.mock(EnhancedIdentityService.class); Mockito.doReturn(Arrays.asList(new VOUserDetails())) .when(besDAO) .getBESTechnologyManagers(Matchers.any(ServiceInstance.class)); Mockito.doReturn(identityService) .when(besDAO) .getBESWebService(Matchers.eq(IdentityService.class), Matchers.any(ServiceInstance.class)); Mockito.doNothing() .when(besDAO) .setUserCredentialsInContext( Matchers.any(BindingProvider.class), Matchers.anyString(), Matchers.anyString(), Matchers.anyMap()); Mockito.doReturn(subcriptionService) .when(besDAO) .getBESWebService( Matchers.eq(SubscriptionService.class), Matchers.any(ServiceInstance.class)); Mockito.doNothing() .when(subcriptionService) .completeAsyncSubscription( Matchers.anyString(), Matchers.anyString(), Matchers.any(VOInstanceInfo.class)); Mockito.doNothing() .when(subcriptionService) .abortAsyncSubscription( Matchers.anyString(), Matchers.anyString(), Matchers.anyListOf(VOLocalizedText.class)); Mockito.doReturn(subcriptionService) .when(serviceMock) .getPort(Matchers.any(QName.class), Matchers.eq(SubscriptionService.class)); Mockito.doReturn(serviceMock) .when(besDAO) .createWebService(Matchers.any(URL.class), Matchers.any(QName.class)); Mockito.doReturn(identityService) .when(serviceMock) .getPort(Matchers.any(QName.class), Matchers.eq(IdentityService.class)); container.addBean(besDAO); container.addBean(Mockito.mock(OperationDAO.class)); container.addBean(Mockito.mock(ServiceInstanceDAO.class)); container.addBean(Mockito.mock(OperationServiceBean.class)); container.addBean(authService = Mockito.spy(new APPAuthenticationServiceBean())); container.addBean(Mockito.mock(OperationServiceBean.class)); container.addBean(new APPlatformServiceBean()); controller = Mockito.mock(APPlatformController.class); InitialContext context = new InitialContext(); context.bind("bss/app/controller/ess.vmware", controller); container.addBean(controller); besDAO = container.get(BesDAO.class); platformService = container.get(APPlatformService.class); em = container.getPersistenceUnit("oscm-app"); defaultAuth = new PasswordAuthentication("user", "password"); }