f3cf0954557a68f85931ed9f9cb2084e7a1e9343
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.fail;
23 import java.io.BufferedReader;
24 import java.io.File;
25 import java.io.FileNotFoundException;
26 import java.io.FileReader;
27 import java.io.IOException;
28 import java.net.URISyntaxException;
29 import java.nio.file.Paths;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.AkkaConfig;
32
33 public class AkkaConfigTest {
34
35     @Test
36     public void test() throws URISyntaxException, IOException {
37
38         AkkaConfig config = null;
39         try {
40             //config = AkkaConfig.load("akka-singlenode.cfg", true);
41             config = AkkaConfig.loadContent(loadResourceContentAsString("akka-singlenode.cfg"));
42         } catch (Exception e) {
43             e.printStackTrace();
44             fail("error loading singlenode config");
45         }
46         assertEquals("no singlenode config detected", false, config.isCluster());
47         assertEquals("more than one node detected", 1, config.getClusterConfig().getSeedNodes().size());
48
49         try {
50             config = AkkaConfig.loadContent(loadResourceContentAsString("akka-cluster.cfg"));
51         } catch (Exception e) {
52             fail("error loading cluster config");
53         }
54         assertEquals("no cluster config detected", true, config.isCluster());
55         assertTrue("only one node detected", config.getClusterConfig().getSeedNodes().size() > 1);
56     }
57
58     public static String loadResourceContentAsString(String resourceName)
59             throws URISyntaxException, FileNotFoundException, IOException {
60
61         StringBuilder sb = new StringBuilder();
62
63         ClassLoader classLoader = AkkaConfigTest.class.getClassLoader();
64         File file = Paths.get(classLoader.getResource(resourceName).toURI()).toFile();
65         try (BufferedReader br = new BufferedReader(new FileReader(file))) {
66             String line = br.readLine();
67
68             while (line != null) {
69                 sb.append(line);
70                 sb.append(System.lineSeparator());
71                 line = br.readLine();
72             }
73         }
74         return sb.toString();
75     }
76 }