\nid | message |
\n"
+ + "11 | <script>alert("This should not be displayed in a browser alert box.");</script> |
\n"
+ + "4 | A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1 |
\n"
+ + "5 | A computer program does what you tell it to do, not what you want it to do. |
\n"
+ + "2 | A computer scientist is someone who fixes things that aren't broken. |
\n"
+ + "8 | A list is only as strong as its weakest link. — Donald Knuth |
\n"
+ + "0 | Additional fortune added at request time. |
\n"
+ + "3 | After enough decimal places, nobody gives a damn. |
\n"
+ + "7 | Any program that runs right is obsolete. |
\n"
+ + "10 | Computers make very fast, very accurate mistakes. |
\n"
+ + "6 | Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen |
\n"
+ + "9 | Feature: A bug with seniority. |
\n"
+ + "1 | fortune: No such file or directory |
\n"
+ + "12 | フレームワークのベンチマーク |
\n"
+ + "\n
\n\n";
+
+ /**
+ * URL for the database.
+ */
+ private static final String DATABASE_URL = "jdbc:h2:mem:exampleDb";
+
+ /**
+ * User for the database.
+ */
+ private static final String DATABASE_USER = "sa";
+
+ @Before
+ public void runApplication() throws Exception {
+ // Start application after database setup
+ }
+
+ @Before
+ public void setupDatabase() throws Exception {
+
+ // Obtain connection via DataSource (sets up in memory database)
+ JdbcConnectionPool dataSource = JdbcConnectionPool.create(DATABASE_URL,
+ DATABASE_USER, "");
+ Connection connection = dataSource.getConnection();
+
+ // Create the table
+ Statement statement = connection.createStatement();
+ statement
+ .execute("CREATE TABLE Fortune (id int primary key, message varchar(200))");
+
+ // Load the values
+ PreparedStatement insert = connection
+ .prepareStatement("INSERT INTO Fortune (id, message) VALUES (?, ?)");
+ this.loadEntry(insert, 1, "fortune: No such file or directory");
+ this.loadEntry(insert, 2,
+ "A computer scientist is someone who fixes things that aren't broken.");
+ this.loadEntry(insert, 3,
+ "After enough decimal places, nobody gives a damn.");
+ this.loadEntry(insert, 4,
+ "A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1");
+ this.loadEntry(insert, 5,
+ "A computer program does what you tell it to do, not what you want it to do.");
+ this.loadEntry(insert, 6,
+ "Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen");
+ this.loadEntry(insert, 7, "Any program that runs right is obsolete.");
+ this.loadEntry(insert, 8,
+ "A list is only as strong as its weakest link. — Donald Knuth");
+ this.loadEntry(insert, 9, "Feature: A bug with seniority.");
+ this.loadEntry(insert, 10,
+ "Computers make very fast, very accurate mistakes.");
+ this.loadEntry(
+ insert,
+ 11,
+ "");
+ this.loadEntry(insert, 12, "フレームワークのベンチマーク");
+
+ // Ensure table is available
+ this.waitForTableToBeAvailable("Fortune", dataSource);
+
+ // Start the application
+ WoofOfficeFloorSource.start();
+ }
+
+ @Override
+ protected int getIterationCount() {
+ return 1000;
+ }
+
+ /**
+ * Loads an row into the table.
+ *
+ * @param insertStatement
+ * {@link PreparedStatement}.
+ * @param identifier
+ * Identifier.
+ * @param message
+ * Message.
+ * @throws SQLException
+ * If fails to insert the row.
+ */
+ private void loadEntry(PreparedStatement insertStatement, int identifier,
+ String message) throws SQLException {
+ insertStatement.setInt(1, identifier);
+ insertStatement.setString(2, message);
+ insertStatement.executeUpdate();
+ }
+
+ @After
+ public void cleanupDatabase() throws SQLException {
+ // Stop database for new instance each test
+ DriverManager.getConnection(DATABASE_URL, DATABASE_USER, "")
+ .createStatement().execute("SHUTDOWN IMMEDIATELY");
+ }
+
+ @Override
+ protected void doRequestTest(CloseableHttpClient client) throws Exception {
+
+ // Request the fortunes
+ HttpResponse response = client.execute(new HttpGet(
+ "http://localhost:7878/fortune.woof"));
+
+ // Validate the response
+ this.assertResponse(response, 200, EXPECTED_RESPONSE, "Content-Length",
+ "Content-Type", "Server", "Date", "set-cookie");
+ this.assertHeader(response, "Content-Type", "text/html; charset=UTF-8");
+ this.assertHeader(response, "Content-Length",
+ String.valueOf(EXPECTED_RESPONSE.getBytes(Charset
+ .forName("UTF-8")).length));
+ }
+
+}
\ No newline at end of file
diff --git a/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/JsonSerialisationTest.java b/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/JsonSerialisationTest.java
new file mode 100644
index 00000000000..48f6dcb043c
--- /dev/null
+++ b/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/JsonSerialisationTest.java
@@ -0,0 +1,30 @@
+package net.officefloor.performance;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+/**
+ * Ensure meet criteria for Test type 1: JSON serialization.
+ *
+ * @author Daniel Sagenschneider
+ */
+public class JsonSerialisationTest extends AbstractTestCase {
+
+ @Override
+ protected void doRequestTest(CloseableHttpClient client) throws Exception {
+
+ // Request the JSON serialisation
+ HttpResponse response = client.execute(new HttpGet(
+ "http://localhost:7878/json-service.woof"));
+
+ // Validate the response
+ this.assertResponse(response, 200, "{\"message\":\"Hello, World!\"}",
+ "Content-Length", "Content-Type", "Server", "Date",
+ "set-cookie");
+ this.assertHeader(response, "Content-Type",
+ "application/json; charset=UTF-8");
+ this.assertHeader(response, "Content-Length", "27");
+ }
+
+}
\ No newline at end of file
diff --git a/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/MultipleDatabaseQueriesTest.java b/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/MultipleDatabaseQueriesTest.java
new file mode 100644
index 00000000000..ee0d274442b
--- /dev/null
+++ b/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/MultipleDatabaseQueriesTest.java
@@ -0,0 +1,61 @@
+package net.officefloor.performance;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.junit.Assert;
+
+/**
+ * Ensures meets criteria for Test type 3: Multiple database queries.
+ *
+ * @author Daniel Sagenschneider.
+ */
+public class MultipleDatabaseQueriesTest extends AbstractDatabaseQueryTestCase {
+
+ @Override
+ protected int getIterationCount() {
+ return 100;
+ }
+
+ @Override
+ protected void doRequestTest(CloseableHttpClient client) throws Exception {
+
+ // Obtain the next index
+ int index = this.nextIndex();
+
+ // Obtain the query string
+ String queryString = this.getQueryString(index);
+
+ // Obtain the expected batch size
+ int batchSize = this.getBatchSize(index);
+
+ // Request the results
+ HttpResponse response = client.execute(new HttpGet(
+ "http://localhost:7878/multipleQueries-service.woof"
+ + queryString));
+
+ // Obtain the entity
+ String entity = EntityUtils.toString(response.getEntity());
+
+ // Validate the response
+ Assert.assertEquals("Should be successful: " + entity, 200, response
+ .getStatusLine().getStatusCode());
+ this.assertHeadersSet(response, "Content-Length", "Content-Type",
+ "Server", "Date", "set-cookie");
+ this.assertHeader(response, "Content-Type",
+ "application/json; charset=UTF-8");
+
+ // Validate the correct random result
+ Result[] results = (Result[]) this.readResults(entity);
+ Assert.assertEquals("Incorrect number of results", batchSize,
+ results.length);
+ for (int i = 0; i < batchSize; i++) {
+ Result result = results[i];
+ Assert.assertEquals("Incorrect random number for item " + i,
+ this.randomNumbers[result.getId() - 1],
+ result.getRandomNumber());
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/PlainTextTest.java b/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/PlainTextTest.java
new file mode 100644
index 00000000000..65593b8192b
--- /dev/null
+++ b/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/PlainTextTest.java
@@ -0,0 +1,28 @@
+package net.officefloor.performance;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+
+/**
+ * Ensures meets criteria for Test type 6: Plaintext.
+ *
+ * @author Daniel Sagenschneider.
+ */
+public class PlainTextTest extends AbstractTestCase {
+
+ @Override
+ protected void doRequestTest(CloseableHttpClient client) throws Exception {
+
+ // Request the plain text
+ HttpResponse response = client.execute(new HttpGet(
+ "http://localhost:7878/plaintext.woof"));
+
+ // Validate the response
+ this.assertResponse(response, 200, "Hello, World!", "Content-Length",
+ "Content-Type", "Server", "Date", "set-cookie");
+ this.assertHeader(response, "Content-Type", "text/plain; charset=UTF-8");
+ this.assertHeader(response, "Content-Length", "13");
+ }
+
+}
\ No newline at end of file
diff --git a/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/SingleDatabaseQueryTest.java b/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/SingleDatabaseQueryTest.java
new file mode 100644
index 00000000000..5fc983eddec
--- /dev/null
+++ b/frameworks/Java/officefloor/src/test/java/net/officefloor/performance/SingleDatabaseQueryTest.java
@@ -0,0 +1,41 @@
+package net.officefloor.performance;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.junit.Assert;
+
+/**
+ * Ensures meets criteria for Test type 2: Single database query.
+ *
+ * @author Daniel Sagenschneider.
+ */
+public class SingleDatabaseQueryTest extends AbstractDatabaseQueryTestCase {
+
+ @Override
+ protected void doRequestTest(CloseableHttpClient client) throws Exception {
+
+ // Request the random database value
+ HttpResponse response = client.execute(new HttpGet(
+ "http://localhost:7878/singleQuery-service.woof"));
+
+ // Obtain the entity
+ String entity = EntityUtils.toString(response.getEntity());
+
+ // Validate the response
+ Assert.assertEquals("Should be successful: " + entity, 200, response
+ .getStatusLine().getStatusCode());
+ this.assertHeadersSet(response, "Content-Length", "Content-Type",
+ "Server", "Date", "set-cookie");
+ this.assertHeader(response, "Content-Type",
+ "application/json; charset=UTF-8");
+
+ // Validate the correct random result
+ Result result = this.readResult(entity);
+ Assert.assertEquals("Incorrect random number",
+ this.randomNumbers[result.getId() - 1],
+ result.getRandomNumber());
+ }
+
+}
\ No newline at end of file