1 package org.onap.appc.flow.controller.node;
3 import static org.mockito.Mockito.mock;
4 import static org.mockito.Mockito.when;
5 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
6 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
7 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PORT_NUMBER;
8 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
9 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_SUB_CONTEXT;
10 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
12 import java.util.Properties;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Rule;
16 import org.junit.Test;
17 import org.junit.rules.ExpectedException;
18 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
20 public class ResourceUriExtractorTest {
22 private Properties prop;
23 private SvcLogicContext ctx;
26 public ExpectedException expectedException = ExpectedException.none();
30 ctx = mock(SvcLogicContext.class);
31 prop = mock(Properties.class);
35 public void should_return_input_url_if_exist() throws Exception {
36 ctx = mock(SvcLogicContext.class);
37 when(ctx.getAttribute(INPUT_URL)).thenReturn("test resource uri");
39 String resourceUri = ResourceUriExtractor.extractResourceUri(ctx, prop);
41 Assert.assertEquals("test resource uri", resourceUri);
45 public void should_extract_url_input_if_context_input_provided() throws Exception {
46 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
47 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
48 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
50 when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
51 when(ctx.getAttribute(INPUT_SUB_CONTEXT)).thenReturn("input-sub-context");
53 String resourceUri = ResourceUriExtractor.extractResourceUri(ctx, prop);
55 Assert.assertEquals("http://localhost:8080/input-context/input-sub-context", resourceUri);
59 public void should_extract_url_input_if_request_action_provided() throws Exception {
61 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
62 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
63 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
65 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
66 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
68 when(prop.getProperty("request-action.context")).thenReturn("ra-context");
69 when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context");
71 String resourceUri = ResourceUriExtractor.extractResourceUri(ctx, prop);
73 Assert.assertEquals("http://localhost:8080/ra-context/ra-sub-context", resourceUri);
77 public void should_throw_exception_if_missing_context() throws Exception {
78 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
79 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
80 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
82 expectedException.expect(Exception.class);
83 expectedException.expectMessage("Could Not found the context for operation null");
85 ResourceUriExtractor.extractResourceUri(ctx, prop);