Package com.taskadapter.redmineapi.bean

Examples of com.taskadapter.redmineapi.bean.TimeEntry


    return result;
  }

  public static TimeEntry parseTimeEntry(JSONObject object)
      throws JSONException {
    /**
     * JsonOutput.addIfNotNull(writer, "hours", timeEntry.getHours());
     * JsonOutput.addIfNotNull(writer, "comment", timeEntry.getComment());
     * addIfNotNullShort(writer, "spent_on", timeEntry.getSpentOn());
     * addIfNotNullFull(writer, "created_on", timeEntry.getSpentOn());
     * addIfNotNullFull(writer, "updated_on", timeEntry.getSpentOn());
     */
    final TimeEntry result = TimeEntryFactory.create(JsonInput.getIntOrNull(object, "id"));
    final JSONObject issueObject = JsonInput.getObjectOrNull(object,
        "issue");
    if (issueObject != null)
      result.setIssueId(JsonInput.getIntOrNull(issueObject, "id"));
    final JSONObject projectObject = JsonInput.getObjectOrNull(object,
        "project");
    if (projectObject != null) {
      result.setProjectId(JsonInput.getIntOrNull(projectObject, "id"));
      result.setProjectName(JsonInput.getStringOrNull(projectObject,
          "name"));
    }
    final JSONObject user = JsonInput.getObjectOrNull(object, "user");
    if (user != null) {
      result.setUserId(JsonInput.getIntOrNull(user, "id"));
      result.setUserName(JsonInput.getStringOrNull(user, "name"));
    }
    final JSONObject activity = JsonInput.getObjectOrNull(object,
        "activity");
    if (activity != null) {
      result.setActivityId(JsonInput.getIntOrNull(activity, "id"));
      result.setActivityName(JsonInput.getStringOrNull(activity, "name"));
    }
    result.setHours(JsonInput.getFloatOrNull(object, "hours"));
    result.setComment(JsonInput.getStringOrEmpty(object, "comments"));
    result.setSpentOn(getShortDateOrNull(object, "spent_on"));
    result.setCreatedOn(getDateOrNull(object, "created_on"));
    result.setUpdatedOn(getDateOrNull(object, "updated_on"));
    return result;
  }
View Full Code Here


    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 = "Redmine Admin";
    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());
  }
View Full Code Here

        }
        return result;
    }

    public static TimeEntry findTimeEntry(List<TimeEntry> list, Integer id) {
        TimeEntry result = null;
        for (TimeEntry obj : list) {
            if (obj.getId().equals(id)) {
                result = obj;
            }
        }
View Full Code Here

    @Test
    public void testTimeEntryComments() throws RedmineException {
        Issue issue = createIssues(issueManager, projectKey, 1).get(0);
        Integer issueId = issue.getId();

        TimeEntry entry = TimeEntryFactory.create();
        Float hours = 11f;
        entry.setHours(hours);
        entry.setIssueId(issueId);
        final String comment = "This is a comment although it may not look like it";
        entry.setComment(comment);
        // TODO We don't know activities IDs!
        // see feature request http://www.redmine.org/issues/7506
        entry.setActivityId(ACTIVITY_ID);
        TimeEntry createdEntry = issueManager.createTimeEntry(entry);

        assertNotNull(createdEntry);
        assertEquals(comment, createdEntry.getComment());

        createdEntry.setComment("New comment");
        issueManager.update(createdEntry);
        final TimeEntry updatedEntry = issueManager.getTimeEntry(createdEntry.getId());
        assertEquals("New comment", updatedEntry.getComment());
    }
View Full Code Here

    @Test
    public void testCreateGetTimeEntry() throws RedmineException {
        Issue issue = createIssues(issueManager, projectKey, 1).get(0);
        Integer issueId = issue.getId();

        TimeEntry entry = TimeEntryFactory.create();
        Float hours = 11f;
        entry.setHours(hours);
        entry.setIssueId(issueId);
        // TODO We don't know activities IDs!
        // see feature request http://www.redmine.org/issues/7506
        entry.setActivityId(ACTIVITY_ID);
        TimeEntry createdEntry = issueManager.createTimeEntry(entry);

        assertNotNull(createdEntry);
        logger.debug("Created time entry " + createdEntry);
        assertEquals(hours, createdEntry.getHours());

        Float newHours = 22f;
        createdEntry.setHours(newHours);

        issueManager.update(createdEntry);

        TimeEntry updatedEntry = issueManager.getTimeEntry(createdEntry.getId());
        assertEquals(newHours, updatedEntry.getHours());
    }
View Full Code Here

    @Test(expected = NotFoundException.class)
    public void testCreateDeleteTimeEntry() throws RedmineException {
        Issue issue = createIssues(issueManager, projectKey, 1).get(0);
        Integer issueId = issue.getId();

        TimeEntry entry = TimeEntryFactory.create();
        Float hours = 4f;
        entry.setHours(hours);
        entry.setIssueId(issueId);
        entry.setActivityId(ACTIVITY_ID);
        TimeEntry createdEntry = issueManager.createTimeEntry(entry);
        assertNotNull(createdEntry);

        issueManager.deleteTimeEntry(createdEntry.getId());
        issueManager.getTimeEntry(createdEntry.getId());
    }
View Full Code Here

        Issue issue = createIssues(issueManager, projectKey, 1).get(0);
        Integer issueId = issue.getId();
        Float hours1 = 2f;
        Float hours2 = 7f;
        Float totalHoursExpected = hours1 + hours2;
        TimeEntry createdEntry1 = createTimeEntry(issueId, hours1);
        TimeEntry createdEntry2 = createTimeEntry(issueId, hours2);
        assertNotNull(createdEntry1);
        assertNotNull(createdEntry2);

        List<TimeEntry> entries = issueManager.getTimeEntriesForIssue(issueId);
        assertEquals(2, entries.size());
View Full Code Here

        assertEquals(totalHoursExpected, totalTime);
    }

    private TimeEntry createTimeEntry(Integer issueId, float hours)
            throws RedmineException {
        TimeEntry entry = TimeEntryFactory.create();
        entry.setHours(hours);
        entry.setIssueId(issueId);
        entry.setActivityId(ACTIVITY_ID);
        return issueManager.createTimeEntry(entry);
    }
View Full Code Here

    public void invalidTimeEntryFailsWithIAEOnUpdate() throws RedmineException {
        issueManager.update(createIncompleteTimeEntry());
    }

    private TimeEntry createIncompleteTimeEntry() {
        TimeEntry timeEntry = TimeEntryFactory.create();
        timeEntry.setActivityId(ACTIVITY_ID);
        timeEntry.setSpentOn(new Date());
        timeEntry.setHours(1.5f);
        return timeEntry;
    }
View Full Code Here

    }

    @Test
    public void testViolateTimeEntryConstraint_ProjectOrIssueID_issue66()
            throws RedmineException {
        TimeEntry timeEntry = createIncompleteTimeEntry();
        // Now can try to verify with project ID (only test with issue ID seems
        // to be already covered)
        int projectId = mgr.getProjectManager().getProjects().get(0).getId();
        timeEntry.setProjectId(projectId);
        try {
            TimeEntry created = issueManager.createTimeEntry(timeEntry);
            logger.debug("Created time entry " + created);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Unexpected " + e.getClass().getSimpleName() + ": "
                    + e.getMessage());
View Full Code Here

TOP

Related Classes of com.taskadapter.redmineapi.bean.TimeEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.