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