예제 #1
0
 @Issue("JENKINS-27441")
 @Test
 public void getLogReturnsAnEmptyListWhenCalledWith0() throws Exception {
   Job j = Mockito.mock(Job.class);
   File tempBuildDir = tmp.newFolder();
   Mockito.when(j.getBuildDir()).thenReturn(tempBuildDir);
   Run<? extends Job<?, ?>, ? extends Run<?, ?>> r = new Run(j, 0) {};
   File f = r.getLogFile();
   f.getParentFile().mkdirs();
   PrintWriter w = new PrintWriter(f, "utf-8");
   w.println("dummy");
   w.close();
   List<String> logLines = r.getLog(0);
   assertTrue(logLines.isEmpty());
 }
예제 #2
0
 @Test
 public void testIsEmbeddableAnnotated() {
   assertTrue(finder.isEmbeddableAnnotated(job.getClass()));
   assertFalse(finder.isEmbeddableAnnotated(person.getClass()));
   assertFalse(finder.isEmbeddableAnnotated(getClass()));
   assertFalse(finder.isEmbeddableAnnotated(null));
 }
예제 #3
0
  @Test
  public void getLogReturnsAllLines() throws Exception {
    Job j = Mockito.mock(Job.class);
    File tempBuildDir = tmp.newFolder();
    Mockito.when(j.getBuildDir()).thenReturn(tempBuildDir);
    Run<? extends Job<?, ?>, ? extends Run<?, ?>> r = new Run(j, 0) {};
    File f = r.getLogFile();
    f.getParentFile().mkdirs();
    PrintWriter w = new PrintWriter(f, "utf-8");
    w.print("a1\nb2\n\nc3");
    w.close();
    List<String> logLines = r.getLog(10);
    assertFalse(logLines.isEmpty());

    assertEquals("a1", logLines.get(0));
    assertEquals("b2", logLines.get(1));
    assertEquals("", logLines.get(2));
    assertEquals("c3", logLines.get(3));
  }
예제 #4
0
 @Test
 public void testFindMethodColumns() {
   Map<String, Class> columnMap = new HashMap<String, Class>();
   finder.findMethodColumns(Job.class, null, columnMap, false);
   String columnType = columnMap.get("job_name").getCanonicalName();
   assertTrue("expecting size == 2 but found " + columnMap.size(), columnMap.size() == 2);
   assertNotNull(
       "expecting not null but found " + columnMap.get("job_name"), columnMap.get("job_name"));
   assertNotNull(
       "expecting not null but found " + columnMap.get("postal_code"),
       columnMap.get("postal_code"));
   columnMap.clear();
   finder.findMethodColumns(Job.class, null, columnMap, true);
   assertTrue("expecting size == 1 but found " + columnMap.size(), columnMap.size() == 1);
   assertNotNull(
       "expecting not null but found " + columnMap.get("job_name"), columnMap.get("job_name"));
   columnMap.clear();
   finder.findMethodColumns(Address.class, "zipcode", columnMap, false);
   assertTrue("expecting size == 1 but found " + columnMap.size(), columnMap.size() == 1);
   assertNotNull(
       "expecting not null but found " + columnMap.get("postal_code"),
       columnMap.get("postal_code"));
   assertTrue(
       "expecting 'java.lang.String' but found " + columnMap.get("postal_code").getCanonicalName(),
       columnMap.get("postal_code").getCanonicalName().equals("java.lang.String"));
   columnMap.clear();
   finder.findMethodColumns(Address.class, "zipcode", columnMap, true);
   assertTrue("expecting size == 1 but found " + columnMap.size(), columnMap.size() == 1);
   assertNotNull(
       "expecting not null but found " + columnMap.get("postal_code"),
       columnMap.get("postal_code"));
   columnMap.clear();
   finder.findMethodColumns(Person.class, "", columnMap, false);
   assertTrue("expecting size == 2 but found " + columnMap.size(), columnMap.size() == 2);
   assertNotNull(
       "expecting not null but found " + columnMap.get("job_name"), columnMap.get("job_name"));
   assertNotNull(
       "expecting not null but found " + columnMap.get("postal_code"),
       columnMap.get("postal_code"));
   columnMap.clear();
   finder.findMethodColumns(Person.class, "", columnMap, true);
   assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
   columnMap.clear();
   finder.findMethodColumns(Person.class, "name", columnMap, false);
   assertTrue("expecting size == 1 but found " + columnMap.size(), columnMap.size() == 1);
   assertNotNull(
       "expecting not null but found " + columnMap.get("job_name"), columnMap.get("job_name"));
   columnMap.clear();
   finder.findMethodColumns(Person.class, "name", columnMap, true);
   assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
   columnMap.clear();
   finder.findMethodColumns(job.getClass(), "dummyMethodName", columnMap, false);
   assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
 }
예제 #5
0
  @Test
  public void getLogReturnsAnRightOrder() throws Exception {
    Job j = Mockito.mock(Job.class);
    File tempBuildDir = tmp.newFolder();
    Mockito.when(j.getBuildDir()).thenReturn(tempBuildDir);
    Run<? extends Job<?, ?>, ? extends Run<?, ?>> r = new Run(j, 0) {};
    File f = r.getLogFile();
    f.getParentFile().mkdirs();
    PrintWriter w = new PrintWriter(f, "utf-8");
    for (int i = 0; i < 20; i++) {
      w.println("dummy" + i);
    }

    w.close();
    List<String> logLines = r.getLog(10);
    assertFalse(logLines.isEmpty());

    for (int i = 1; i < 10; i++) {
      assertEquals("dummy" + (10 + i), logLines.get(i));
    }
    assertEquals("[...truncated 68 B...]", logLines.get(0));
  }
예제 #6
0
  @Test
  public void testFindAllColumnNamesFrom() {
    checkColumnNameWith(finder.findAllColumnNamesFrom(job.getClass(), null, false));
    checkColumnNameWith(finder.findAllColumnNamesFrom(person.getClass(), "", false));

    Map<String, Class> columnMap = finder.findAllColumnNamesFrom(person.getClass(), "name", false);
    assertEquals(columnMap.get("job_name").getCanonicalName(), "java.lang.String");
    assertTrue("expecting size == 1 but found " + columnMap.size(), columnMap.size() == 1);

    columnMap = finder.findAllColumnNamesFrom(person.getClass(), "dummy", false);
    assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());

    columnMap = finder.findAllColumnNamesFrom(job.getClass(), null, true);
    assertTrue("expecting size == 2 but found " + columnMap.size(), columnMap.size() == 2);
    assertNotNull(
        "expecting not null but found " + columnMap.get("job_name"), columnMap.get("job_name"));
    assertNotNull(
        "expecting not null but found " + columnMap.get("summary"), columnMap.get("summary"));

    columnMap = finder.findAllColumnNamesFrom(person.getClass(), "", true);
    assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
    columnMap = finder.findAllColumnNamesFrom(person.getClass(), "name", true);
    assertTrue("expecing size == 0 but found " + columnMap.size(), columnMap.isEmpty());
  }
예제 #7
0
 @Test
 public void testFindFieldColumns() {
   Map<String, Class> columnMap = new HashMap<String, Class>();
   finder.findFieldColumns(job.getClass(), null, columnMap, false);
   String columnType = columnMap.get("summary").getCanonicalName();
   assertEquals(
       "expecting 'java.lang.String' but found " + columnType, columnType, "java.lang.String");
   columnMap.clear();
   finder.findFieldColumns(job.getClass(), null, columnMap, true);
   assertNotNull(
       "expecting not null but found " + columnMap.get("summary"), columnMap.get("summary"));
   assertTrue("expecting size == 1 but found " + columnMap.size(), columnMap.size() == 1);
   columnMap.clear();
   finder.findFieldColumns(person.getClass(), null, columnMap, false);
   columnType = columnMap.get("summary").getCanonicalName();
   assertTrue(
       "expecting 'java.lang.String' but found " + columnType,
       columnType.equals("java.lang.String"));
   columnMap.clear();
   finder.findFieldColumns(person.getClass(), null, columnMap, true);
   assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
   columnMap.clear();
   finder.findFieldColumns(job.getClass(), "zipCode", columnMap, false);
   assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
   columnMap.clear();
   finder.findFieldColumns(job.getClass(), "zipCode", columnMap, true);
   assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
   columnMap.clear();
   finder.findFieldColumns(job.getClass(), "name", columnMap, true);
   assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
   columnMap.clear();
   finder.findFieldColumns(job.getClass(), "dummyFieldName", columnMap, false);
   assertTrue("expecting size == 0 but found " + columnMap.size(), columnMap.isEmpty());
   columnMap.clear();
   finder.findFieldColumns(job.getClass(), "description", columnMap, true);
   assertTrue("expecting size == 1 but found " + columnMap.size(), columnMap.size() == 1);
   assertNotNull(
       "expecting not null but found " + columnMap.get("summary"), columnMap.get("summary"));
 }