f16dd65cc125a10b9e22f8de0c6251a3dbf4b637
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / controller / node / TransactionHandlerTest.java
1 package org.onap.appc.flow.controller.node;
2
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;
7
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;
16
17 public class TransactionHandlerTest {
18
19   private static final String RESOURCE_URI = "some uri";
20
21   private TransactionHandler transactionHandler;
22   private SvcLogicContext ctx;
23   private Properties prop;
24
25   @Rule
26   public ExpectedException expectedException = ExpectedException.none();
27
28   @Before
29   public void setUp() {
30     transactionHandler = new TransactionHandler();
31     ctx = mock(SvcLogicContext.class);
32     prop = mock(Properties.class);
33   }
34
35   @Test
36   public void should_throw_exception_when_input_request_action_type_missing() throws Exception {
37
38     when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");
39
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);
44   }
45
46   @Test
47   public void should_throw_exception_when_input_request_action_missing() throws Exception {
48
49     when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");
50
51     expectedException.expect(Exception.class);
52     expectedException.expectMessage("Don't know request-action request-action");
53     transactionHandler.buildTransaction(ctx, prop, "some uri");
54   }
55
56   @Test
57   public void should_return_proper_transaction() throws Exception {
58
59     when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type");
60     when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra");
61
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");
66
67     Transaction transaction = transactionHandler.buildTransaction(ctx, prop, "some uri");
68
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());
74   }
75
76 }