aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-08-22 00:13:02 +0300
committerGravatar Vitaly Takmazov2021-08-22 00:13:02 +0300
commit9100b5bda037fcd1b051b98585744077132320bc (patch)
treefdda04472de22e8f53eafc342a05e31b46cfb15d /src/test/java/com
parente5c28b65b5d3ef2e5c98c71f55faa7c60d7864f0 (diff)
Type-safe ActivityStreams deserialization
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index e25f0b0d..c11dfb46 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -40,6 +40,7 @@ import com.juick.www.api.activity.Profile;
import com.juick.www.api.activity.model.Context;
import com.juick.www.api.activity.model.activities.*;
import com.juick.www.api.activity.model.objects.Application;
+import com.juick.www.api.activity.model.objects.Image;
import com.juick.www.api.activity.model.objects.Note;
import com.juick.www.api.activity.model.objects.Person;
import com.juick.www.api.webfinger.model.Account;
@@ -1778,12 +1779,12 @@ public class ServerTests {
Person person = (Person) jsonMapper.readValue(personJsonStr, Context.class);
String undoJsonStr = IOUtils.toString(new ClassPathResource("undo.json").getURI(), StandardCharsets.UTF_8);
Undo undo = jsonMapper.readValue(undoJsonStr, Undo.class);
- String undoFollower = (String) ((Map) undo.getObject()).get("object");
+ String undoFollower = undo.getObject().getId();
String createJsonStr = IOUtils.toString(new ClassPathResource("create.json").getURI(), StandardCharsets.UTF_8);
Create create = jsonMapper.readValue(createJsonStr, Create.class);
- Map<String, Object> note = (Map<String, Object>) create.getObject();
- Map<String, Object> attachmentObj = (Map<String, Object>) ((List<Object>) note.get("attachment")).get(0);
- String attachment = attachmentObj != null ? (String) attachmentObj.get("url") : StringUtils.EMPTY;
+ Note note = (Note) create.getObject();
+ Context attachmentObj = note.getAttachment().get(0);
+ String attachment = attachmentObj != null ? (String) attachmentObj.getUrl() : StringUtils.EMPTY;
String deleteJsonStr = IOUtils.toString(new ClassPathResource("delete.json").getURI(), StandardCharsets.UTF_8);
Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
int mid = messagesService.createMessage(ugnich.getUid(), "YO", "", null);
@@ -1811,7 +1812,7 @@ public class ServerTests {
String undoPleromaStr = IOUtils.toString(new ClassPathResource("undo_pleroma.json").getURI(),
StandardCharsets.UTF_8);
Undo undoPleroma = jsonMapper.readValue(undoPleromaStr, Undo.class);
- String undoPleromaFollower = (String) ((Map) undoPleroma.getObject()).get("object");
+ String undoPleromaFollower = undoPleroma.getObject().getId();
String deletev3JsonStr = IOUtils.toString(new ClassPathResource("delete_v3.json").getURI(),
StandardCharsets.UTF_8);
Delete deleteObject = jsonMapper.readValue(deletev3JsonStr, Delete.class);
@@ -1850,7 +1851,7 @@ public class ServerTests {
Person to = (Person) signatureManager.getContext(URI.create("http://localhost:8080/u/ugnich")).get();
Follow follow = new Follow();
follow.setActor("http://localhost:8080/u/freefd");
- follow.setObject("http://localhost:8080/u/ugnich");
+ follow.setObject(new Context("http://localhost:8080/u/ugnich"));
signatureManager.post(from, to, follow);
}
@@ -2073,9 +2074,9 @@ public class ServerTests {
Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
ClientHttpRequestFactory originalRequestFactory = apClient.getRequestFactory();
MockRestServiceServer restServiceServer = MockRestServiceServer.createServer(apClient);
- restServiceServer.expect(times(2), requestTo((String) delete.getObject()))
+ restServiceServer.expect(times(2), requestTo(delete.getObject().getId()))
.andRespond(withStatus(HttpStatus.GONE));
- restServiceServer.expect(requestTo((String) delete.getObject())).andRespond(response -> {
+ restServiceServer.expect(requestTo(delete.getObject().getId())).andRespond(response -> {
throw new ResourceAccessException("Connection reset");
});
mockMvc.perform(post("/api/inbox").contentType(ACTIVITY_MEDIA_TYPE).content(deleteJsonStr))
@@ -2094,7 +2095,7 @@ public class ServerTests {
Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
ClientHttpRequestFactory originalRequestFactory = apClient.getRequestFactory();
MockRestServiceServer restServiceServer = MockRestServiceServer.createServer(apClient);
- restServiceServer.expect(requestTo((String) delete.getObject())).andRespond(response -> {
+ restServiceServer.expect(requestTo(delete.getObject().getId())).andRespond(response -> {
throw new ResourceAccessException("Connection reset");
});
mockMvc.perform(post("/api/inbox").contentType(ACTIVITY_MEDIA_TYPE).content(deleteJsonStr).header("Signature",
@@ -2117,13 +2118,12 @@ public class ServerTests {
Announce announce = jsonMapper.readValue(activity, Announce.class);
String noteString = IOUtils.toString(noteWithAttachment.getInputStream(), StandardCharsets.UTF_8);
Create create = jsonMapper.readValue(noteString, Create.class);
- Map<String, Object> note = (Map<String, Object>) create.getObject();
- String markdown = remarkConverter.convertFragment((String) note.get("content"));
- String commandBody = note.get("attachment") == null ? markdown
- : ((List<Object>) note.get("attachment")).stream().map(attachmentObj -> {
- Map<String, String> attachment = (Map<String, String>) attachmentObj;
- String attachmentUrl = attachment.get("url");
- String attachmentName = attachment.get("name");
+ Note note = (Note) create.getObject();
+ String markdown = remarkConverter.convertFragment((String) note.getContent());
+ String commandBody = note.getContent() == null ? markdown
+ : note.getAttachment().stream().map(attachment -> {
+ String attachmentUrl = attachment.getUrl();
+ String attachmentName = attachment.getName();
return PlainTextFormatter.markdownUrl(attachmentUrl, attachmentName);
}).reduce(markdown, (current, next) -> String.format("%s\n%s", current, next));
}