aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-10-23 08:57:30 +0300
committerGravatar Vitaly Takmazov2021-10-23 08:57:30 +0300
commit6b5d0deb398b0b77c13c16fbf116b4639feef574 (patch)
treea64401907e866429f541a06de71303de2fa96bb8 /src/test/java
parent4b96a9b2e71b7a67effdd55b26ca532ff849d0ef (diff)
Fix tests
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java211
1 files changed, 153 insertions, 58 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 5aee3af8..479a1fc6 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -17,6 +17,92 @@
package com.juick.server.tests;
+import static com.juick.www.api.activity.model.Context.ACTIVITY_MEDIA_TYPE;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.emptyString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.lessThan;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
+import static org.springframework.test.util.AssertionErrors.assertNotEquals;
+import static org.springframework.test.web.client.ExpectedCount.times;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.xpath;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.security.KeyFactory;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
+import java.security.Security;
+import java.security.spec.InvalidKeySpecException;
+import java.sql.Timestamp;
+import java.time.Instant;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Scanner;
+import java.util.Set;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.StreamSupport;
+
+import javax.inject.Inject;
+import javax.servlet.http.Cookie;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -29,35 +115,67 @@ import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.github.scribejava.apis.AppleClientSecretGenerator;
import com.jayway.jsonpath.JsonPath;
-import com.juick.*;
-import com.juick.util.*;
+import com.juick.ActivityPubManager;
+import com.juick.CommandsManager;
+import com.juick.EmailManager;
+import com.juick.KeystoreManager;
+import com.juick.ServerManager;
+import com.juick.SignatureManager;
+import com.juick.model.AnonymousUser;
+import com.juick.model.Attachment;
+import com.juick.model.CommandResult;
+import com.juick.model.ExternalToken;
+import com.juick.model.Message;
+import com.juick.model.PrivateChats;
+import com.juick.model.Reaction;
+import com.juick.model.Tag;
+import com.juick.model.TagStats;
+import com.juick.model.User;
+import com.juick.server.MockDeleteListener;
+import com.juick.server.MockNotificationListener;
+import com.juick.server.MockUpdateListener;
+import com.juick.service.EmailService;
+import com.juick.service.MessagesService;
+import com.juick.service.PMQueriesService;
+import com.juick.service.PrivacyQueriesService;
+import com.juick.service.StorageService;
+import com.juick.service.SubscriptionService;
+import com.juick.service.TagService;
+import com.juick.service.TelegramService;
+import com.juick.service.UserService;
+import com.juick.service.activities.DeleteUserEvent;
+import com.juick.service.activities.UpdateEvent;
+import com.juick.service.component.SystemEvent;
+import com.juick.test.util.MockUtils;
+import com.juick.util.DateFormattersHolder;
+import com.juick.util.HttpUtils;
+import com.juick.util.MessageUtils;
+import com.juick.util.UsernameTakenException;
+import com.juick.util.WebUtils;
import com.juick.util.formatters.PlainTextFormatter;
-import com.juick.model.*;
-import com.juick.server.*;
+import com.juick.www.WebApp;
+import com.juick.www.ad.models.Site;
import com.juick.www.api.SystemActivity;
import com.juick.www.api.Users;
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.activities.Announce;
+import com.juick.www.api.activity.model.activities.Create;
+import com.juick.www.api.activity.model.activities.Delete;
+import com.juick.www.api.activity.model.activities.Follow;
+import com.juick.www.api.activity.model.activities.Like;
+import com.juick.www.api.activity.model.activities.Undo;
import com.juick.www.api.activity.model.objects.Actor;
import com.juick.www.api.activity.model.objects.Application;
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;
import com.juick.www.api.xnodeinfo2.model.NodeInfo;
-import com.juick.www.WebApp;
-import com.juick.service.*;
-import com.juick.service.activities.DeleteUserEvent;
-import com.juick.service.activities.UpdateEvent;
-import com.juick.service.component.SystemEvent;
-import com.juick.test.util.MockUtils;
import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
import com.overzealous.remark.Remark;
-import io.jsonwebtoken.Claims;
-import io.jsonwebtoken.Jws;
-import io.jsonwebtoken.Jwts;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.io.IOUtils;
@@ -92,7 +210,11 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
-import org.springframework.http.*;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.mock.web.MockMultipartFile;
@@ -111,56 +233,21 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.tomitribe.auth.signatures.Base64;
-import org.w3c.dom.*;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
import org.xml.sax.SAXException;
+
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jws;
+import io.jsonwebtoken.Jwts;
import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.session.Extension;
import rocks.xmpp.core.session.XmppSession;
import rocks.xmpp.core.session.XmppSessionConfiguration;
-import com.juick.www.ad.models.Site;
import ru.sape.SapePageLinks;
-import javax.inject.Inject;
-import javax.servlet.http.Cookie;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.*;
-import java.net.URI;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.CopyOption;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.security.*;
-import java.security.spec.InvalidKeySpecException;
-import java.sql.Timestamp;
-import java.time.Instant;
-import java.util.*;
-import java.util.function.BiFunction;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-import java.util.stream.StreamSupport;
-
-import static com.juick.www.api.activity.model.Context.ACTIVITY_MEDIA_TYPE;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
-import static org.junit.jupiter.api.Assertions.*;
-import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
-import static org.springframework.test.util.AssertionErrors.assertNotEquals;
-import static org.springframework.test.web.client.ExpectedCount.times;
-import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
-import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
-import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
-import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
-
/**
* Created by vitalyster on 25.11.2016.
*/
@@ -290,6 +377,7 @@ public class ServerTests {
FileSystemUtils.deleteRecursively(Paths.get(imgDir, "a"));
FileSystemUtils.deleteRecursively(Paths.get(imgDir, "ao"));
FileSystemUtils.deleteRecursively(Paths.get(imgDir, "as"));
+ Files.createDirectories(Paths.get(imgDir));
Files.createDirectory(Paths.get(imgDir, "p"));
Files.createDirectory(Paths.get(imgDir, "photos-1024"));
Files.createDirectory(Paths.get(imgDir, "photos-512"));
@@ -2050,6 +2138,7 @@ public class ServerTests {
String imgDir = storageService.getImageDirectory();
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)));
@@ -2061,6 +2150,12 @@ public class ServerTests {
String newHash = DigestUtils.md5DigestAsHex(newAvatarData);
URI newUri = Paths.get(imgDir, "ao", String.format("%d.png", freefd.getUid())).toUri();
assertThat(DigestUtils.md5DigestAsHex(IOUtils.toByteArray(newUri)), is(newHash));
+ URI convertedAvatarUri = Paths.get(imgDir, "a", String.format("%d.png", freefd.getUid())).toUri();
+ String convertedAvatarHash = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(convertedAvatarUri));
+ mockMvc.perform(get("/api/me").with(httpBasic(freefdName, freefdPassword)))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.avatar",
+ is(String.format("http://localhost:8080/i/a/%d-%s.png", freefd.getUid(), convertedAvatarHash))));
mockMvc.perform(post("/api/me").with(httpBasic(ugnichName, ugnichPassword)).param("password", "newPassword"))
.andExpect(status().isOk());
mockMvc.perform(get("/api/me").with(httpBasic(ugnichName, ugnichPassword)))