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 SvcLogicContext ctx;
22 private Properties prop;
25 public ExpectedException expectedException = ExpectedException.none();
29 ctx = mock(SvcLogicContext.class);
30 prop = mock(Properties.class);
34 public void should_throw_exception_when_input_request_action_type_missing() throws Exception {
36 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");
38 expectedException.expect(IllegalArgumentException.class);
39 expectedException.expectMessage("Don't know REST operation for Action");
40 TransactionHandler.buildTransaction(ctx, prop, RESOURCE_URI);
44 public void should_throw_exception_when_input_request_action_missing() throws Exception {
46 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");
48 expectedException.expect(IllegalArgumentException.class);
49 expectedException.expectMessage("Don't know request-action request-action");
50 TransactionHandler.buildTransaction(ctx, prop, "some uri");
54 public void should_return_proper_transaction() throws Exception {
56 when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type");
57 when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra");
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");
64 Transaction transaction = TransactionHandler.buildTransaction(ctx, prop, "some uri");
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());