generated from quarkiverse/quarkiverse-template
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test CXF interceptor constructor injection #943
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...ment/src/test/java/io/quarkiverse/cxf/deployment/test/UnremovableInterceptorBeanTest.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,79 @@ | ||
package io.quarkiverse.cxf.deployment.test; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.apache.cxf.binding.soap.SoapMessage; | ||
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor; | ||
import org.apache.cxf.interceptor.Fault; | ||
import org.apache.cxf.phase.Phase; | ||
import org.assertj.core.api.Assertions; | ||
import org.jboss.logging.Logger; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkiverse.cxf.annotation.CXFClient; | ||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class UnremovableInterceptorBeanTest { | ||
|
||
@RegisterExtension | ||
public static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(FruitWebService.class) | ||
.addClass(FruitWebServiceImpl.class) | ||
.addClass(Fruit.class) | ||
.addClass(Add.class) | ||
.addClass(Delete.class) | ||
.addClass(ApplicationScopedDescriptionAppender.class)) | ||
.overrideConfigKey("quarkus.cxf.endpoint.\"/fruit\".implementor", | ||
"io.quarkiverse.cxf.deployment.test.FruitWebServiceImpl") | ||
.overrideConfigKey("quarkus.cxf.client.fruitClient.client-endpoint-url", | ||
"http://localhost:8081/services/fruit") | ||
.overrideConfigKey("quarkus.cxf.client.fruitClient.out-interceptors", | ||
"io.quarkiverse.cxf.deployment.test.UnremovableInterceptorBeanTest$ApplicationScopedDescriptionAppender") | ||
.setLogRecordPredicate(lr -> lr.getMessage().contains(">>> Hello from MyBean <<<")) | ||
.assertLogRecords(lrs -> Assertions.assertThat(lrs.size()).isGreaterThan(0)); | ||
|
||
@Inject | ||
@CXFClient("fruitClient") | ||
FruitWebService client; | ||
|
||
@Test | ||
public void unremovableInterceptor() { | ||
client.add(new Fruit("Pear", "Sweet")); | ||
Assertions.assertThat(client.getDescriptionByName("Pear")).isEqualTo("Sweet"); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyBean { | ||
public String getMessage() { | ||
return "Hello from MyBean"; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
@Unremovable | ||
public static class ApplicationScopedDescriptionAppender extends AbstractSoapInterceptor { | ||
MyBean bean; | ||
|
||
ApplicationScopedDescriptionAppender() { | ||
super(Phase.PRE_LOGICAL); | ||
} | ||
|
||
@Inject | ||
ApplicationScopedDescriptionAppender(MyBean bean) { | ||
super(Phase.PRE_LOGICAL); | ||
this.bean = bean; | ||
} | ||
|
||
@Override | ||
public void handleMessage(SoapMessage message) throws Fault { | ||
Logger.getLogger(getClass()).info(">>> " + bean.getMessage() + " <<<"); | ||
} | ||
} | ||
|
||
} |