You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2018/04/16 22:45:14 UTC

[10/38] tomee git commit: Integ test for MPJWT on TomEE

Integ test for MPJWT on TomEE


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/35e671d3
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/35e671d3
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/35e671d3

Branch: refs/heads/master
Commit: 35e671d395496a89316659e671d15609c534ef86
Parents: ad9e222
Author: Jean-Louis Monteiro <je...@gmail.com>
Authored: Thu Feb 22 11:28:44 2018 +0100
Committer: Jean-Louis Monteiro <je...@gmail.com>
Committed: Thu Feb 22 11:28:44 2018 +0100

----------------------------------------------------------------------
 .../tests/jaxrs/mpjwt/HelloResource.java        | 49 +++++++++++++
 .../tests/jaxrs/mpjwt/MPJWTApplication.java     | 28 +++++++
 .../arquillian/tests/jaxrs/mpjwt/MPJWTTest.java | 77 ++++++++++++++++++++
 3 files changed, 154 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/35e671d3/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/HelloResource.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/HelloResource.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/HelloResource.java
new file mode 100644
index 0000000..bc030f1
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/HelloResource.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.jaxrs.mpjwt;
+
+import org.eclipse.microprofile.jwt.Claim;
+import org.eclipse.microprofile.jwt.ClaimValue;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.SecurityContext;
+
+@Path("/hello")
+@Stateless
+@Lock(LockType.READ)
+public class HelloResource {
+
+    @Inject
+    @Claim("jti")
+    private ClaimValue<String> jti;
+
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    @RolesAllowed("helloRole")
+    public String sayHello(@Context SecurityContext context) {
+        return "hello " + context.getUserPrincipal().getName();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tomee/blob/35e671d3/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/MPJWTApplication.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/MPJWTApplication.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/MPJWTApplication.java
new file mode 100644
index 0000000..18bdee6
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/MPJWTApplication.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.jaxrs.mpjwt;
+
+import org.eclipse.microprofile.auth.LoginConfig;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("/api")
+@LoginConfig(authMethod = "MP-JWT")
+public class MPJWTApplication extends Application {
+    // discovered
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/35e671d3/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/MPJWTTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/MPJWTTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/MPJWTTest.java
new file mode 100644
index 0000000..d29b2fc
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-jaxrs-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/mpjwt/MPJWTTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.jaxrs.mpjwt;
+
+import org.apache.openejb.arquillian.tests.jaxrs.staticresources.PreviousFilter;
+import org.apache.openejb.arquillian.tests.jaxrs.staticresources.SimpleServlet;
+import org.apache.openejb.arquillian.tests.jaxrs.staticresources.TheResource;
+import org.apache.ziplock.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Arquillian.class)
+public class MPJWTTest {
+    @Deployment(testable = false)
+    public static Archive<?> war() {
+        return ShrinkWrap.create(WebArchive.class, "mpjwt.war")
+                    .addClasses(TheResource.class, SimpleServlet.class, PreviousFilter.class, MPJWTApplication.class, HelloResource.class)
+                    .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+                    .addAsWebResource(new StringAsset("static"), "index.html")
+                    .addAsWebResource(new StringAsset("JSP <%= 5 %>"), "sample.jsp");
+    }
+
+    @ArquillianResource
+    private URL url;
+
+    @Test
+    public void jaxrs() throws IOException {
+        assertEquals("resource", IO.slurp(new URL(url.toExternalForm() + "api/the")));
+    }
+
+    @Test
+    public void staticResource() throws IOException {
+        assertEquals("static", IO.slurp(url));
+    }
+
+    @Test
+    public void servlet() throws IOException {
+        assertEquals("Servlet!", IO.slurp(new URL(url + "servlet")));
+    }
+
+    @Test
+    public void jsp() throws IOException {
+        assertEquals("JSP 5", IO.slurp(new URL(url + "sample.jsp")).trim());
+    }
+
+    @Test
+    public void filterOrder() throws IOException {
+        assertEquals("I'm the first", IO.slurp(new URL(url.toExternalForm() + "api/gotFilter")));
+    }
+}