Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,142 @@ public class PortalServiceImpl implements PortalService {
@Autowired
private PortalDao<Portal> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
45 changes: 21 additions & 24 deletions src/test/java/org/wise/vle/web/CRaterControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
Loading