2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. 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.
19 * * ============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_REQUEST_ACTION;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE;
29 import java.util.Properties;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.onap.appc.flow.controller.data.Transaction;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38 public class TransactionHandlerTest {
40 private static final String RESOURCE_URI = "some uri";
42 private TransactionHandler transactionHandler;
43 private SvcLogicContext ctx;
44 private Properties prop;
47 public ExpectedException expectedException = ExpectedException.none();
51 transactionHandler = new TransactionHandler();
52 ctx = mock(SvcLogicContext.class);
53 prop = mock(Properties.class);
57 public void should_throw_exception_when_input_request_action_type_missing() throws Exception {
59 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");
61 expectedException.expect(Exception.class);
62 expectedException.expectMessage("Don't know REST operation for Action");
63 transactionHandler = new TransactionHandler();
64 transactionHandler.buildTransaction(ctx, prop, RESOURCE_URI);
68 public void should_throw_exception_when_input_request_action_missing() throws Exception {
70 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");
72 expectedException.expect(Exception.class);
73 expectedException.expectMessage("Don't know request-action request-action");
74 transactionHandler.buildTransaction(ctx, prop, "some uri");
78 public void should_return_proper_transaction() throws Exception {
80 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type");
81 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra");
83 when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-user")))
84 .thenReturn("rest-user");
85 when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-pass")))
86 .thenReturn("rest-pass");
88 Transaction transaction = transactionHandler.buildTransaction(ctx, prop, "some uri");
90 Assert.assertEquals(INPUT_REQUEST_ACTION, transaction.getAction());
91 Assert.assertEquals("input-ra-type", transaction.getExecutionRPC());
92 Assert.assertEquals("some uri", transaction.getExecutionEndPoint());
93 Assert.assertEquals("rest-user", transaction.getuId());
94 Assert.assertEquals("rest-pass", transaction.getPswd());