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 * ===================================================================
23 package org.onap.clamp.clds.sdc.controller.installer;
25 import java.util.Arrays;
26 import java.util.HashSet;
27 import java.util.List;
29 import org.junit.Assert;
30 import org.junit.Test;
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";
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);
45 List<MicroService> expectedList = Arrays.asList(ms1, ms2, ms3, ms4);
46 Set<MicroService> inputSet = new HashSet<>(expectedList);
48 List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
49 Assert.assertEquals(expectedList, actualList);
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);
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());
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);
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());