ed3b02b9a233cbcf6e07d817a08b9b505ab8695d
[ccsdk/sli.git] /
1 package org.onap.ccsdk.sli.core.slipluginutils;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
6 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
7 import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils;
8 import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils_ctxSortList;
9 import org.onap.ccsdk.sli.core.slipluginutils.SliTopologyUtils;
10 import org.onap.ccsdk.sli.core.slipluginutils.slitopologyutils.JsonParserHelper;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 import java.nio.file.Files;
15 import java.nio.file.Paths;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import static org.junit.Assert.assertTrue;
20
21 public class SliTopologyUtilsTest {
22     private SvcLogicContext ctx;
23     private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtils_ctxSortList.class);
24     private HashMap<String, String> param;
25     private SliTopologyUtils topologyUtil = new SliTopologyUtils();
26     @Before
27     public void setUp() throws Exception {
28         //Loading test logicallinks and pnfs
29         this.ctx = new SvcLogicContext();
30         param = new HashMap<String, String>();
31         String fileName1 = "src/test/resources/Pnfs.json";
32         String fileName2 = "src/test/resources/LogicalLinks.json";
33         try {
34             byte[] encoded = Files.readAllBytes(Paths.get(fileName1));
35             String fileString = new String(encoded, "UTF-8");
36             String pp1 = "Pnfs.";
37             Map<String, String> mm = null;
38             mm = JsonParserHelper.convertToProperties(fileString);
39             if (mm != null) {
40                 for (Map.Entry<String, String> entry : mm.entrySet()) {
41                     ctx.setAttribute(pp1 + entry.getKey(), entry.getValue());
42                 }
43             }
44
45             encoded = Files.readAllBytes(Paths.get(fileName2));
46             fileString = new String(encoded, "UTF-8");
47             String pp2 = "LogicalLinks.";
48             mm = null;
49             mm = JsonParserHelper.convertToProperties(fileString);
50             if (mm != null) {
51                 for (Map.Entry<String, String> entry : mm.entrySet()) {
52                     ctx.setAttribute(pp2 + entry.getKey(), entry.getValue());
53                 }
54             }
55
56         } catch (Exception e ){
57             LOG.trace("Failed to read topology json files" +  e.getMessage());
58         }
59     }
60
61     @Test
62     public void computePath()  throws SvcLogicException {
63
64         param.put("pnfs-pfx", "Pnfs");
65         param.put("links-pfx", "LogicalLinks");
66         param.put("response-pfx", "prefix");
67         param.put("output-end-to-end-path", "true");
68         param.put("src-node","networkId-providerId-20-clientId-0-topologyId-1-nodeId-10.2.1.2" );
69         param.put("dst-node", "networkId-providerId-10-clientId-0-topologyId-1-nodeId-10.1.1.4");
70
71         SliTopologyUtils.computePath(param, ctx);
72         SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE);
73         assertTrue(Integer.parseInt(this.ctx.getAttribute("prefix.solutions_length") ) > 0);
74     }
75 }