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();
27 private ResourceUriExtractor resourceUriExtractor;
31 ctx = mock(SvcLogicContext.class);
32 prop = mock(Properties.class);
33 resourceUriExtractor = new ResourceUriExtractor();
37 public void should_return_input_url_if_exist() throws Exception {
38 ctx = mock(SvcLogicContext.class);
39 when(ctx.getAttribute(INPUT_URL)).thenReturn("http://localhost:8080");
41 resourceUriExtractor = new ResourceUriExtractor();
42 String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
44 Assert.assertEquals("http://localhost:8080", resourceUri);
48 public void should_extract_url_input_if_context_input_provided() throws Exception {
49 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
50 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
51 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
53 when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
54 when(ctx.getAttribute(INPUT_SUB_CONTEXT)).thenReturn("input-sub-context");
56 String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
58 Assert.assertEquals("http://localhost:8080/input-context/input-sub-context", resourceUri);
62 public void should_extract_url_input_if_request_action_provided() throws Exception {
64 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
65 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
66 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
68 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
69 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
71 when(prop.getProperty("request-action.context")).thenReturn("ra-context");
72 when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context");
74 String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
76 Assert.assertEquals("http://localhost:8080/ra-context/ra-sub-context", resourceUri);
80 public void should_throw_exception_if_missing_context() throws Exception {
81 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
82 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
83 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
85 expectedException.expect(Exception.class);
86 expectedException.expectMessage("Could Not found the context for operation null");
88 resourceUriExtractor.extractResourceUri(ctx, prop);