@Test public void shouldNotThrowException_instedReturnAppropriateErrorCode_whenSomethingGoesWrongInLaunch() { AgentLaunchDescriptor launchDesc = mock(AgentLaunchDescriptor.class); when((String) launchDesc.context().get(AgentBootstrapperArgs.SERVER_URL)).thenThrow(new RuntimeException("Ouch!")); try { assertThat(new AgentLauncherImpl().launch(launchDesc), is(-273)); } catch (Exception e) { fail("should not have blown up, because it directly interfaces with bootstrapper"); } }
@Test public void shouldDownloadLauncherJarIfLocalCopyIsStale_butShouldReturnWithoutDownloadingOrLaunchingAgent() throws Exception { File launcher = randomFile(AGENT_LAUNCHER_JAR); long original = launcher.length(); File agentFile = randomFile(AGENT_BINARY_JAR); long originalAgentLength = agentFile.length(); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(launcher.length(), not(original)); assertThat(agentFile.length(), is(originalAgentLength)); }
@Test public void shouldDownloadLauncherJarIfLocalCopyIsStale() throws IOException { //because new invocation will take care of pulling latest agent down, and will then operate on it with the latest launcher -jj File staleJar = randomFile(AGENT_LAUNCHER_JAR); long original = staleJar.length(); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(staleJar.length(), not(original)); }
@Test public void shouldDownload_AgentJar_IfTheCurrentJarIsStale() throws Exception { if (!OS_CHECKER.satisfy()) { TEST_AGENT_LAUNCHER.copyTo(AGENT_LAUNCHER_JAR); File staleJar = randomFile(AGENT_BINARY_JAR); long original = staleJar.length(); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(staleJar.length(), not(original)); } }
@Test public void should_NOT_Download_AgentJar_IfTheCurrentJarIsUpToDate() throws Exception { if (!OS_CHECKER.satisfy()) { TEST_AGENT_LAUNCHER.copyTo(AGENT_LAUNCHER_JAR); TEST_AGENT.copyTo(AGENT_BINARY_JAR); assertTrue(AGENT_BINARY_JAR.setLastModified(0)); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(AGENT_BINARY_JAR.lastModified(), is(0L)); } }
@Test public void should_NOT_Download_TfsImplJar_IfTheCurrentJarIsUpToDate() throws Exception { if (!OS_CHECKER.satisfy()) { TEST_AGENT_LAUNCHER.copyTo(AGENT_LAUNCHER_JAR); TEST_AGENT.copyTo(AGENT_BINARY_JAR); TEST_TFS_IMPL.copyTo(TFS_IMPL_JAR); assertTrue(TFS_IMPL_JAR.setLastModified(0)); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(TFS_IMPL_JAR.lastModified(), is(0L)); } }