2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.sdc.controller.installer;
26 import java.util.Arrays;
27 import java.util.HashSet;
28 import java.util.List;
31 import org.junit.Assert;
32 import org.junit.Test;
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";
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, "");
47 List<MicroService> expectedList = Arrays.asList(ms1, ms2, ms3, ms4);
48 Set<MicroService> inputSet = new HashSet<>(expectedList);
50 List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
51 Assert.assertEquals(expectedList, actualList);
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, "");
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());
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, "");
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());