Skip to content

Commit f4d7ff4

Browse files
authored
Add taskWidgetLayout property to Challenge model and update tests (#134)
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.
1 parent 915f020 commit f4d7ff4

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

src/integrationTest/java/org/maproulette/client/api/ChallengeAPIIntegrationTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.maproulette.client.model.PriorityRule;
1818
import org.maproulette.client.model.RuleList;
1919
import org.maproulette.client.model.Task;
20+
import org.maproulette.client.utilities.ObjectMapperSingleton;
2021

2122
/**
2223
* @author mcuthbert
@@ -82,6 +83,8 @@ public void updateTest() throws MapRouletteException
8283
.mediumPriorityRule(this.getRuleList("AND", "pr.medium"))
8384
.lowPriorityRule(this.getRuleList("OR", "pr.low")).defaultZoom(11).minZoom(10)
8485
.maxZoom(12).defaultBasemapId("defaultBaseMap").defaultBasemap(67)
86+
.taskWidgetLayout(ObjectMapperSingleton.getMapper().createObjectNode()
87+
.put("testKey", "testValue"))
8588
.customBasemap("customBasemap").build();
8689

8790
final var updatedChallenge = this.getChallengeAPI().update(toUpdateChallenge);
@@ -116,6 +119,12 @@ public void updateTest() throws MapRouletteException
116119
Assertions.assertNotEquals(createdChallenge.getCustomBasemap(),
117120
updatedChallenge.getCustomBasemap());
118121
Assertions.assertTrue(updatedChallenge.getHighPriorityRule().getCondition().equals("OR"));
122+
123+
// Check that taskWidgetLayout was updated to a json object with "testKey" : "testValue"
124+
Assertions.assertTrue(updatedChallenge.getTaskWidgetLayout().isObject());
125+
Assertions.assertTrue(updatedChallenge.getTaskWidgetLayout().get("testKey").isTextual());
126+
Assertions.assertEquals("testValue",
127+
updatedChallenge.getTaskWidgetLayout().get("testKey").asText());
119128
}
120129

121130
@Test
@@ -198,6 +207,9 @@ private void compareChallenges(final Challenge challenge1, final Challenge chall
198207
Assertions.assertEquals(challenge1.getPreferredTags(), challenge2.getPreferredTags());
199208
Assertions.assertEquals(challenge1.getPreferredReviewTags(),
200209
challenge2.getPreferredReviewTags());
210+
211+
// Check that the returned task widget layout is a json object
212+
Assertions.assertTrue(challenge2.getTaskWidgetLayout().isObject());
201213
}
202214

203215
private Challenge getBasicChallenge()

src/main/java/org/maproulette/client/model/Challenge.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import java.io.Serializable;
44

5+
import javax.annotation.Nullable;
6+
57
import org.maproulette.client.exception.MapRouletteException;
68
import org.maproulette.client.utilities.Utilities;
79

810
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
911
import com.fasterxml.jackson.annotation.JsonInclude;
1012
import com.fasterxml.jackson.annotation.JsonInclude.Include;
13+
import com.fasterxml.jackson.databind.JsonNode;
1114

1215
import lombok.AllArgsConstructor;
1316
import lombok.Builder;
@@ -76,6 +79,8 @@ public class Challenge implements IMapRouletteObject, Serializable
7679
private String[] tags;
7780
@Builder.Default
7881
private boolean changesetUrl = false;
82+
@Nullable
83+
private JsonNode taskWidgetLayout;
7984

8085
public static Challenge fromJson(final String json) throws MapRouletteException
8186
{

src/test/java/org/maproulette/client/serializer/ChallengeSerializationTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void defaultSerializationTest() throws IOException
7676
final var value = Challenge.builder().parent(1L).name("TestChallenge")
7777
.instruction("TestInstruction").description("TestDescription").blurb("TestBlurb")
7878
.customBasemap("customBaseMap").defaultBasemap(56)
79+
.taskWidgetLayout(this.mapper.readTree("{\"key\":\"value\"}"))
7980
.defaultBasemapId("defaultBaseMap").id(1234L).build();
8081

8182
final var serializedString = this.mapper.writeValueAsString(value);
@@ -92,6 +93,10 @@ public void defaultSerializationTest() throws IOException
9293
Assertions.assertEquals(19, deserializedChallenge.getMaxZoom());
9394
Assertions.assertEquals(1, deserializedChallenge.getMinZoom());
9495
Assertions.assertEquals(1L, deserializedChallenge.getParent());
96+
Assertions.assertEquals("value",
97+
deserializedChallenge.getTaskWidgetLayout().get("key").textValue());
98+
Assertions.assertEquals("{\"key\":\"value\"}",
99+
deserializedChallenge.getTaskWidgetLayout().toString());
95100
}
96101

97102
/**
@@ -114,6 +119,10 @@ public void serializationNoDefaultPrioritySpecifiedTest() throws Exception
114119
Assertions.assertFalse(deserializedChallenge.getHighPriorityRule().isSet());
115120
Assertions.assertFalse(deserializedChallenge.getMediumPriorityRule().isSet());
116121
Assertions.assertFalse(deserializedChallenge.getLowPriorityRule().isSet());
122+
Assertions.assertEquals("value",
123+
deserializedChallenge.getTaskWidgetLayout().get("key").textValue());
124+
Assertions.assertEquals("{\"key\":\"value\"}",
125+
deserializedChallenge.getTaskWidgetLayout().toString());
117126
}
118127

119128
/**
@@ -137,6 +146,7 @@ public void serializationNoPriorityTest() throws Exception
137146
Assertions.assertFalse(deserializedChallenge.getHighPriorityRule().isSet());
138147
Assertions.assertFalse(deserializedChallenge.getMediumPriorityRule().isSet());
139148
Assertions.assertFalse(deserializedChallenge.getLowPriorityRule().isSet());
149+
Assertions.assertEquals("\"{}\"", deserializedChallenge.getTaskWidgetLayout().toString());
140150
}
141151

142152
/**
@@ -184,6 +194,7 @@ public void serializationTest() throws Exception
184194
Assertions.assertEquals("#tag1,#tag2", deserializedChallenge.getPreferredTags());
185195
Assertions.assertEquals("#reviewTag1,#reviewTag2",
186196
deserializedChallenge.getPreferredReviewTags());
197+
Assertions.assertNull(deserializedChallenge.getTaskWidgetLayout());
187198
}
188199

189200
/**

src/test/resources/challenges/testChallenge2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"blurb": "BLURB",
44
"instruction": "INSTRUCTION",
55
"difficulty": "NORMAL",
6-
"defaultPriority": "NONE"
6+
"defaultPriority": "NONE",
7+
"taskWidgetLayout": "{}"
78
}

src/test/resources/challenges/testChallenge4.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"description": "DESCRIPTION",
44
"blurb": "BLURB",
55
"instruction": "INSTRUCTION",
6-
"difficulty": "NORMAL"
6+
"difficulty": "NORMAL",
7+
"taskWidgetLayout": {
8+
"key": "value"
9+
}
710
}

0 commit comments

Comments
 (0)