Skip to content

Commit

Permalink
refactoring: combining Module and Provider for non-deprecated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Nov 25, 2023
1 parent d0c3a7e commit 81119ea
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 198 deletions.
18 changes: 12 additions & 6 deletions bootique-cxf-core/src/main/java/io/bootique/cxf/CxfModule.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.bootique.cxf;

import io.bootique.ConfigModule;
import io.bootique.BQModuleProvider;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.cxf.conf.BQBeanLocator;
import io.bootique.cxf.conf.BqConfigurer;
import io.bootique.cxf.conf.CustomConfigurer;
import io.bootique.di.Binder;
import io.bootique.di.Injector;
import io.bootique.di.Provides;
import io.bootique.di.TypeLiteral;
import io.bootique.di.*;
import org.apache.cxf.Bus;
import org.apache.cxf.configuration.ConfiguredBeanLocator;
import org.apache.cxf.configuration.Configurer;
Expand All @@ -17,12 +15,20 @@
import java.util.List;
import java.util.Map;

public class CxfModule extends ConfigModule {
public class CxfModule implements BQModule, BQModuleProvider {

public static CxfModuleExtender extend(Binder binder) {
return new CxfModuleExtender(binder);
}

@Override
public BuiltModule buildModule() {
return BuiltModule.of(this)
.provider(this)
.description("Integrates Apache CXF core")
.build();
}

@Override
public void configure(Binder binder) {
CxfModule.extend(binder).initAllExtensions();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.bootique.cxf.CxfModuleProvider
io.bootique.cxf.CxfModule
14 changes: 14 additions & 0 deletions bootique-cxf-core/src/test/java/io/bootique/cxf/CxfModuleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.bootique.cxf;

import io.bootique.junit5.BQModuleProviderChecker;
import io.bootique.junit5.BQTest;
import org.junit.jupiter.api.Test;

@BQTest
public class CxfModuleTest {

@Test
public void testAutoLoading() {
BQModuleProviderChecker.testAutoLoadable(CxfModule.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

package io.bootique.cxf;

import io.bootique.ConfigModule;
import io.bootique.BQModuleProvider;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.config.ConfigurationFactory;
import io.bootique.cxf.annotations.CxfFeature;
import io.bootique.cxf.annotations.CxfResource;
import io.bootique.cxf.annotations.CxfServlet;
import io.bootique.di.Binder;
import io.bootique.di.Key;
import io.bootique.di.Provides;
import io.bootique.di.TypeLiteral;
import io.bootique.di.*;
import io.bootique.jetty.JettyModule;
import io.bootique.jetty.JettyModuleProvider;
import io.bootique.jetty.MappedServlet;
import org.apache.cxf.Bus;
import org.apache.cxf.feature.Feature;
Expand All @@ -38,17 +37,18 @@
import javax.inject.Singleton;
import javax.servlet.Servlet;
import javax.ws.rs.core.Application;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.*;

import static java.util.Arrays.asList;

/**
* CXF module.
*
* @author Ruslan Ibragimov
*/
public class CxfJaxrsModule extends ConfigModule {
public class CxfJaxrsModule implements BQModule, BQModuleProvider {

private static final String CONFIG_PREFIX = "cxfjaxrs";

/**
* Returns an instance of {@link CxfJaxrsModuleExtender} used by downstream modules to load custom extensions of
Expand All @@ -61,6 +61,24 @@ public static CxfJaxrsModuleExtender extend(Binder binder) {
return new CxfJaxrsModuleExtender(binder);
}

@Override
public BuiltModule buildModule() {
return BuiltModule.of(this)
.provider(this)
.description("Integrates Apache CXF JAX-RS engine")
.config(CONFIG_PREFIX, CxfJaxrsModuleConfig.class)
.build();
}

@Override
@Deprecated(since = "3.0", forRemoval = true)
public Collection<BQModuleProvider> dependencies() {
return asList(
new JettyModuleProvider(),
new CxfModule()
);
}

@Override
public void configure(Binder binder) {
CxfJaxrsModule.extend(binder).initAllExtensions();
Expand All @@ -85,7 +103,7 @@ private MappedServlet<Servlet> createCxfServlet(CxfJaxrsModuleConfig config, App
@Singleton
@Provides
private CxfJaxrsModuleConfig createCxfFactory(ConfigurationFactory configFactory) {
return config(CxfJaxrsModuleConfig.class, configFactory);
return configFactory.config(CxfJaxrsModuleConfig.class, CONFIG_PREFIX);
}

@Singleton
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.bootique.cxf.CxfJaxrsModuleProvider
io.bootique.cxf.CxfJaxrsModule
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
import io.bootique.junit5.BQModuleProviderChecker;
import org.junit.jupiter.api.Test;

public class CxfJaxrsModuleProviderTest {
public class CxfJaxrsModuleTest {

@Test
public void autoLoadable() {
BQModuleProviderChecker.testAutoLoadable(CxfJaxrsModuleProvider.class);
BQModuleProviderChecker.testAutoLoadable(CxfJaxrsModule.class);

}

@Test
public void metadata() {
BQModuleProviderChecker.testMetadata(CxfJaxrsModuleProvider.class);
BQModuleProviderChecker.testMetadata(CxfJaxrsModule.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.bootique.cxf.jaxws;

import io.bootique.ConfigModule;
import io.bootique.BQModuleProvider;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.config.ConfigurationFactory;
import io.bootique.cxf.CxfModule;
import io.bootique.cxf.jaxws.annotation.CxfInterceptorsClientIn;
import io.bootique.cxf.jaxws.annotation.CxfInterceptorsClientInFault;
import io.bootique.cxf.jaxws.annotation.CxfInterceptorsClientOut;
import io.bootique.cxf.jaxws.annotation.CxfInterceptorsClientOutFault;
import io.bootique.di.BQModule;
import io.bootique.di.Binder;
import io.bootique.di.Provides;
import org.apache.cxf.interceptor.Interceptor;
Expand All @@ -16,16 +18,35 @@

import javax.inject.Singleton;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

public class CxfJaxwsClientModule extends ConfigModule {
public class CxfJaxwsClientModule implements BQModule, BQModuleProvider {

private static final String CONFIG_PREFIX = "cxfjaxwsclient";

public static CxfJaxwsClientModuleExtender extend(Binder binder) {
return new CxfJaxwsClientModuleExtender(binder);
}

@Override
public BuiltModule buildModule() {
return BuiltModule.of(this)
.provider(this)
.description("Integrates Apache CXF JAX-WS client")
.config(CONFIG_PREFIX, CxfJaxwsClientConfiguration.class)
.build();
}

@Override
@Deprecated(since = "3.0", forRemoval = true)
public Collection<BQModuleProvider> dependencies() {
return Collections.singletonList(new CxfModule());
}


@Override
public void configure(Binder binder) {
CxfJaxwsClientModule.extend(binder).initAllExtensions();
Expand All @@ -36,10 +57,10 @@ public void configure(Binder binder) {
@Provides
@Singleton
public JaxWsProxyFactoryConfigurer provideProxyFactoryConfigurer(
@CxfInterceptorsClientIn Set<Interceptor<? extends Message>> inInterceptors,
@CxfInterceptorsClientOut Set<Interceptor<? extends Message>> outInterceptors,
@CxfInterceptorsClientInFault Set<Interceptor<? extends Message>> inFaultInterceptors,
@CxfInterceptorsClientOutFault Set<Interceptor<? extends Message>> outFaultInterceptors
@CxfInterceptorsClientIn Set<Interceptor<? extends Message>> inInterceptors,
@CxfInterceptorsClientOut Set<Interceptor<? extends Message>> outInterceptors,
@CxfInterceptorsClientInFault Set<Interceptor<? extends Message>> inFaultInterceptors,
@CxfInterceptorsClientOutFault Set<Interceptor<? extends Message>> outFaultInterceptors
) {
return new JaxWsProxyFactoryConfigurer(
inInterceptors,
Expand All @@ -52,7 +73,7 @@ public JaxWsProxyFactoryConfigurer provideProxyFactoryConfigurer(
@Provides
@Singleton
public CxfJaxwsClientConfiguration provideConfiguration(ConfigurationFactory configurationFactory) {
return config(CxfJaxwsClientConfiguration.class, configurationFactory);
return configurationFactory.config(CxfJaxwsClientConfiguration.class, CONFIG_PREFIX);
}

@Provides
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.bootique.cxf.jaxws.CxfJaxwsClientModuleProvider
io.bootique.cxf.jaxws.CxfJaxwsClientModule
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import org.junit.jupiter.api.Test;

@BQTest
public class CxfJaxwsClientModuleProviderIT {
public class CxfJaxwsClientModuleIT {

@BQTestTool
final BQTestFactory testFactory = new BQTestFactory();

@Test
public void autoLoadable() {
BQModuleProviderChecker.testAutoLoadable(CxfJaxwsClientModuleProvider.class);
BQModuleProviderChecker.testAutoLoadable(CxfJaxwsClientModule.class);
}

@Test
public void moduleDeclaresDependencies() {
final BQRuntime bqRuntime = testFactory.app().moduleProvider(new CxfJaxwsClientModuleProvider()).createRuntime();
final BQRuntime bqRuntime = testFactory.app().moduleProvider(new CxfJaxwsClientModule()).createRuntime();
BQRuntimeChecker.testModulesLoaded(bqRuntime,
CxfModule.class,
CxfJaxwsClientModule.class
Expand Down
Loading

0 comments on commit 81119ea

Please sign in to comment.