2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * =============================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.appc.flow.controller.node;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.when;
24 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PORT_NUMBER;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_SUB_CONTEXT;
29 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
31 import java.util.Properties;
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 public class ResourceUriExtractorTest {
41 private Properties prop;
42 private SvcLogicContext ctx;
45 public ExpectedException expectedException = ExpectedException.none();
46 private ResourceUriExtractor resourceUriExtractor;
50 ctx = mock(SvcLogicContext.class);
51 prop = mock(Properties.class);
52 resourceUriExtractor = new ResourceUriExtractor();
56 public void should_return_input_url_if_exist() throws Exception {
57 ctx = mock(SvcLogicContext.class);
58 when(ctx.getAttribute(INPUT_URL)).thenReturn("http://localhost:8080");
60 resourceUriExtractor = new ResourceUriExtractor();
61 String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
63 Assert.assertEquals("http://localhost:8080", resourceUri);
67 public void should_extract_url_input_if_context_input_provided() throws Exception {
68 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
69 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
70 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
72 when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
73 when(ctx.getAttribute(INPUT_SUB_CONTEXT)).thenReturn("input-sub-context");
75 String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
77 Assert.assertEquals("http://localhost:8080/input-context/input-sub-context", resourceUri);
81 public void should_extract_url_input_if_request_action_provided() throws Exception {
83 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
84 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
85 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
87 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
88 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
90 when(prop.getProperty("request-action.context")).thenReturn("ra-context");
91 when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context");
93 String resourceUri = resourceUriExtractor.extractResourceUri(ctx, prop);
95 Assert.assertEquals("http://localhost:8080/ra-context/ra-sub-context", resourceUri);
99 public void should_throw_exception_if_missing_context() throws Exception {
100 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
101 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
102 when(ctx.getAttribute(INPUT_PORT_NUMBER)).thenReturn("8080");
104 expectedException.expect(Exception.class);
105 expectedException.expectMessage("Could Not found the context for operation null");
107 resourceUriExtractor.extractResourceUri(ctx, prop);