Skip to content

Commit

Permalink
[RESTEASY-3366] Simple test changes of migrating from @context inject…
Browse files Browse the repository at this point in the history
…ion to using CDI.

https://issues.redhat.com/browse/RESTEASY-3366
Signed-off-by: James R. Perkins <jperkins@redhat.com>
  • Loading branch information
jamezp committed Aug 15, 2023
1 parent 65e1926 commit 91d3cc6
Show file tree
Hide file tree
Showing 52 changed files with 272 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ public static Asset createBeansXml() {
return new StringAsset("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<beans xmlns=\"https://jakarta.ee/xml/ns/jakartaee\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd\"\n"
" xsi:schemaLocation=\"https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd\"\n"
+
" version=\"3.0\" bean-discovery-mode=\"all\">\n" +
" version=\"4.0\" bean-discovery-mode=\"all\">\n" +
"</beans>");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import jakarta.ejb.EJB;
import jakarta.ejb.EJBException;
import jakarta.ejb.Singleton;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;

@Singleton
Expand All @@ -30,7 +30,7 @@ public SingletonLocalIF getLocalSub() {
return rl;
}

@Context
@Inject
private Application injectedApplication;
private boolean isJaxrsInjectedPriorToPostConstruct = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import jakarta.ejb.Local;
import jakarta.ejb.Stateless;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;

@Stateless(name = "SingletonTestBean")
Expand All @@ -16,7 +16,7 @@ public SingletonTestBean() {
public void remove() {
}

@Context
@Inject
private UriInfo ui;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jboss.resteasy.test.cdi.injection.resource.LazyInitUriInfoInjectionSingletonResource;
import org.jboss.resteasy.utils.TestUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -31,7 +32,8 @@ public class LazyInitUriInfoInjectionTest {

@Deployment
public static Archive<?> deploySimpleResource() {
WebArchive war = TestUtil.prepareArchive(LazyInitUriInfoInjectionTest.class.getSimpleName());
WebArchive war = TestUtil.prepareArchive(LazyInitUriInfoInjectionTest.class.getSimpleName())
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return TestUtil.finishContainerPrepare(war, null, LazyInitUriInfoInjectionSingletonResource.class,
LazyInitUriInfoInjectionResource.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.jboss.resteasy.test.cdi.injection.resource;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;

import org.jboss.logging.Logger;
Expand All @@ -14,7 +14,7 @@ public class LazyInitUriInfoInjectionResource {

private UriInfo info;

@Context
@Inject
public void setUriInfo(UriInfo i) {
this.info = i;
logger.info(i.getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import jakarta.inject.Inject;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyWriter;
import jakarta.ws.rs.ext.Provider;

import org.jboss.resteasy.test.annotations.FollowUpRequired;

@Provider
public class ProviderOneArgConstructorStringHandlerBodyWriter
implements MessageBodyWriter<ProviderOneArgConstructorStringHandler> {

@Inject
@SuppressWarnings("unused")
public ProviderOneArgConstructorStringHandlerBodyWriter(@Context final Application application) {
public ProviderOneArgConstructorStringHandlerBodyWriter(final Application application) {
}

@FollowUpRequired("This should not be required, but currently RESTEasy requires it")
@SuppressWarnings("unused")
private ProviderOneArgConstructorStringHandlerBodyWriter() {
public ProviderOneArgConstructorStringHandlerBodyWriter() {
}

public boolean isWriteable(Class<?> type, Type genericType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import java.io.IOException;

import jakarta.inject.Inject;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.container.ContainerResponseContext;
import jakarta.ws.rs.container.ContainerResponseFilter;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Context;

@NameBoundProxiesAnnotation
public class NameBoundCDIProxiesInterceptor implements ContainerRequestFilter, ContainerResponseFilter {

private static String in = "";

/** The application context, used for retrieving the {@link ApplicationPath} value. */
@Context
@Inject
Application application;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/**
* Tests that a {@link DynamicFeature} can inject {@link jakarta.ws.rs.core.UriInfo} via
* {@link jakarta.ws.rs.core.Context @Context} and in a CDI bean. The feature is registered as a provider with
* {@link jakarta.inject.Inject @Inject} and in a CDI bean. The feature is registered as a provider with
* {@link Provider @Provider}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/**
* Tests that a {@link DynamicFeature} can inject {@link jakarta.ws.rs.core.UriInfo} via
* {@link jakarta.ws.rs.core.Context @Context} and in a CDI bean. The feature is registered as a provider with via a
* {@link jakarta.inject.Inject @Inject} and in a CDI bean. The feature is registered as a provider with via a
* {@link java.util.ServiceLoader service}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/**
* Tests that a {@link Feature} can inject {@link jakarta.ws.rs.core.UriInfo} via
* {@link jakarta.ws.rs.core.Context @Context} and in a CDI bean. The feature is registered as a provider with
* {@link jakarta.inject.Inject @Inject} and in a CDI bean. The feature is registered as a provider with
* {@link Provider @Provider}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

/**
* Tests that a {@link Feature} can inject {@link jakarta.ws.rs.core.UriInfo} via
* {@link jakarta.ws.rs.core.Context @Context} and in a CDI bean. The feature is registered as a provider with via a
* {@link jakarta.inject.Inject @Inject} and in a CDI bean. The feature is registered as a provider with via a
* {@link java.util.ServiceLoader service}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import jakarta.json.JsonObjectBuilder;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerRequestFilter;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;

Expand All @@ -37,7 +36,7 @@
@RequestScoped
public class ContextAndInjectionFilter implements ContainerRequestFilter {

@Context
@Inject
private UriInfo uriInfo;

@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.jboss.resteasy.test.client.proxy.resource;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Context;

import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.test.annotations.FollowUpRequired;
import org.jboss.resteasy.test.client.proxy.DefaultMediaTypesTest;

@Path("foo")
@RequestScoped
@FollowUpRequired("The @RequestScope annotation can be removed once @Path is considered a bean defining annotation.")
public class DefaultMediaTypesResource implements DefaultMediaTypesTest.Foo {
@Context
@Inject
HttpRequest request;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

import java.util.List;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;

import org.jboss.logging.Logger;
import org.jboss.resteasy.test.annotations.FollowUpRequired;
import org.junit.Assert;

@Path(value = "/sayhello")
@RequestScoped
@FollowUpRequired("The @RequestScope annotation can be removed once @Path is considered a bean defining annotation.")
public class WhiteSpaceResource {

String SPACES_REQUEST = "something something";
private static final Logger logger = Logger.getLogger(WhiteSpaceResource.class);

@Context
@Inject
UriInfo info;

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package org.jboss.resteasy.test.client.resource;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;

import org.jboss.logging.Logger;
import org.jboss.resteasy.test.annotations.FollowUpRequired;

@Path("/headeremptyhostresource")
@RequestScoped
@FollowUpRequired("The @RequestScope annotation can be removed once @Path is considered a bean defining annotation.")
public class HeaderEmptyHostResource {
private static Logger logger = Logger.getLogger(HeaderEmptyHostResource.class);

@Context
@Inject
UriInfo uriInfo;

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.jboss.resteasy.test.client.resource;

import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;

@Path("/test-client")
public class InContainerClientResource {

@Context
@Inject
private UriInfo uriInfo;

@POST
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package org.jboss.resteasy.test.client.resource;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;

import org.jboss.logging.Logger;
import org.jboss.resteasy.test.annotations.FollowUpRequired;
import org.jboss.resteasy.test.client.TraceTest;

@Path("resource")
@RequestScoped
@FollowUpRequired("The @RequestScope annotation can be removed once @Path is considered a bean defining annotation.")
public class TraceResource {

private static Logger logger = Logger.getLogger(TraceResource.class);

@Context
@Inject
UriInfo uriInfo;

@TraceTest.TRACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.runner.RunWith;

/**
* @tpSubChapter @Context injection
* @tpSubChapter context injection
* @tpChapter Integration tests
* @tpTestCaseDetails Regression tests for RESTEASY-2866
* @tpSince RESTEasy 3.7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.jboss.resteasy.test.contextProxyInterfaces.resource;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Configuration;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;

import org.jboss.resteasy.spi.HeaderValueProcessor;
import org.jboss.resteasy.test.annotations.FollowUpRequired;

@Path("/config")
@RequestScoped
@FollowUpRequired("The @RequestScope annotation can be removed once @Path is considered a bean defining annotation.")
public class CastableConfigurationResource {
@Context
@Inject
Configuration config;

@GET
Expand Down

0 comments on commit 91d3cc6

Please sign in to comment.