From a7a48341fa773fd07b7bee871d4e278642bcb158 Mon Sep 17 00:00:00 2001 From: Lucas Burson Date: Fri, 27 Oct 2023 19:38:44 -0500 Subject: [PATCH] Add taskWidgetLayout property to Challenge model and update tests Added a new property `taskWidgetLayout` of type `JsonNode` to the `Challenge` model, which is an optional JSON object to store additional layout information for tasks. Updated `ChallengeAPIIntegrationTest`, `ChallengeSerializationTest`, and test challenge JSON files to include and validate the new `taskWidgetLayout` property. --- .../client/api/ChallengeAPIIntegrationTest.java | 12 ++++++++++++ .../java/org/maproulette/client/model/Challenge.java | 5 +++++ .../serializer/ChallengeSerializationTest.java | 11 +++++++++++ src/test/resources/challenges/testChallenge2.json | 3 ++- src/test/resources/challenges/testChallenge4.json | 5 ++++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/integrationTest/java/org/maproulette/client/api/ChallengeAPIIntegrationTest.java b/src/integrationTest/java/org/maproulette/client/api/ChallengeAPIIntegrationTest.java index 2797056..b4f3975 100644 --- a/src/integrationTest/java/org/maproulette/client/api/ChallengeAPIIntegrationTest.java +++ b/src/integrationTest/java/org/maproulette/client/api/ChallengeAPIIntegrationTest.java @@ -17,6 +17,7 @@ import org.maproulette.client.model.PriorityRule; import org.maproulette.client.model.RuleList; import org.maproulette.client.model.Task; +import org.maproulette.client.utilities.ObjectMapperSingleton; /** * @author mcuthbert @@ -82,6 +83,8 @@ public void updateTest() throws MapRouletteException .mediumPriorityRule(this.getRuleList("AND", "pr.medium")) .lowPriorityRule(this.getRuleList("OR", "pr.low")).defaultZoom(11).minZoom(10) .maxZoom(12).defaultBasemapId("defaultBaseMap").defaultBasemap(67) + .taskWidgetLayout(ObjectMapperSingleton.getMapper().createObjectNode() + .put("testKey", "testValue")) .customBasemap("customBasemap").build(); final var updatedChallenge = this.getChallengeAPI().update(toUpdateChallenge); @@ -116,6 +119,12 @@ public void updateTest() throws MapRouletteException Assertions.assertNotEquals(createdChallenge.getCustomBasemap(), updatedChallenge.getCustomBasemap()); Assertions.assertTrue(updatedChallenge.getHighPriorityRule().getCondition().equals("OR")); + + // Check that taskWidgetLayout was updated to a json object with "testKey" : "testValue" + Assertions.assertTrue(updatedChallenge.getTaskWidgetLayout().isObject()); + Assertions.assertTrue(updatedChallenge.getTaskWidgetLayout().get("testKey").isTextual()); + Assertions.assertEquals("testValue", + updatedChallenge.getTaskWidgetLayout().get("testKey").asText()); } @Test @@ -198,6 +207,9 @@ private void compareChallenges(final Challenge challenge1, final Challenge chall Assertions.assertEquals(challenge1.getPreferredTags(), challenge2.getPreferredTags()); Assertions.assertEquals(challenge1.getPreferredReviewTags(), challenge2.getPreferredReviewTags()); + + // Check that the returned task widget layout is a json object + Assertions.assertTrue(challenge2.getTaskWidgetLayout().isObject()); } private Challenge getBasicChallenge() diff --git a/src/main/java/org/maproulette/client/model/Challenge.java b/src/main/java/org/maproulette/client/model/Challenge.java index b7a5e60..6cd215d 100644 --- a/src/main/java/org/maproulette/client/model/Challenge.java +++ b/src/main/java/org/maproulette/client/model/Challenge.java @@ -2,12 +2,15 @@ import java.io.Serializable; +import javax.annotation.Nullable; + import org.maproulette.client.exception.MapRouletteException; import org.maproulette.client.utilities.Utilities; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.JsonNode; import lombok.AllArgsConstructor; import lombok.Builder; @@ -76,6 +79,8 @@ public class Challenge implements IMapRouletteObject, Serializable private String[] tags; @Builder.Default private boolean changesetUrl = false; + @Nullable + JsonNode taskWidgetLayout; public static Challenge fromJson(final String json) throws MapRouletteException { diff --git a/src/test/java/org/maproulette/client/serializer/ChallengeSerializationTest.java b/src/test/java/org/maproulette/client/serializer/ChallengeSerializationTest.java index e94f0c3..8303fa6 100644 --- a/src/test/java/org/maproulette/client/serializer/ChallengeSerializationTest.java +++ b/src/test/java/org/maproulette/client/serializer/ChallengeSerializationTest.java @@ -76,6 +76,7 @@ public void defaultSerializationTest() throws IOException final var value = Challenge.builder().parent(1L).name("TestChallenge") .instruction("TestInstruction").description("TestDescription").blurb("TestBlurb") .customBasemap("customBaseMap").defaultBasemap(56) + .taskWidgetLayout(this.mapper.readTree("{\"key\":\"value\"}")) .defaultBasemapId("defaultBaseMap").id(1234L).build(); final var serializedString = this.mapper.writeValueAsString(value); @@ -92,6 +93,10 @@ public void defaultSerializationTest() throws IOException Assertions.assertEquals(19, deserializedChallenge.getMaxZoom()); Assertions.assertEquals(1, deserializedChallenge.getMinZoom()); Assertions.assertEquals(1L, deserializedChallenge.getParent()); + Assertions.assertEquals("value", + deserializedChallenge.getTaskWidgetLayout().get("key").textValue()); + Assertions.assertEquals("{\"key\":\"value\"}", + deserializedChallenge.getTaskWidgetLayout().toString()); } /** @@ -114,6 +119,10 @@ public void serializationNoDefaultPrioritySpecifiedTest() throws Exception Assertions.assertFalse(deserializedChallenge.getHighPriorityRule().isSet()); Assertions.assertFalse(deserializedChallenge.getMediumPriorityRule().isSet()); Assertions.assertFalse(deserializedChallenge.getLowPriorityRule().isSet()); + Assertions.assertEquals("value", + deserializedChallenge.getTaskWidgetLayout().get("key").textValue()); + Assertions.assertEquals("{\"key\":\"value\"}", + deserializedChallenge.getTaskWidgetLayout().toString()); } /** @@ -137,6 +146,7 @@ public void serializationNoPriorityTest() throws Exception Assertions.assertFalse(deserializedChallenge.getHighPriorityRule().isSet()); Assertions.assertFalse(deserializedChallenge.getMediumPriorityRule().isSet()); Assertions.assertFalse(deserializedChallenge.getLowPriorityRule().isSet()); + Assertions.assertEquals("\"{}\"", deserializedChallenge.getTaskWidgetLayout().toString()); } /** @@ -184,6 +194,7 @@ public void serializationTest() throws Exception Assertions.assertEquals("#tag1,#tag2", deserializedChallenge.getPreferredTags()); Assertions.assertEquals("#reviewTag1,#reviewTag2", deserializedChallenge.getPreferredReviewTags()); + Assertions.assertNull(deserializedChallenge.getTaskWidgetLayout()); } /** diff --git a/src/test/resources/challenges/testChallenge2.json b/src/test/resources/challenges/testChallenge2.json index 531ecd1..ff4fcc1 100644 --- a/src/test/resources/challenges/testChallenge2.json +++ b/src/test/resources/challenges/testChallenge2.json @@ -3,5 +3,6 @@ "blurb": "BLURB", "instruction": "INSTRUCTION", "difficulty": "NORMAL", - "defaultPriority": "NONE" + "defaultPriority": "NONE", + "taskWidgetLayout": "{}" } diff --git a/src/test/resources/challenges/testChallenge4.json b/src/test/resources/challenges/testChallenge4.json index 89b28d8..5b46de5 100644 --- a/src/test/resources/challenges/testChallenge4.json +++ b/src/test/resources/challenges/testChallenge4.json @@ -3,5 +3,8 @@ "description": "DESCRIPTION", "blurb": "BLURB", "instruction": "INSTRUCTION", - "difficulty": "NORMAL" + "difficulty": "NORMAL", + "taskWidgetLayout": { + "key": "value" + } }