4b4563cd49c6503cc883c88831a1baafd3df141c
[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
24 package org.onap.clamp.clds.sdc.controller.installer;
25
26 import java.util.Arrays;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Set;
30
31 import org.junit.Assert;
32 import org.junit.Test;
33
34 public class ChainGeneratorTest {
35     private static final String FIRST_APPP = "first_app";
36     private static final String SECOND_APPP = "second_app";
37     private static final String THIRD_APPP = "third_app";
38     private static final String FOURTH_APPP = "fourth_app";
39
40     @Test
41     public void getChainOfMicroServicesTest() {
42         MicroService ms1 = new MicroService(FIRST_APPP, "", "", "");
43         MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "");
44         MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "");
45         MicroService ms4 = new MicroService(FOURTH_APPP, "", THIRD_APPP, "");
46
47         List<MicroService> expectedList = Arrays.asList(ms1, ms2, ms3, ms4);
48         Set<MicroService> inputSet = new HashSet<>(expectedList);
49
50         List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
51         Assert.assertEquals(expectedList, actualList);
52     }
53
54     @Test
55     public void getChainOfMicroServicesTwiceNoInputTest() {
56         MicroService ms1 = new MicroService(FIRST_APPP, "", "", "");
57         MicroService ms2 = new MicroService(SECOND_APPP, "", "", "");
58         MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "");
59         MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "");
60
61         Set<MicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
62         List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
63         Assert.assertTrue(actualList.isEmpty());
64     }
65
66     @Test
67     public void getChainOfMicroServicesBranchingTest() {
68         MicroService ms1 = new MicroService(FIRST_APPP, "", "", "");
69         MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "");
70         MicroService ms3 = new MicroService(THIRD_APPP, "", FIRST_APPP, "");
71         MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "");
72
73         Set<MicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
74         List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
75         Assert.assertTrue(actualList.isEmpty());
76     }
77 }