aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-06 13:58:40 +0300
committerGravatar Vitaly Takmazov2018-09-07 05:15:51 -0400
commit670913698776e09b7ff44f44ccdcf56303d79be3 (patch)
tree96f932645ab0faf9de6861f89072d1eb4b2622a3 /juick-server/src/test/java/com/juick/server/tests/ServerTests.java
parent51489a954463567f8dd50854826c03ce51c45cb3 (diff)
merge legacy www
Diffstat (limited to 'juick-server/src/test/java/com/juick/server/tests/ServerTests.java')
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java110
1 files changed, 55 insertions, 55 deletions
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 1931f13b..fc18dbf5 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -368,19 +368,19 @@ public class ServerTests {
@Test
public void testAllUnAuthorized() throws Exception {
- mockMvc.perform(get("/"))
+ mockMvc.perform(get("/api/"))
.andExpect(status().isMovedPermanently());
- mockMvc.perform(get("/auth"))
+ mockMvc.perform(get("/api/auth"))
.andExpect(status().isUnauthorized());
- mockMvc.perform(get("/home"))
+ mockMvc.perform(get("/api/home"))
.andExpect(status().isUnauthorized());
- mockMvc.perform(get("/messages/recommended"))
+ mockMvc.perform(get("/api/messages/recommended"))
.andExpect(status().isUnauthorized());
- mockMvc.perform(get("/messages/set_privacy"))
+ mockMvc.perform(get("/api/messages/set_privacy"))
.andExpect(status().isUnauthorized());
}
@@ -392,7 +392,7 @@ public class ServerTests {
Message msg = messagesService.getMessage(mid);
tagService.createTag("ั‚ะตัั‚");
mockMvc.perform(
- get("/home")
+ get("/api/home")
.with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@@ -411,12 +411,12 @@ public class ServerTests {
public void homeTestWithMessagesAndRememberMe() throws Exception {
String ugnichHash = userService.getHashByUID(ugnich.getUid());
mockMvc.perform(
- get("/home")
+ get("/api/home")
.with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isOk())
.andReturn();
- mockMvc.perform(get("/home")
+ mockMvc.perform(get("/api/home")
.param("hash", ugnichHash))
.andExpect(status().isOk());
}
@@ -424,7 +424,7 @@ public class ServerTests {
@Test
public void homeTestWithMessagesAndSimpleCors() throws Exception {
mockMvc.perform(
- get("/home")
+ get("/api/home")
.with(httpBasic(ugnichName, ugnichPassword))
.header("Origin", "http://api.example.net"))
.andExpect(status().isOk())
@@ -434,7 +434,7 @@ public class ServerTests {
@Test
public void homeTestWithPreflightCors() throws Exception {
mockMvc.perform(
- options("/home")
+ options("/api/home")
.with(httpBasic(ugnichName, ugnichPassword))
.header("Origin", "http://api.example.net")
.header("Access-Control-Request-Method", "POST")
@@ -449,10 +449,10 @@ public class ServerTests {
public void anonymousApis() throws Exception {
- mockMvc.perform(get("/messages"))
+ mockMvc.perform(get("/api/messages"))
.andExpect(status().isOk());
- mockMvc.perform(get("/users")
+ mockMvc.perform(get("/api/users")
.param("uname", "ugnich")
.param("uname", "freefd"))
.andExpect(status().isOk())
@@ -473,7 +473,7 @@ public class ServerTests {
messagesService.likeMessage(mid, freefdId, 2 );
messagesService.likeMessage(mid, freefdId, 3 );
- mockMvc.perform(get("/messages?"+ "hash=" + userIdHash))
+ mockMvc.perform(get("/api/messages?"+ "hash=" + userIdHash))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@@ -482,7 +482,7 @@ public class ServerTests {
.andExpect((jsonPath("$[0].reactions[?(@.id == 2)].count",
is(Collections.singletonList(2)))));
- mockMvc.perform(get("/reactions?hash=" + userIdHash))
+ mockMvc.perform(get("/api/reactions?hash=" + userIdHash))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.length()", is(7)));
@@ -494,14 +494,14 @@ public class ServerTests {
Tag yo = tagService.getTag("yo", true);
messagesService.createMessage(ugnich.getUid(), "text", null, Arrays.asList(yo, weather));
messagesService.createMessage(freefd.getUid(), "text2", null, Collections.singletonList(yo));
- MvcResult result = mockMvc.perform(get("/tags"))
+ MvcResult result = mockMvc.perform(get("/api/tags"))
.andExpect(status().isOk())
.andReturn();
List<TagStats> tagsFromApi = jsonMapper.readValue(result.getResponse().getContentAsString(),
new TypeReference<List<TagStats>>(){});
TagStats yoStats = tagsFromApi.stream().filter(t -> t.getTag().getName().equals("yo")).findFirst().get();
assertThat(yoStats.getUsageCount(), is(2));
- MvcResult result2 = mockMvc.perform(get("/tags")
+ MvcResult result2 = mockMvc.perform(get("/api/tags")
.param("user_id", String.valueOf(ugnich.getUid())))
.andExpect(status().isOk())
.andReturn();
@@ -513,40 +513,40 @@ public class ServerTests {
@Test
public void postWithReferer() throws Exception {
- mockMvc.perform(post("/post")
+ mockMvc.perform(post("/api/post")
.param("body", "yo")
.with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isOk());
}
@Test
public void threadWithEphemeralNumberShouldReturn404() throws Exception {
- mockMvc.perform(get("/thread").param("mid", "999999999")
+ mockMvc.perform(get("/api/thread").param("mid", "999999999")
.with(httpBasic(ugnichName, ugnichPassword))).andExpect(status().is4xxClientError());
}
@Test
public void performRequestsWithIssuedToken() throws Exception {
String ugnichHash = userService.getHashByUID(ugnich.getUid());
- mockMvc.perform(get("/home")).andExpect(status().isUnauthorized());
- mockMvc.perform(get("/auth"))
+ mockMvc.perform(get("/api/home")).andExpect(status().isUnauthorized());
+ mockMvc.perform(get("/api/auth"))
.andExpect(status().isUnauthorized());
- mockMvc.perform(get("/auth").with(httpBasic(ugnichName, "wrongpassword")))
+ mockMvc.perform(get("/api/auth").with(httpBasic(ugnichName, "wrongpassword")))
.andExpect(status().isUnauthorized());
- MvcResult result = mockMvc.perform(get("/auth").with(httpBasic(ugnichName, ugnichPassword)))
+ MvcResult result = mockMvc.perform(get("/api/auth").with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isOk())
.andReturn();
String authHash = result.getResponse().getContentAsString();
assertThat(authHash, equalTo(ugnichHash));
- mockMvc.perform(get("/home").param("hash", ugnichHash)).andExpect(status().isOk());
+ mockMvc.perform(get("/api/home").param("hash", ugnichHash)).andExpect(status().isOk());
}
@Test
public void registerForNotificationsTests() throws Exception {
String token = "123456";
ExternalToken registration = new ExternalToken(null, "apns", token, null);
- mockMvc.perform(put("/notifications").with(httpBasic(ugnichName, ugnichPassword))
+ mockMvc.perform(put("/api/notifications").with(httpBasic(ugnichName, ugnichPassword))
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(jsonMapper.writeValueAsBytes(Collections.singletonList(registration))))
.andExpect(status().isOk());
- MvcResult result = mockMvc.perform(get("/notifications")
+ MvcResult result = mockMvc.perform(get("/api/notifications")
.param("uid", String.valueOf(ugnich.getUid()))
.with(httpBasic(juickName, juickPassword)))
.andExpect(status().isOk())
@@ -565,10 +565,10 @@ public class ServerTests {
@Test
public void notificationsTokensTest() throws Exception {
List<ExternalToken> tokens = Collections.singletonList(new ExternalToken(null, "gcm", "123456", null));
- mockMvc.perform(delete("/notifications").with(httpBasic(ugnichName, ugnichPassword))
+ mockMvc.perform(delete("/api/notifications").with(httpBasic(ugnichName, ugnichPassword))
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(jsonMapper.writeValueAsBytes(tokens))).andExpect(status().isForbidden());
- mockMvc.perform(delete("/notifications").with(httpBasic(juickName, juickPassword))
+ mockMvc.perform(delete("/api/notifications").with(httpBasic(juickName, juickPassword))
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(jsonMapper.writeValueAsBytes(tokens))).andExpect(status().isOk());
}
@@ -576,9 +576,9 @@ public class ServerTests {
public void notificationsSettingsAllowedOnlyForServiceUser() throws Exception {
CommandResult result = commandsManager.processCommand(ugnich, "yo", emptyUri);
String stringValueOfMid = String.valueOf(result.getNewMessage().get().getMid());
- mockMvc.perform(get("/notifications").with(httpBasic(juickName, juickPassword))
+ mockMvc.perform(get("/api/notifications").with(httpBasic(juickName, juickPassword))
.param("mid", stringValueOfMid).param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isOk());
- mockMvc.perform(get("/notifications")
+ mockMvc.perform(get("/api/notifications")
.param("mid", stringValueOfMid).param("uid", String.valueOf(ugnich.getUid()))).andExpect(status().isUnauthorized());
}
@Test
@@ -858,7 +858,7 @@ public class ServerTests {
"<div dir=\"ltr\">s2313334</div>\n" +
"\n" +
"--001a11454886e42be5056786ca70--";
- mockMvc.perform(post("/mail").with(httpBasic(juickName, juickPassword)).content(mail))
+ mockMvc.perform(post("/api/mail").with(httpBasic(juickName, juickPassword)).content(mail))
.andExpect(status().isOk());
}
@@ -869,14 +869,14 @@ public class ServerTests {
String freefdHash = userService.getHashByUID(freefd.getUid());
int freefdMid = messagesService.createMessage(freefd.getUid(), "to be not liked", null, null);
- mockMvc.perform(post("/like?mid=" + mid + "&hash=" + freefdHash))
+ mockMvc.perform(post("/api/like?mid=" + mid + "&hash=" + freefdHash))
.andExpect(status().isOk())
.andExpect(jsonPath("$.status", is("Message is added to your recommendations")));
- mockMvc.perform(get("/thread?mid=" + mid + "&hash=" + freefdHash))
+ mockMvc.perform(get("/api/thread?mid=" + mid + "&hash=" + freefdHash))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].recommendations.length()", is(1)))
.andExpect(jsonPath("$[0].recommendations[0]", is(freefdName)));
- mockMvc.perform(post("/like?mid=" + freefdMid + "&hash=" + freefdHash))
+ mockMvc.perform(post("/api/like?mid=" + freefdMid + "&hash=" + freefdHash))
.andExpect(status().isForbidden());
}
@@ -886,7 +886,7 @@ public class ServerTests {
String freefdHash = userService.getHashByUID(freefd.getUid());
int mid1 = messagesService.createMessage(user_id, "yo", null, new ArrayList<>());
- mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=2"))
+ mockMvc.perform(post("/api/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=2"))
.andExpect(status().isOk());
Message msg4 = messagesService.getMessage(mid1);
@@ -894,9 +894,9 @@ public class ServerTests {
assertThat(messagesService.getMessages(AnonymousUser.INSTANCE, Collections.singletonList(mid1)).get(0).getLikes(), is(0));
Assert.assertEquals(1, msg4.getReactions().stream().filter(r -> r.getId() == 2)
.findFirst().orElseThrow(IllegalStateException::new).getCount());
- mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=1"))
+ mockMvc.perform(post("/api/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=1"))
.andExpect(status().isOk());
- mockMvc.perform(post("/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=1"))
+ mockMvc.perform(post("/api/react?mid=" + mid1 + "&hash=" + freefdHash+ "&reactionId=1"))
.andExpect(status().isOk());
assertThat(messagesService.getMessage(mid1).getLikes(), is(1));
}
@@ -920,7 +920,7 @@ public class ServerTests {
assertThat(lastRead.apply(ugnich, mid), is(1));
String ugnichHash = userService.getHashByUID(ugnich.getUid());
int freefdrid = messagesService.createReply(mid, 0, freefd, "again", null);
- mockMvc.perform(get(String.format("/thread/mark_read/%d-%d.gif?hash=%s", mid, freefdrid, ugnichHash)))
+ mockMvc.perform(get(String.format("/api/thread/mark_read/%d-%d.gif?hash=%s", mid, freefdrid, ugnichHash)))
.andExpect(status().isOk())
.andExpect(content().bytes(IOUtils.toByteArray(
Objects.requireNonNull(getClass().getClassLoader().getResource("Transparent.gif")))));
@@ -934,7 +934,7 @@ public class ServerTests {
privacyQueriesService.blacklistUser(ugnich, freefd);
newfreefdrid = messagesService.createReply(mid, 0, freefd, "after ban", null);
assertThat(lastRead.apply(ugnich, mid), lessThan(newfreefdrid));
- mockMvc.perform(get(String.format("/thread?mid=%d&hash=%s", mid, ugnichHash)))
+ mockMvc.perform(get(String.format("/api/thread?mid=%d&hash=%s", mid, ugnichHash)))
.andExpect(status().isOk());
assertThat(lastRead.apply(ugnich, mid), is(newfreefdrid));
}
@@ -1035,13 +1035,13 @@ public class ServerTests {
map.add("body", "yo");
map.add("hash", userService.getHashByUID(ugnich.getUid()));
ResponseEntity<CommandResult> result = restTemplate.postForEntity(
- "/post",
+ "/api/post",
request, CommandResult.class);
assertThat(result.getStatusCode(), is(HttpStatus.OK));
}
@Test
public void emptyAuthenticatedPostShouldThrowBadRequest() throws Exception {
- mockMvc.perform(post("/post")
+ mockMvc.perform(post("/api/post")
.with(httpBasic(juickName, juickPassword)))
.andExpect(status().isBadRequest());
}
@@ -1061,7 +1061,7 @@ public class ServerTests {
commandsManager.processCommand(ugnich, "S @freefd", emptyUri);
assertThat(userService.getUserReaders(ugnich.getUid()).size(), is(1));
String hash = userService.getHashByUID(ugnich.getUid());
- mockMvc.perform(get("/me")
+ mockMvc.perform(get("/api/me")
.with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(jsonPath("$.hash", is(hash)))
.andExpect(jsonPath("$.readers.length()", is(1)))
@@ -1148,7 +1148,7 @@ public class ServerTests {
}
@Test
public void messageEditingSpec() throws Exception {
- MvcResult result = mockMvc.perform(post("/post").with(httpBasic(ugnichName, ugnichPassword))
+ MvcResult result = mockMvc.perform(post("/api/post").with(httpBasic(ugnichName, ugnichPassword))
.param("body", "YO")).andExpect(status().is2xxSuccessful()).andReturn();
Message original = jsonMapper.readValue(result.getResponse().getContentAsString(), CommandResult.class)
.getNewMessage().get();
@@ -1156,17 +1156,17 @@ public class ServerTests {
assertThat(original.getUpdatedAt(), equalTo(original.getTimestamp()));
// to have updated_at greater than ts
Thread.sleep(1000);
- result = mockMvc.perform(post("/update").with(httpBasic(ugnichName, ugnichPassword))
+ result = mockMvc.perform(post("/api/update").with(httpBasic(ugnichName, ugnichPassword))
.param("mid", String.valueOf(original.getMid()))
.param("body", "PEOPLE")).andExpect(status().is2xxSuccessful()).andReturn();
Message edited = jsonMapper.readValue(result.getResponse().getContentAsString(), CommandResult.class)
.getNewMessage().get();
assertThat(edited.getText(), equalTo("PEOPLE"));
assertThat(edited.getUpdatedAt(), greaterThan(edited.getTimestamp()));
- mockMvc.perform(post("/update").with(httpBasic(freefdName, freefdPassword))
+ mockMvc.perform(post("/api/update").with(httpBasic(freefdName, freefdPassword))
.param("mid", String.valueOf(original.getMid()))
.param("body", "PEOPLE")).andExpect(status().is(403));
- result = mockMvc.perform(post("/comment").with(httpBasic(freefdName, freefdPassword))
+ result = mockMvc.perform(post("/api/comment").with(httpBasic(freefdName, freefdPassword))
.param("mid", String.valueOf(original.getMid()))
.param("body", "HEY")).andExpect(status().is2xxSuccessful()).andReturn();
Message comment = jsonMapper.readValue(result.getResponse().getContentAsString(), Message.class);
@@ -1174,7 +1174,7 @@ public class ServerTests {
assertThat(comment.getUpdatedAt(), is(comment.getTimestamp()));
// to have updated_at greater than ts
Thread.sleep(1000);
- result = mockMvc.perform(post("/update").with(httpBasic(freefdName, freefdPassword))
+ result = mockMvc.perform(post("/api/update").with(httpBasic(freefdName, freefdPassword))
.param("mid", String.valueOf(comment.getMid()))
.param("rid", String.valueOf(comment.getRid()))
.param("body", "HEY, JOE")).andExpect(status().is2xxSuccessful()).andReturn();
@@ -1223,7 +1223,7 @@ public class ServerTests {
public void xmppStatusApi() throws Exception {
Supplier<XMPPStatus> getStatus = () -> {
try {
- MvcResult result = mockMvc.perform(get("/xmpp/status").with(httpBasic(ugnichName, ugnichPassword)))
+ MvcResult result = mockMvc.perform(get("/api/xmpp-status").with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isOk()).andReturn();
return jsonMapper.readValue(result.getResponse().getContentAsString(), XMPPStatus.class);
} catch (Exception e) {
@@ -1273,16 +1273,16 @@ public class ServerTests {
User isilmine = userService.getUserByUID(userService.createUser(userName, userPassword)).orElseThrow(IllegalStateException::new);
int mid = messagesService.createMessage(isilmine.getUid(), msgText, null, null);
- mockMvc.perform(get(String.format("/thread?mid=%d", mid)).with(httpBasic(ugnichName, ugnichPassword)))
+ mockMvc.perform(get(String.format("/api/thread?mid=%d", mid)).with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isOk());
jdbcTemplate.update("UPDATE users SET banned=1 WHERE id=?", isilmine.getUid());
- mockMvc.perform(get(String.format("/thread?mid=%d", mid)).with(httpBasic(ugnichName, ugnichPassword)))
+ mockMvc.perform(get(String.format("/api/thread?mid=%d", mid)).with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isNotFound());
- mockMvc.perform(get("/messages?uname=isilmine").with(httpBasic(ugnichName, ugnichPassword)))
+ mockMvc.perform(get("/api/messages?uname=isilmine").with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isNotFound());
- mockMvc.perform(get("/info/isilmine").with(httpBasic(ugnichName, ugnichPassword)))
+ mockMvc.perform(get("/api/info/isilmine").with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isNotFound());
- mockMvc.perform(get("/info/ugnich").with(httpBasic(ugnichName, ugnichPassword)))
+ mockMvc.perform(get("/api/info/ugnich").with(httpBasic(ugnichName, ugnichPassword)))
.andExpect(status().isOk());
}
@@ -1293,7 +1293,7 @@ public class ServerTests {
userService.createUser(userName, userPassword);
- mockMvc.perform(get("/auth").with(httpBasic(userName, userPassword))).andExpect(status().isUnauthorized());
+ mockMvc.perform(get("/api/auth").with(httpBasic(userName, userPassword))).andExpect(status().isUnauthorized());
}
@Test
public void bannedUserShouldBeShadowedFromRecommendationsList() throws IOException {
@@ -1342,7 +1342,7 @@ public class ServerTests {
}
@Test
public void userProfileAndBlogShouldBeExposedAsActivityStream() throws Exception {
- mockMvc.perform(get("/u/ugnich").accept(ActivityObject.LD_JSON_MEDIA_TYPE))
+ mockMvc.perform(get("/api/u/ugnich").accept(ActivityObject.LD_JSON_MEDIA_TYPE))
.andExpect(status().isOk())
.andExpect(jsonPath("$.icon.url", is("http://localhost:8080/i/a/1.png")))
.andExpect(jsonPath("$.publicKey.publicKeyPem", is(keystoreManager.getPublicKey())));
@@ -1352,7 +1352,7 @@ public class ServerTests {
String.format("message %d", i), null, null))
.collect(Collectors.toCollection(ArrayDeque::new)).descendingIterator());
List<Integer> midsPage = mids.stream().limit(20).collect(Collectors.toList());
- mockMvc.perform(get("/u/ugnich/blog").accept(ActivityObject.ACTIVITY_JSON_MEDIA_TYPE))
+ mockMvc.perform(get("/api/u/ugnich/blog").accept(ActivityObject.ACTIVITY_JSON_MEDIA_TYPE))
.andExpect(status().isOk())
.andExpect(jsonPath("$.orderedItems", hasSize(20)))
.andExpect(jsonPath("$.next", is("http://localhost:8080/u/ugnich/blog?before=" + midsPage.get(midsPage.size() - 1))));