Skip to content

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Aug 31, 2018
1 parent 5edba1b commit ec4ad27
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 260 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jboss.shamrock.example.test;

import org.jboss.shamrock.junit.GraalTest;
import org.junit.runner.RunWith;

@RunWith(GraalTest.class)
public class JaxRSInjectionITCase extends JaxRSInjectionTestCase {

}
Original file line number Diff line number Diff line change
@@ -1,61 +1,12 @@
package org.jboss.shamrock.example.test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Set;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;

import org.jboss.shamrock.junit.GraalTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @author Ken Finnigan
*/
@RunWith(GraalTest.class)
public class OpenApiITCase {

@Test
public void testOpenAPIJSON() throws Exception {
URL uri = new URL("http://localhost:8080/openapi");
URLConnection connection = uri.openConnection();
connection.setRequestProperty("Accept", "application/json");
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
JsonReader parser = Json.createReader(new ByteArrayInputStream(out.toByteArray()));
JsonObject obj = parser.readObject();
Assert.assertNotNull(obj);

Assert.assertEquals("3.0.1", obj.getString("openapi"));
Assert.assertEquals("Generated API", obj.getJsonObject("info").getString("title"));
Assert.assertEquals("1.0", obj.getJsonObject("info").getString("version"));

JsonObject paths = obj.getJsonObject("paths");
Assert.assertEquals(2, paths.size());

JsonObject testObj = paths.getJsonObject("/rest/test");
Assert.assertNotNull(testObj);
Set<String> keys = testObj.keySet();
Assert.assertEquals(1, keys.size());
Assert.assertEquals("get", keys.iterator().next());

public class OpenApiITCase extends OpenApiTestCase {

JsonObject injectionObj = paths.getJsonObject("/rest/test/injection");
Assert.assertNotNull(injectionObj);
keys = injectionObj.keySet();
Assert.assertEquals(1, keys.size());
Assert.assertEquals("get", keys.iterator().next());
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
package org.jboss.shamrock.example.test;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import org.jboss.shamrock.junit.GraalTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(GraalTest.class)
public class ServletInjectionITCase {
public class ServletInjectionITCase extends ServletInjectionTestCase {

@Test
public void testServletInjection() throws Exception {
URL uri = new URL("http://localhost:8080/injection");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
Assert.assertEquals("A message", new String(out.toByteArray()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.json.JsonObject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.xml.bind.annotation.XmlRootElement;

Expand All @@ -15,6 +16,12 @@ public String getTest() {
return "TEST";
}

@GET
@Path("/int/{val}")
public Integer getInt(@PathParam("val") Integer val) {
return val + 1;
}

@GET
@Path("/jackson")
@Produces("application/json")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jboss.shamrock.example.test;

import org.jboss.shamrock.junit.GraalTest;
import org.junit.runner.RunWith;

@RunWith(GraalTest.class)
public class ExternalIndexITCase extends ExternalIndexTestCase {

}
Original file line number Diff line number Diff line change
@@ -1,39 +1,14 @@
package org.jboss.shamrock.example.test;

import org.jboss.shamrock.junit.GraalTest;
import org.jboss.shamrock.junit.ShamrockTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;

import static org.junit.Assert.assertEquals;

/**
* Test reflection around JPA entities
*
* @author Emmanuel Bernard [email protected]
*/
@RunWith(GraalTest.class)
public class JPAReflectionInGraalITCase {
public class JPAReflectionInGraalITCase extends JPAReflectionTestCase {

@Test
public void testFieldAndGetterReflectionOnEntityFromServlet() throws Exception {
URL uri = new URL("http://localhost:8080/jpa/test");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
assertEquals("OK", new String(out.toByteArray()));
}
}
Original file line number Diff line number Diff line change
@@ -1,113 +1,9 @@
package org.jboss.shamrock.example.test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import javax.json.Json;
import javax.json.JsonObject;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.jboss.shamrock.junit.GraalTest;
import org.jboss.shamrock.junit.ShamrockTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

@RunWith(GraalTest.class)
public class JaxRSITCase {

@Test
public void testJAXRS() throws Exception {
URL uri = new URL("http://localhost:8080/rest/test");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
Assert.assertEquals("TEST", new String(out.toByteArray()));
}

@Test
public void testJsonp() throws Exception {

URL uri = new URL("http://localhost:8080/rest/test/jsonp");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
JsonObject obj = Json.createReader(new ByteArrayInputStream(out.toByteArray())).readObject();
Assert.assertEquals("Stuart", obj.getString("name"));
Assert.assertEquals("A Value", obj.getString("value"));
}

@Test
public void testJackson() throws Exception {

URL uri = new URL("http://localhost:8080/rest/test/jackson");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
JsonObject obj = Json.createReader(new ByteArrayInputStream(out.toByteArray())).readObject();
Assert.assertEquals("Stuart", obj.getString("name"));
Assert.assertEquals("A Value", obj.getString("value"));
}


@Test
public void testJaxb() throws Exception {

URL uri = new URL("http://localhost:8080/rest/test/xml");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(new ByteArrayInputStream(out.toByteArray()) );
Element root = dom.getDocumentElement();
Assert.assertEquals("xmlObject", root.getTagName());
NodeList value = root.getElementsByTagName("value");
Assert.assertEquals(1, value.getLength());
Assert.assertEquals("A Value", value.item(0).getTextContent());
}


@Test
public void testBytecodeTransformation() throws Exception {
public class JaxRSITCase extends JaxRSTestCase {

URL uri = new URL("http://localhost:8080/rest/test/transformed");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
Assert.assertEquals("Transformed Endpoint", new String(out.toByteArray()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ public void testJAXRS() throws Exception {
Assert.assertEquals("TEST", new String(out.toByteArray()));
}

@Test
public void testInteger() throws Exception {
URL uri = new URL("http://localhost:8080/rest/test/int/10");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
Assert.assertEquals("11", new String(out.toByteArray()));
}

@Test
public void testJsonp() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.junit.runner.RunWith;

@RunWith(GraalTest.class)
public class ServletITCase {
public class ServletITCase extends ServletTestCase {

@Test
public void testServlet() throws Exception {
Expand All @@ -26,32 +26,4 @@ public void testServlet() throws Exception {
}
Assert.assertEquals("A message", new String(out.toByteArray()));
}

@Test
public void testFilter() throws Exception {
URL uri = new URL("http://localhost:8080/filter");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
Assert.assertEquals("A Filter", new String(out.toByteArray()));
}

@Test
public void testStaticResource() throws Exception {
URL uri = new URL("http://localhost:8080/index.html");
URLConnection connection = uri.openConnection();
InputStream in = connection.getInputStream();
byte[] buf = new byte[100];
int r;
ByteArrayOutputStream out = new ByteArrayOutputStream();
while ((r = in.read(buf)) > 0) {
out.write(buf, 0, r);
}
Assert.assertTrue(new String(out.toByteArray()).contains("A HTML page"));
}
}

0 comments on commit ec4ad27

Please sign in to comment.