Improve coverage flow/controller/node #2
[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 SvcLogicContext ctx;
22   private Properties prop;
23
24   @Rule
25   public ExpectedException expectedException = ExpectedException.none();
26
27   @Before
28   public void setUp() {
29     ctx = mock(SvcLogicContext.class);
30     prop = mock(Properties.class);
31   }
32
33   @Test
34   public void should_throw_exception_when_input_request_action_type_missing() throws Exception {
35
36     when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");
37
38     expectedException.expect(IllegalArgumentException.class);
39     expectedException.expectMessage("Don't know REST operation for Action");
40     TransactionHandler.buildTransaction(ctx, prop, RESOURCE_URI);
41   }
42
43   @Test
44   public void should_throw_exception_when_input_request_action_missing() throws Exception {
45
46     when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");
47
48     expectedException.expect(IllegalArgumentException.class);
49     expectedException.expectMessage("Don't know request-action request-action");
50     TransactionHandler.buildTransaction(ctx, prop, "some uri");
51   }
52
53   @Test
54   public void should_return_proper_transaction() throws Exception {
55
56     when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type");
57     when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra");
58
59     when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-user")))
60         .thenReturn("rest-user");
61     when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-pass")))
62         .thenReturn("rest-pass");
63
64     Transaction transaction = TransactionHandler.buildTransaction(ctx, prop, "some uri");
65
66     Assert.assertEquals(INPUT_REQUEST_ACTION, transaction.getAction());
67     Assert.assertEquals("input-ra-type", transaction.getExecutionRPC());
68     Assert.assertEquals("some uri", transaction.getExecutionEndPoint());
69     Assert.assertEquals("rest-user", transaction.getId());
70     Assert.assertEquals("rest-pass", transaction.getPswd());
71   }
72
73 }