You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2018/11/19 20:24:34 UTC
[4/6] tomee git commit: adding test to microprofile metrics
adding test to microprofile metrics
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/017b98e8
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/017b98e8
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/017b98e8
Branch: refs/heads/master
Commit: 017b98e89ac68e4d5b695e06a16c7a7e43561d20
Parents: b85fe05
Author: ivanjunckes <ij...@tomitribe.com>
Authored: Mon Nov 19 17:42:38 2018 -0200
Committer: ivanjunckes <ij...@tomitribe.com>
Committed: Mon Nov 19 17:42:38 2018 -0200
----------------------------------------------------------------------
examples/rest-mp-metrics/pom.xml | 27 +++++++++
.../java/org/superbiz/rest/GreetingService.java | 5 +-
.../org/superbiz/rest/GreetingServiceTest.java | 61 ++++++++++++++++++++
.../src/test/resources/arquillian.xml | 30 ++++++++++
4 files changed, 122 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/017b98e8/examples/rest-mp-metrics/pom.xml
----------------------------------------------------------------------
diff --git a/examples/rest-mp-metrics/pom.xml b/examples/rest-mp-metrics/pom.xml
index 97890db..ded0689 100644
--- a/examples/rest-mp-metrics/pom.xml
+++ b/examples/rest-mp-metrics/pom.xml
@@ -12,6 +12,7 @@
<artifactId>rest-mp-metrics</artifactId>
<packaging>war</packaging>
+
<dependencies>
<dependency>
<groupId>org.apache.tomee</groupId>
@@ -25,6 +26,32 @@
<version>1.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>openejb-cxf-rs</artifactId>
+ <version>${tomee.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <version>1.0.3.Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>arquillian-tomee-remote</artifactId>
+ <version>${tomee.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>apache-tomee</artifactId>
+ <version>${tomee.version}</version>
+ <type>zip</type>
+ <classifier>microprofile</classifier>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/tomee/blob/017b98e8/examples/rest-mp-metrics/src/main/java/org/superbiz/rest/GreetingService.java
----------------------------------------------------------------------
diff --git a/examples/rest-mp-metrics/src/main/java/org/superbiz/rest/GreetingService.java b/examples/rest-mp-metrics/src/main/java/org/superbiz/rest/GreetingService.java
index fa84c69..a75087e 100644
--- a/examples/rest-mp-metrics/src/main/java/org/superbiz/rest/GreetingService.java
+++ b/examples/rest-mp-metrics/src/main/java/org/superbiz/rest/GreetingService.java
@@ -2,6 +2,7 @@ package org.superbiz.rest;
import org.eclipse.microprofile.metrics.annotation.Counted;
+import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -11,10 +12,12 @@ import javax.ws.rs.core.MediaType;
@Path("/greeting")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
+@ApplicationScoped
public class GreetingService {
- @Counted(monotonic = true, name = "count_messages")
+ @Counted(monotonic = true, name = "message_counter", absolute = true)
@GET
+ @Produces(MediaType.TEXT_PLAIN)
public String message() {
return "Hi Microprofile Metrics!";
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/017b98e8/examples/rest-mp-metrics/src/test/java/org/superbiz/rest/GreetingServiceTest.java
----------------------------------------------------------------------
diff --git a/examples/rest-mp-metrics/src/test/java/org/superbiz/rest/GreetingServiceTest.java b/examples/rest-mp-metrics/src/test/java/org/superbiz/rest/GreetingServiceTest.java
new file mode 100644
index 0000000..dff4044
--- /dev/null
+++ b/examples/rest-mp-metrics/src/test/java/org/superbiz/rest/GreetingServiceTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.superbiz.rest;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+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.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ws.rs.core.MediaType;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Arquillian.class)
+public class GreetingServiceTest {
+
+ @Deployment(testable = false)
+ public static WebArchive createDeployment() {
+ final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war")
+ .addClass(GreetingService.class)
+ .addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
+ return webArchive;
+ }
+
+ @ArquillianResource
+ private URL base;
+
+ @Test
+ public void testPrometheusApplicationMetric() {
+ final String message = WebClient.create(base.toExternalForm())
+ .path("/greeting/")
+ .get(String.class);
+ assertEquals("Hi Microprofile Metrics!", message);
+
+ final String metric = WebClient.create(base.toExternalForm())
+ .path("/metrics/application/message_counter")
+ .accept(MediaType.TEXT_PLAIN)
+ .get(String.class);
+ assertEquals("# TYPE application:message_counter counter\napplication:message_counter 1.0\n", metric);
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/017b98e8/examples/rest-mp-metrics/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/examples/rest-mp-metrics/src/test/resources/arquillian.xml b/examples/rest-mp-metrics/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..3029d48
--- /dev/null
+++ b/examples/rest-mp-metrics/src/test/resources/arquillian.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+-->
+<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+ <container qualifier="tomee" default="true">
+ <configuration>
+ <property name="httpPort">-1</property>
+ <property name="stopPort">-1</property>
+ <property name="classifier">microprofile</property>
+ <property name="dir">target/apache-tomee-remote</property>
+ <property name="appWorkingDir">target/arquillian-test-working-dir</property>
+ </configuration>
+ </container>
+</arquillian>
\ No newline at end of file