Skip to content

Commit

Permalink
🐛 self-provided objects are not subject to interception, damn you guice
Browse files Browse the repository at this point in the history
Signed-off-by: dseurotech <[email protected]>
  • Loading branch information
dseurotech committed Aug 1, 2024
1 parent 68817c4 commit 1f3d03e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,8 @@ protected void configureModule() {
bind(DeviceEventFactory.class).to(DeviceEventFactoryImpl.class).in(Singleton.class);
bind(DeviceLifeCycleService.class).to(DeviceLifeCycleServiceImpl.class).in(Singleton.class);
bind(KapuaDeviceRegistrySettings.class).in(Singleton.class);
}

@Provides
@Singleton
public DeviceConnectionService deviceConnectionService(
Map<Class<?>, ServiceConfigurationManager> serviceConfigurationManagersByServiceClass,
AuthorizationService authorizationService,
PermissionFactory permissionFactory,
DeviceConnectionFactory entityFactory,
@Named("DeviceRegistryTransactionManager") TxManager txManager,
DeviceConnectionRepository repository,
Map<String, DeviceConnectionCredentialAdapter> availableDeviceConnectionAdapters,
EventStorer eventStorer) {
return new DeviceConnectionServiceImpl(serviceConfigurationManagersByServiceClass.get(DeviceConnectionService.class),
authorizationService,
permissionFactory,
entityFactory,
txManager,
repository,
availableDeviceConnectionAdapters,
eventStorer);
//This needs to be auto-created by guice, otherwise the RaiseServiceEventInterceptor will not work (sic!)
bind(DeviceConnectionService.class).to(DeviceConnectionServiceImpl.class).in(Singleton.class);
}

@ProvidesIntoSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.commons.lang.NotImplementedException;
import org.eclipse.kapua.KapuaDuplicateNameException;
import org.eclipse.kapua.KapuaEntityNotFoundException;
Expand Down Expand Up @@ -51,6 +55,7 @@
*
* @since 1.0.0
*/
@Singleton
public class DeviceConnectionServiceImpl extends KapuaConfigurableServiceBase implements DeviceConnectionService {

private static final Logger LOG = LoggerFactory.getLogger(DeviceConnectionServiceImpl.class);
Expand All @@ -67,16 +72,17 @@ public class DeviceConnectionServiceImpl extends KapuaConfigurableServiceBase im
* The {@link ServiceConfigurationManager} instance.
* @since 2.0.0
*/
@Inject
public DeviceConnectionServiceImpl(
ServiceConfigurationManager serviceConfigurationManager,
Map<Class<?>, ServiceConfigurationManager> serviceConfigurationManagersByServiceClass,
AuthorizationService authorizationService,
PermissionFactory permissionFactory,
DeviceConnectionFactory entityFactory,
TxManager txManager,
@Named("DeviceRegistryTransactionManager") TxManager txManager,
DeviceConnectionRepository repository,
Map<String, DeviceConnectionCredentialAdapter> availableDeviceConnectionAdapters,
EventStorer eventStorer) {
super(txManager, serviceConfigurationManager, Domains.DEVICE_CONNECTION, authorizationService, permissionFactory);
super(txManager, serviceConfigurationManagersByServiceClass.get(DeviceConnectionService.class), Domains.DEVICE_CONNECTION, authorizationService, permissionFactory);
this.entityFactory = entityFactory;
this.repository = repository;
this.availableDeviceConnectionAdapters = availableDeviceConnectionAdapters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ protected void configure() {
final KapuaJpaRepositoryConfiguration jpaRepoConfig = new KapuaJpaRepositoryConfiguration();
final TxManager txManager = new KapuaJpaTxManagerFactory(maxInsertAttempts).create("kapua-device");
final EventStorer eventStorer = new EventStorerImpl(new EventStoreRecordImplJpaRepository(jpaRepoConfig));
final Map<Class<?>, ServiceConfigurationManager> classServiceConfigurationManagerMap = new HashMap<>();
classServiceConfigurationManagerMap.put(DeviceConnectionService.class, Mockito.mock(ServiceConfigurationManager.class));

final DeviceConnectionService deviceConnectionService = new DeviceConnectionServiceImpl(
Mockito.mock(ServiceConfigurationManager.class),
classServiceConfigurationManagerMap,
mockedAuthorization,
permissionFactory,
new DeviceConnectionFactoryImpl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package org.eclipse.kapua.service.tag.test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.configuration.AccountRelativeFinder;
Expand Down Expand Up @@ -147,9 +149,11 @@ protected void configure() {
final KapuaJpaRepositoryConfiguration jpaRepoConfig = new KapuaJpaRepositoryConfiguration();
final EventStorer eventStorer = new EventStorerImpl(new EventStoreRecordImplJpaRepository(jpaRepoConfig));
bind(TagRepository.class).toInstance(new TagImplJpaRepository(jpaRepoConfig));
final Map<Class<?>, ServiceConfigurationManager> classServiceConfigurationManagerMap = new HashMap<>();
classServiceConfigurationManagerMap.put(DeviceConnectionService.class, Mockito.mock(ServiceConfigurationManager.class));

final DeviceConnectionServiceImpl deviceConnectionService = new DeviceConnectionServiceImpl(
Mockito.mock(ServiceConfigurationManager.class),
classServiceConfigurationManagerMap,
mockedAuthorization,
permissionFactory,
new DeviceConnectionFactoryImpl(),
Expand Down Expand Up @@ -198,16 +202,7 @@ protected void configure() {
deviceValidation)
);
bind(DeviceFactory.class).toInstance(new DeviceFactoryImpl());

bind(DeviceConnectionService.class).toInstance(new DeviceConnectionServiceImpl(
Mockito.mock(ServiceConfigurationManager.class),
mockedAuthorization,
permissionFactory,
new DeviceConnectionFactoryImpl(),
new KapuaJpaTxManagerFactory(maxInsertAttempts).create("kapua-device"),
new DeviceConnectionImplJpaRepository(jpaRepoConfig),
Collections.emptyMap(),
eventStorer));
bind(DeviceConnectionService.class).toInstance(deviceConnectionService);
bind(DeviceConnectionFactory.class).to(DeviceConnectionFactoryImpl.class);

bind(DeviceRepository.class).toInstance(new DeviceImplJpaRepository(jpaRepoConfig));
Expand Down

0 comments on commit 1f3d03e

Please sign in to comment.