diff options
Diffstat (limited to 'sdnr/wt/websocketmanager/provider/src/test')
13 files changed, 787 insertions, 0 deletions
diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java new file mode 100644 index 000000000..f3cf09545 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Paths; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.AkkaConfig; + +public class AkkaConfigTest { + + @Test + public void test() throws URISyntaxException, IOException { + + AkkaConfig config = null; + try { + //config = AkkaConfig.load("akka-singlenode.cfg", true); + config = AkkaConfig.loadContent(loadResourceContentAsString("akka-singlenode.cfg")); + } catch (Exception e) { + e.printStackTrace(); + fail("error loading singlenode config"); + } + assertEquals("no singlenode config detected", false, config.isCluster()); + assertEquals("more than one node detected", 1, config.getClusterConfig().getSeedNodes().size()); + + try { + config = AkkaConfig.loadContent(loadResourceContentAsString("akka-cluster.cfg")); + } catch (Exception e) { + fail("error loading cluster config"); + } + assertEquals("no cluster config detected", true, config.isCluster()); + assertTrue("only one node detected", config.getClusterConfig().getSeedNodes().size() > 1); + } + + public static String loadResourceContentAsString(String resourceName) + throws URISyntaxException, FileNotFoundException, IOException { + + StringBuilder sb = new StringBuilder(); + + ClassLoader classLoader = AkkaConfigTest.class.getClassLoader(); + File file = Paths.get(classLoader.getResource(resourceName).toURI()).toFile(); + try (BufferedReader br = new BufferedReader(new FileReader(file))) { + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append(System.lineSeparator()); + line = br.readLine(); + } + } + return sb.toString(); + } +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/RateFilterTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/RateFilterTest.java new file mode 100644 index 000000000..f4fab6810 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/RateFilterTest.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import java.time.Duration; +import java.time.Instant; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.RateFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * {@link #RateFilter} Problems of to many notifications during mount of thousand of devices. + * + * <pre> + * Testcase (e: 17 Event received, rateMaxCount=3) + * eee e e e e e e e e e e e e e e + * ---//--|--------------|-----//-------|--------------|--------------|--------------|---//----|--------------| + * P1:1 P2:1 P1:2 P2:2 P3:2 P4:2 P1:3 + * 1000-1002 2000 3500 10 millis + *Overload no no yes yes no no + * </pre> + * + */ +public class RateFilterTest { + + private static final Logger LOG = LoggerFactory.getLogger(RateFilterTest.class.getName()); + + private static int MILLIS = 1000; + private static long[] now = { 1000, 1001, 1002, //P1:1 0-2 + 3500, 3550, 3560, 3570, 3580, 3590, 3800, //P1:2 3500 3-9 + 4510, 4520, 4530, 4540, 4900, //P2:2 4500 10-14 + 5700, //P3:2 5500 15 + 7000, 8000};//P1:3 16-17 + private static int idx; + + @Test + public void test() { + RateFilter rateFilter = new RateFilter(Duration.ofMillis(MILLIS), 4, () -> getNow()); + LOG.info("Init done"); + + for (int t=0; t < 20; t++) { + LOG.info("{}", t); + rateFilter.filterEvent(); + LOG.info("{}", rateFilter.getOverloadStatus()); + } + + } + + Instant getNow() { + long res; + if (idx < now.length) { + res = now[idx]; + } else { + int lastIdx = now.length - 1; + res = now[lastIdx] + (idx - lastIdx) * MILLIS; + } + idx++; + return Instant.ofEpochMilli(res); + } + +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestDeserialize.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestDeserialize.java new file mode 100644 index 000000000..8c7b451fe --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestDeserialize.java @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import static org.junit.Assert.fail; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.ScopeRegistration; +import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper; + +public class TestDeserialize { + + private static final String SCOPE_REGISTRATION_JSON = "{\n" + " \"data\":\"scopes\",\n" + " \"scopes\":[\n" + + " {\n" + " \"node-id\":\"ROADM-A\",\n" + " \"schema\":{\n" + + " \"namespace\":\"onf:params:xml:ns:yang:microwave-model\",\n" + + " \"revision\":\"2018-10-10\",\n" + " \"notification\":[\"problem-notification\"]\n" + + " }\n" + " }\n" + " ]\n" + "}"; + private static final String SCOPE_REGISTRATION2_JSON = "{\n" + " \"data\":\"scopes\",\n" + " \"scopes\":[\n" + + " {\n" + " \"node-id\":\"ROADM-A\",\n" + " \"schema\":{\n" + + " \"namespace\":\"onf:params:xml:ns:yang:microwave-model\",\n" + + " \"revision\":\"2018-10-10\",\n" + " \"notification\":[\"problem-notification\"]\n" + + " }\n" + " }\n" + " ],\n" + " \"ratio\":\"120/min\"\n" + "}"; + private static final String SCOPE_REGISTRATION3_INVALID_JSON = "{\n" + " \"data\":\"scopes\",\n" + + " \"scopes\":[\n" + " {\n" + " \"node-id\":\"ROADM-A\",\n" + " \"schema\":{\n" + + " \"namespace\":\"onf:params:xml:ns:yang:microwave-model\",\n" + + " \"revision\":\"2018-10-10\",\n" + " \"notification\":[\"problem-notification\"]\n" + + " }\n" + " }\n" + " ],\n" + " \"ratio\":\"120/sec\"\n" + "}"; + + @Test + public void testScopeRegistration() { + YangToolsMapper mapper = new YangToolsMapper(); + ScopeRegistration obj = null; + try { + obj = mapper.readValue(SCOPE_REGISTRATION_JSON, ScopeRegistration.class); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + System.out.println(obj); + } + + @Test + public void testScopeRegistration2() { + YangToolsMapper mapper = new YangToolsMapper(); + ScopeRegistration obj = null; + try { + obj = mapper.readValue(SCOPE_REGISTRATION2_JSON, ScopeRegistration.class); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + System.out.println(obj); + } + + @Test + public void testScopeRegistration3() { + YangToolsMapper mapper = new YangToolsMapper(); + try { + mapper.readValue(SCOPE_REGISTRATION3_INVALID_JSON, ScopeRegistration.class); + } catch (JsonProcessingException | IllegalArgumentException e) { + // e.printStackTrace(); + return; + } + fail("json should not contain a valid ratio"); + } +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestSerializer.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestSerializer.java new file mode 100644 index 000000000..962838489 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/TestSerializer.java @@ -0,0 +1,59 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.NotificationOutput; +import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotification; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotificationBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestSerializer { + + private static final Logger LOG = LoggerFactory.getLogger(TestSerializer.class); + private static final YangToolsMapper mapper = new YangToolsMapper(); + private static final String TIMESTAMP = "2020-04-01T10:20:40.0Z"; + private static final String NODEID = "node1"; + + @Test + public void test1() { + ObjectCreationNotification notification = new ObjectCreationNotificationBuilder().setCounter(Integer.valueOf(5)).build(); + NotificationOutput output = new NotificationOutput(notification, NODEID, ObjectCreationNotification.QNAME,DateAndTime.getDefaultInstance(TIMESTAMP)); + String sOutput=null; + try { + sOutput = mapper.writeValueAsString(output); + LOG.debug(sOutput); + } catch (JsonProcessingException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + assertNotNull(sOutput); + assertTrue(sOutput.contains("\"type\"")); + } +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java new file mode 100644 index 000000000..d21bb529c --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java @@ -0,0 +1,61 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.ReducedSchemaInfo; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.SchemaInfo; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.Scope; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.UserScopes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotification; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ProblemNotification; +import org.opendaylight.yangtools.yang.common.QName; + +public class UserScopeTest { + + private static final String SCOPE1 = "problem-notification"; + private static final String SCOPE2 = "scope2"; + private static final String SCOPE3 = "scope3"; + private static final String SCOPE4 = "scope4"; + + @Test + public void test() { + UserScopes scopes1 = new UserScopes(); + List<String> json1 = Arrays.asList(SCOPE1, SCOPE2, SCOPE3); + scopes1.setScopes(Arrays.asList(buildScope(null, ProblemNotification.QNAME))); + + assertTrue(scopes1.hasScope(new ReducedSchemaInfo(ProblemNotification.QNAME))); + assertFalse(scopes1.hasScope("RoadmA", new ReducedSchemaInfo(ObjectCreationNotification.QNAME))); + + assertTrue(scopes1.hasScope("RoadmA", new ReducedSchemaInfo(ProblemNotification.QNAME))); + + } + + + private static final Scope buildScope(String nodeId, QName qname) { + Scope scope = new Scope(); + scope.setNodeId(nodeId); + scope.setSchema(new SchemaInfo(qname)); + return scope; + } + +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java new file mode 100644 index 000000000..bc3cd10f8 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import static org.junit.Assert.fail; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.WebSocketManagerProvider; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.osgi.service.http.HttpService; + +public class WebsockerProviderTest extends Mockito { + + @Test + public void test() { + RpcProviderService rpcProviderServiceMock = mock(RpcProviderService.class); + HttpService httpService = mock(HttpService.class); + + try (WebSocketManagerProvider provider = new WebSocketManagerProvider();) { + provider.init(); + provider.onBindService(httpService); + provider.close(); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + } + +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketClientTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketClientTest.java new file mode 100644 index 000000000..0ef1bff63 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketClientTest.java @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import static org.junit.Assert.fail; +import org.java_websocket.handshake.ServerHandshake; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.websocket.SyncWebSocketClient; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.websocket.SyncWebSocketClient.WebsocketEventHandler; + +public class WebsocketClientTest extends Mockito { + + @Test + public void test() { + + WebsocketEventHandler clientHandlerMock = mock(WebsocketEventHandler.class); + ServerHandshake serverHandshakeMock = mock(ServerHandshake.class); + + try { + SyncWebSocketClient client = new SyncWebSocketClient("url"); + + client.addEventHandler(clientHandlerMock); + client.onMessage("TestMessage"); + client.onOpen(serverHandshakeMock); + client.close(); + } catch (Exception e) { + e.printStackTrace(); + fail("Exception " + e.getMessage()); + } + } + +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketMessageTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketMessageTest.java new file mode 100644 index 000000000..e029150fa --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketMessageTest.java @@ -0,0 +1,83 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.net.InetSocketAddress; +import org.eclipse.jetty.websocket.api.Session; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.WebSocketManagerSocket; + +public class WebsocketMessageTest { + + private static final String MSG1 = "{\"data\":\"scopes\",\"scopes\":[{\"node-id\":\"scope1\"}]}"; + private static final String MSG1_RESPONSE = "{\"status\":\"success\",\"scopes\":[{\"node-id\":\"scope1\"}]}"; + private static final String MSG2 = "{}"; + private static final String MSG3 = "{\n" + + " \"event-time\": \"2021-03-12T05:08:55.3Z\",\n" + + " \"type\": \"urn:opendaylight:params:xml:ns:yang:devicemanager@2019-01-09:object-creation-notification\",\n" + + " \"node-id\": \"SDN-Controller-0\",\n" + + " \"data\": {\n" + + " \"object-id-ref\": \"sim1\",\n" + + " \"counter\": 7,\n" + + " \"time-stamp\": \"2021-03-12T05:08:55.2Z\"\n" + + " }\n" + + "}"; + private static final String MSG4 = "{ Not correct messga}"; + + @Test + public void test() { + MyWebSocketManagerSocket socketToTest = new MyWebSocketManagerSocket(); + Session sess = mock(Session.class); + InetSocketAddress remoteAdr = new InetSocketAddress("127.0.0.1", 4444); + when(sess.getRemoteAddress()).thenReturn(remoteAdr); + socketToTest.onWebSocketConnect(sess); + // message from client + socketToTest.setExpected(MSG1_RESPONSE); + socketToTest.onWebSocketText(MSG1); + socketToTest.setExpected(MSG2); + socketToTest.onWebSocketText(MSG2); + socketToTest.setExpected(MSG3); + socketToTest.onWebSocketText(MSG3); + socketToTest.setExpected(MSG4); + socketToTest.onWebSocketText(MSG4); + socketToTest.onWebSocketClose(0, "by default"); + sess.close(); + + } + + private static class MyWebSocketManagerSocket extends WebSocketManagerSocket { + + private String expected; + + public MyWebSocketManagerSocket() {} + + void setExpected(String expected) { + this.expected = expected; + } + + @Override + public void send(String msg) { + System.out.println(msg); + assertTrue("Expected '" + expected + "' answer '" + msg + "'", msg.contains(expected)); + } + + } +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketServerConnectTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketServerConnectTest.java new file mode 100644 index 000000000..b9869419e --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketServerConnectTest.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ +package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test; + +import static org.junit.Assert.fail; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.AkkaConfig; + +public class WebsocketServerConnectTest { + + private static final String XML1 = "<notification></notification>"; + private static final String NODENAME = "abc"; + private static final String EVENTTYPE = "test"; + protected boolean responseReceived; + + @Test + public void test() { + responseReceived = false; + AkkaConfig config = null; + try { + // config = AkkaConfig.load("akka-singlenode.cfg", true); + config = AkkaConfig.loadContent(AkkaConfigTest.loadResourceContentAsString("akka-cluster-local.cfg")); + } catch (Exception e) { + e.printStackTrace(); + fail("error loading singlenode config"); + } + + } + +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/resources/akka-cluster-local.cfg b/sdnr/wt/websocketmanager/provider/src/test/resources/akka-cluster-local.cfg new file mode 100644 index 000000000..465dcad83 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/resources/akka-cluster-local.cfg @@ -0,0 +1,49 @@ +odl-cluster-data { + akka { + remote { + artery { + enabled = off + canonical.hostname = "192.168.178.143" + canonical.port = 2550 + } + netty.tcp { + hostname = "192.168.178.143" + port = 2550 + } + # when under load we might trip a false positive on the failure detector + # transport-failure-detector { + # heartbeat-interval = 4 s + # acceptable-heartbeat-pause = 16s + # } + } + + cluster { + # Remove ".tcp" when using artery. + seed-nodes = ["akka.tcp://opendaylight-cluster-data@192.168.178.142:2550", + "akka.tcp://opendaylight-cluster-data@192.168.178.143:2550", + "akka.tcp://opendaylight-cluster-data@192.168.178.144:2550", + "akka.tcp://opendaylight-cluster-data@192.168.178.145:2550"] + + roles = ["member-2"] + + } + + persistence { + # By default the snapshots/journal directories live in KARAF_HOME. You can choose to put it somewhere else by + # modifying the following two properties. The directory location specified may be a relative or absolute path. + # The relative path is always relative to KARAF_HOME. + + # snapshot-store.local.dir = "target/snapshots" + # journal.leveldb.dir = "target/journal" + + journal { + leveldb { + # Set native = off to use a Java-only implementation of leveldb. + # Note that the Java-only version is not currently considered by Akka to be production quality. + + # native = off + } + } + } + } +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/resources/akka-cluster.cfg b/sdnr/wt/websocketmanager/provider/src/test/resources/akka-cluster.cfg new file mode 100644 index 000000000..465dcad83 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/resources/akka-cluster.cfg @@ -0,0 +1,49 @@ +odl-cluster-data { + akka { + remote { + artery { + enabled = off + canonical.hostname = "192.168.178.143" + canonical.port = 2550 + } + netty.tcp { + hostname = "192.168.178.143" + port = 2550 + } + # when under load we might trip a false positive on the failure detector + # transport-failure-detector { + # heartbeat-interval = 4 s + # acceptable-heartbeat-pause = 16s + # } + } + + cluster { + # Remove ".tcp" when using artery. + seed-nodes = ["akka.tcp://opendaylight-cluster-data@192.168.178.142:2550", + "akka.tcp://opendaylight-cluster-data@192.168.178.143:2550", + "akka.tcp://opendaylight-cluster-data@192.168.178.144:2550", + "akka.tcp://opendaylight-cluster-data@192.168.178.145:2550"] + + roles = ["member-2"] + + } + + persistence { + # By default the snapshots/journal directories live in KARAF_HOME. You can choose to put it somewhere else by + # modifying the following two properties. The directory location specified may be a relative or absolute path. + # The relative path is always relative to KARAF_HOME. + + # snapshot-store.local.dir = "target/snapshots" + # journal.leveldb.dir = "target/journal" + + journal { + leveldb { + # Set native = off to use a Java-only implementation of leveldb. + # Note that the Java-only version is not currently considered by Akka to be production quality. + + # native = off + } + } + } + } +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/resources/akka-singlenode.cfg b/sdnr/wt/websocketmanager/provider/src/test/resources/akka-singlenode.cfg new file mode 100644 index 000000000..19e723319 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/resources/akka-singlenode.cfg @@ -0,0 +1,48 @@ +odl-cluster-data { + akka { + remote { + artery { + enabled = off + canonical.hostname = "127.0.0.1" + canonical.port = 2550 + } + netty.tcp { + hostname = "127.0.0.1" + port = 2550 + } + # when under load we might trip a false positive on the failure detector + # transport-failure-detector { + # heartbeat-interval = 4 s + # acceptable-heartbeat-pause = 16s + # } + } + + cluster { + # Remove ".tcp" when using artery. + seed-nodes = ["akka.tcp://opendaylight-cluster-data@127.0.0.1:2550"] + + roles = [ + "member-1" + ] + + } + + persistence { + # By default the snapshots/journal directories live in KARAF_HOME. You can choose to put it somewhere else by + # modifying the following two properties. The directory location specified may be a relative or absolute path. + # The relative path is always relative to KARAF_HOME. + + # snapshot-store.local.dir = "target/snapshots" + # journal.leveldb.dir = "target/journal" + + journal { + leveldb { + # Set native = off to use a Java-only implementation of leveldb. + # Note that the Java-only version is not currently considered by Akka to be production quality. + + # native = off + } + } + } + } +} diff --git a/sdnr/wt/websocketmanager/provider/src/test/resources/simplelogger.properties b/sdnr/wt/websocketmanager/provider/src/test/resources/simplelogger.properties new file mode 100644 index 000000000..1aa3824a1 --- /dev/null +++ b/sdnr/wt/websocketmanager/provider/src/test/resources/simplelogger.properties @@ -0,0 +1,58 @@ +# +# ============LICENSE_START======================================================= +# ONAP : ccsdk features +# ================================================================================ +# Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END======================================================= +# +# + +# SLF4J's SimpleLogger configuration file +# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. + +# Default logging detail level for all instances of SimpleLogger. +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, defaults to "info". +org.slf4j.simpleLogger.defaultLogLevel=trace + +# Logging detail level for a SimpleLogger instance named "xxx.yyy.zzz". +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, the default logging detail level is used. +# org.slf4j.simpleLogger.log.xxx.yyy=debug +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager=debug +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.Resources=info +org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container=trace + +# Set to true if you want the current date and time to be included in output messages. +# Default is false, and will output the number of milliseconds elapsed since startup. +#org.slf4j.simpleLogger.showDateTime=false + +# The date and time format to be used in the output messages. +# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. +# If the format is not specified or is invalid, the default format is used. +# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. +#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z + +# Set to true if you want to output the current thread name. +# Defaults to true. +#org.slf4j.simpleLogger.showThreadName=true + +# Set to true if you want the Logger instance name to be included in output messages. +# Defaults to true. +#org.slf4j.simpleLogger.showLogName=true + +# Set to true if you want the last component of the name to be included in output messages. +# Defaults to false. +#org.slf4j.simpleLogger.showShortLogName=false |