From b0bdce22447ff815512ae7612dd4ab4a5d9a409a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 3 Jun 2020 17:32:55 +0300 Subject: sape: switch to xml output --- .../java/com/juick/server/tests/ServerTests.java | 26 +++++++++++++++++----- src/test/resources/sape.xml | 12 ++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/sape.xml (limited to 'src/test') 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("")); + SapePageLinks botLinks = new SapePageLinks(site, "ugnich", URI.create("http://localhost/"), "ugnich", false); + assertThat(botLinks.render(), is("")); + SapePageLinks visitorLinks = new SapePageLinks(site, "ugnich", URI.create("http://localhost/"), null, false); + assertThat(visitorLinks.render(), is(" Тест ссылки - passed. . Тест ссылки 2 - 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 @@ + + + + ссылки - passed. ]]> + ссылки 2 - passed. ]]> + + + ссылки - passed. ]]> + + ]]> + + \ No newline at end of file -- cgit v1.2.3