@@ -682,74 +682,6 @@ Set `jboss.home` to the provisioning directory:
682682
683683This chapter covers advanced features and extensibility points in {project-name}.
684684
685- == Extending Resource Injection
686-
687- The framework supports custom resource injection via the `ServerResourceProducer` SPI.
688-
689- === Implementing a Resource Producer
690-
691- Create a class that implements `org.wildfly.testing.junit.extension.api.ServerResourceProducer`:
692-
693- [source,java]
694- ----
695- package com.example;
696-
697- import java.lang.annotation.Annotation;
698-
699- import jakarta.ws.rs.client.Client;
700- import jakarta.ws.rs.client.ClientBuilder;
701- import org.junit.jupiter.api.extension.ExtensionContext;
702- import org.kohsuke.MetaInfServices;
703- import org.wildfly.testing.junit.extension.api.ServerResourceProducer;
704-
705- @MetaInfServices
706- public class RestClientProducer implements ServerResourceProducer {
707-
708- private static final ExtensionContext.Namespace NAMESPACE =
709- ExtensionContext.Namespace.create("Rest.Client");
710-
711- @Override
712- public boolean canInject(ExtensionContext context, Class<?> clazz,
713- Annotation... annotations) {
714- return Client.class.isAssignableFrom(clazz);
715- }
716-
717- @Override
718- public Object produce(ExtensionContext context, Class<?> clazz,
719- Annotation... annotations) {
720- ExtensionContext.Store store = context.getRoot().getStore(NAMESPACE);
721- return store.computeIfAbsent("rest-client",
722- (c) -> ClientBuilder.newClient(), Client.class);
723- }
724- }
725- ----
726-
727- === Using the Custom Producer
728-
729- Now you can inject the custom resource type:
730-
731- [source,java]
732- ----
733- @WildFlyTest
734- public class RestApiTest {
735-
736- @ServerResource
737- private Client client;
738-
739- @ServerResource
740- private URI uri;
741-
742- @Test
743- public void testRestApi() {
744- Response response = client.target(uri)
745- .path("api/resource")
746- .request()
747- .get();
748- Assertions.assertEquals(200, response.getStatus());
749- }
750- }
751- ----
752-
753685== Custom Server Configurations
754686
755687=== Standalone Configuration
0 commit comments