Split sequence generation to classess
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / controller / node / ResourceUriExtractorTest.java
index d7a853d..e3f108e 100644 (file)
@@ -1,3 +1,22 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Nokia. 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
 package org.onap.appc.flow.controller.node;
 
 import static org.mockito.Mockito.mock;
@@ -20,29 +39,32 @@ 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() {
-    prop = new Properties();
+    ctx = mock(SvcLogicContext.class);
+    prop = mock(Properties.class);
+    resourceUriExtractor = new ResourceUriExtractor();
   }
 
   @Test
   public void should_return_input_url_if_exist() throws Exception {
-    SvcLogicContext ctx = mock(SvcLogicContext.class);
-    when(ctx.getAttribute(INPUT_URL)).thenReturn("test resource uri");
+    ctx = mock(SvcLogicContext.class);
+    when(ctx.getAttribute(INPUT_URL)).thenReturn("http://localhost:8080");
 
-    String resourceUri = ResourceUriExtractor.extractResourceUri(ctx, prop);
+    resourceUriExtractor = new ResourceUriExtractor();
+    String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
 
-    Assert.assertEquals("test resource uri", resourceUri);
+    Assert.assertEquals("http://localhost:8080", resourceUri);
   }
 
   @Test
   public void should_extract_url_input_if_context_input_provided() throws Exception {
-    SvcLogicContext ctx = mock(SvcLogicContext.class);
-
     when(ctx.getAttribute(INPUT_URL)).thenReturn("");
     when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
     when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
@@ -50,14 +72,13 @@ public class ResourceUriExtractorTest {
     when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
     when(ctx.getAttribute(INPUT_SUB_CONTEXT)).thenReturn("input-sub-context");
 
-    String resourceUri = ResourceUriExtractor.extractResourceUri(ctx, prop);
+    String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
 
     Assert.assertEquals("http://localhost:8080/input-context/input-sub-context", resourceUri);
   }
 
   @Test
   public void should_extract_url_input_if_request_action_provided() throws Exception {
-    SvcLogicContext ctx = mock(SvcLogicContext.class);
 
     when(ctx.getAttribute(INPUT_URL)).thenReturn("");
     when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
@@ -66,25 +87,24 @@ public class ResourceUriExtractorTest {
     when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
     when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
 
-    prop.put("request-action.context", "ra-context");
-    prop.put("request-action.sub-context", "ra-sub-context");
+    when(prop.getProperty("request-action.context")).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);
   }
 
   @Test
   public void should_throw_exception_if_missing_context() throws Exception {
-    SvcLogicContext ctx = mock(SvcLogicContext.class);
-
     when(ctx.getAttribute(INPUT_URL)).thenReturn("");
     when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
     when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
 
     expectedException.expect(Exception.class);
     expectedException.expectMessage("Could Not found the context for operation null");
-    ResourceUriExtractor.extractResourceUri(ctx, prop);
+
+    resourceUriExtractor.extractResourceUri(ctx, prop);
   }
 
 }
\ No newline at end of file