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_REQUEST_ACTION;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE;
27 import java.util.Properties;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.ExpectedException;
33 import org.onap.appc.flow.controller.data.Transaction;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 public class TransactionHandlerTest {
38 private static final String RESOURCE_URI = "some uri";
40 private TransactionHandler transactionHandler;
41 private SvcLogicContext ctx;
42 private Properties prop;
45 public ExpectedException expectedException = ExpectedException.none();
49 transactionHandler = new TransactionHandler();
50 ctx = mock(SvcLogicContext.class);
51 prop = mock(Properties.class);
55 public void should_throw_exception_when_input_request_action_type_missing() throws Exception {
57 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");
59 expectedException.expect(Exception.class);
60 expectedException.expectMessage("Don't know REST operation for Action");
61 transactionHandler = new TransactionHandler();
62 transactionHandler.buildTransaction(ctx, prop, RESOURCE_URI);
66 public void should_throw_exception_when_input_request_action_missing() throws Exception {
68 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");
70 expectedException.expect(Exception.class);
71 expectedException.expectMessage("Don't know request-action request-action");
72 transactionHandler.buildTransaction(ctx, prop, "some uri");
76 public void should_return_proper_transaction() throws Exception {
78 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type");
79 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra");
81 when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-user")))
82 .thenReturn("rest-user");
83 when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-pass")))
84 .thenReturn("rest-pass");
86 Transaction transaction = transactionHandler.buildTransaction(ctx, prop, "some uri");
88 Assert.assertEquals(INPUT_REQUEST_ACTION, transaction.getAction());
89 Assert.assertEquals("input-ra-type", transaction.getExecutionRPC());
90 Assert.assertEquals("some uri", transaction.getExecutionEndPoint());
91 Assert.assertEquals("rest-user", transaction.getuId());
92 Assert.assertEquals("rest-pass", transaction.getPswd());