2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.appc.flow.controller.node;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_CONTEXT;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_HOST_IP_ADDRESS;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
29 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_SUB_CONTEXT;
30 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_URL;
31 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_CONTEXT_URL;
32 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PORT;
33 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PROTOCOL;
34 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
35 import java.util.Properties;
36 import org.junit.Assert;
37 import org.junit.Before;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.rules.ExpectedException;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
43 public class ResourceUriExtractorTest {
45 private Properties prop;
46 private SvcLogicContext ctx;
49 public ExpectedException expectedException = ExpectedException.none();
50 private ResourceUriExtractor resourceUriExtractor;
54 ctx = mock(SvcLogicContext.class);
55 prop = mock(Properties.class);
56 resourceUriExtractor = new ResourceUriExtractor();
60 public void should_return_input_url_if_exist() throws Exception {
61 ctx = mock(SvcLogicContext.class);
62 when(ctx.getAttribute(INPUT_URL)).thenReturn("http://localhost:8080");
64 resourceUriExtractor = new ResourceUriExtractor();
65 String resourceUri = resourceUriExtractor.extractResourceUri(ctx);
67 Assert.assertEquals("http://localhost:8080", resourceUri);
71 public void should_extract_url_input_if_context_input_provided() throws Exception {
72 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
73 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
74 when(ctx.getAttribute(REST_PORT)).thenReturn("8080");
76 when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("input-context");
78 String resourceUri = resourceUriExtractor.extractResourceUri(ctx);
80 Assert.assertEquals("http://localhost:8080/input-context", resourceUri);
84 public void should_extract_url_input_if_request_action_provided() throws Exception {
85 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("request-action");
86 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
87 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
88 when(ctx.getAttribute(REST_PORT)).thenReturn("8080");
89 when(ctx.getAttribute(INPUT_CONTEXT)).thenReturn("ra-context");
90 when(prop.getProperty("request-action.sub-context")).thenReturn("ra-sub-context");
92 String resourceUri = resourceUriExtractor.extractResourceUri(ctx);
94 Assert.assertEquals("http://localhost:8080/ra-context", resourceUri);
98 public void should_throw_exception_if_missing_context() throws Exception {
99 when(ctx.getAttribute(INPUT_URL)).thenReturn("");
100 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
101 when(ctx.getAttribute(INPUT_HOST_IP_ADDRESS)).thenReturn("localhost");
102 when(prop.getProperty(ctx.getAttribute(VNF_TYPE)+"."+(REST_PROTOCOL)+"."+ctx.getAttribute(INPUT_REQUEST_ACTION)
103 +"."+(REST_PORT))).thenReturn("8080");
105 expectedException.expect(Exception.class);
106 expectedException.expectMessage("Could not find the context for operation null");
108 resourceUriExtractor.extractResourceUri(ctx);