5937e2330b488f01d767b86bdaab324645bc9406
[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.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 import java.io.*;
11 import java.nio.charset.StandardCharsets;
12 import java.util.HashMap;
13
14
15 import static org.junit.Assert.assertTrue;
16
17 public class SliTopologyUtilsTest {
18     private SvcLogicContext ctx;
19     private static final Logger LOG = LoggerFactory.getLogger(SliTopologyUtils.class);
20     private HashMap<String, String> param;
21     private SliTopologyUtils topologyUtil = new SliTopologyUtils();
22     @Before
23     public void setUp() throws Exception {
24         //Loading test logicallinks and pnfs
25         this.ctx = new SvcLogicContext();
26         param = new HashMap<String, String>();
27         String fileName = "src/test/resources/3domain.dump";
28
29         try (FileInputStream fstr = new FileInputStream(new File(fileName));
30              InputStreamReader is = new InputStreamReader(fstr,StandardCharsets.UTF_8);
31              BufferedReader br = new BufferedReader(is))
32         {
33             String line;
34             while ((line = br.readLine()) != null){
35                 if (! line.startsWith("#")){
36                     String [] curpair = line.split("\\s=\\s");
37                     if (curpair.length == 2){
38                         ctx.setAttribute(curpair[0], curpair[1]);
39                     } else if (curpair.length == 1){
40                         //ctx.setAttribute(curpair[0], "");
41                         //LOG.info("Ignore empty (value) context memory record format {}", line);
42                     } else {
43                         //LOG.info("Ignore incorrect context memory record format {}", line);
44                     }
45                 }
46             }
47             //SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.INFO);
48         } catch (Exception e) {
49             throw new SvcLogicException("Cannot read context from file " + fileName, e);
50         }
51     }
52
53     @Test
54     public void testComputePath()  throws SvcLogicException {
55
56         param.put("pnfs-pfx", "ccsdkTopopnfs");
57         param.put("links-pfx", "ccsdkTopologicalLinks");
58         param.put("response-pfx", "prefix");
59         param.put("output-end-to-end-path", "false");
60
61         param.put("src-node","networkId-providerId-30-clientId-0-topologyId-1-nodeId-10.3.1.1" );
62         param.put("dst-node", "networkId-providerId-50-clientId-0-topologyId-1-nodeId-10.5.1.4");
63
64         SliTopologyUtils.computePath(param, ctx);
65         //SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.INFO);
66         assertTrue(Integer.parseInt(this.ctx.getAttribute("prefix.solutions_length") ) > 0);
67         LOG.info("Computation finished");
68
69         for (String key: this.ctx.getAttributeKeySet()){
70             if (key.startsWith("prefix")){
71                 LOG.info("Results: {} : {}" , key, this.ctx.getAttribute(key));
72             }
73         }
74
75     }
76 }