diff options
author | Michael DÜrre <michael.duerre@highstreet-technologies.com> | 2021-04-08 06:34:22 +0200 |
---|---|---|
committer | Michael DÜrre <michael.duerre@highstreet-technologies.com> | 2021-04-08 06:34:46 +0200 |
commit | f3969004c6ccac18e742c5fc48c844e315991023 (patch) | |
tree | f5486a62e842bb16ca7d3af47a8663df08feef55 /sdnr/wt/websocketmanager/provider/src/test/java | |
parent | a252be83694ae33260d99d5371ed48c1558aa2e8 (diff) |
update websocketmanager
update complete notification flow
Issue-ID: CCSDK-3252
Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Change-Id: I87ba00f615707b942471fcace57bcda50ce37e61
Diffstat (limited to 'sdnr/wt/websocketmanager/provider/src/test/java')
9 files changed, 583 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"); + } + + } + +} |