Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ations as bean defining annotations. https://issues.redhat.com/browse/WFLY-16545 Signed-off-by: James R. Perkins <jperkins@redhat.com>
- Loading branch information
Showing
13 changed files
with
209 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...c/test/java/org/jboss/as/test/integration/jaxrs/integration/cdi/CdiInjectionTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package org.jboss.as.test.integration.jaxrs.integration.cdi; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.UriBuilder; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
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.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class CdiInjectionTestCase { | ||
|
||
@Deployment(testable = false) | ||
public static Archive<?> deploy() { | ||
return ShrinkWrap.create(WebArchive.class, CdiInjectionTestCase.class.getSimpleName() + ".war") | ||
.add(new StringAsset("<beans bean-discovery-mode=\"annotated\"></beans>"), "WEB-INF/beans.xml") | ||
.addClasses(CDIApplication.class, CDIProvider.class, CDIResource.class, CDIBean.class, InjectionResource.class); | ||
} | ||
|
||
|
||
private static Client CLIENT; | ||
|
||
@ArquillianResource | ||
private URL url; | ||
|
||
@BeforeClass | ||
public static void createClient() { | ||
CLIENT = ClientBuilder.newClient(); | ||
} | ||
|
||
@AfterClass | ||
public static void closeClient() { | ||
if (CLIENT != null) { | ||
CLIENT.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void checkApplication() throws Exception { | ||
checkResponse("app", CDIApplication.class); | ||
} | ||
|
||
@Test | ||
public void checkProvider() throws Exception { | ||
checkResponse("provider", CDIProvider.class); | ||
} | ||
|
||
@Test | ||
public void checkResource() throws Exception { | ||
checkResponse("resource", CDIResource.class); | ||
} | ||
|
||
private void checkResponse(final String path, final Class<?> expectedType) throws Exception { | ||
try ( | ||
Response response = CLIENT.target(createUri(path)) | ||
.request() | ||
.get() | ||
) { | ||
final String text = response.readEntity(String.class); | ||
Assert.assertEquals(text, Response.Status.OK, response.getStatusInfo()); | ||
Assert.assertTrue(String.format("Expected type %s, but found %s", expectedType.getName(), text), text.startsWith(expectedType.getName())); | ||
} | ||
} | ||
|
||
private UriBuilder createUri(final String path) throws URISyntaxException { | ||
return UriBuilder.fromUri(url.toURI()) | ||
.path("rest/inject/" + path); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
.../src/test/java/org/jboss/as/test/integration/jaxrs/integration/cdi/InjectionResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2022 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package org.jboss.as.test.integration.jaxrs.integration.cdi; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a> | ||
*/ | ||
@Path("/inject") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public class InjectionResource { | ||
|
||
@Inject | ||
private Application app; | ||
@Inject | ||
private CDIProvider provider; | ||
@Inject | ||
private CDIResource resource; | ||
|
||
@GET | ||
@Path("/app") | ||
public Response app() { | ||
if (app == null) { | ||
return Response.serverError().entity("Application was null").build(); | ||
} | ||
return Response.ok(app.getClass().getName()).build(); | ||
} | ||
|
||
@GET | ||
@Path("/provider") | ||
public Response provider() { | ||
if (provider == null) { | ||
return Response.serverError().entity("Provider was null").build(); | ||
} | ||
return Response.ok(provider.getClass().getName()).build(); | ||
} | ||
|
||
@GET | ||
@Path("/resource") | ||
public Response resource() { | ||
if (resource == null) { | ||
return Response.serverError().entity("Resource was null").build(); | ||
} | ||
return Response.ok(resource.getClass().getName()).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters