Skip to content

Commit ea20a2b

Browse files
authored
Merge pull request cloudbees-oss#396 from bratwurzt/issue_387
Fix dates format on PermissionGroup object
2 parents d56abf5 + b5e87a0 commit ea20a2b

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

src/main/java/org/zendesk/client/v2/model/hc/PermissionGroup.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.zendesk.client.v2.model.hc;
22

3-
import com.fasterxml.jackson.annotation.JsonFormat;
43
import com.fasterxml.jackson.annotation.JsonProperty;
54
import org.zendesk.client.v2.model.SearchResultEntity;
65

@@ -24,11 +23,9 @@ public class PermissionGroup implements SearchResultEntity {
2423
private List<Long> publish;
2524
/** When the permission group was created */
2625
@JsonProperty("created_at")
27-
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss Z")
2826
private Date createdAt;
2927
/** When the permission group was last updated */
3028
@JsonProperty("updated_at")
31-
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss Z")
3229
private Date updatedAt;
3330
/** Whether the permission group is built-in. Built-in permission groups cannot be modified */
3431
@JsonProperty("built_in")

src/test/java/org/zendesk/client/v2/RealSmokeTest.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.zendesk.client.v2.model.events.Event;
4242
import org.zendesk.client.v2.model.hc.Article;
4343
import org.zendesk.client.v2.model.hc.Category;
44+
import org.zendesk.client.v2.model.hc.PermissionGroup;
4445
import org.zendesk.client.v2.model.hc.Section;
4546
import org.zendesk.client.v2.model.hc.Subscription;
4647
import org.zendesk.client.v2.model.hc.Translation;
@@ -77,9 +78,10 @@
7778
import static org.hamcrest.MatcherAssert.assertThat;
7879
import static org.hamcrest.Matchers.containsInAnyOrder;
7980
import static org.hamcrest.Matchers.empty;
80-
import static org.hamcrest.Matchers.isEmptyString;
8181
import static org.hamcrest.Matchers.greaterThan;
8282
import static org.hamcrest.Matchers.hasSize;
83+
import static org.hamcrest.Matchers.isEmptyString;
84+
import static org.hamcrest.Matchers.lessThan;
8385
import static org.hamcrest.Matchers.lessThanOrEqualTo;
8486
import static org.hamcrest.core.StringContains.containsString;
8587
import static org.junit.Assert.assertEquals;
@@ -1245,6 +1247,49 @@ public void getGroups() throws Exception {
12451247
}
12461248
}
12471249

1250+
@Test
1251+
public void getPermissionGroups() throws Exception {
1252+
createClientWithTokenOrPassword();
1253+
int count = 0;
1254+
for (PermissionGroup pg : instance.getPermissionGroups()) {
1255+
assertThat(pg.getId(), notNullValue());
1256+
assertThat(pg.getName(), notNullValue());
1257+
assertThat(pg.getBuiltIn(), notNullValue());
1258+
assertThat(pg.getCreatedAt(), notNullValue());
1259+
assertThat(pg.getUpdatedAt(), notNullValue());
1260+
if (++count > 1) {
1261+
break;
1262+
}
1263+
}
1264+
}
1265+
1266+
@Test
1267+
public void permissionGroupCRUD() throws Exception {
1268+
createClientWithTokenOrPassword();
1269+
PermissionGroup pg = new PermissionGroup();
1270+
pg.setName("[zendesk-java-client] This is a creation test " + UUID.randomUUID());
1271+
pg = instance.createPermissionGroup(pg);
1272+
Long pgId = pg.getId();
1273+
try {
1274+
assertThat(pg.getId(), notNullValue());
1275+
assertThat(pg.getName(), containsString("[zendesk-java-client] This is a creation test"));
1276+
assertThat(pg.getCreatedAt(), notNullValue());
1277+
assertThat(pg.getUpdatedAt(), notNullValue());
1278+
assertThat(pg.getCreatedAt(), is(pg.getUpdatedAt()));
1279+
pg.setName("[zendesk-java-client] This is an update test" + UUID.randomUUID());
1280+
pg = instance.updatePermissionGroup(pg);
1281+
assertThat(pg.getId(), is(pgId));
1282+
assertThat(pg.getName(), containsString("[zendesk-java-client] This is an update test"));
1283+
assertThat(pg.getCreatedAt(), notNullValue());
1284+
assertThat(pg.getUpdatedAt(), notNullValue());
1285+
assertThat(pg.getCreatedAt(), lessThanOrEqualTo(pg.getUpdatedAt()));
1286+
} finally {
1287+
instance.deletePermissionGroup(pg);
1288+
}
1289+
PermissionGroup ghost = instance.getPermissionGroup(pgId);
1290+
assertThat(ghost, nullValue());
1291+
}
1292+
12481293
@Test
12491294
public void getArticles() throws Exception {
12501295
createClientWithTokenOrPassword();

src/test/java/org/zendesk/client/v2/model/hc/PermissionGroupTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public void testParsePermissionGroup() throws ParseException {
3535
" \"name\": \"ApiGroup\",\n" +
3636
" \"built_in\": false,\n" +
3737
" \"publish\": [360001413871],\n" +
38-
" \"created_at\": \"2019-06-10 12:39:23 +0000\",\n" +
39-
" \"updated_at\": \"2019-06-10 12:39:23 +0000\",\n" +
38+
" \"created_at\": \"2019-06-10T12:39:25Z\",\n" +
39+
" \"updated_at\": \"2020-11-04T11:30:42Z\",\n" +
4040
" \"edit\": [360001413871]\n" +
4141
"}";
4242
PermissionGroup pg = parseJson(json.getBytes());
@@ -51,10 +51,11 @@ public void testParsePermissionGroup() throws ParseException {
5151
assertEquals(ids, pg.getPublish());
5252
assertEquals(ids, pg.getEdit());
5353

54-
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss Z");
55-
Date date = simpleDateFormat.parse("2019-06-10 12:39:23 +0000");
56-
assertEquals(date, pg.getCreatedAt());
57-
assertEquals(date, pg.getUpdatedAt());
54+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
55+
Date created = simpleDateFormat.parse("2019-06-10 12:39:25 +0000");
56+
assertEquals(created, pg.getCreatedAt());
57+
Date updated = simpleDateFormat.parse("2020-11-04 11:30:42 +0000");
58+
assertEquals(updated, pg.getUpdatedAt());
5859
}
5960

6061
}

0 commit comments

Comments
 (0)