WorklogJsonParser implements JsonParser<Worklog> { @Override public Worklog parse(JSONObject json) throws JSONException { final URI self = JsonParseUtil.getSelfUri(json); final URI issueUri = JsonParseUtil.parseURI(json.getString("issue")); final BasicUser author = JsonParseUtil.parseBasicUser(json.getJSONObject("author")); final BasicUser updateAuthor = JsonParseUtil.parseBasicUser(json.getJSONObject("updateAuthor")); final String comment = JsonParseUtil.getOptionalString(json, "comment"); final DateTime creationDate = JsonParseUtil.parseDateTime(json, "created"); final DateTime updateDate = JsonParseUtil.parseDateTime(json, "updated"); final DateTime startDate = JsonParseUtil.parseDateTime(json, "started"); final int minutesSpent = json.getInt("minutesSpent"); final Visibility visibility = new VisibilityJsonParser().parseVisibility(json); return new Worklog(self, issueUri, author, updateAuthor, comment, creationDate, updateDate, startDate, minutesSpent, visibility); }  @Override Worklog parse(JSONObject json);  }
@Test public void testParse() throws Exception { final WorklogJsonParser parser = new WorklogJsonParser(); final Worklog worklog = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/worklog/valid.json")); assertEquals(toUri("http: assertEquals(toUri("http: assertEquals(TestConstants.USER_ADMIN, worklog.getAuthor()); assertEquals(TestConstants.USER_ADMIN, worklog.getUpdateAuthor()); assertEquals("my first work", worklog.getComment()); assertEquals(TestUtil.toDateTime("2010-08-17T16:35:47.466+0200"), worklog.getCreationDate()); assertEquals(TestUtil.toDateTime("2010-08-17T16:35:47.466+0200"), worklog.getUpdateDate()); assertEquals(TestUtil.toDateTime("2010-08-15T16:35:00.000+0200"), worklog.getStartDate()); assertEquals(60, worklog.getMinutesSpent()); Assert.assertNull(worklog.getVisibility()); }
@Test public void testParseWithRoleLevel() throws Exception { final WorklogJsonParser parser = new WorklogJsonParser(); final Worklog worklog = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/worklog/valid-roleLevel.json")); assertEquals(toUri("http: assertEquals(toUri("http: assertEquals(TestConstants.USER1, worklog.getAuthor()); assertEquals(TestConstants.USER1, worklog.getUpdateAuthor()); assertEquals("another piece of work", worklog.getComment()); assertEquals(TestUtil.toDateTime("2010-08-17T16:38:00.013+0200"), worklog.getCreationDate()); assertEquals(TestUtil.toDateTime("2010-08-17T16:38:24.948+0200"), worklog.getUpdateDate()); assertEquals(TestUtil.toDateTime("2010-08-17T16:37:00.000+0200"), worklog.getStartDate()); assertEquals(Visibility.role("Developers"), worklog.getVisibility()); assertEquals(15, worklog.getMinutesSpent()); }
@Test public void testParseWithGroupLevel() throws Exception { final WorklogJsonParser parser = new WorklogJsonParser(); final Worklog worklog = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/worklog/valid-groupLevel.json")); assertEquals(Visibility.group("jira-users"), worklog.getVisibility()); }