streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject [05/11] incubator-streams git commit: added tests decided not to add StreamsResource to core at this time
Date Thu, 12 Feb 2015 16:18:14 GMT
added tests
decided not to add StreamsResource to core at this time


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/cecd67a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/cecd67a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/cecd67a4

Branch: refs/heads/master
Commit: cecd67a420111bc9831504b5699c574063587e76
Parents: 1b74c99
Author: sblackmon <sblackmon@apache.org>
Authored: Fri Nov 21 13:24:45 2014 -0600
Committer: sblackmon <sblackmon@w2odigital.com>
Committed: Fri Feb 6 18:06:26 2015 -0600

----------------------------------------------------------------------
 .../apache/streams/core/StreamsResource.java    | 17 ----
 .../test/GenericWebhookResourceTest.java        | 82 ++++++++++++++++++++
 .../dropwizard/test/StreamsApplicationIT.java   | 30 +++++++
 .../dropwizard/test/TestStreamsApplication.java |  9 +++
 .../src/test/resources/configuration.yml        | 27 +++++++
 5 files changed, 148 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/cecd67a4/streams-core/src/main/java/org/apache/streams/core/StreamsResource.java
----------------------------------------------------------------------
diff --git a/streams-core/src/main/java/org/apache/streams/core/StreamsResource.java b/streams-core/src/main/java/org/apache/streams/core/StreamsResource.java
deleted file mode 100644
index 4bd18e2..0000000
--- a/streams-core/src/main/java/org/apache/streams/core/StreamsResource.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.apache.streams.core;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-
-/**
- * Created by sblackmon on 11/20/14.
- */
-public interface StreamsResource {
-
-    public Response json(HttpHeaders headers, String body);
-
-    public Response json_new_line(HttpHeaders headers, String body);
-
-    public Response json_meta(HttpHeaders headers, String body);
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/cecd67a4/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/GenericWebhookResourceTest.java
----------------------------------------------------------------------
diff --git a/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/GenericWebhookResourceTest.java
b/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/GenericWebhookResourceTest.java
new file mode 100644
index 0000000..d1d02ac
--- /dev/null
+++ b/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/GenericWebhookResourceTest.java
@@ -0,0 +1,82 @@
+package org.apache.streams.dropwizard.test;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Lists;
+import com.google.common.io.Resources;
+import io.dropwizard.testing.junit.DropwizardAppRule;
+import io.dropwizard.testing.junit.ResourceTestRule;
+import org.apache.streams.dropwizard.GenericWebhookData;
+import org.apache.streams.dropwizard.GenericWebhookResource;
+import org.apache.streams.jackson.StreamsJacksonMapper;
+import org.apache.streams.pojo.json.Person;
+import org.joda.time.DateTime;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.xml.ws.Response;
+
+import java.util.List;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * Created by sblackmon on 11/21/14.
+ */
+public class GenericWebhookResourceTest {
+
+    private static ObjectMapper mapper = new StreamsJacksonMapper();
+
+    private static final GenericWebhookResource genericWebhookResource = new GenericWebhookResource();
+
+    @ClassRule
+    public static final ResourceTestRule resources = ResourceTestRule.builder()
+            .addResource(genericWebhookResource)
+            .build();
+
+    @Test
+    public void testPostJson() {
+        Assert.assertEquals(400, genericWebhookResource.json(null, "{").getStatus());
+        Assert.assertEquals(400, genericWebhookResource.json(null, "}").getStatus());
+        Assert.assertEquals(400, genericWebhookResource.json(null, "srg").getStatus());
+        Assert.assertEquals(400, genericWebhookResource.json(null, "123").getStatus());
+        Assert.assertEquals(200, genericWebhookResource.json(null, "{}").getStatus());
+        Assert.assertEquals(200, genericWebhookResource.json(null, "{\"valid\":\"true\"}").getStatus());
+    };
+
+    @Test
+    public void testPostJsonNewLine() {
+        Assert.assertEquals(200, genericWebhookResource.json_new_line(null, "{}").getStatus());
+        Assert.assertEquals(400, genericWebhookResource.json_new_line(null, "notvalid").getStatus());
+        Assert.assertEquals(200, genericWebhookResource.json_new_line(null, "{\"valid\":\"true\"}").getStatus());
+        Assert.assertEquals(200, genericWebhookResource.json_new_line(null, "{\"valid\":\"true\"}\n{\"valid\":\"true\"}\r{\"valid\":\"true\"}").getStatus());
+    };
+
+    @Test
+    public void testPostJsonMeta() throws JsonProcessingException {
+        Assert.assertEquals(200, genericWebhookResource.json_meta(null, "{}").getStatus());
+        Assert.assertEquals(400, genericWebhookResource.json_meta(null, "notvalid").getStatus());
+        GenericWebhookData testPostJsonMeta = new GenericWebhookData()
+                .withHash("test")
+                .withDeliveredAt(DateTime.now())
+                .withCount(1)
+                .withHashType("type")
+                .withId("test");
+        List<ObjectNode> testPostJsonData = Lists.newArrayList();
+        testPostJsonData.add(mapper.createObjectNode().put("valid", "true"));
+        testPostJsonMeta.setData(testPostJsonData);
+        String testPostJsonEntity = mapper.writeValueAsString(testPostJsonMeta);
+        Assert.assertEquals(200, genericWebhookResource.json_meta(null, testPostJsonEntity).getStatus());
+
+    };
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/cecd67a4/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/StreamsApplicationIT.java
----------------------------------------------------------------------
diff --git a/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/StreamsApplicationIT.java
b/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/StreamsApplicationIT.java
new file mode 100644
index 0000000..83b7b89
--- /dev/null
+++ b/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/StreamsApplicationIT.java
@@ -0,0 +1,30 @@
+package org.apache.streams.dropwizard.test;
+
+import com.google.common.collect.Lists;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+/**
+ * Tests {@link: org.apache.streams.dropwizard.StreamsApplication}
+ */
+public class StreamsApplicationIT {
+
+    @Before
+    public void setupTest() throws Exception {
+        String[] testArgs = Lists.newArrayList("server", "src/test/resources/configuration.yml").toArray(new
String[2]);
+        TestStreamsApplication.main(testArgs);
+    }
+
+    @Test
+    public void testApplicationStarted() throws Exception {
+
+        final URL url = new URL("http://localhost:8003/admin/ping");
+        final String response = new BufferedReader(new InputStreamReader(url.openStream())).readLine();
+        Assert.assertEquals("pong", response);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/cecd67a4/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/TestStreamsApplication.java
----------------------------------------------------------------------
diff --git a/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/TestStreamsApplication.java
b/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/TestStreamsApplication.java
new file mode 100644
index 0000000..7fe17cf
--- /dev/null
+++ b/streams-runtimes/streams-runtime-dropwizard/src/test/java/org/apache/streams/dropwizard/test/TestStreamsApplication.java
@@ -0,0 +1,9 @@
+package org.apache.streams.dropwizard.test;
+
+import org.apache.streams.dropwizard.StreamsApplication;
+
+/**
+ * This class exists to support {@link: org.apache.streams.dropwizard.test.StreamsApplicationIT}
+ */
+public class TestStreamsApplication extends StreamsApplication {
+}

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/cecd67a4/streams-runtimes/streams-runtime-dropwizard/src/test/resources/configuration.yml
----------------------------------------------------------------------
diff --git a/streams-runtimes/streams-runtime-dropwizard/src/test/resources/configuration.yml
b/streams-runtimes/streams-runtime-dropwizard/src/test/resources/configuration.yml
new file mode 100644
index 0000000..e2943cd
--- /dev/null
+++ b/streams-runtimes/streams-runtime-dropwizard/src/test/resources/configuration.yml
@@ -0,0 +1,27 @@
+template: Hello, %s!
+defaultName: datasift
+
+server:
+  type: simple
+  applicationContextPath: /
+  adminContextPath: /admin
+  connector:
+    type: http
+    port: 8000
+
+logging:
+  level: DEBUG
+  appenders:
+    - type: console
+      threshold: ALL
+      target: stdout
+
+elasticsearch:
+  hosts:
+    - "localhost"
+  port: 9300
+  clusterName: elasticsearch
+  index: datasift_webhook
+  type: activity
+  batchSize: 100
+


Mime
View raw message