Skip to content

Commit

Permalink
:fix: test wiring
Browse files Browse the repository at this point in the history
Signed-off-by: dseurotech <[email protected]>
  • Loading branch information
dseurotech committed Aug 22, 2023
1 parent a74b21a commit e72dcdf
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,33 +48,41 @@ public List<KapuaService> getServices() {

@Override
public <T> T getComponent(Class<T> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
1 change: 1 addition & 0 deletions qa/integration/src/test/resources/locator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</provide>
</provided>
<packages>
<package>org.eclipse.kapua.integration.misc</package>
<package>org.eclipse.kapua.commons</package>
<package>org.eclipse.kapua.job.engine.client</package>
<package>org.eclipse.kapua.message</package>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,33 +48,41 @@ public List<KapuaService> getServices() {

@Override
public <T> T getComponent(Class<T> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
1 change: 1 addition & 0 deletions service/account/internal/src/test/resources/locator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</provided>

<packages>
<package>org.eclipse.kapua.service.account.xml</package>
<package>org.eclipse.kapua.commons</package>
</packages>
</locator-config>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,33 +48,41 @@ public List<KapuaService> getServices() {

@Override
public <T> T getComponent(Class<T> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit e72dcdf

Please sign in to comment.