Skip to content

Commit

Permalink
Merge pull request #3272 from gbarbon/fix-KapuaLifeCycleConverterTest
Browse files Browse the repository at this point in the history
Fixed KapuaLifeCycleConverterTest (JUnit tests)
  • Loading branch information
Coduz authored Mar 12, 2021
2 parents 3389a91 + e6e92fe commit f6ac4d3
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.kapua.broker.core.plugin.ConnectorDescriptor;
import org.eclipse.kapua.broker.core.plugin.ConnectorDescriptorProvider;
import org.eclipse.kapua.broker.core.plugin.ConnectorDescriptorProviders;
import org.eclipse.kapua.broker.core.utils.Utils;
import org.eclipse.kapua.commons.metric.MetricServiceFactory;
import org.eclipse.kapua.message.KapuaMessage;
import org.eclipse.kapua.model.id.KapuaId;
Expand All @@ -34,6 +35,7 @@
import org.eclipse.kapua.transport.message.jms.JmsPayload;
import org.eclipse.kapua.transport.message.jms.JmsTopic;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -68,6 +70,7 @@ public void initialize() throws TranslateException {
exchange = Mockito.mock(Exchange.class);
camelKapuaMessage = Mockito.mock(CamelKapuaMessage.class);
converterDeviceManagementNotificationMessage = MetricServiceFactory.getInstance().getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_NOTIFY, ConverterMetrics.METRIC_COUNT);
Utils.initCounter(converterDeviceManagementNotificationMessage);
provider = ConnectorDescriptorProviders.getInstance();
connectorDescriptor = provider.getDescriptor("foo");
connectorDescriptorBytes = SerializationUtils.serialize(connectorDescriptor);
Expand All @@ -87,6 +90,11 @@ public void initialize() throws TranslateException {
messageKapua = translator2.translate(jmsMessage);
}

@After
public void tearDown() {
Utils.initCounter(converterDeviceManagementNotificationMessage);
}

@Test
public void convertToManagementNotificationNullTest() {
assertEquals("Expected and actual values should be the same.", 0L, converterDeviceManagementNotificationMessage.getCount());
Expand All @@ -98,7 +106,6 @@ public void convertToManagementNotificationNullTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDeviceManagementNotificationMessage.getCount());

converterDeviceManagementNotificationMessage.dec();
}

@Test
Expand All @@ -112,7 +119,6 @@ public void convertToManagementNotificationNullExchangeTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDeviceManagementNotificationMessage.getCount());

converterDeviceManagementNotificationMessage.dec();
}

@Test
Expand All @@ -128,7 +134,6 @@ public void convertToManagementNotificationNullValueTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDeviceManagementNotificationMessage.getCount());

converterDeviceManagementNotificationMessage.dec();
}

@Test
Expand Down Expand Up @@ -164,7 +169,6 @@ public void convertToManagementNotificationOnExceptionNullTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDeviceManagementNotificationMessage.getCount());

converterDeviceManagementNotificationMessage.dec();
}

@Test
Expand All @@ -177,7 +181,6 @@ public void convertToManagementNotificationOnExceptionNullExchangeTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDeviceManagementNotificationMessage.getCount());

converterDeviceManagementNotificationMessage.dec();
}

@Test
Expand All @@ -193,7 +196,6 @@ public void convertToManagementNotificationOnExceptionNullObjectTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDeviceManagementNotificationMessage.getCount());

converterDeviceManagementNotificationMessage.dec();
}

@Test
Expand All @@ -206,7 +208,6 @@ public void convertToManagementNotificationOnExceptionCamelMessageTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDeviceManagementNotificationMessage.getCount());

converterDeviceManagementNotificationMessage.dec();
}

@Test
Expand All @@ -230,6 +231,5 @@ public void convertToManagementNotificationOnExceptionObjectMessageTest() throws
}
assertEquals("Expected and actual values should be the same.", 1L, converterDeviceManagementNotificationMessage.getCount());

converterDeviceManagementNotificationMessage.dec();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.kapua.broker.core.plugin.ConnectorDescriptor;
import org.eclipse.kapua.broker.core.plugin.ConnectorDescriptorProvider;
import org.eclipse.kapua.broker.core.plugin.ConnectorDescriptorProviders;
import org.eclipse.kapua.broker.core.utils.Utils;
import org.eclipse.kapua.commons.metric.MetricServiceFactory;
import org.eclipse.kapua.message.KapuaMessage;
import org.eclipse.kapua.model.id.KapuaId;
Expand All @@ -35,6 +36,7 @@
import org.eclipse.kapua.transport.message.jms.JmsPayload;
import org.eclipse.kapua.transport.message.jms.JmsTopic;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -73,6 +75,7 @@ public void initialize() throws TranslateException {
kapuaDataConverter = new KapuaDataConverter();
message = Mockito.mock(Message.class);
converterDataMessage = MetricServiceFactory.getInstance().getCounter(ConverterMetrics.METRIC_MODULE_NAME, ConverterMetrics.METRIC_COMPONENT_NAME, ConverterMetrics.METRIC_KAPUA_MESSAGE, ConverterMetrics.METRIC_MESSAGES, ConverterMetrics.METRIC_DATA, ConverterMetrics.METRIC_COUNT);
Utils.initCounter(converterDataMessage);
provider = ConnectorDescriptorProviders.getInstance();
connectorDescriptor = provider.getDescriptor("foo");
connectorDescriptorBytes = SerializationUtils.serialize(connectorDescriptor);
Expand All @@ -92,6 +95,11 @@ public void initialize() throws TranslateException {
translator2.translate(jmsMessage);
}

@After
public void tearDown() {
Utils.initCounter(converterDataMessage);
}

@Test
public void convertToDataNullTest() {
assertEquals("Expected and actual values should be the same.", 0L, converterDataMessage.getCount());
Expand All @@ -102,7 +110,6 @@ public void convertToDataNullTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -115,7 +122,6 @@ public void convertToDataNullExchangeTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -130,7 +136,6 @@ public void convertToNullValueData() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -154,7 +159,6 @@ public void convertToDataTest() throws KapuaException {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -169,7 +173,6 @@ public void convertToDataObjectValueTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -182,7 +185,6 @@ public void convertToDataOnExceptionNullTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -195,7 +197,6 @@ public void convertToDataOnExceptionNullExchangeTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -210,7 +211,6 @@ public void convertToDataOnExceptionNullValueData() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -220,7 +220,6 @@ public void convertToDataOnExceptionEmptyDatastoreIdTest() throws KapuaException
assertNull("Null expected.", kapuaDataConverter.convertToDataOnException(exchange, camelKapuaMessage).getDatastoreId());
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -231,7 +230,6 @@ public void convertToDataOnExceptionCamelKapuaMessageValueTest() throws KapuaExc
assertEquals("Expected and actual values should be the same.", "message", kapuaDataConverter.convertToDataOnException(exchange, camelKapuaMessage).getDatastoreId());
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -246,7 +244,6 @@ public void convertToDataOnExceptionObjectValueTest() {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}

@Test
Expand All @@ -270,6 +267,5 @@ public void convertToDataOnExceptionTest() throws KapuaException {
}
assertEquals("Expected and actual values should be the same.", 1L, converterDataMessage.getCount());

converterDataMessage.dec();
}
}
}
Loading

0 comments on commit f6ac4d3

Please sign in to comment.