Skip to content

Commit

Permalink
Support RESTeasy 4.0 version in unit tests
Browse files Browse the repository at this point in the history
* Split jaxrs-2.0 into jaxrs-2.0-common and jaxrs-2.0-testing (similar to e.g. play)
* Support newest RESTEasy version in unit tests
  • Loading branch information
mateuszrzeszutek committed Aug 24, 2020
1 parent 95ad352 commit 67018d6
Show file tree
Hide file tree
Showing 28 changed files with 410 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply from: "$rootDir/gradle/instrumentation.gradle"

muzzle {
fail {
group = "javax.ws.rs"
module = "jsr311-api"
versions = "[,]"
}
pass {
group = "javax.ws.rs"
module = "javax.ws.rs-api"
versions = "[,]"
}
}

dependencies {
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ public static SpanWithScope createOrUpdateAbortSpan(
Span parent = BaseTracer.getCurrentServerSpan();
Span span = TRACER.getCurrentSpan();

if (span == null) {
// in case of impl -> default order: span == parent (never null!) and no span is created
// in case of default -> impl order: span is always created by default, updated here
// TODO: how to fix that properly?
if (span == null || span == parent) {
span = TRACER.startSpan(resourceClass, method);
return new SpanWithScope(span, currentContextWith(span));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ muzzle {

dependencies {
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
compileOnly group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.0'
library group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.0'

implementation project(':instrumentation:jaxrs:jaxrs-2.0')
implementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common')

testImplementation project(':instrumentation:servlet:servlet-3.0')
testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-testing')

// First version with DropwizardTestSupport:
testLibrary group: 'io.dropwizard', name: 'dropwizard-testing', version: '0.8.0'
testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3'
testImplementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner', version: '2.9.10'

latestDepTestLibrary group: 'io.dropwizard', name: 'dropwizard-testing', version: '1.+'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed 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.
*/

class JerseyAnnotationInstrumentationTest extends JaxRsAnnotationsInstrumentationTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed 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.
*/

import static Resource.Test1
import static Resource.Test2
import static Resource.Test3

import io.dropwizard.testing.junit.ResourceTestRule
import javax.ws.rs.client.Entity
import javax.ws.rs.core.Response
import org.junit.ClassRule
import spock.lang.Shared

class JerseyFilterTest extends JaxRsFilterTest {
@Shared
@ClassRule
ResourceTestRule resources = ResourceTestRule.builder()
.addResource(new Test1())
.addResource(new Test2())
.addResource(new Test3())
.addProvider(simpleRequestFilter)
.addProvider(prematchRequestFilter)
.build()

@Override
def makeRequest(String url) {
Response response = resources.client().target(url).request().post(Entity.text(""))

return [response.readEntity(String), response.statusInfo.statusCode]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed 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.
*/

import io.dropwizard.jetty.NonblockingServletHolder
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.ServletContextHandler
import org.glassfish.jersey.server.ResourceConfig
import org.glassfish.jersey.servlet.ServletContainer

class JerseyHttpServerTest extends JaxRsHttpServerTest<Server> {

@Override
Server startServer(int port) {
def servlet = new ServletContainer(ResourceConfig.forApplicationClass(JaxRsTestApplication))

def handler = new ServletContextHandler(ServletContextHandler.SESSIONS)
handler.setContextPath("/")
handler.addServlet(new NonblockingServletHolder(servlet), "/*")

def server = new Server(port)
server.setHandler(handler)
server.start()

return server
}

@Override
void stopServer(Server httpServer) {
httpServer.stop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ muzzle {

dependencies {
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
compileOnly group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.0.0.Final'
library group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.0.0.Final'

implementation project(':instrumentation:jaxrs:jaxrs-2.0')
implementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common')

testImplementation project(':instrumentation:servlet:servlet-3.0')
testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-testing')

testLibrary(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.0.4.Final') {
exclude group: 'org.jboss.resteasy', module: 'resteasy-client'
}
testLibrary group: 'io.undertow', name: 'undertow-servlet', version: '1.0.0.Final'

latestDepTestLibrary group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.+'
latestDepTestLibrary(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.+') {
exclude group: 'org.jboss.resteasy', module: 'resteasy-client'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed 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.
*/

class ResteasyAnnotationInstrumentationTest extends JaxRsAnnotationsInstrumentationTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed 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.
*/

import static Resource.Test1
import static Resource.Test2
import static Resource.Test3

import javax.ws.rs.core.MediaType
import org.jboss.resteasy.mock.MockDispatcherFactory
import org.jboss.resteasy.mock.MockHttpRequest
import org.jboss.resteasy.mock.MockHttpResponse
import spock.lang.Shared

class ResteasyFilterTest extends JaxRsFilterTest {
@Shared
def dispatcher

def setupSpec() {
dispatcher = MockDispatcherFactory.createDispatcher()
def registry = dispatcher.getRegistry()
registry.addSingletonResource(new Test1())
registry.addSingletonResource(new Test2())
registry.addSingletonResource(new Test3())

dispatcher.getProviderFactory().register(simpleRequestFilter)
dispatcher.getProviderFactory().register(prematchRequestFilter)
}

@Override
def makeRequest(String url) {
MockHttpRequest request = MockHttpRequest.post(url)
request.contentType(MediaType.TEXT_PLAIN_TYPE)
request.content(new byte[0])

MockHttpResponse response = new MockHttpResponse()
dispatcher.invoke(request, response)

return [response.contentAsString, response.status]
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed 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.
*/

import io.undertow.Undertow
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer

class ResteasyHttpServerTest extends JaxRsHttpServerTest<UndertowJaxrsServer> {

@Override
UndertowJaxrsServer startServer(int port) {
def server = new UndertowJaxrsServer()
server.deploy(JaxRsTestApplication)
server.start(Undertow.builder()
.addHttpListener(port, "localhost"))
return server
}

@Override
void stopServer(UndertowJaxrsServer server) {
server.stop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ muzzle {

dependencies {
compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
compileOnly group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.0.Final'
library group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.0.Final'

implementation project(':instrumentation:jaxrs:jaxrs-2.0')
implementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common')

testImplementation project(':instrumentation:servlet:servlet-3.0')
testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-testing')

testLibrary(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.1.0.Final') {
exclude group: 'org.jboss.resteasy', module: 'resteasy-client'
}

latestDepTestLibrary group: 'org.jboss.resteasy', name: 'resteasy-core', version: '+'
}

if (findProperty('testLatestDeps')) {
configurations {
testImplementation.exclude group: 'org.jboss.resteasy', module: 'resteasy-jaxrs'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed 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.
*/

class ResteasyAnnotationInstrumentationTest extends JaxRsAnnotationsInstrumentationTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed 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.
*/

import static Resource.Test1
import static Resource.Test2
import static Resource.Test3

import javax.ws.rs.core.MediaType
import org.jboss.resteasy.mock.MockDispatcherFactory
import org.jboss.resteasy.mock.MockHttpRequest
import org.jboss.resteasy.mock.MockHttpResponse
import spock.lang.Shared

class ResteasyFilterTest extends JaxRsFilterTest {
@Shared
def dispatcher

def setupSpec() {
dispatcher = MockDispatcherFactory.createDispatcher()
def registry = dispatcher.getRegistry()
registry.addSingletonResource(new Test1())
registry.addSingletonResource(new Test2())
registry.addSingletonResource(new Test3())

dispatcher.getProviderFactory().register(simpleRequestFilter)
dispatcher.getProviderFactory().register(prematchRequestFilter)
}

@Override
def makeRequest(String url) {
MockHttpRequest request = MockHttpRequest.post(url)
request.contentType(MediaType.TEXT_PLAIN_TYPE)
request.content(new byte[0])

MockHttpResponse response = new MockHttpResponse()
dispatcher.invoke(request, response)

return [response.contentAsString, response.status]
}

}
Loading

0 comments on commit 67018d6

Please sign in to comment.