diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 26 | ||||
-rw-r--r-- | src/test/resources/sape.xml | 12 |
2 files changed, 33 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())); + } } diff --git a/src/test/resources/sape.xml b/src/test/resources/sape.xml new file mode 100644 index 00000000..d1245ed4 --- /dev/null +++ b/src/test/resources/sape.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8" ?> +<sape site_url="http://localhost" delimiter=". "> + <page uri="/"> + <link><![CDATA[ Тест <a href="https://example.com" target="_blank">ссылки</a> - passed. ]]></link> + <link><![CDATA[ Тест <a href="https://example.com" target="_blank">ссылки 2</a> - passed. ]]></link> + </page> + <page uri="/ugnich/"> + <link><![CDATA[ Тест <a href="https://ugnich.com" target="_blank">ссылки</a> - passed. ]]></link> + </page> + <page uri="*"><![CDATA[<!--1234567890123-->]]></page> + <sape_page_obligatory_output><![CDATA[]]></sape_page_obligatory_output> +</sape>
\ No newline at end of file |