@Test
 public void doesNotFailWithNoNews() {
   // "news" xml with no items in the list should not break the loader.
   try {
     String str = MyIOUtils.getResourceAsString("redmine_news_empty.json");
     List<News> news =
         JsonInput.getListOrEmpty(
             RedmineJSONParser.getResponse(str), "news", RedmineJSONParser.NEWS_PARSER);
     Assert.assertTrue(news.isEmpty());
   } catch (Exception e) {
     Assert.fail("Error:" + e);
   }
 }
 @Test
 public void testParseIssueNonUnicodeSymbols() throws IOException, JSONException {
   String json = MyIOUtils.getResourceAsString("issues_foreign_symbols.json");
   String nonLatinAccentSymbols = "Accent symbols: Ação";
   String nonLatinRussianSymbols = "Russian symbols: Привет";
   List<Issue> issues =
       JsonInput.getListOrEmpty(
           RedmineJSONParser.getResponse(json), "issues", RedmineJSONParser.ISSUE_PARSER);
   // must be 2 issues in the file
   Assert.assertTrue(issues.size() == 2);
   assertNotNull(RedmineTestUtils.findIssueInList(issues, nonLatinRussianSymbols));
   assertNotNull(RedmineTestUtils.findIssueInList(issues, nonLatinAccentSymbols));
 }
 @Test
 public void testParseUsers() throws IOException, JSONException {
   String json = MyIOUtils.getResourceAsString("redmine_users.json");
   List<User> users =
       JsonInput.getListOrEmpty(
           RedmineJSONParser.getResponse(json), "users", RedmineJSONParser.USER_PARSER);
   boolean found = false;
   for (User u : users) {
     if (u.getLogin().equals("dina")) {
       found = true;
     }
   }
   Assert.assertTrue("Admin user must be among all the users", found);
 }
  @Test
  public void parses2NewsItems() {
    // "news" xml with no items in the list should not break the loader.
    try {
      String str = MyIOUtils.getResourceAsString("redmine_news_2_items.json");
      List<News> news =
          JsonInput.getListOrEmpty(
              RedmineJSONParser.getResponse(str), "news", RedmineJSONParser.NEWS_PARSER);
      assertEquals(2, news.size());

      News anyItem = news.get(0);
      assertEquals("rest last", anyItem.getUser().getFullName());
    } catch (Exception e) {
      Assert.fail("Error:" + e);
    }
  }
 /**
  * regression test for http://code.google.com/p/redmine-java-api/issues/detail?id=91 with Redmine
  * 1.3.0: NULL value returned by getIssues call is interpreted as 0.0
  */
 @Test
 public void nullEstimatedTimeProcessedCorrectlyWithRedmine122() {
   try {
     String str = MyIOUtils.getResourceAsString("redmine_1.2.2_dev_issues.json");
     List<Issue> issues =
         JsonInput.getListOrEmpty(
             RedmineJSONParser.getResponse(str), "issues", RedmineJSONParser.ISSUE_PARSER);
     Issue issue = RedmineTestUtils.findIssueInList(issues, 4808);
     assertNull(issue.getEstimatedHours());
     Issue issue1 = RedmineTestUtils.findIssueInList(issues, 4809);
     assertNull(issue1.getEstimatedHours());
   } catch (Exception e) {
     e.printStackTrace();
     Assert.fail("Error:" + e);
   }
 }
  @Test
  public void testParseIssuesFromEmptyList() {
    /*
     * issues result with no individual issues in the list should not break
     * the loader.
     */

    try {
      String str = MyIOUtils.getResourceAsString(FILE_EMPTY_ISSUES);
      List<Issue> issues =
          JsonInput.getListOrEmpty(
              RedmineJSONParser.getResponse(str), "issues", RedmineJSONParser.ISSUE_PARSER);
      Assert.assertTrue(issues.isEmpty());
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail("Error:" + e);
    }
  }
 @Test
 public void issueStatusesCanBeParsed() {
   try {
     String str = MyIOUtils.getResourceAsString("redmine_issue_statuses.json");
     List<IssueStatus> statuses =
         JsonInput.getListOrEmpty(
             RedmineJSONParser.getResponse(str), "statuses", RedmineJSONParser.STATUS_PARSER);
     assertEquals(6, statuses.size());
     IssueStatus status5 = statuses.get(4);
     assertEquals(new Integer(5), status5.getId());
     assertEquals("Closed", status5.getName());
     assertEquals(false, status5.isDefaultStatus());
     assertEquals(true, status5.isClosed());
   } catch (Exception e) {
     e.printStackTrace();
     Assert.fail("Error:" + e);
   }
 }
  @Test
  public void testParseTimeEntries() throws IOException, JSONException {
    String xml = MyIOUtils.getResourceAsString("redmine_time_entries.json");
    List<TimeEntry> objects =
        JsonInput.getListOrEmpty(
            RedmineJSONParser.getResponse(xml),
            "time_entries",
            RedmineJSONParser.TIME_ENTRY_PARSER);
    Integer objId = 2;
    TimeEntry obj2 = RedmineTestUtils.findTimeEntry(objects, objId);
    Assert.assertNotNull(obj2);

    Integer expectedIssueId = 44;
    String expectedProjectName = "Permanent test project for Task Adapter";
    Integer expectedProjectId = 1;
    String expectedUserName = "******";
    Integer expectedUserId = 1;
    String expectedActivityName = "Design";
    Integer expectedActivityId = 8;
    Float expectedHours = 2f;

    Assert.assertEquals(objId, obj2.getId());
    Assert.assertEquals(expectedIssueId, obj2.getIssueId());
    Assert.assertEquals(expectedProjectName, obj2.getProjectName());
    Assert.assertEquals(expectedProjectId, obj2.getProjectId());
    Assert.assertEquals(expectedUserName, obj2.getUserName());
    Assert.assertEquals(expectedUserId, obj2.getUserId());
    Assert.assertEquals(expectedActivityName, obj2.getActivityName());
    Assert.assertEquals(expectedActivityId, obj2.getActivityId());
    Assert.assertEquals(expectedHours, obj2.getHours());
    Assert.assertEquals("spent 2 hours working on ABC", obj2.getComment());

    DateComparator.testLongDate(
        2011, Calendar.JANUARY, 31, 11, 10, 40, "GMT-8", obj2.getCreatedOn());
    DateComparator.testLongDate(
        2011, Calendar.JANUARY, 31, 11, 12, 32, "GMT-8", obj2.getUpdatedOn());

    DateComparator.testShortDate(2011, Calendar.JANUARY, 30, obj2.getSpentOn());
  }
 private List<Issue> loadRedmine11Issues() throws IOException, JSONException {
   String json = MyIOUtils.getResourceAsString(REDMINE_ISSUES);
   return JsonInput.getListOrEmpty(
       RedmineJSONParser.getResponse(json), "issues", RedmineJSONParser.ISSUE_PARSER);
 }