diff --git a/src/main/java/org/wise/portal/domain/project/impl/ProjectMetadataImpl.java b/src/main/java/org/wise/portal/domain/project/impl/ProjectMetadataImpl.java index 8559b5b4b..a19d850ef 100644 --- a/src/main/java/org/wise/portal/domain/project/impl/ProjectMetadataImpl.java +++ b/src/main/java/org/wise/portal/domain/project/impl/ProjectMetadataImpl.java @@ -213,7 +213,12 @@ public class ProjectMetadataImpl implements ProjectMetadata, Serializable { @Setter private String resources; - private String standardsDefault = "{\"commonCore\": [], \"ngss\": [], \"learningForJustice\": []}"; + private String standardsDefault = """ + { + "commonCore": [], + "ngss": [], + "learningForJustice": [] + }"""; @Getter @Setter diff --git a/src/main/java/org/wise/portal/service/portal/impl/PortalServiceImpl.java b/src/main/java/org/wise/portal/service/portal/impl/PortalServiceImpl.java index a6f291055..13ab73942 100644 --- a/src/main/java/org/wise/portal/service/portal/impl/PortalServiceImpl.java +++ b/src/main/java/org/wise/portal/service/portal/impl/PortalServiceImpl.java @@ -42,11 +42,142 @@ public class PortalServiceImpl implements PortalService { @Autowired private PortalDao portalDao; - private String defaultProjectMetadataSettings = "{\"fields\":[{\"name\":\"Title\",\"key\":\"title\",\"type\":\"input\"},{\"name\":\"Summary\",\"key\":\"summary\",\"type\":\"textarea\"},{\"name\":\"Language\",\"key\":\"language\",\"type\":\"radio\",\"choices\":[\"English\",\"Chinese (Simplified)\",\"Chinese (Traditional)\",\"Dutch\",\"German\",\"Greek\",\"Hebrew\",\"Japanese\",\"Korean\",\"Portuguese\",\"Spanish\",\"Thai\",\"Turkish\"]},{\"name\":\"Subject\",\"key\":\"subject\",\"type\":\"radio\",\"choices\":[\"Life Science\",\"Physical Science\",\"Earth Science\",\"General Science\",\"Biology\",\"Chemistry\",\"Physics\",\"Other\"]},{\"name\":\"Time Required to Complete Project\",\"key\":\"time\",\"type\":\"input\"},{\"name\":\"Supported Devices\",\"key\":\"supportedDevices\",\"type\":\"checkbox\",\"choices\":[\"PC\",\"Tablet\"]}],\"i18n\":{\"lifeScience\":{\"en\":\"Life Science\",\"ja\":\"ライフサイエンス\"},\"earthScience\":{\"en\":\"Earth Science\",\"ja\":\"地球科学\"},\"physicalScience\":{\"en\":\"Physical Science\",\"ja\":\"物理科学\",\"es\":\"ciencia física\"}}}"; + private String defaultProjectMetadataSettings = """ + { + "fields": [ + { + "name": "Title", + "key": "title", + "type": "input" + }, + { + "name": "Summary", + "key": "summary", + "type": "textarea" + }, + { + "name": "Language", + "key": "language", + "type": "radio", + "choices": [ + "English", + "Chinese (Simplified)", + "Chinese (Traditional)", + "Dutch", + "German", + "Greek", + "Hebrew", + "Japanese", + "Korean", + "Portuguese", + "Spanish", + "Thai", + "Turkish" + ] + }, + { + "name": "Subject", + "key": "subject", + "type": "radio", + "choices": [ + "Life Science", + "Physical Science", + "Earth Science", + "General Science", + "Biology", + "Chemistry", + "Physics", + "Other" + ] + }, + { + "name": "Time Required to Complete Project", + "key": "time", + "type": "input" + }, + { + "name": "Supported Devices", + "key": "supportedDevices", + "type": "checkbox", + "choices": [ + "PC", + "Tablet" + ] + } + ], + "i18n": { + "lifeScience": { + "en": "Life Science", + "ja": "ライフサイエンス" + }, + "earthScience": { + "en": "Earth Science", + "ja": "地球科学" + }, + "physicalScience": { + "en": "Physical Science", + "ja": "物理科学", + "es": "ciencia física" + } + } + }"""; - private String defaultProjectLibraryGroups = "[{\"name\":\"Integrated\",\"id\":\"integrated\",\"type\":\"group\",\"children\":[{\"name\":\"Grade6\",\"id\":\"grade6\",\"type\":\"group\",\"children\":[]},{\"name\":\"Grade7\",\"id\":\"grade7\",\"type\":\"group\",\"children\":[]},{\"name\":\"Grade8\",\"id\":\"grade8\",\"type\":\"group\",\"children\":[]}]},{\"name\":\"DisciplineSpecific\",\"id\":\"disciplineSpecific\",\"type\":\"group\",\"children\":[]},{\"name\":\"Grade7\",\"id\":\"grade7\",\"type\":\"group\",\"children\":[]},{\"name\":\"Grade8\",\"id\":\"grade8\",\"type\":\"group\",\"children\":[]}]"; + private String defaultProjectLibraryGroups = """ + [ + { + "name": "Integrated", + "id": "integrated", + "type": "group", + "children": [ + { + "name": "Grade6", + "id": "grade6", + "type": "group", + "children": [] + }, + { + "name": "Grade7", + "id": "grade7", + "type": "group", + "children": [] + }, + { + "name": "Grade8", + "id": "grade8", + "type": "group", + "children": [] + } + ] + }, + { + "name": "DisciplineSpecific", + "id": "disciplineSpecific", + "type": "group", + "children": [] + }, + { + "name": "Grade7", + "id": "grade7", + "type": "group", + "children": [] + }, + { + "name": "Grade8", + "id": "grade8", + "type": "group", + "children": [] + } + ]"""; - private String defaultAnnouncement = "{\"visible\":false,\"bannerText\":\"\",\"bannerButton\":\"\",\"title\":\"\",\"content\":\"\",\"buttons\":[]}"; + private String defaultAnnouncement = """ + { + "visible": false, + "bannerText": "", + "bannerButton": "", + "title": "", + "content": "", + "buttons": [] + }"""; @Transactional() public Portal getById(Serializable id) throws ObjectNotFoundException { diff --git a/src/test/java/org/wise/portal/presentation/web/AWSBedrockControllerTest.java b/src/test/java/org/wise/portal/presentation/web/AWSBedrockControllerTest.java index e9e41ea19..0b4b5b52b 100644 --- a/src/test/java/org/wise/portal/presentation/web/AWSBedrockControllerTest.java +++ b/src/test/java/org/wise/portal/presentation/web/AWSBedrockControllerTest.java @@ -40,8 +40,14 @@ public void setUp() { @Test public void sendChatMessage_successfulResponse() { - String requestBody = "{\"prompt\":\"test prompt\"}"; - String expectedResponse = "{\"response\":\"test response\"}"; + String requestBody = """ + { + "prompt": "test prompt" + }"""; + String expectedResponse = """ + { + "response": "test response" + }"""; mockServer.expect(requestTo(EXPECTED_URL)) .andExpect(method(HttpMethod.POST)) diff --git a/src/test/java/org/wise/portal/presentation/web/controllers/ChatGptControllerTest.java b/src/test/java/org/wise/portal/presentation/web/controllers/ChatGptControllerTest.java index a1a11c046..e63688f38 100644 --- a/src/test/java/org/wise/portal/presentation/web/controllers/ChatGptControllerTest.java +++ b/src/test/java/org/wise/portal/presentation/web/controllers/ChatGptControllerTest.java @@ -33,8 +33,19 @@ public void setUp() { @Test public void sendChatMessage_successfulResponse() { - String requestBody = "{\"model\":\"gpt-4\",\"messages\":[{\"role\":\"user\",\"content\":\"hello\"}]}"; - String expectedResponse = "{\"choices\":[{\"message\":{\"role\":\"assistant\",\"content\":\"hi!\"}}]}"; + String requestBody = """ + { + "model": "gpt-4", + "messages": [ + {"role": "user", "content": "hello"} + ] + }"""; + String expectedResponse = """ + { + "choices": [ + {"message": {"role": "assistant", "content": "hi!"}} + ] + }"""; mockServer.expect(requestTo(CHAT_URL)) .andExpect(method(HttpMethod.POST)) diff --git a/src/test/java/org/wise/portal/presentation/web/controllers/peergroup/PeerGroupStudentWorkAnnotationControllerTest.java b/src/test/java/org/wise/portal/presentation/web/controllers/peergroup/PeerGroupStudentWorkAnnotationControllerTest.java index b22c0beb2..d7490e254 100644 --- a/src/test/java/org/wise/portal/presentation/web/controllers/peergroup/PeerGroupStudentWorkAnnotationControllerTest.java +++ b/src/test/java/org/wise/portal/presentation/web/controllers/peergroup/PeerGroupStudentWorkAnnotationControllerTest.java @@ -61,8 +61,16 @@ public void getStudentDataForDynamicPrompt_InvalidDynamicPromptContent_Exception } private void expectInvalidDynamicPromptContent() throws IOException { - String project_sans_reference_component = "{\"nodes\": [{\"id\": \"" + run1Node2Id - + "\",\"type\": \"node\"," + "\"components\": [{\"id\": \"" + run1Component2Id + "\"}]}]}"; + String project_sans_reference_component = """ + { + "nodes": [ + { + "id": "%s", + "type": "node", + "components": [{"id": "%s"}] + } + ] + }""".formatted(run1Node2Id, run1Component2Id); expect(projectService.getProjectContent(project1)).andReturn(project_sans_reference_component); } @@ -83,11 +91,29 @@ public void getStudentDataForDynamicPrompt_ReturnReferenceComponentWork() throws } private void expectValidDynamicPromptContent() throws IOException { - String project_with_reference_component = "{\"nodes\": [{\"id\": \"" + run1Node2Id - + "\",\"type\": \"node\"," + "\"components\": [{\"id\": \"" + run1Component2Id - + "\",\"type\":\"HTML\", \"dynamicPrompt\":{\"peerGroupingTag\":\"" + peerGrouping1Tag - + "\", \"referenceComponent\": {\"nodeId\":\"" + run1Node1Id + "\",\"componentId\":\"" - + run1Component1Id + "\", \"type\":\"HTML\"}}}]}]}"; + String project_with_reference_component = """ + { + "nodes": [ + { + "id": "%s", + "type": "node", + "components": [ + { + "id": "%s", + "type": "HTML", + "dynamicPrompt": { + "peerGroupingTag": "%s", + "referenceComponent": { + "nodeId": "%s", + "componentId": "%s", + "type": "HTML" + } + } + } + ] + } + ] + }""".formatted(run1Node2Id, run1Component2Id, peerGrouping1Tag, run1Node1Id, run1Component1Id); expect(projectService.getProjectContent(project1)).andReturn(project_with_reference_component) .anyTimes(); } diff --git a/src/test/java/org/wise/portal/presentation/web/controllers/teacher/run/WorkgroupMembershipAPIControllerTest.java b/src/test/java/org/wise/portal/presentation/web/controllers/teacher/run/WorkgroupMembershipAPIControllerTest.java index ac5fff091..0c917074c 100644 --- a/src/test/java/org/wise/portal/presentation/web/controllers/teacher/run/WorkgroupMembershipAPIControllerTest.java +++ b/src/test/java/org/wise/portal/presentation/web/controllers/teacher/run/WorkgroupMembershipAPIControllerTest.java @@ -26,7 +26,11 @@ public class WorkgroupMembershipAPIControllerTest extends APIControllerTest { @BeforeEach public void init() throws Exception { - String paramString = "{\"workgroupIdTo\":\"2\",\"periodId\":\"1\"}"; + String paramString = """ + { + "workgroupIdTo": "2", + "periodId": "1" + }"""; ObjectMapper objectMapper = new ObjectMapper(); postedParams = objectMapper.readTree(paramString); } diff --git a/src/test/java/org/wise/portal/service/peergrouping/PeerGroupingServiceImplTest.java b/src/test/java/org/wise/portal/service/peergrouping/PeerGroupingServiceImplTest.java index 93d79080e..acdff4dff 100644 --- a/src/test/java/org/wise/portal/service/peergrouping/PeerGroupingServiceImplTest.java +++ b/src/test/java/org/wise/portal/service/peergrouping/PeerGroupingServiceImplTest.java @@ -84,10 +84,26 @@ public class PeerGroupingServiceImplTest { PeerGrouping peerGrouping = new PeerGroupingImpl(); - private String projectJSONString = "{" + "\"peerGroupings\":[{\"tag\": \"" + tagInDB + "\"}]," - + "\"nodes\":[{\"id\":\"" + nodeId + "\"," + "\"components\":[" + "{\"id\":\"" - + componentIdWithPeerGrouping + "\"," + "\"peerGroupingTag\":\"" + tagInDB + "\"" - + "}, {\"id\":\"" + componentIdWithoutPeerGrouping + "\"}]}]}"; + private String projectJSONString = """ + { + "peerGroupings": [ + {"tag": "%s"} + ], + "nodes": [ + { + "id": "%s", + "components": [ + { + "id": "%s", + "peerGroupingTag": "%s" + }, + { + "id": "%s" + } + ] + } + ] + }""".formatted(tagInDB, nodeId, componentIdWithPeerGrouping, tagInDB, componentIdWithoutPeerGrouping); @BeforeEach public void setUp() { diff --git a/src/test/java/org/wise/portal/service/peergrouping/logic/impl/DifferentIdeasLogicServiceImplTest.java b/src/test/java/org/wise/portal/service/peergrouping/logic/impl/DifferentIdeasLogicServiceImplTest.java index 052e2d495..8b64048e0 100644 --- a/src/test/java/org/wise/portal/service/peergrouping/logic/impl/DifferentIdeasLogicServiceImplTest.java +++ b/src/test/java/org/wise/portal/service/peergrouping/logic/impl/DifferentIdeasLogicServiceImplTest.java @@ -52,9 +52,13 @@ public void setup() throws Exception { private String createIdeaString(boolean idea1Detected, boolean idea2Detected, boolean idea3Detected, boolean idea4Detected) { - return "[{\"name\":\"1\",\"detected\":" + idea1Detected + "}," + "{\"name\":\"2\",\"detected\":" - + idea2Detected + "}," + "{\"name\":\"3\",\"detected\":" + idea3Detected + "}," - + "{\"name\":\"4\",\"detected\":" + idea4Detected + "}]"; + return """ + [ + {"name": "1", "detected": %b}, + {"name": "2", "detected": %b}, + {"name": "3", "detected": %b}, + {"name": "4", "detected": %b} + ]""".formatted(idea1Detected, idea2Detected, idea3Detected, idea4Detected); } private Annotation createIdeasAnnotation(Workgroup workgroup, String ideas) { diff --git a/src/test/java/org/wise/portal/service/peergrouping/logic/impl/DifferentKIScoresLogicServiceImplTest.java b/src/test/java/org/wise/portal/service/peergrouping/logic/impl/DifferentKIScoresLogicServiceImplTest.java index 6f88baa0f..2ea9c6002 100644 --- a/src/test/java/org/wise/portal/service/peergrouping/logic/impl/DifferentKIScoresLogicServiceImplTest.java +++ b/src/test/java/org/wise/portal/service/peergrouping/logic/impl/DifferentKIScoresLogicServiceImplTest.java @@ -49,7 +49,8 @@ private Annotation createKIScoreAnnotation(Workgroup workgroup, int score) { annotation.setToWorkgroup(workgroup); annotation.setPeriod(period1); annotation.setType("autoScore"); - annotation.setData("{\"scores\": [{\"id\":\"ki\",\"score\":" + score + "}]}"); + annotation.setData(""" + {"scores": [{"id": "ki", "score": %d}]}""".formatted(score)); return annotation; } diff --git a/src/test/java/org/wise/vle/web/CRaterControllerTest.java b/src/test/java/org/wise/vle/web/CRaterControllerTest.java index df24b34af..fe92991f1 100644 --- a/src/test/java/org/wise/vle/web/CRaterControllerTest.java +++ b/src/test/java/org/wise/vle/web/CRaterControllerTest.java @@ -50,14 +50,13 @@ public void verifyItemId_ShouldReturnString() { private String createVerificationResponseString(String itemId, Boolean available, Long trackingId, String clientId) { - StringBuffer responseBuffer = new StringBuffer(); - responseBuffer.append("{"); - responseBuffer.append(" \"item_id\": \"" + itemId + "\","); - responseBuffer.append(" \"available\": \"" + available + "\","); - responseBuffer.append(" \"tracking_id\": " + trackingId + ","); - responseBuffer.append(" \"client_id\": \"" + clientId + "\""); - responseBuffer.append("}"); - return responseBuffer.toString(); + return """ + { + "item_id": "%s", + "available": "%s", + "tracking_id": %d, + "client_id": "%s" + }""".formatted(itemId, available, trackingId, clientId); } @Test @@ -77,14 +76,13 @@ public void scoreItemId_ShouldReturnString() { } private String createScoringResponseString(String itemId, Long trackingId, String clientId) { - StringBuffer responseBuffer = new StringBuffer(); - responseBuffer.append("{"); - responseBuffer.append(" \"item_id\": \"" + itemId + "\","); - responseBuffer.append(" \"responses\": {},"); - responseBuffer.append(" \"tracking_id\": " + trackingId + ","); - responseBuffer.append(" \"client_id\": \"" + clientId + "\""); - responseBuffer.append("}"); - return responseBuffer.toString(); + return """ + { + "item_id": "%s", + "responses": {}, + "tracking_id": %d, + "client_id": "%s" + }""".formatted(itemId, trackingId, clientId); } @Test @@ -124,13 +122,12 @@ public void pingItem_ItemNotPinged_ShouldReturnString() { } private String createPingResponseString(String itemId, Long trackingId, String clientId) { - StringBuffer responseBuffer = new StringBuffer(); - responseBuffer.append("{"); - responseBuffer.append(" \"item_id\": \"" + itemId + "\","); - responseBuffer.append(" \"success\": true,"); - responseBuffer.append(" \"tracking_id\": " + trackingId + ","); - responseBuffer.append(" \"client_id\": \"" + clientId + "\""); - responseBuffer.append("}"); - return responseBuffer.toString(); + return """ + { + "item_id": "%s", + "success": true, + "tracking_id": %d, + "client_id": "%s" + }""".formatted(itemId, trackingId, clientId); } }