Skip to content

Commit

Permalink
Add taskWidgetLayout property to Challenge model and update tests (#134)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ljdelight authored Oct 28, 2023
1 parent 915f020 commit f4d7ff4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/maproulette/client/model/Challenge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +79,8 @@ public class Challenge implements IMapRouletteObject, Serializable
private String[] tags;
@Builder.Default
private boolean changesetUrl = false;
@Nullable
private JsonNode taskWidgetLayout;

public static Challenge fromJson(final String json) throws MapRouletteException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/challenges/testChallenge2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"blurb": "BLURB",
"instruction": "INSTRUCTION",
"difficulty": "NORMAL",
"defaultPriority": "NONE"
"defaultPriority": "NONE",
"taskWidgetLayout": "{}"
}
5 changes: 4 additions & 1 deletion src/test/resources/challenges/testChallenge4.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"description": "DESCRIPTION",
"blurb": "BLURB",
"instruction": "INSTRUCTION",
"difficulty": "NORMAL"
"difficulty": "NORMAL",
"taskWidgetLayout": {
"key": "value"
}
}

0 comments on commit f4d7ff4

Please sign in to comment.