Changes needed for MultiStep Actions
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / controller / node / TransactionHandlerTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.appc.flow.controller.node;
22
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;
29
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;
38
39 public class TransactionHandlerTest {
40
41   private static final String RESOURCE_URI = "some uri";
42
43   private TransactionHandler transactionHandler;
44   private SvcLogicContext ctx;
45   private Properties prop;
46
47   @Rule
48   public ExpectedException expectedException = ExpectedException.none();
49
50   @Before
51   public void setUp() {
52     transactionHandler = new TransactionHandler();
53     ctx = mock(SvcLogicContext.class);
54     prop = mock(Properties.class);
55   }
56
57   @Test
58   public void should_throw_exception_when_input_request_action_type_missing() throws Exception {
59
60     when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");
61
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);
66   }
67
68   @Test
69   public void should_throw_exception_when_input_request_action_missing() throws Exception {
70
71     when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");
72
73     expectedException.expect(Exception.class);
74     expectedException.expectMessage("Don't know request-action request-action");
75     transactionHandler.buildTransaction(ctx, "some uri");
76   }
77
78   @Test
79   public void should_return_proper_transaction() throws Exception {
80
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");
84
85     String userKey = ctx.getAttribute(VNF_TYPE) + "." + REST_PROTOCOL + "." + ctx.getAttribute(INPUT_REQUEST_ACTION)
86                      + ".user";
87     String passwordKey = ctx.getAttribute(VNF_TYPE) + "." + REST_PROTOCOL + "." + ctx.getAttribute(INPUT_REQUEST_ACTION)
88                      + ".password";
89
90     when(ctx.getAttribute("user")).thenReturn("rest-user");
91     when(ctx.getAttribute("pwd")).thenReturn("rest-pass");
92
93     Transaction transaction = transactionHandler.buildTransaction(ctx,"some uri");
94
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());
100   }
101
102 }