Rework the submit operation
[clamp.git] / src / test / java / org / onap / clamp / clds / sdc / controller / installer / ChainGeneratorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Nokia Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23 package org.onap.clamp.clds.sdc.controller.installer;
24
25 import java.util.Arrays;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Set;
29
30 import org.junit.Assert;
31 import org.junit.Test;
32
33 public class ChainGeneratorTest {
34     private static final String FIRST_APPP = "first_app";
35     private static final String SECOND_APPP = "second_app";
36     private static final String THIRD_APPP = "third_app";
37     private static final String FOURTH_APPP = "fourth_app";
38
39     @Test
40     public void getChainOfMicroServicesTest() {
41         MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
42         MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "", "");
43         MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "", "");
44         MicroService ms4 = new MicroService(FOURTH_APPP, "", THIRD_APPP, "", "");
45
46         List<MicroService> expectedList = Arrays.asList(ms1, ms2, ms3, ms4);
47         Set<MicroService> inputSet = new HashSet<>(expectedList);
48
49         List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
50         Assert.assertEquals(expectedList, actualList);
51     }
52
53     @Test
54     public void getChainOfMicroServicesTwiceNoInputTest() {
55         MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
56         MicroService ms2 = new MicroService(SECOND_APPP, "", "", "", "");
57         MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "", "");
58         MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "", "");
59
60         Set<MicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
61         List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
62         Assert.assertTrue(actualList.isEmpty());
63     }
64
65     @Test
66     public void getChainOfMicroServicesBranchingTest() {
67         MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
68         MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "", "");
69         MicroService ms3 = new MicroService(THIRD_APPP, "", FIRST_APPP, "", "");
70         MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "", "");
71
72         Set<MicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
73         List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
74         Assert.assertTrue(actualList.isEmpty());
75     }
76 }