aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server/tests/ServerTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/juick/server/tests/ServerTests.java')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 43a0dc7b..0bc23bf7 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -74,7 +74,6 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@@ -105,14 +104,14 @@ import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
+import org.w3c.dom.*;
+import org.xml.sax.SAXException;
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;
@@ -122,6 +121,7 @@ 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;
@@ -246,6 +246,8 @@ public class ServerTests {
private Resource jpegNoJfifTiff;
@Value("classpath:Transparent.gif")
private Resource invisiblePixel;
+ @Value("classpath:sape.xml")
+ private Resource sapeOutput;
@Inject
AppleClientSecretGenerator clientSecretGenerator;
@Inject
@@ -2420,4 +2422,18 @@ public class ServerTests {
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("http://localhost/login"));
}
+ @Test
+ public void linksTest() throws IOException, ParserConfigurationException, SAXException {
+
+ Site site = Site.fromXMLData(IOUtils.toString(sapeOutput.getInputStream(), StandardCharsets.UTF_8));
+ assertThat(site.getPages().size(), is(3));
+ assertThat(site.getPages().get(0).getLinks().size(), is(2));
+ assertThat(site.getCode(), is("<!--1234567890123-->"));
+ SapePageLinks botLinks = new SapePageLinks(site, "ugnich", URI.create("http://localhost/"), "ugnich", false);
+ assertThat(botLinks.render(), is("<sape_noindex><!--1234567890123--></sape_noindex>"));
+ SapePageLinks visitorLinks = new SapePageLinks(site, "ugnich", URI.create("http://localhost/"), null, false);
+ assertThat(visitorLinks.render(), is(" Тест <a href=\"https://example.com\" target=\"_blank\">ссылки</a> - passed. . Тест <a href=\"https://example.com\" target=\"_blank\">ссылки 2</a> - passed. "));
+ SapePageLinks emptyLinks = new SapePageLinks(site, "ugnich", URI.create("http://localhost/yo"), null, false);
+ assertThat(emptyLinks.render(), is(emptyString()));
+ }
}