@Test public void successful_install_changesSdkStatus_inProgress() { sdkService.addStatusUpdateListener(mockStatusUpdateListener); emulateMockSdkInstallationProcess(MOCK_SDK_PATH); sdkService.install(); ArgumentCaptor<SdkStatus> statusCaptor = ArgumentCaptor.forClass(SdkStatus.class); verify(mockStatusUpdateListener, times(2)).onSdkStatusChange(any(), statusCaptor.capture()); assertThat(statusCaptor.getAllValues()) .isEqualTo(Arrays.asList(SdkStatus.INSTALLING, SdkStatus.READY)); }
@Test public void failed_install_changesSdkStatus_inProgress() throws Exception { sdkService.addStatusUpdateListener(mockStatusUpdateListener); emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller mockInstaller = mockManagedCloudSdk.newInstaller(); when(mockInstaller.install(any(), any())).thenThrow(new IOException("IO Error")); sdkService.install(); ArgumentCaptor<SdkStatus> statusCaptor = ArgumentCaptor.forClass(SdkStatus.class); verify(mockStatusUpdateListener, times(2)).onSdkStatusChange(any(), statusCaptor.capture()); assertThat(statusCaptor.getAllValues()) .isEqualTo(Arrays.asList(SdkStatus.INSTALLING, SdkStatus.NOT_AVAILABLE)); }
@Test public void failed_install_showsErrorNotification() throws Exception { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller mockInstaller = mockManagedCloudSdk.newInstaller(); IOException ioException = new IOException("IO Error"); when(mockInstaller.install(any(), any())).thenThrow(ioException); sdkService.install(); verify(mockUiPresenter) .notifyManagedSdkJobFailure(ManagedSdkJobType.INSTALL, ioException.toString()); }
@Test public void failed_install_removesProgressIndicator() throws Exception { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller mockInstaller = mockManagedCloudSdk.newInstaller(); IOException ioException = new IOException("IO Error"); when(mockInstaller.install(any(), any())).thenThrow(ioException); sdkService.install(); verify(mockProgressListener, atLeastOnce()).done(); }
@Test public void interruptedInstall_showsCancelNotification() throws Exception { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller sdkInstaller = mockManagedCloudSdk.newInstaller(); when(sdkInstaller.install(any(), any())).thenThrow(new InterruptedException()); when(mockManagedCloudSdk.newInstaller()).thenReturn(sdkInstaller); sdkService.install(); verify(mockUiPresenter).notifyManagedSdkJobCancellation(ManagedSdkJobType.INSTALL); }
@Test public void cancelledInstall_stops_installing_onActivation() throws Exception { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller sdkInstaller = mockManagedCloudSdk.newInstaller(); when(sdkInstaller.install(any(), any())).thenThrow(new CancellationException()); when(mockManagedCloudSdk.newInstaller()).thenReturn(sdkInstaller); sdkService.install(); // cancelled, now attempt to do clean install process and activation. emulateMockSdkInstallationProcess(MOCK_SDK_PATH); sdkService.activate(); // install is not supposed to run on activation anymore. assertThat(sdkService.getStatus()).isEqualTo(SdkStatus.NOT_AVAILABLE); }
@Test public void failed_install_appEngineException_changesSdkStatus_inProgress() throws Exception { sdkService.addStatusUpdateListener(mockStatusUpdateListener); emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkComponentInstaller mockComponentInstaller = mockManagedCloudSdk.newComponentInstaller(); doThrow(new CommandExecutionException(new UnsupportedOperationException())) .when(mockComponentInstaller) .installComponent(any(), any(), any()); sdkService.install(); ArgumentCaptor<SdkStatus> statusCaptor = ArgumentCaptor.forClass(SdkStatus.class); verify(mockStatusUpdateListener, times(2)).onSdkStatusChange(any(), statusCaptor.capture()); assertThat(statusCaptor.getAllValues()) .isEqualTo(Arrays.asList(SdkStatus.INSTALLING, SdkStatus.NOT_AVAILABLE)); }
@Test public void cancelledInstall_showsCancelNotification() throws Exception { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller sdkInstaller = mockManagedCloudSdk.newInstaller(); when(sdkInstaller.install(any(), any())).thenThrow(new CancellationException()); when(mockManagedCloudSdk.newInstaller()).thenReturn(sdkInstaller); sdkService.install(); verify(mockUiPresenter).notifyManagedSdkJobCancellation(ManagedSdkJobType.INSTALL); }
@Test public void removeListener_does_remove() { sdkService.addStatusUpdateListener(mockStatusUpdateListener); sdkService.removeStatusUpdateListener(mockStatusUpdateListener); emulateMockSdkInstallationProcess(MOCK_SDK_PATH); verifyNoMoreInteractions(mockStatusUpdateListener); }
@Test public void interruptedInstall_status_notAvailable() throws Exception { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller sdkInstaller = mockManagedCloudSdk.newInstaller(); when(sdkInstaller.install(any(), any())).thenThrow(new InterruptedException()); when(mockManagedCloudSdk.newInstaller()).thenReturn(sdkInstaller); sdkService.install(); assertThat(sdkService.getStatus()).isEqualTo(SdkStatus.NOT_AVAILABLE); }
@Test public void successful_install_showsNotification() { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); sdkService.install(); verify(mockUiPresenter) .notifyManagedSdkJobSuccess(ManagedSdkJobType.INSTALL, ManagedSdkJobResult.PROCESSED); }
@Test public void actual_install_notifiesListeners_onProcessingStart() { sdkService.addStatusUpdateListener(mockStatusUpdateListener); emulateMockSdkInstallationProcess(MOCK_SDK_PATH); sdkService.install(); // for real new install, 2 invocations - SDK and app-engine-java components. verify(mockStatusUpdateListener, times(2)).onSdkProcessingStarted(); }
@Test public void successful_install_returnsValidSdkPath() { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); sdkService.install(); assertThat((Object) sdkService.getSdkHomePath()).isEqualTo(MOCK_SDK_PATH); }
@Test public void install_blocks_whenSDKReadOperations_running() throws Exception { emulateMockSdkInstallationProcess(MOCK_SDK_PATH); SdkInstaller mockInstaller = mock(SdkInstaller.class); when(mockManagedCloudSdk.newInstaller()).thenReturn(mockInstaller); CloudSdkServiceManager.getInstance().getSdkReadLock().lock(); try { // signal when install is about to start write operation. CountDownLatch waitForInstallToStart = new CountDownLatch(1); doAnswer( invocationOnMock -> { waitForInstallToStart.countDown(); return false; }) .when(mockManagedCloudSdk) .isInstalled(); Runnable installProcess = () -> sdkService.install(); Thread installProcessThread = new Thread(installProcess, "test-install-blocking-thread"); installProcessThread.start(); // do timed wait in case of test issues not to cause it to hang. waitForInstallToStart.await(100, TimeUnit.MILLISECONDS); installProcessThread.interrupt(); // finalize install() installProcessThread.join(); // since the write block was not available at the install, install() should never be called. verifyNoMoreInteractions(mockInstaller); } finally { CloudSdkServiceManager.getInstance().getSdkReadLock().unlock(); } }