2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
7 * =============================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.appc.flow.controller.node;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST_PROTOCOL;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
30 import java.util.Properties;
31 import org.junit.Assert;
32 import org.junit.Before;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.onap.appc.flow.controller.data.Transaction;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 public class TransactionHandlerTest {
41 private static final String RESOURCE_URI = "some uri";
43 private TransactionHandler transactionHandler;
44 private SvcLogicContext ctx;
45 private Properties prop;
48 public ExpectedException expectedException = ExpectedException.none();
52 transactionHandler = new TransactionHandler();
53 ctx = mock(SvcLogicContext.class);
54 prop = mock(Properties.class);
58 public void should_throw_exception_when_input_request_action_type_missing() throws Exception {
60 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");
62 expectedException.expect(Exception.class);
63 expectedException.expectMessage("Don't know REST operation for Action");
64 transactionHandler = new TransactionHandler();
65 transactionHandler.buildTransaction(ctx, RESOURCE_URI);
69 public void should_throw_exception_when_input_request_action_missing() throws Exception {
71 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");
73 expectedException.expect(Exception.class);
74 expectedException.expectMessage("Don't know request-action request-action");
75 transactionHandler.buildTransaction(ctx, "some uri");
79 public void should_return_proper_transaction() throws Exception {
81 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type");
82 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra");
83 when(ctx.getAttribute(VNF_TYPE)).thenReturn("vnf");
85 String userKey = ctx.getAttribute(VNF_TYPE) + "." + REST_PROTOCOL + "." + ctx.getAttribute(INPUT_REQUEST_ACTION)
87 String passwordKey = ctx.getAttribute(VNF_TYPE) + "." + REST_PROTOCOL + "." + ctx.getAttribute(INPUT_REQUEST_ACTION)
90 when(ctx.getAttribute("user")).thenReturn("rest-user");
91 when(ctx.getAttribute("pwd")).thenReturn("rest-pass");
93 Transaction transaction = transactionHandler.buildTransaction(ctx,"some uri");
95 Assert.assertEquals(INPUT_REQUEST_ACTION, transaction.getAction());
96 Assert.assertEquals("input-ra-type", transaction.getExecutionRPC());
97 Assert.assertEquals("some uri", transaction.getExecutionEndPoint());
98 Assert.assertEquals("rest-user", transaction.getuId());
99 Assert.assertEquals("rest-pass", transaction.getPswd());