Repository: aries-jax-rs-whiteboard Updated Branches: refs/heads/master bdbabeaaf -> 825974e31
target filter tests Signed-off-by: Raymond Auge <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/825974e3 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/825974e3 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/825974e3 Branch: refs/heads/master Commit: 825974e313f576f6d74c111359b83a9019695a2e Parents: bdbabea Author: Raymond Auge <[email protected]> Authored: Fri Aug 4 10:12:42 2017 -0400 Committer: Raymond Auge <[email protected]> Committed: Fri Aug 4 10:12:42 2017 -0400 ---------------------------------------------------------------------- .../java/test/WhiteboardTargetFilterTest.java | 63 ++++++++++++++++++-- 1 file changed, 58 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/825974e3/jax-rs.itests/src/main/java/test/WhiteboardTargetFilterTest.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/WhiteboardTargetFilterTest.java b/jax-rs.itests/src/main/java/test/WhiteboardTargetFilterTest.java index 8600649..3fad059 100644 --- a/jax-rs.itests/src/main/java/test/WhiteboardTargetFilterTest.java +++ b/jax-rs.itests/src/main/java/test/WhiteboardTargetFilterTest.java @@ -24,6 +24,9 @@ import static org.junit.Assert.assertTrue; import java.util.Dictionary; import java.util.Hashtable; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.WebTarget; + import org.junit.Ignore; import org.junit.Test; import org.osgi.framework.ServiceRegistration; @@ -32,11 +35,20 @@ import org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants; import test.types.TestAddon; import test.types.TestHelper; -@Ignore public class WhiteboardTargetFilterTest extends TestHelper { @Test public void testInvalidTargetFilter() throws Exception { + Client client = createClient(); + + WebTarget webTarget = client. + target("http://localhost:8080"). + path("extended"); + + assertEquals( + "This should return nothing", "", + webTarget.request().get().readEntity(String.class)); + Dictionary<String, Object> properties = new Hashtable<>(); properties.put(JaxRSWhiteboardConstants.JAX_RS_RESOURCE, "true"); properties.put(JaxRSWhiteboardConstants.JAX_RS_WHITEBOARD_TARGET, "//"); @@ -45,9 +57,9 @@ public class WhiteboardTargetFilterTest extends TestHelper { Object.class, new TestAddon(), properties); try { - - //System.out.println("blad"); - + assertEquals( + "This should return nothing", "", + webTarget.request().get().readEntity(String.class)); } finally { serviceRegistration.unregister(); @@ -56,6 +68,16 @@ public class WhiteboardTargetFilterTest extends TestHelper { @Test public void testNonMatchingFilter() throws Exception { + Client client = createClient(); + + WebTarget webTarget = client. + target("http://localhost:8080"). + path("extended"); + + assertEquals( + "This should return nothing", "", + webTarget.request().get().readEntity(String.class)); + Dictionary<String, Object> properties = new Hashtable<>(); properties.put(JaxRSWhiteboardConstants.JAX_RS_RESOURCE, "true"); properties.put(JaxRSWhiteboardConstants.JAX_RS_WHITEBOARD_TARGET, "(crazy=the joker)"); @@ -64,9 +86,40 @@ public class WhiteboardTargetFilterTest extends TestHelper { Object.class, new TestAddon(), properties); try { + assertEquals( + "This should return nothing", "", + webTarget.request().get().readEntity(String.class)); + } + finally { + serviceRegistration.unregister(); + } + } + + @Test + public void testMatchingFilter() throws Exception { + Client client = createClient(); + + WebTarget webTarget = client. + target("http://localhost:8080"). + path("extended"); + + assertEquals( + "This should return nothing", "", + webTarget.request().get().readEntity(String.class)); - //System.out.println("blad"); + Dictionary<String, Object> properties = new Hashtable<>(); + properties.put(JaxRSWhiteboardConstants.JAX_RS_RESOURCE, "true"); + properties.put( + JaxRSWhiteboardConstants.JAX_RS_WHITEBOARD_TARGET, + "(service.pid=org.apache.aries.jax.rs.whiteboard.default)"); + + ServiceRegistration<Object> serviceRegistration = bundleContext.registerService( + Object.class, new TestAddon(), properties); + try { + assertEquals( + "This should say hello", "Hello extended", + webTarget.request().get().readEntity(String.class)); } finally { serviceRegistration.unregister();
