Search in sources :

Example 6 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class SSLCertMonitorIT method testExpiringDateForCertificate.

@Test
@JUnitHttpServer(port = 10342, https = true)
public void testExpiringDateForCertificate() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor() {

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 4);
            return cal;
        }
    };
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "10342");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isUnavailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 7 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class SSLCertMonitorIT method testHostNameVerificationSucceeds.

@Test
@JUnitHttpServer(port = 10342, https = true, vhosts = "test.example.com")
public void testHostNameVerificationSucceeds() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor() {

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 5);
            return cal;
        }
    };
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "10342");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    parameters.put("server-name", "${nodelabel}.example.com");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "test", DnsUtils.resolveHostname("localhost", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isAvailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 8 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project opennms by OpenNMS.

the class SSLCertMonitorIT method testValidDateForCertificate.

@Test
@JUnitHttpServer(port = 10342, https = true)
public void testValidDateForCertificate() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor() {

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 5);
            return cal;
        }
    };
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "10342");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isAvailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 9 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.

the class MqttDeviceMethodTest method receiveSucceeds.

/*
    Tests_SRS_MqttDeviceMethod_25_024: [**This method shall call parseTopic to parse the topic from the received Messages queue looking for presence of $iothub/methods/ in the topics .**]**
    Tests_SRS_MqttDeviceMethod_25_026: [**This method shall call parsePayload to get the message payload from the recevived Messages queue corresponding to the messaging client's operation.**]**
    Tests_SRS_MqttDeviceMethod_25_028: [**If the topic is of type post topic then this method shall parse further for method name and set it for the message by calling setMethodName for the message**]**
    Tests_SRS_MqttDeviceMethod_25_030: [**If the topic is of type post topic then this method shall parse further to look for request id which if found is set by calling setRequestId**]**
    Tests_SRS_MqttDeviceMethod_25_032: [**If the topic is of type post topic and if method name and request id has been successfully parsed then this method shall set operation type as DEVICE_OPERATION_METHOD_RECEIVE_REQUEST **]**
     */
@Test
public void receiveSucceeds() throws IOException {
    //arrange
    String topic = "$iothub/methods/POST/testMethod/?$rid=10";
    byte[] actualPayload = "TestPayload".getBytes();
    ConcurrentSkipListMap<String, byte[]> testAllReceivedMessages = new ConcurrentSkipListMap<>();
    testAllReceivedMessages.put(topic, actualPayload);
    Deencapsulation.setField(mockedMqtt, "allReceivedMessages", testAllReceivedMessages);
    MqttDeviceMethod testMethod = new MqttDeviceMethod();
    testMethod.start();
    //act
    Message testMessage = testMethod.receive();
    DeviceMethodMessage testDMMessage = (DeviceMethodMessage) testMessage;
    //assert
    assertNotNull(testMessage);
    assertTrue(testMessage.getMessageType().equals(MessageType.DeviceMethods));
    assertTrue(testDMMessage.getRequestId().equals(String.valueOf(10)));
    assertTrue(testDMMessage.getMethodName().equals("testMethod"));
    assertTrue(testDMMessage.getDeviceOperationType().equals(DEVICE_OPERATION_METHOD_RECEIVE_REQUEST));
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Message(com.microsoft.azure.sdk.iot.device.Message) DeviceMethodMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage) DeviceMethodMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceMethodMessage) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Test(org.junit.Test)

Example 10 with ConcurrentSkipListMap

use of java.util.concurrent.ConcurrentSkipListMap in project azure-iot-sdk-java by Azure.

the class MqttDeviceTwinTest method receiveParsesPatchTopicForDesiredPropertiesNotificationSucceeds.

/*
    **Tests_SRS_MQTTDEVICETWIN_25_042: [**If the topic is of type patch for desired properties then this method shall parse further to look for version which if found is set by calling setVersion**]**
     */
@Test
public void receiveParsesPatchTopicForDesiredPropertiesNotificationSucceeds(@Mocked final Mqtt mockMqtt) throws IOException {
    final byte[] actualPayload = "UpdateDesiredPropertiesNotificationData".getBytes();
    final String expectedTopic = "$iothub/twin/PATCH/properties/desired/" + "?$version=" + mockVersion;
    DeviceTwinMessage receivedMessage = null;
    try {
        //arrange
        MqttDeviceTwin testTwin = new MqttDeviceTwin();
        String insertTopic = expectedTopic;
        ConcurrentSkipListMap<String, byte[]> testMap = new ConcurrentSkipListMap<String, byte[]>();
        testMap.put(insertTopic, actualPayload);
        Deencapsulation.setField(mockMqtt, "allReceivedMessages", testMap);
        //act
        receivedMessage = (DeviceTwinMessage) testTwin.receive();
    } finally {
        //assert
        assertNotNull(receivedMessage);
        assertTrue(receivedMessage.getMessageType() == MessageType.DeviceTwin);
        assertTrue(receivedMessage.getDeviceOperationType() == DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
        assertTrue(receivedMessage.getVersion().equals(mockVersion));
        assertTrue(receivedMessage.getRequestId() == null);
        assertTrue(receivedMessage.getStatus() == null);
    }
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) DeviceTwinMessage(com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Aggregations

ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)183 Test (org.junit.Test)66 PollStatus (org.opennms.netmgt.poller.PollStatus)32 MonitoredService (org.opennms.netmgt.poller.MonitoredService)31 Map (java.util.Map)30 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)25 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)23 HashMap (java.util.HashMap)21 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)17 NavigableMap (java.util.NavigableMap)14 Set (java.util.Set)12 Iterator (java.util.Iterator)11 NavigableSet (java.util.NavigableSet)11 MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)11 IOException (java.io.IOException)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)10 ArrayList (java.util.ArrayList)9 BitSet (java.util.BitSet)9 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)8