-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Junit test for classes in: broker/api module: BrokerDomain class BrokerDomains class broker/core/message package: CamelKapuaMessage class CamelUtil class MessageConstants class DefaultSystemMessageCreator class broker/core/plugin/metric package: ClientMetric class LoginMetric class PublishMetric class SecurityMetrics class SubscribeMetric class Signed-off-by: Sonja <sonja.matic@endava.com>
- Loading branch information
Showing
13 changed files
with
694 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
broker/api/src/test/java/org/eclipse/kapua/broker/BrokerDomainTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 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.broker; | ||
|
||
import org.eclipse.kapua.qa.markers.junit.JUnitTests; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category(JUnitTests.class) | ||
public class BrokerDomainTest extends Assert { | ||
|
||
BrokerDomain brokerDomain; | ||
BrokerDomain secondBrokerDomain; | ||
Object[] objects; | ||
|
||
@Before | ||
public void initialize() { | ||
brokerDomain = new BrokerDomain(); | ||
secondBrokerDomain = new BrokerDomain(); | ||
objects = new Object[]{0, 10, 100000, "String", 'c', -10, -1000000000, -100000000000L, 10L, 10.0f, null, 10.10d, true, false}; | ||
} | ||
|
||
@Test | ||
public void getNameTest() { | ||
assertEquals("Expected and actual values should be the same.", "broker", brokerDomain.getName()); | ||
} | ||
|
||
@Test | ||
public void getActionsTest() { | ||
assertEquals("Expected and actual values should be the same.", "[connect]", brokerDomain.getActions().toString()); | ||
} | ||
|
||
@Test | ||
public void getGroupableTest() { | ||
assertFalse("False expected.", brokerDomain.getGroupable()); | ||
} | ||
|
||
@Test | ||
public void equalsTest() { | ||
assertTrue("True expected.", brokerDomain.equals(secondBrokerDomain)); | ||
for (Object object : objects) { | ||
assertFalse("False expected.", brokerDomain.equals(object)); | ||
} | ||
} | ||
|
||
@Test | ||
public void hashCodeTest() { | ||
assertNotNull("NotNull expected.", brokerDomain.hashCode()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
broker/api/src/test/java/org/eclipse/kapua/broker/BrokerDomainsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 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.broker; | ||
|
||
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 BrokerDomainsTest extends Assert { | ||
|
||
@Test | ||
public void brokerDomainsTest() throws Exception { | ||
Constructor<BrokerDomains> brokerDomains = BrokerDomains.class.getDeclaredConstructor(); | ||
assertTrue("True expected.", Modifier.isPrivate(brokerDomains.getModifiers())); | ||
brokerDomains.setAccessible(true); | ||
brokerDomains.newInstance(); | ||
} | ||
|
||
@Test | ||
public void brokerDomainTest() { | ||
BrokerDomain brokerDomain = BrokerDomains.BROKER_DOMAIN; | ||
assertNotNull("NotNull expected.", brokerDomain); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
broker/core/src/test/java/org/eclipse/kapua/broker/core/message/CamelKapuaMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 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.broker.core.message; | ||
|
||
import org.eclipse.kapua.broker.core.plugin.ConnectorDescriptor; | ||
import org.eclipse.kapua.message.KapuaMessage; | ||
import org.eclipse.kapua.model.id.KapuaId; | ||
import org.eclipse.kapua.qa.markers.junit.JUnitTests; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.mockito.Mockito; | ||
|
||
@Category(JUnitTests.class) | ||
public class CamelKapuaMessageTest extends Assert { | ||
|
||
CamelKapuaMessage camelKapuaMessage; | ||
|
||
@Before | ||
public void initialize() { | ||
camelKapuaMessage = new CamelKapuaMessage(null, null, null); | ||
} | ||
|
||
@Test | ||
public void setAndGetMessageTest() { | ||
KapuaMessage kapuaMessage = Mockito.mock(KapuaMessage.class); | ||
|
||
assertNull("Null expected.", camelKapuaMessage.getMessage()); | ||
camelKapuaMessage.setMessage(kapuaMessage); | ||
assertEquals("Expected and actual values should be the same.", kapuaMessage, camelKapuaMessage.getMessage()); | ||
camelKapuaMessage.setMessage(null); | ||
assertNull("Null expected.", camelKapuaMessage.getMessage()); | ||
} | ||
|
||
@Test | ||
public void setAndGetConnectionIdTest() { | ||
KapuaId connectionId = KapuaId.ONE; | ||
|
||
assertNull("Null expected.", camelKapuaMessage.getConnectionId()); | ||
camelKapuaMessage.setConnectionId(connectionId); | ||
assertEquals("Expected and actual values should be the same.", connectionId, camelKapuaMessage.getConnectionId()); | ||
camelKapuaMessage.setConnectionId(null); | ||
assertNull("Null expected.", camelKapuaMessage.getConnectionId()); | ||
} | ||
|
||
@Test | ||
public void setAndGetConnectorDescriptorTest() { | ||
ConnectorDescriptor descriptor = Mockito.mock(ConnectorDescriptor.class); | ||
|
||
assertNull("Null expected.", camelKapuaMessage.getConnectorDescriptor()); | ||
camelKapuaMessage.setConnectorDescriptor(descriptor); | ||
assertEquals("Expected and actual values should be the same.", descriptor, camelKapuaMessage.getConnectorDescriptor()); | ||
camelKapuaMessage.setConnectorDescriptor(null); | ||
assertNull("Null expected.", camelKapuaMessage.getConnectorDescriptor()); | ||
} | ||
|
||
@Test | ||
public void setAndGetDatastoreIdTest() { | ||
String[] dataStoreIds = {null, "", "1", "awsd", "123123123", "-123", "ASDa12$%~", "~ˇ#$%&/()=?*\\", "DSUrCucsvb2qUwbdD5yyiCC5v1wwF5FmBIcWa2oXafNw5bqV2RAcyyN0gCHQTdL2JedME5A4PXsXt7iHekhys52GZVmiCNcA065RxFEsDasCcaH1dzeRioRvA14NoJPGmScHdHf8Mfzv03vWrs7n2W59f1In9NdUtnaxY1Wp5TjknB6X8U5ZRczLntQZNX3MSu5f4OzF29oTtuDcuPIUal6OBTKnm8qLVhsiu3oMK3YnFhoHuiATBk3Pl0q9LaL"}; | ||
|
||
assertNull("Null expected.", camelKapuaMessage.getDatastoreId()); | ||
for (String id : dataStoreIds) { | ||
camelKapuaMessage.setDatastoreId(id); | ||
assertEquals("Expected and actual values should be the same.", id, camelKapuaMessage.getDatastoreId()); | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
broker/core/src/test/java/org/eclipse/kapua/broker/core/message/CamelUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 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.broker.core.message; | ||
|
||
import org.apache.activemq.command.ActiveMQDestination; | ||
import org.apache.activemq.command.ActiveMQTopic; | ||
import org.apache.camel.impl.DefaultMessage; | ||
import org.eclipse.kapua.broker.core.listener.CamelConstants; | ||
import org.eclipse.kapua.qa.markers.junit.JUnitTests; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.mockito.Mockito; | ||
|
||
import javax.jms.JMSException; | ||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Modifier; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Category(JUnitTests.class) | ||
public class CamelUtilTest extends Assert { | ||
|
||
@Test | ||
public void camelUtilTest() throws Exception { | ||
Constructor<CamelUtil> camelUtil = CamelUtil.class.getDeclaredConstructor(); | ||
assertTrue("True expected.", Modifier.isPrivate(camelUtil.getModifiers())); | ||
camelUtil.setAccessible(true); | ||
camelUtil.newInstance(); | ||
} | ||
|
||
@Test(expected = NullPointerException.class) | ||
public void getTopicNullTest() throws JMSException { | ||
CamelUtil.getTopic(null); | ||
} | ||
|
||
@Test | ||
public void getTopicTest() throws JMSException { | ||
org.apache.camel.Message message = new DefaultMessage(); | ||
Map<String, Object> map = new HashMap(); | ||
map.put("originalTopic", "testTopic"); | ||
message.setHeaders(map); | ||
String topic = CamelUtil.getTopic(message); | ||
assertEquals("Expected and actual values should be the same.", "testTopic", topic); | ||
} | ||
|
||
@Test | ||
public void getTopicWithActiveMQTopicTest() throws JMSException { | ||
org.apache.camel.Message message = new DefaultMessage(); | ||
Map<String, Object> map = new HashMap(); | ||
map.put(CamelConstants.JMS_HEADER_DESTINATION, new ActiveMQTopic("VirtualTopic.Topic")); | ||
message.setHeaders(map); | ||
String topic = CamelUtil.getTopic(message); | ||
assertEquals("Expected and actual values should be the same.", "Topic", topic); | ||
} | ||
|
||
@Test | ||
public void getTopicWithActiveMQDestinationTest() { | ||
org.apache.camel.Message message = new DefaultMessage(); | ||
Map<String, Object> map = new HashMap(); | ||
map.put(MessageConstants.PROPERTY_ORIGINAL_TOPIC, null); | ||
map.put(CamelConstants.JMS_HEADER_DESTINATION, Mockito.mock(ActiveMQDestination.class)); | ||
message.setHeaders(map); | ||
try { | ||
CamelUtil.getTopic(message); | ||
fail("JMSException expected."); | ||
} catch (Exception e) { | ||
assertTrue("True expected.", e.getMessage().contains("Unable to extract the destination. Wrong destination Mock for ActiveMQDestination")); | ||
} | ||
} | ||
|
||
@Test | ||
public void getTopicNullDestinationTest() { | ||
org.apache.camel.Message message = new DefaultMessage(); | ||
Map<String, Object> map = new HashMap(); | ||
map.put(MessageConstants.PROPERTY_ORIGINAL_TOPIC, null); | ||
map.put(CamelConstants.JMS_HEADER_DESTINATION, null); | ||
message.setHeaders(map); | ||
try { | ||
CamelUtil.getTopic(message); | ||
fail("JMSException expected."); | ||
} catch (Exception e) { | ||
assertEquals("Expected and actual values should be the same.", new JMSException("Unable to extract the destination. Wrong destination null").toString(), e.toString()); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
broker/core/src/test/java/org/eclipse/kapua/broker/core/message/MessageConstantsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 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.broker.core.message; | ||
|
||
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 MessageConstantsTest extends Assert { | ||
|
||
@Test | ||
public void messageConstantsTest() throws Exception { | ||
Constructor<MessageConstants> messageConstants = MessageConstants.class.getDeclaredConstructor(); | ||
assertTrue("True expected.", Modifier.isPrivate(messageConstants.getModifiers())); | ||
messageConstants.setAccessible(true); | ||
messageConstants.newInstance(); | ||
} | ||
|
||
@Test | ||
public void constantsTest() { | ||
assertEquals("Expected and actual values should be the same.", "username", MessageConstants.METRIC_USERNAME); | ||
assertEquals("Expected and actual values should be the same.", "account", MessageConstants.METRIC_ACCOUNT); | ||
assertEquals("Expected and actual values should be the same.", "clientId", MessageConstants.METRIC_CLIENT_ID); | ||
assertEquals("Expected and actual values should be the same.", "ip", MessageConstants.METRIC_IP); | ||
assertEquals("Expected and actual values should be the same.", "originalTopic", MessageConstants.PROPERTY_ORIGINAL_TOPIC); | ||
assertEquals("Expected and actual values should be the same.", "enqueuedTimestamp", MessageConstants.PROPERTY_ENQUEUED_TIMESTAMP); | ||
assertEquals("Expected and actual values should be the same.", "brokerId", MessageConstants.PROPERTY_BROKER_ID); | ||
assertEquals("Expected and actual values should be the same.", "clientId", MessageConstants.PROPERTY_CLIENT_ID); | ||
assertEquals("Expected and actual values should be the same.", "scopeId", MessageConstants.PROPERTY_SCOPE_ID); | ||
assertEquals("Expected and actual values should be the same.", "userId", MessageConstants.METRIC_USER_ID); | ||
assertEquals("Expected and actual values should be the same.", "nodeId", MessageConstants.METRIC_NODE_ID); | ||
assertEquals("Expected and actual values should be the same.", "KAPUA_CONNECTION_ID", MessageConstants.HEADER_KAPUA_CONNECTION_ID); | ||
assertEquals("Expected and actual values should be the same.", "KAPUA_RECEIVED_TIMESTAMP", MessageConstants.HEADER_KAPUA_RECEIVED_TIMESTAMP); | ||
assertEquals("Expected and actual values should be the same.", "KAPUA_CLIENT_ID", MessageConstants.HEADER_KAPUA_CLIENT_ID); | ||
assertEquals("Expected and actual values should be the same.", "KAPUA_DEVICE_PROTOCOL", MessageConstants.HEADER_KAPUA_CONNECTOR_DEVICE_PROTOCOL); | ||
assertEquals("Expected and actual values should be the same.", "KAPUA_SESSION", MessageConstants.HEADER_KAPUA_SESSION); | ||
assertEquals("Expected and actual values should be the same.", "KAPUA_BROKER_CONTEXT", MessageConstants.HEADER_KAPUA_BROKER_CONTEXT); | ||
assertEquals("Expected and actual values should be the same.", "KAPUA_PROCESSING_EXCEPTION", MessageConstants.HEADER_KAPUA_PROCESSING_EXCEPTION); | ||
} | ||
} |
Oops, something went wrong.