Skip to content

Commit

Permalink
All tests in Base should now run
Browse files Browse the repository at this point in the history
Also, removed generated target files and moved Base test resources to test
folder
  • Loading branch information
Sitron Te committed Apr 7, 2014
1 parent 5ab142d commit 2a31326
Show file tree
Hide file tree
Showing 63 changed files with 74 additions and 3,435 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ out/
*.sublime*
.idea/
*META-INF/
*/target/
26 changes: 0 additions & 26 deletions Base/Base.iml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import javax.xml.bind.JAXBElement;
import java.io.FileInputStream;
import java.io.InputStream;

/**
* Created by tormod on 3/6/14.
Expand Down Expand Up @@ -47,7 +48,7 @@ public void testSimpleServer() throws Exception {
request.method(HttpMethod.POST);
request.header(HttpHeader.CONTENT_TYPE, "application");
request.header(HttpHeader.CONTENT_LENGTH, "200");
request.content(new InputStreamContentProvider(new FileInputStream("Base/testres/server_test_html_content.html")),
request.content(new InputStreamContentProvider(getClass().getResourceAsStream("/server_test_html_content.html")),
"text/html;charset/utf-8");
ContentResponse response = request.send();
assertEquals(500, response.getStatus());
Expand All @@ -68,7 +69,7 @@ public void testSendingXML() throws Exception {
request.method(HttpMethod.POST);
request.header(HttpHeader.CONTENT_TYPE, "application");
request.header(HttpHeader.CONTENT_LENGTH, "200");
request.content(new InputStreamContentProvider(new FileInputStream("Base/testres/server_test_xml.xml")),
request.content(new InputStreamContentProvider(getClass().getResourceAsStream("/server_test_xml.xml")),
"application/soap+xml;charset/utf-8");

ContentResponse response = request.send();
Expand All @@ -87,15 +88,15 @@ public void testSendingSoap() throws Exception {
client.setFollowRedirects(true);
client.start();

Object object = XMLParser.parse(new FileInputStream("Base/testres/server_test_soap.xml"));
Object object = XMLParser.parse(getClass().getResourceAsStream("/server_test_soap.xml"));
Envelope env = (Envelope)((JAXBElement)((InternalMessage) object).getMessage()).getValue();
Header head = env.getHeader();
Body body = env.getBody();

// Send response
Request request = client.newRequest("http://localhost:8080/");
request.method(HttpMethod.POST);
request.content(new InputStreamContentProvider(new FileInputStream("Base/testres/server_test_soap.xml")),
request.content(new InputStreamContentProvider(getClass().getResourceAsStream("/server_test_soap.xml")),
"application/soap+xml;charset/utf-8");

ContentResponse response = request.send();
Expand All @@ -116,7 +117,7 @@ public void testSubscribe() throws Exception {
client.start();

// Send response
FileInputStream file = new FileInputStream("Base/testres/server_test_subscribe.xml");
InputStream file = getClass().getResourceAsStream("/server_test_subscribe.xml");

Request request = client.newRequest("http://localhost:8080/");
request.method(HttpMethod.POST);
Expand Down
27 changes: 11 additions & 16 deletions Base/src/test/java/org/ntnunotif/wsnu/base/net/XMLParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.ntnunotif.wsnu.base.net.XMLParser;
import org.ntnunotif.wsnu.base.util.InternalMessage;
import org.ntnunotif.wsnu.base.util.Log;
import org.oasis_open.docs.wsn.b_2.FilterType;
Expand All @@ -13,19 +12,16 @@
import org.w3._2001._12.soap_envelope.*;

import javax.xml.bind.JAXBElement;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;

/**
* Created by Inge on 07.03.14.
*/
public class XMLParserTest {

private static final String notifyFilePlace = "Base/testres/parse_test_notify.xml";
private static final String soapFilePlace = "Base/testres/server_test_soap.xml";
private static final String subscribeFilePlace = "Base/testres/server_test_subscribe.xml";
private static final String notifyResourcePlace = "/parse_test_notify.xml";
private static final String soapResourcePlace = "/server_test_soap.xml";
private static final String subscribeResourcePlace = "/server_test_subscribe.xml";

private InputStream notifyTestStream = null;
private InputStream soapTestStream = null;
Expand All @@ -34,9 +30,9 @@ public class XMLParserTest {
@Before
public void setup() {
try {
notifyTestStream = new FileInputStream(notifyFilePlace);
soapTestStream = new FileInputStream(soapFilePlace);
subscribeTestStream = new FileInputStream(subscribeFilePlace);
notifyTestStream = getClass().getResourceAsStream(notifyResourcePlace);
soapTestStream = getClass().getResourceAsStream(soapResourcePlace);
subscribeTestStream = getClass().getResourceAsStream(subscribeResourcePlace);
} catch (Exception e) {
Log.e("XMLParser", "Could not read test files");
e.printStackTrace();
Expand Down Expand Up @@ -100,13 +96,13 @@ public void testToXmlParse() throws Exception {
}
// TODO write to real tests:
// Writing the three parsed objects to file for manual inspection:
FileOutputStream fileOutputStream = new FileOutputStream("Base/testres/parser_n2xml.xml");
FileOutputStream fileOutputStream = new FileOutputStream(getClass().getResource("/parser_n2xml.xml").getFile());
XMLParser.writeObjectToStream(parsedObject1, fileOutputStream);
fileOutputStream.close();
fileOutputStream = new FileOutputStream("Base/testres/parser_s2xml.xml");
fileOutputStream = new FileOutputStream(getClass().getResource("/parser_s2xml.xml").getFile());
XMLParser.writeObjectToStream(parsedObject2, fileOutputStream);
fileOutputStream.close();
fileOutputStream = new FileOutputStream("Base/testres/parser_sub2xml.xml");
fileOutputStream = new FileOutputStream(getClass().getResource("/parser_sub2xml.xml").getFile());
XMLParser.writeObjectToStream(parsedObject3, fileOutputStream);
fileOutputStream.close();
}
Expand All @@ -122,8 +118,7 @@ public void testMarshallingFaultInEnvelope() throws Exception {

Fault fault = new Fault();
body.getAny().add(new ObjectFactory().createFault(fault));

FileOutputStream fileOut = new FileOutputStream("Base/testres/test_fault.xml");
FileOutputStream fileOut = new FileOutputStream(getClass().getResource("/test_fault.xml").getFile());
XMLParser.writeObjectToStream(new ObjectFactory().createEnvelope(envelope), fileOut);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.ntnunotif.wsnu.base.topics;

import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.ntnunotif.wsnu.base.net.NuNamespaceContext;
import org.ntnunotif.wsnu.base.topics.FullEvaluator;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class TopicUtilsTest {
private static final String[] rootNSs = {"http://root_test1.com", "http://root_test2.com", "http://root_test3.com" };
private static final String[] rootLocalNames = {"roo1", "root2" };

private static final String OUTQNameToTopicSet = "Base/testres/out_topic_utils_qnames_topic_set.xml";
private static final String OUTQNameToTopicSetRes = "/out_topic_utils_qnames_topic_set.xml";

@BeforeClass
public static void setup() {
Expand Down Expand Up @@ -111,6 +111,6 @@ public void testOutputOfQNameToTopicSet() throws Exception{

// Write to file, so it is possible to see actual content of returned set
JAXBElement e = new JAXBElement<>(new QName("http://docs.oasis-open.org/wsn/t-1", "TopicSet"), TopicSetType.class, topicSetType);
XMLParser.writeObjectToStream(e, new FileOutputStream(OUTQNameToTopicSet));
XMLParser.writeObjectToStream(e, new FileOutputStream(getClass().getResource(OUTQNameToTopicSetRes).getFile()));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.ntnunotif.wsnu.base.topics;

import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.ntnunotif.wsnu.base.util.InternalMessage;
import org.ntnunotif.wsnu.base.net.XMLParser;
import org.ntnunotif.wsnu.base.topics.TopicUtils;
import org.ntnunotif.wsnu.base.topics.TopicValidator;
import org.oasis_open.docs.wsn.b_2.GetCurrentMessage;
import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
import org.oasis_open.docs.wsn.bw_2.InvalidTopicExpressionFault;
Expand All @@ -22,9 +20,9 @@
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -33,25 +31,25 @@
* Created by Inge on 06.03.14.
*/
public class TopicValidatorTest {
private static final String gcmXPathMulPath = "Base/testres/topic_gcm_xpath_boolean_multiple_test.xml";
private static final String gcmXPathSinPath = "Base/testres/topic_gcm_xpath_boolean_single_test.xml";
private static final String gcmXPathFalsePath = "Base/testres/topic_gcm_xpath_false.xml";
private static final String gcmIllegalDialectPath = "Base/testres/topic_gcm_illegal_dialect_test.xml";
private static final String topicNamespacePath = "Base/testres/topic_namespace_test.xml";
private static final String topicSetPath = "Base/testres/topic_set_test.xml";
private static final String OUTGcmXPathMulPath = "Base/testres/out_topic_gcm_xpath_boolean_multiple_test.xml";
private static final String OUTGcmXPathSinPath = "Base/testres/out_topic_gcm_xpath_boolean_single_test.xml";
private static final String gcmXPathMulPathRes = "/topic_gcm_xpath_boolean_multiple_test.xml";
private static final String gcmXPathSinPathRes = "/topic_gcm_xpath_boolean_single_test.xml";
private static final String gcmXPathFalsePathRes = "/topic_gcm_xpath_false.xml";
private static final String gcmIllegalDialectPathRes = "/topic_gcm_illegal_dialect_test.xml";
private static final String topicNamespacePathRes = "/topic_namespace_test.xml";
private static final String topicSetPathRes = "/topic_set_test.xml";
private static final String OUTGcmXPathMulPathRes = "/out_topic_gcm_xpath_boolean_multiple_test.xml";
private static final String OUTGcmXPathSinPathRes = "/out_topic_gcm_xpath_boolean_single_test.xml";

// locations of simple, concrete and full expressions
private static final String simpleLegalLocation = "Base/testres/topic_gcm_simple_legal_test.xml";
private static final String simpleIllegalLocation = "Base/testres/topic_gcm_simple_illegal_test.xml";
private static final String simpleLegalLocationRes = "/topic_gcm_simple_legal_test.xml";
private static final String simpleIllegalLocationRes = "/topic_gcm_simple_illegal_test.xml";

private static final String concreteLegalLocation = "Base/testres/topic_gcm_concrete_legal_test.xml";
private static final String concreteIllegalLocation = "Base/testres/topic_gcm_concrete_illegal_test.xml";
private static final String concreteLegalLocationRes = "/topic_gcm_concrete_legal_test.xml";
private static final String concreteIllegalLocationRes = "/topic_gcm_concrete_illegal_test.xml";

private static final String fullLegalSingleLocation = "Base/testres/topic_gcm_full_legal_single_test.xml";
private static final String fullLegalMultipleLocation = "Base/testres/topic_gcm_full_legal_multiple_test.xml";
private static final String fullIllegalLocation = "Base/testres/topic_gcm_full_illegal_test.xml";
private static final String fullLegalSingleLocationRes = "/topic_gcm_full_legal_single_test.xml";
private static final String fullLegalMultipleLocationRes = "/topic_gcm_full_legal_multiple_test.xml";
private static final String fullIllegalLocationRes = "/topic_gcm_full_illegal_test.xml";

private static TopicExpressionType xPathMultipleHits;
private static TopicExpressionType xPathSingleHit;
Expand Down Expand Up @@ -86,65 +84,61 @@ public class TopicValidatorTest {

@BeforeClass
public static void setup() {
FileInputStream fis = null;
InputStream fis = null;
try {
fis = new FileInputStream(gcmXPathFalsePath);
fis = TopicValidatorTest.class.getResourceAsStream(gcmXPathFalsePathRes);
xPathFalMsg = XMLParser.parse(fis);
GetCurrentMessage msg = (GetCurrentMessage)xPathFalMsg.getMessage();
xPathFalse = msg.getTopic();
fis.close();
fis = new FileInputStream(gcmXPathMulPath);

fis = TopicValidatorTest.class.getResourceAsStream(gcmXPathMulPathRes);
xPathMulMsg = XMLParser.parse(fis);
msg = (GetCurrentMessage)xPathMulMsg.getMessage();
xPathMultipleHits = msg.getTopic();
fis.close();
fis = new FileInputStream(gcmXPathSinPath);

fis = TopicValidatorTest.class.getResourceAsStream(gcmXPathSinPathRes);
xPathSinMsg = XMLParser.parse(fis);
msg = (GetCurrentMessage)xPathSinMsg.getMessage();
xPathSingleHit = msg.getTopic();
fis.close();
fis = new FileInputStream(gcmIllegalDialectPath);

fis = TopicValidatorTest.class.getResourceAsStream(gcmIllegalDialectPathRes);
illExprDiaMsg = XMLParser.parse(fis);
msg = (GetCurrentMessage)illExprDiaMsg.getMessage();
illegalExpressionDialect = msg.getTopic();
fis.close();
fis = new FileInputStream(topicNamespacePath);

fis = TopicValidatorTest.class.getResourceAsStream(topicNamespacePathRes);
topNSMsg = XMLParser.parse(fis);
JAXBElement<TopicNamespaceType> ns = (JAXBElement)topNSMsg.getMessage();
topicNamespace = ns.getValue();
fis.close();
fis = new FileInputStream(topicSetPath);

fis = TopicValidatorTest.class.getResourceAsStream(topicSetPathRes);
topSetMsg = XMLParser.parse(fis);
JAXBElement<TopicSetType> ts = (JAXBElement)topSetMsg.getMessage();
topicSet = ts.getValue();
fis.close();

// Simple load
fis = new FileInputStream(simpleLegalLocation);
fis = TopicValidatorTest.class.getResourceAsStream(simpleLegalLocationRes);
simpleLegalMsg = XMLParser.parse(fis);
fis.close();
fis = new FileInputStream(simpleIllegalLocation);

fis = TopicValidatorTest.class.getResourceAsStream(simpleIllegalLocationRes);
simpleIllegalMsg = XMLParser.parse(fis);
fis.close();

// concrete load
fis = new FileInputStream(concreteLegalLocation);
fis = TopicValidatorTest.class.getResourceAsStream(concreteLegalLocationRes);
concreteLegalMsg = XMLParser.parse(fis);
fis.close();
fis = new FileInputStream(concreteIllegalLocation);

fis = TopicValidatorTest.class.getResourceAsStream(concreteIllegalLocationRes);
concreteIllegalMsg = XMLParser.parse(fis);
fis.close();

// full load
fis = new FileInputStream(fullLegalSingleLocation);
fis = TopicValidatorTest.class.getResourceAsStream(fullLegalSingleLocationRes);
fullLegalSingleMsg = XMLParser.parse(fis);
fis.close();
fis = new FileInputStream(fullLegalMultipleLocation);

fis = TopicValidatorTest.class.getResourceAsStream(fullLegalMultipleLocationRes);
fullLegalMultipleMsg = XMLParser.parse(fis);
fis.close();
fis = new FileInputStream(fullIllegalLocation);

fis = TopicValidatorTest.class.getResourceAsStream(fullIllegalLocationRes);
fullIllegalMsg = XMLParser.parse(fis);
fis.close();

} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -317,7 +311,7 @@ public void testGetIntersectionOne() throws Exception{

// Write to file, so it is possible to see actual content of returned set
JAXBElement e = new JAXBElement<>(new QName("http://docs.oasis-open.org/wsn/t-1", "TopicSet"), TopicSetType.class, ret);
XMLParser.writeObjectToStream(e, new FileOutputStream(OUTGcmXPathSinPath));
XMLParser.writeObjectToStream(e, new FileOutputStream(getClass().getResource(OUTGcmXPathSinPathRes).getFile()));
}

@Test
Expand All @@ -343,7 +337,7 @@ public void testGetIntersectionTwo() throws Exception{
Assert.assertTrue("Returned list did not contain child_topic!", retAsQNameList.contains(child));

JAXBElement e = new JAXBElement<>(new QName("http://docs.oasis-open.org/wsn/t-1", "TopicSet"), TopicSetType.class, ret);
XMLParser.writeObjectToStream(e, new FileOutputStream(OUTGcmXPathMulPath));
XMLParser.writeObjectToStream(e, new FileOutputStream(getClass().getResource(OUTGcmXPathMulPathRes).getFile()));
}

@Test(expected = TopicExpressionDialectUnknownFault.class)
Expand Down
1 change: 0 additions & 1 deletion Base/src/test/java/resources/parser_n2xml.xml

This file was deleted.

Loading

0 comments on commit 2a31326

Please sign in to comment.