コード例 #1
0
  @Test
  public void assertJobNameWithoutComputerIsResolved() {
    when(project.getName()).thenReturn("ThisIsAJob");

    BuildVariableResolver resolver = new BuildVariableResolver(project);
    assertEquals("Variable resolution was incorrect", "ThisIsAJob", resolver.resolve("JOB_NAME"));
    assertNull("Variable resolution was performed", resolver.resolve("NONE_EXISTING_KEY"));
  }
コード例 #2
0
  /**
   * Asserts that NODE_NAME works on the master computer, as the MasterComputer.getName() returns
   * null.
   */
  @Test
  public void assertMasterNodeNameIsResolved() {
    when(computer.getName()).thenReturn("");

    BuildVariableResolver resolver = new BuildVariableResolver(project, computer);
    assertEquals("Variable resolution was incorrect", "MASTER", resolver.resolve("NODE_NAME"));
    verifyZeroInteractions(project);
  }
コード例 #3
0
  @Test
  public void assertJobNameIsResolved() {
    when(project.getName()).thenReturn("ThisIsAJob");

    BuildVariableResolver resolver = new BuildVariableResolver(project, computer);
    assertEquals("Variable resolution was incorrect", "ThisIsAJob", resolver.resolve("JOB_NAME"));
    verifyZeroInteractions(computer);
  }
コード例 #4
0
  @Test
  public void assertNoComputeraDoesNotThrowNPEWhenResolvingNodeName() {
    when(launcher.getComputer()).thenReturn(null);

    BuildVariableResolver resolver = new BuildVariableResolver(project, launcher);
    assertNull("Variable resolution was incorrect", resolver.resolve("NODE_NAME"));
    verifyZeroInteractions(project);
  }
コード例 #5
0
  @Test
  public void assertNodeNameIsResolved() {
    Computer computer = mock(Computer.class);
    when(launcher.getComputer()).thenReturn(computer);
    when(computer.getName()).thenReturn("AKIRA");

    BuildVariableResolver resolver = new BuildVariableResolver(project, launcher);
    assertEquals("Variable resolution was incorrect", "AKIRA", resolver.resolve("NODE_NAME"));
    verifyZeroInteractions(project);
  }
コード例 #6
0
  @Test
  public void assertComputerUserNameIsResolved() throws Exception {
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("user.name", "Other_user");

    when(computer.getSystemProperties()).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(project, computer);
    assertEquals("Variable resolution was incorrect", "Other_user", resolver.resolve("USER_NAME"));
    verifyZeroInteractions(project);
  }
コード例 #7
0
  @Test
  public void assertComputerEnvVarIsResolved() throws Exception {
    EnvVars map = new EnvVars();
    map.put("ENV_VAR", "This is an env var");

    when(computer.getEnvironment()).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(project, computer);
    assertEquals(
        "Variable resolution was incorrect", "This is an env var", resolver.resolve("ENV_VAR"));
    verifyZeroInteractions(project);
  }
コード例 #8
0
  @Test
  public void assertBuildEnvVarIsResolved() throws Exception {
    EnvVars map = new EnvVars();
    map.put("BUILD_ID", "121212");

    when(build.getProject()).thenReturn(project);
    when(build.getEnvironment(TaskListener.NULL)).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(build, computer);
    assertEquals("Variable resolution was incorrect", "121212", resolver.resolve("BUILD_ID"));
    verify(build).getEnvironment(TaskListener.NULL);
    verifyZeroInteractions(project);
  }
コード例 #9
0
  @Test
  public void assertBuildEnvVarIsResolved() throws Exception {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("BUILD_ID", "121212");

    when(build.getProject()).thenReturn(project);
    when(build.getEnvVars()).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(build, launcher);
    assertEquals("Variable resolution was incorrect", "121212", resolver.resolve("BUILD_ID"));
    verify(build).getEnvVars();
    verifyZeroInteractions(project);
  }
コード例 #10
0
  @Test
  public void assertComputerEnvVarIsResolved() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("ENV_VAR", "This is an env var");

    Computer computer = mock(Computer.class);
    when(launcher.getComputer()).thenReturn(computer);
    when(computer.getEnvVars()).thenReturn(map);

    BuildVariableResolver resolver = new BuildVariableResolver(project, launcher);
    assertEquals(
        "Variable resolution was incorrect", "This is an env var", resolver.resolve("ENV_VAR"));
    verifyZeroInteractions(project);
  }