diff options
author | Vitaly Takmazov | 2018-03-16 11:35:08 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-16 11:35:08 +0300 |
commit | 223e8ec7742855ac83da445c40656aea3bec7e9b (patch) | |
tree | eafe323999559ebe7e4492e665b458abcfe7fe6f /src/test/java/com/juick/tests | |
parent | 9ef168a03b75aeca0c2f7dda9ce87d4014c703a9 (diff) |
gradle: remove tests from root project
Diffstat (limited to 'src/test/java/com/juick/tests')
-rw-r--r-- | src/test/java/com/juick/tests/MessageTests.java | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java deleted file mode 100644 index 0baf53b6..00000000 --- a/src/test/java/com/juick/tests/MessageTests.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.tests; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.juick.Message; -import com.juick.util.DateFormattersHolder; -import com.juick.util.MessageUtils; -import org.apache.commons.codec.CharEncoding; -import org.json.JSONObject; -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.StringWriter; -import java.text.ParseException; -import java.time.Instant; - -import static org.junit.Assert.assertEquals; - -public class MessageTests { - @Test - public void messageParserSerializer() throws ParseException, ParserConfigurationException, - IOException, SAXException, JAXBException { - Message msg = new Message(); - msg.setTags(MessageUtils.parseTags("test test" + (char) 0xA0 + "2 test3")); - assertEquals("First tag must be", "test", msg.getTags().get(0).getName()); - assertEquals("Third tag must be", "test3", msg.getTags().get(2).getName()); - assertEquals("Count of tags must be", 3, msg.getTags().size()); - Instant currentDate = Instant.now(); - msg.setTimestamp(currentDate); - ObjectMapper serializer = new ObjectMapper(); - serializer.registerModule(new Jdk8Module()); - serializer.registerModule(new JavaTimeModule()); - String jsonMessage = serializer.writeValueAsString(msg); - JSONObject jsonObject = new JSONObject(jsonMessage); - assertEquals("date should be in timestamp field", DateFormattersHolder.getMessageFormatterInstance().format(currentDate), - jsonObject.getString("timestamp")); - - - JAXBContext context = JAXBContext - .newInstance(Message.class); - Marshaller m = context.createMarshaller(); - - StringWriter sw = new StringWriter(); - m.marshal(msg, sw); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(new ByteArrayInputStream(sw.toString().getBytes(CharEncoding.UTF_8))); - Node juickNode = doc.getElementsByTagName("juick").item(0); - NamedNodeMap attrs = juickNode.getAttributes(); - assertEquals("date should be in ts field", DateFormattersHolder.getMessageFormatterInstance().format(currentDate), - attrs.getNamedItem("ts").getNodeValue()); - } -}
\ No newline at end of file |