aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/juick/server/tests')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 7fe39d0d..5ee8b1f4 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -201,12 +201,16 @@ public class ServerTests {
private Resource testuserResponse;
@Value("classpath:mocks/activity/testfollow.json")
private Resource testfollowRequest;
+ @Value("classpath:static/av-96.png")
+ private Resource defaultAvatar;
+ @Value("classpath:cmyk.jpg")
+ private Resource cmykJpeg;
+ @Value("classpath:nojfif.jpg")
+ private Resource nojfif;
@Inject
private KeystoreManager testKeystoreManager;
- private MockRestServiceServer restServiceServer;
-
private static User ugnich, freefd, juick;
static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword;
URI emptyUri = URI.create(StringUtils.EMPTY);
@@ -448,7 +452,6 @@ public class ServerTests {
int mid = result.getNewMessage().get().getMid();
Message msg = messagesService.getMessage(mid).get();
tagService.createTag("ั‚ะตัั‚");
- ClassPathResource defaultAvatar = new ClassPathResource("static/av-96.png");
String hash = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(defaultAvatar.getInputStream()));
mockMvc.perform(
get("/api/home")
@@ -1124,7 +1127,7 @@ public class ServerTests {
}
@Test
public void cmykJpegShouldBeProcessedCorrectly() throws Exception {
- CommandResult postJpgCmyk = commandsManager.processCommand(ugnich, "YO", new ClassPathResource("cmyk.jpg").getURI());
+ CommandResult postJpgCmyk = commandsManager.processCommand(ugnich, "YO", cmykJpeg.getURI());
assertThat(postJpgCmyk.getNewMessage().isPresent(), is(true));
int mid = postJpgCmyk.getNewMessage().get().getMid();
File originalFile = Paths.get(imgDir, "p", String.format("%d.jpg", mid)).toFile();
@@ -1138,7 +1141,7 @@ public class ServerTests {
}
@Test
public void JpegWithoutJfifShouldBeProcessedCorrectly() throws Exception {
- CommandResult postJpgCmyk = commandsManager.processCommand(ugnich, "YO", new ClassPathResource("nojfif.jpg").getURI());
+ CommandResult postJpgCmyk = commandsManager.processCommand(ugnich, "YO", nojfif.getURI());
assertThat(postJpgCmyk.getNewMessage().isPresent(), is(true));
int mid = postJpgCmyk.getNewMessage().get().getMid();
File originalFile = Paths.get(imgDir, "p", String.format("%d.jpg", mid)).toFile();
@@ -1171,7 +1174,7 @@ public class ServerTests {
public void changeExtensionWhenReceiveFileWithWrongContentType() throws Exception {
Path pngOutput = Paths.get(tmpDir, "cmyk.png");
Files.deleteIfExists(pngOutput);
- Files.copy(Paths.get(new ClassPathResource("cmyk.jpg").getURI()), pngOutput);
+ Files.copy(Paths.get(cmykJpeg.getURI()), pngOutput);
assertThat(pngOutput.toFile().exists(), is(true));
CommandResult postJpgCmyk = commandsManager.processCommand(ugnich, "YO", pngOutput.toUri());
assertThat(postJpgCmyk.getNewMessage().isPresent(), is(true));
@@ -1730,9 +1733,9 @@ public class ServerTests {
assertThat(meUser, is(ugnich));
String testuserResponseString = IOUtils.toString(testuserResponse.getInputStream(), StandardCharsets.UTF_8);
ClientHttpRequestFactory originalRequestFactory = apClient.getRequestFactory();
- restServiceServer = MockRestServiceServer.bindTo(apClient).build();
URI testuserUri = URI.create("https://example.com/u/testuser");
URI testuserkeyUri = URI.create("https://example.com/u/testuser#main-key");
+ MockRestServiceServer restServiceServer = MockRestServiceServer.createServer(apClient);
restServiceServer.expect(times(3), requestTo(testuserUri))
.andRespond(withSuccess(testuserResponseString, MediaType.APPLICATION_JSON_UTF8));
restServiceServer.expect(times(3), requestTo(testuserkeyUri))
@@ -1891,12 +1894,14 @@ public class ServerTests {
public void federatedUserDeletionFlow() throws Exception {
String deleteJsonStr = IOUtils.toString(new ClassPathResource("delete_user.json").getURI(), StandardCharsets.UTF_8);
Delete delete = jsonMapper.readValue(deleteJsonStr, Delete.class);
- restServiceServer = MockRestServiceServer.bindTo(apClient).build();
+ ClientHttpRequestFactory originalRequestFactory = apClient.getRequestFactory();
+ MockRestServiceServer restServiceServer = MockRestServiceServer.createServer(apClient);
restServiceServer.expect(times(1), requestTo((String)delete.getObject()))
.andRespond(withStatus(HttpStatus.GONE));
mockMvc.perform(post("/api/inbox")
.contentType(ACTIVITY_MEDIA_TYPE)
.content(deleteJsonStr))
.andExpect(status().isAccepted());
+ apClient.setRequestFactory(originalRequestFactory);
}
}