Changes to get properties from southbound propfile
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / controller / node / ResourceUriExtractorTest.java
index e3f108e..3422758 100644 (file)
@@ -3,12 +3,14 @@
  * ONAP : APPC
  * ================================================================================
  * Copyright (C) 2018 Nokia. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,11 +25,13 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
-import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PORT_NUMBER;
 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_SUB_CONTEXT;
 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
-
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_CONTEXT_URL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PORT;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PROTOCOL;
+import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
 import java.util.Properties;
 import org.junit.Assert;
 import org.junit.Before;
@@ -38,73 +42,74 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
 public class ResourceUriExtractorTest {
 
-  private Properties prop;
-  private SvcLogicContext ctx;
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-  private ResourceUriExtractor resourceUriExtractor;
-
-  @Before
-  public void setUp() {
-    ctx = mock(SvcLogicContext.class);
-    prop = mock(Properties.class);
-    resourceUriExtractor = new ResourceUriExtractor();
-  }
+    private Properties prop;
+    private SvcLogicContext ctx;
 
-  @Test
-  public void should_return_input_url_if_exist() throws Exception {
-    ctx = mock(SvcLogicContext.class);
-    when(ctx.getAttribute(INPUT_URL)).thenReturn("http://localhost:8080");
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+    private ResourceUriExtractor resourceUriExtractor;
 
-    resourceUriExtractor = new ResourceUriExtractor();
-    String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
+    @Before
+    public void setUp() {
+        ctx = mock(SvcLogicContext.class);
+        prop = mock(Properties.class);
+        resourceUriExtractor = new ResourceUriExtractor();
+    }
 
-    Assert.assertEquals("http://localhost:8080", resourceUri);
-  }
+    @Test
+    public void should_return_input_url_if_exist() throws Exception {
+        ctx = mock(SvcLogicContext.class);
+        when(ctx.getAttribute(INPUT_URL)).thenReturn("http://localhost:8080");
 
-  @Test
-  public void should_extract_url_input_if_context_input_provided() throws Exception {
-    when(ctx.getAttribute(INPUT_URL)).thenReturn("");
-    when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
-    when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
+        resourceUriExtractor = new ResourceUriExtractor();
+        String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
 
-    when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
-    when(ctx.getAttribute(INPUT_SUB_CONTEXT)).thenReturn("input-sub-context");
+        Assert.assertEquals("http://localhost:8080", resourceUri);
+    }
 
-    String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
+    @Test
+    public void should_extract_url_input_if_context_input_provided() throws Exception {
+        when(ctx.getAttribute(INPUT_URL)).thenReturn("");
+        when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
+        when(prop.getProperty(ctx.getAttribute(VNF_TYPE) + "." + (REST_PROTOCOL) + "."
+                + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + (REST_PORT))).thenReturn("8080");
 
-    Assert.assertEquals("http://localhost:8080/input-context/input-sub-context", resourceUri);
-  }
+        when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
+        when(ctx.getAttribute(INPUT_SUB_CONTEXT)).thenReturn("input-sub-context");
 
-  @Test
-  public void should_extract_url_input_if_request_action_provided() throws Exception {
+        String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
 
-    when(ctx.getAttribute(INPUT_URL)).thenReturn("");
-    when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
-    when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
+        Assert.assertEquals("http://localhost:8080/input-context/input-sub-context", resourceUri);
+    }
 
-    when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
-    when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
+    @Test
+    public void should_extract_url_input_if_request_action_provided() throws Exception {
+        when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
+        when(ctx.getAttribute(INPUT_URL)).thenReturn("");
+        when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
+        when(prop.getProperty(ctx.getAttribute(VNF_TYPE) + "." + (REST_PROTOCOL) + "."
+                + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + (REST_PORT))).thenReturn("8080");
 
-    when(prop.getProperty("request-action.context")).thenReturn("ra-context");
-    when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context");
+        when(prop.getProperty(ctx.getAttribute(VNF_TYPE) + "." + REST_PROTOCOL + "."
+                + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + REST_CONTEXT_URL)).thenReturn("ra-context");
+        when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context");
 
-    String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
+        String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
 
-    Assert.assertEquals("http://localhost:8080/ra-context/ra-sub-context", resourceUri);
-  }
+        Assert.assertEquals("http://localhost:8080/ra-context/ra-sub-context", resourceUri);
+    }
 
-  @Test
-  public void should_throw_exception_if_missing_context() throws Exception {
-    when(ctx.getAttribute(INPUT_URL)).thenReturn("");
-    when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
-    when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
+    @Test
+    public void should_throw_exception_if_missing_context() throws Exception {
+        when(ctx.getAttribute(INPUT_URL)).thenReturn("");
+        when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
+        when(prop.getProperty(ctx.getAttribute(VNF_TYPE) + "." + (REST_PROTOCOL) + "."
+                + ctx.getAttribute(INPUT_REQUEST_ACTION) + "." + (REST_PORT))).thenReturn("8080");
 
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Could Not found the context for operation null");
+        expectedException.expect(Exception.class);
+        expectedException.expectMessage("Could not find the context for operation null");
 
-    resourceUriExtractor.extractResourceUri(ctx, prop);
-  }
+        resourceUriExtractor.extractResourceUri(ctx, prop);
+    }
 
-}
\ No newline at end of file
+}