Skip to content

Commit

Permalink
Test CXF interceptor constructor injection #943
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Aug 9, 2023
1 parent 6cea9f2 commit 438ddfe
Showing 1 changed file with 79 additions and 0 deletions.
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() + " <<<");
}
}

}

0 comments on commit 438ddfe

Please sign in to comment.