aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server/tests
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-12-11 16:14:14 +0300
committerGravatar Vitaly Takmazov2018-12-11 16:14:14 +0300
commitae5870f1fa9bbf045f1881664bb8a3a098fd2610 (patch)
tree102f511c55bfbaa9b0dd70485cc705eab3372f99 /src/test/java/com/juick/server/tests
parentc1320bed982d4cff77f231f03eaa9eb34d14305f (diff)
avatar upload api
Diffstat (limited to 'src/test/java/com/juick/server/tests')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index deef6f30..b732cb98 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -44,6 +44,7 @@ import com.juick.server.api.webfinger.model.Account;
import com.juick.server.api.xnodeinfo2.model.NodeInfo;
import com.juick.server.util.HttpUtils;
import com.juick.server.util.ImageUtils;
+import com.juick.server.www.WebApp;
import com.juick.server.xmpp.helpers.XMPPStatus;
import com.juick.server.xmpp.s2s.ConnectionIn;
import com.juick.service.*;
@@ -76,6 +77,7 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.util.DigestUtils;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.LinkedMultiValueMap;
@@ -204,6 +206,8 @@ public class ServerTests {
private SignatureManager signatureManager;
@Inject
private ActivityPubManager activityPubManager;
+ @Inject
+ private WebApp webApp;
private static User ugnich, freefd, juick;
static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword;
@@ -1858,4 +1862,19 @@ public class ServerTests {
jdbcTemplate.update("INSERT INTO facebook(user_id, fb_id) VALUES(?, ?)", ugnich.getUid(), "100001866137681");
assertThat(userService.getUserByName("ugnich").isVerified(), is(true));
}
+ @Test
+ public void avatarUploadOverApi() throws Exception {
+ ClassPathResource defaultAvatar = new ClassPathResource("static/av-96.png");
+ String hash = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(defaultAvatar.getInputStream()));
+ assertThat(webApp.getAvatarUrl(userService.getUserByName(freefdName)), is(String.format("http://localhost:8080/av-96-%s.png", hash)));
+
+ ClassPathResource newAvatar = new ClassPathResource("cmyk.jpg");
+ byte[] newAvatarData = IOUtils.toByteArray(newAvatar.getInputStream());
+ mockMvc.perform(MockMvcRequestBuilders.multipart("/api/me/upload")
+ .file("avatar", newAvatarData)
+ .with(httpBasic(freefdName, freefdPassword))
+ ).andExpect(status().isOk());
+ String newHash = DigestUtils.md5DigestAsHex(newAvatarData);
+ assertThat(webApp.getAvatarUrl(userService.getUserByName(freefdName)), is(String.format("http://localhost:8080/i/a/%d-%s.png", freefd.getUid(), newHash)));
+ }
}