aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java
blob: f16dd65cc125a10b9e22f8de0c6251a3dbf4b637 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.onap.appc.flow.controller.node;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE;

import java.util.Properties;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onap.appc.flow.controller.data.Transaction;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;

public class TransactionHandlerTest {

  private static final String RESOURCE_URI = "some uri";

  private TransactionHandler transactionHandler;
  private SvcLogicContext ctx;
  private Properties prop;

  @Rule
  public ExpectedException expectedException = ExpectedException.none();

  @Before
  public void setUp() {
    transactionHandler = new TransactionHandler();
    ctx = mock(SvcLogicContext.class);
    prop = mock(Properties.class);
  }

  @Test
  public void should_throw_exception_when_input_request_action_type_missing() throws Exception {

    when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("");

    expectedException.expect(Exception.class);
    expectedException.expectMessage("Don't know REST operation for Action");
    transactionHandler = new TransactionHandler();
    transactionHandler.buildTransaction(ctx, prop, RESOURCE_URI);
  }

  @Test
  public void should_throw_exception_when_input_request_action_missing() throws Exception {

    when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("foo");

    expectedException.expect(Exception.class);
    expectedException.expectMessage("Don't know request-action request-action");
    transactionHandler.buildTransaction(ctx, prop, "some uri");
  }

  @Test
  public void should_return_proper_transaction() throws Exception {

    when(ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE)).thenReturn("input-ra-type");
    when(ctx.getAttribute(INPUT_REQUEST_ACTION)).thenReturn("input-ra");

    when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-user")))
        .thenReturn("rest-user");
    when(prop.getProperty(ctx.getAttribute(INPUT_REQUEST_ACTION).concat(".default-rest-pass")))
        .thenReturn("rest-pass");

    Transaction transaction = transactionHandler.buildTransaction(ctx, prop, "some uri");

    Assert.assertEquals(INPUT_REQUEST_ACTION, transaction.getAction());
    Assert.assertEquals("input-ra-type", transaction.getExecutionRPC());
    Assert.assertEquals("some uri", transaction.getExecutionEndPoint());
    Assert.assertEquals("rest-user", transaction.getId());
    Assert.assertEquals("rest-pass", transaction.getPswd());
  }

}