1 package org.onap.ccsdk.sli.core.slipluginutils;
3 import org.junit.Before;
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;
11 import java.nio.charset.StandardCharsets;
12 import java.util.HashMap;
15 import static org.junit.Assert.assertTrue;
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();
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";
29 try (FileInputStream fstr = new FileInputStream(new File(fileName));
30 InputStreamReader is = new InputStreamReader(fstr,StandardCharsets.UTF_8);
31 BufferedReader br = new BufferedReader(is))
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);
43 //LOG.info("Ignore incorrect context memory record format {}", line);
47 //SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.INFO);
48 } catch (Exception e) {
49 throw new SvcLogicException("Cannot read context from file " + fileName, e);
54 public void testComputePath() throws SvcLogicException {
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");
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");
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");
69 for (String key: this.ctx.getAttributeKeySet()){
70 if (key.startsWith("prefix")){
71 LOG.info("Results: {} : {}" , key, this.ctx.getAttribute(key));