1 package org.onap.appc.flow.controller.node;
3 import static org.mockito.Mockito.mock;
4 import static org.mockito.Mockito.when;
5 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
6 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE;
8 import java.util.Properties;
9 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.rules.ExpectedException;
14 import org.onap.appc.flow.controller.data.Transaction;
15 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
17 public class TransactionHandlerTest {
19 private static final String RESOURCE_URI = "some uri";
21 private TransactionHandler transactionHandler;
22 private SvcLogicContext ctx;
23 private Properties prop;
26 public ExpectedException expectedException = ExpectedException.none();
30 transactionHandler = new TransactionHandler();
31 ctx = mock(SvcLogicContext.class);
32 prop = mock(Properties.class);
36 public void should_throw_exception_when_input_request_action_type_missing() throws Exception {
38 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");
40 expectedException.expect(Exception.class);
41 expectedException.expectMessage("Don't know REST operation for Action");
42 transactionHandler = new TransactionHandler();
43 transactionHandler.buildTransaction(ctx, prop, RESOURCE_URI);
47 public void should_throw_exception_when_input_request_action_missing() throws Exception {
49 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");
51 expectedException.expect(Exception.class);
52 expectedException.expectMessage("Don't know request-action request-action");
53 transactionHandler.buildTransaction(ctx, prop, "some uri");
57 public void should_return_proper_transaction() throws Exception {
59 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type");
60 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra");
62 when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-user")))
63 .thenReturn("rest-user");
64 when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-pass")))
65 .thenReturn("rest-pass");
67 Transaction transaction = transactionHandler.buildTransaction(ctx, prop, "some uri");
69 Assert.assertEquals(INPUT_REQUEST_ACTION, transaction.getAction());
70 Assert.assertEquals("input-ra-type", transaction.getExecutionRPC());
71 Assert.assertEquals("some uri", transaction.getExecutionEndPoint());
72 Assert.assertEquals("rest-user", transaction.getId());
73 Assert.assertEquals("rest-pass", transaction.getPswd());