2460ca42f0ec35965451be5580879dd3b96080d3
[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.*;
21
22 import java.io.BufferedReader;
23 import java.io.File;
24 import java.io.FileNotFoundException;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.net.URISyntaxException;
28 import java.nio.file.Paths;
29 import org.junit.Test;
30 import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.utils.AkkaConfig;
31
32 public class AkkaConfigTest {
33
34     @Test
35     public void test() throws URISyntaxException, IOException {
36
37         AkkaConfig config=null;
38         try {
39             //config = AkkaConfig.load("akka-singlenode.cfg", true);
40             config = AkkaConfig.loadContent(loadResourceContentAsString("akka-singlenode.cfg"));
41         } catch (Exception e) {
42             e.printStackTrace();
43             fail("error loading singlenode config");
44         }
45         assertEquals("no singlenode config detected",false,config.isCluster());
46         assertEquals("more than one node detected",1,config.getClusterConfig().getSeedNodes().size());
47
48         try {
49             config = AkkaConfig.loadContent(loadResourceContentAsString("akka-cluster.cfg"));
50         } catch (Exception e) {
51             fail("error loading cluster config");
52         }
53         assertEquals("no cluster config detected",true,config.isCluster());
54         assertTrue("only one node detected",config.getClusterConfig().getSeedNodes().size()>1);
55     }
56
57     public static String loadResourceContentAsString(String resourceName) throws URISyntaxException, FileNotFoundException, IOException {
58
59         StringBuilder sb = new StringBuilder();
60
61         ClassLoader classLoader = AkkaConfigTest.class.getClassLoader();
62         File file = Paths.get(classLoader.getResource(resourceName).toURI()).toFile();
63         try(BufferedReader br = new BufferedReader(new FileReader(file))) {
64             String line = br.readLine();
65
66             while (line != null) {
67                 sb.append(line);
68                 sb.append(System.lineSeparator());
69                 line = br.readLine();
70             }
71         }
72         return sb.toString();
73     }
74 }