diff --git a/commons/src/test/java/org/eclipse/kapua/commons/service/internal/cache/MockitoLocator.java b/commons/src/test/java/org/eclipse/kapua/commons/service/internal/cache/MockitoLocator.java index c213bf504b3..ef5f9a30155 100644 --- a/commons/src/test/java/org/eclipse/kapua/commons/service/internal/cache/MockitoLocator.java +++ b/commons/src/test/java/org/eclipse/kapua/commons/service/internal/cache/MockitoLocator.java @@ -19,6 +19,7 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.KapuaObjectFactory; @@ -47,33 +48,41 @@ public List getServices() { @Override public T getComponent(Class componentClass) { - if (MetricsService.class.equals(componentClass)) { - return (T) new MetricsService() { - @Override - public Counter getCounter(String module, String component, String... names) { - return new Counter(); - } + final MetricsService metricsService = new MetricsService() { + @Override + public Counter getCounter(String module, String component, String... names) { + return new Counter(); + } - @Override - public Histogram getHistogram(String module, String component, String... names) { - return new Histogram(new ExponentiallyDecayingReservoir()); - } + @Override + public Histogram getHistogram(String module, String component, String... names) { + return new Histogram(new ExponentiallyDecayingReservoir()); + } - @Override - public Timer getTimer(String module, String component, String... names) { - return new Timer(); - } + @Override + public Timer getTimer(String module, String component, String... names) { + return new Timer(); + } - @Override - public void registerGauge(Gauge gauge, String module, String component, String... names) throws KapuaException { + @Override + public void registerGauge(Gauge gauge, String module, String component, String... names) throws KapuaException { - } + } - @Override - public MetricRegistry getMetricRegistry() { - return new MetricRegistry(); - } - }; + @Override + public MetricRegistry getMetricRegistry() { + return new MetricRegistry(); + } + }; + if (MetricsService.class.equals(componentClass)) { + return (T) metricsService; + } + if (CommonsMetric.class.equals(componentClass)) { + try { + return (T) new CommonsMetric(metricsService, "tests"); + } catch (KapuaException e) { + throw new RuntimeException(e); + } } return Mockito.mock(componentClass); } diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/TestConfigModule.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/TestConfigModule.java new file mode 100644 index 00000000000..b3193d101cb --- /dev/null +++ b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/TestConfigModule.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.integration.misc; + +import com.google.inject.Provides; +import org.eclipse.kapua.commons.core.AbstractKapuaModule; + +import javax.inject.Named; + +public class TestConfigModule extends AbstractKapuaModule { + @Override + protected void configureModule() { + + } + + + @Provides + @Named("metricModuleName") + String metricModuleName() { + return "qa-tests"; + } +} diff --git a/qa/integration/src/test/resources/locator.xml b/qa/integration/src/test/resources/locator.xml index c665b6421f4..86475b7d6e2 100644 --- a/qa/integration/src/test/resources/locator.xml +++ b/qa/integration/src/test/resources/locator.xml @@ -20,6 +20,7 @@ + org.eclipse.kapua.integration.misc org.eclipse.kapua.commons org.eclipse.kapua.job.engine.client org.eclipse.kapua.message diff --git a/rest-api/core/src/test/java/org/eclipse/kapua/app/api/core/auth/MockitoLocator.java b/rest-api/core/src/test/java/org/eclipse/kapua/app/api/core/auth/MockitoLocator.java index 7f33a9e7fcd..c44d41b4845 100644 --- a/rest-api/core/src/test/java/org/eclipse/kapua/app/api/core/auth/MockitoLocator.java +++ b/rest-api/core/src/test/java/org/eclipse/kapua/app/api/core/auth/MockitoLocator.java @@ -19,6 +19,7 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.KapuaObjectFactory; @@ -47,33 +48,41 @@ public List getServices() { @Override public T getComponent(Class componentClass) { - if (MetricsService.class.equals(componentClass)) { - return (T) new MetricsService() { - @Override - public Counter getCounter(String module, String component, String... names) { - return new Counter(); - } + final MetricsService metricsService = new MetricsService() { + @Override + public Counter getCounter(String module, String component, String... names) { + return new Counter(); + } - @Override - public Histogram getHistogram(String module, String component, String... names) { - return new Histogram(new ExponentiallyDecayingReservoir()); - } + @Override + public Histogram getHistogram(String module, String component, String... names) { + return new Histogram(new ExponentiallyDecayingReservoir()); + } - @Override - public Timer getTimer(String module, String component, String... names) { - return new Timer(); - } + @Override + public Timer getTimer(String module, String component, String... names) { + return new Timer(); + } - @Override - public void registerGauge(Gauge gauge, String module, String component, String... names) throws KapuaException { + @Override + public void registerGauge(Gauge gauge, String module, String component, String... names) throws KapuaException { - } + } - @Override - public MetricRegistry getMetricRegistry() { - return new MetricRegistry(); - } - }; + @Override + public MetricRegistry getMetricRegistry() { + return new MetricRegistry(); + } + }; + if (MetricsService.class.equals(componentClass)) { + return (T) metricsService; + } + if (CommonsMetric.class.equals(componentClass)) { + try { + return (T) new CommonsMetric(metricsService, "tests"); + } catch (KapuaException e) { + throw new RuntimeException(e); + } } return Mockito.mock(componentClass); } diff --git a/service/account/internal/src/test/java/org/eclipse/kapua/service/account/xml/TestConfigModule.java b/service/account/internal/src/test/java/org/eclipse/kapua/service/account/xml/TestConfigModule.java new file mode 100644 index 00000000000..bb9e229d896 --- /dev/null +++ b/service/account/internal/src/test/java/org/eclipse/kapua/service/account/xml/TestConfigModule.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.account.xml; + +import com.google.inject.Provides; +import org.eclipse.kapua.commons.core.AbstractKapuaModule; + +import javax.inject.Named; + +public class TestConfigModule extends AbstractKapuaModule { + @Override + protected void configureModule() { + + } + + + @Provides + @Named("metricModuleName") + String metricModuleName() { + return "qa-tests"; + } +} diff --git a/service/account/internal/src/test/resources/locator.xml b/service/account/internal/src/test/resources/locator.xml index 4d75a7809c6..e82224c33b6 100644 --- a/service/account/internal/src/test/resources/locator.xml +++ b/service/account/internal/src/test/resources/locator.xml @@ -17,6 +17,7 @@ + org.eclipse.kapua.service.account.xml org.eclipse.kapua.commons diff --git a/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java b/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java index 630ffb0ab99..b3e3050f08c 100644 --- a/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java +++ b/service/account/test/src/test/java/org/eclipse/kapua/service/account/test/AccountLocatorConfiguration.java @@ -16,6 +16,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.name.Names; import io.cucumber.java.Before; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.AccountChildrenFinder; @@ -63,6 +64,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); bind(RootUserTester.class).toInstance(Mockito.mock(RootUserTester.class)); // Inject mocked Authorization Service method checkPermission diff --git a/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java b/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java index 1d5134fa8c2..719e3b897ca 100644 --- a/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java +++ b/service/device/registry/test/src/test/java/org/eclipse/kapua/service/device/registry/test/DeviceRegistryLocatorConfiguration.java @@ -16,6 +16,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.name.Names; import io.cucumber.java.Before; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.AccountChildrenFinder; @@ -82,6 +83,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); // Inject mocked Authorization Service method checkPermission diff --git a/service/job/test/src/test/java/org/eclipse/kapua/service/job/test/JobLocatorConfiguration.java b/service/job/test/src/test/java/org/eclipse/kapua/service/job/test/JobLocatorConfiguration.java index aaca0eb8a2d..4ea1fc9ffcf 100644 --- a/service/job/test/src/test/java/org/eclipse/kapua/service/job/test/JobLocatorConfiguration.java +++ b/service/job/test/src/test/java/org/eclipse/kapua/service/job/test/JobLocatorConfiguration.java @@ -16,6 +16,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.name.Names; import io.cucumber.java.Before; import org.eclipse.kapua.commons.configuration.AccountChildrenFinder; import org.eclipse.kapua.commons.configuration.RootUserTester; @@ -92,6 +93,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); // Commons diff --git a/service/scheduler/test/src/test/java/org/eclipse/kapua/service/scheduler/test/SchedulerLocatorConfiguration.java b/service/scheduler/test/src/test/java/org/eclipse/kapua/service/scheduler/test/SchedulerLocatorConfiguration.java index 86ba529272c..0540cb5b08f 100644 --- a/service/scheduler/test/src/test/java/org/eclipse/kapua/service/scheduler/test/SchedulerLocatorConfiguration.java +++ b/service/scheduler/test/src/test/java/org/eclipse/kapua/service/scheduler/test/SchedulerLocatorConfiguration.java @@ -16,6 +16,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.name.Names; import io.cucumber.java.Before; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.AccountChildrenFinder; @@ -68,6 +69,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); // Inject mocked Authorization Service method checkPermission diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/setting/KapuaCryptoSettingTest.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/setting/KapuaCryptoSettingTest.java deleted file mode 100644 index 916052f655a..00000000000 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authentication/shiro/setting/KapuaCryptoSettingTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.service.authentication.shiro.setting; - -import org.eclipse.kapua.qa.markers.junit.JUnitTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - - -@Category(JUnitTests.class) -public class KapuaCryptoSettingTest { - - @Test - public void kapuaCryptoSettingTest() throws Exception { - Constructor kapuaCryptoSetting = KapuaCryptoSetting.class.getDeclaredConstructor(); - kapuaCryptoSetting.setAccessible(true); - kapuaCryptoSetting.newInstance(); - Assert.assertTrue("True expected.", Modifier.isPrivate(kapuaCryptoSetting.getModifiers())); - } - - @Test - public void getInstanceTest() { - Assert.assertTrue("True expected.", KapuaCryptoSetting.getInstance() instanceof KapuaCryptoSetting); - } -} \ No newline at end of file diff --git a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/MockitoLocator.java b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/MockitoLocator.java index 60962a38b46..369cfec2c6c 100644 --- a/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/MockitoLocator.java +++ b/service/security/shiro/src/test/java/org/eclipse/kapua/service/authorization/access/shiro/MockitoLocator.java @@ -19,6 +19,7 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.metric.CommonsMetric; import org.eclipse.kapua.commons.metric.MetricsService; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.KapuaObjectFactory; @@ -47,33 +48,41 @@ public List getServices() { @Override public T getComponent(Class componentClass) { - if (MetricsService.class.equals(componentClass)) { - return (T) new MetricsService() { - @Override - public Counter getCounter(String module, String component, String... names) { - return new Counter(); - } + final MetricsService metricsService = new MetricsService() { + @Override + public Counter getCounter(String module, String component, String... names) { + return new Counter(); + } - @Override - public Histogram getHistogram(String module, String component, String... names) { - return new Histogram(new ExponentiallyDecayingReservoir()); - } + @Override + public Histogram getHistogram(String module, String component, String... names) { + return new Histogram(new ExponentiallyDecayingReservoir()); + } - @Override - public Timer getTimer(String module, String component, String... names) { - return new Timer(); - } + @Override + public Timer getTimer(String module, String component, String... names) { + return new Timer(); + } - @Override - public void registerGauge(Gauge gauge, String module, String component, String... names) throws KapuaException { + @Override + public void registerGauge(Gauge gauge, String module, String component, String... names) throws KapuaException { - } + } - @Override - public MetricRegistry getMetricRegistry() { - return new MetricRegistry(); - } - }; + @Override + public MetricRegistry getMetricRegistry() { + return new MetricRegistry(); + } + }; + if (MetricsService.class.equals(componentClass)) { + return (T) metricsService; + } + if (CommonsMetric.class.equals(componentClass)) { + try { + return (T) new CommonsMetric(metricsService, "tests"); + } catch (KapuaException e) { + throw new RuntimeException(e); + } } return Mockito.mock(componentClass); } diff --git a/service/security/test/src/test/java/org/eclipse/kapua/service/security/test/SecurityLocatorConfiguration.java b/service/security/test/src/test/java/org/eclipse/kapua/service/security/test/SecurityLocatorConfiguration.java index 2af4938b346..52551a5a507 100644 --- a/service/security/test/src/test/java/org/eclipse/kapua/service/security/test/SecurityLocatorConfiguration.java +++ b/service/security/test/src/test/java/org/eclipse/kapua/service/security/test/SecurityLocatorConfiguration.java @@ -16,6 +16,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.name.Names; import io.cucumber.java.Before; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.AccountChildrenFinder; @@ -78,6 +79,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); // Inject mocked Authorization Service method checkPermission diff --git a/service/system/test/src/test/java/org/eclipse/kapua/service/systeminfo/test/SystemInfoLocatorConfiguration.java b/service/system/test/src/test/java/org/eclipse/kapua/service/systeminfo/test/SystemInfoLocatorConfiguration.java index e1bbbe25836..18f464bb0d4 100644 --- a/service/system/test/src/test/java/org/eclipse/kapua/service/systeminfo/test/SystemInfoLocatorConfiguration.java +++ b/service/system/test/src/test/java/org/eclipse/kapua/service/systeminfo/test/SystemInfoLocatorConfiguration.java @@ -16,6 +16,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.name.Names; import io.cucumber.java.Before; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.metatype.KapuaMetatypeFactoryImpl; @@ -56,6 +57,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); // Inject mocked Authorization Service method checkPermission diff --git a/service/tag/test/src/test/java/org/eclipse/kapua/service/tag/test/TagLocatorConfiguration.java b/service/tag/test/src/test/java/org/eclipse/kapua/service/tag/test/TagLocatorConfiguration.java index 9f369dc0efc..1c9bb7fdd84 100644 --- a/service/tag/test/src/test/java/org/eclipse/kapua/service/tag/test/TagLocatorConfiguration.java +++ b/service/tag/test/src/test/java/org/eclipse/kapua/service/tag/test/TagLocatorConfiguration.java @@ -92,6 +92,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); // Inject mocked Authorization Service method checkPermission diff --git a/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java b/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java index 88b246b0b35..85c7300ca49 100644 --- a/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java +++ b/service/user/test/src/test/java/org/eclipse/kapua/service/user/test/UserLocatorConfiguration.java @@ -16,6 +16,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.name.Names; import io.cucumber.java.Before; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.AccountChildrenFinder; @@ -64,6 +65,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); bind(KapuaJpaRepositoryConfiguration.class).toInstance(new KapuaJpaRepositoryConfiguration()); // Inject mocked Authorization Service method checkPermission diff --git a/translator/test/src/test/java/org/eclipse/kapua/translator/test/TranslatorLocatorConfiguration.java b/translator/test/src/test/java/org/eclipse/kapua/translator/test/TranslatorLocatorConfiguration.java index 8a8513becfc..868a82731e7 100644 --- a/translator/test/src/test/java/org/eclipse/kapua/translator/test/TranslatorLocatorConfiguration.java +++ b/translator/test/src/test/java/org/eclipse/kapua/translator/test/TranslatorLocatorConfiguration.java @@ -16,6 +16,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Singleton; +import com.google.inject.name.Names; import io.cucumber.java.Before; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.configuration.metatype.KapuaMetatypeFactoryImpl; @@ -65,6 +66,7 @@ public void setupDI() { @Override protected void configure() { + bind(String.class).annotatedWith(Names.named("metricModuleName")).toInstance("tests"); bind(MetricsService.class).to(MetricsServiceImpl.class).in(Singleton.class); bind(KapuaMessageFactory.class).to(KapuaMessageFactoryImpl.class).in(Singleton.class); // Inject mocked Authorization Service method checkPermission