Split sequence generation to classess
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / controller / node / FlowGeneratorTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. All rights reserved.
6  * =============================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.appc.flow.controller.node;
21
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.when;
24 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.ACTION_LEVEL;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.PAYLOAD;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REQUEST_ACTION;
27
28 import java.util.HashMap;
29 import java.util.List;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.appc.flow.controller.data.Response;
34 import org.onap.appc.flow.controller.data.ResponseAction;
35 import org.onap.appc.flow.controller.data.Transaction;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37
38 public class FlowGeneratorTest {
39
40   private HashMap<String, String> inParams;
41   private SvcLogicContext ctx;
42
43   @Before
44   public void setUp() {
45     inParams = new HashMap<>();
46     ctx = mock(SvcLogicContext.class);
47   }
48
49   @Test
50   public void should_get_proper_transactions() {
51     when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action");
52     when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level");
53     when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload");
54
55     FlowGenerator flowGenerator = new FlowGenerator();
56     List<Transaction> transactionsList = flowGenerator.createSingleStepModel(inParams, ctx).getTransactions();
57
58     Assert.assertEquals(1, transactionsList.size());
59
60     Transaction transaction = transactionsList.get(0);
61     Assert.assertEquals(1, transaction.getTransactionId());
62     Assert.assertEquals("some-request-action", transaction.getAction());
63     Assert.assertEquals("some-payload", transaction.getPayload());
64     Assert.assertEquals("some-action-level", transaction.getActionLevel());
65
66     List<Response> responses = transaction.getResponses();
67     Assert.assertEquals(1, responses.size());
68
69     ResponseAction responseAction = responses.get(0).getResponseAction();
70     Assert.assertTrue(responseAction.isStop());
71   }
72
73 }