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";
39 private static final String DEFAULT_VERSION = "1.0.0";
42 public void getChainOfMicroServicesTest() {
43 BlueprintMicroService ms1 = new BlueprintMicroService(FIRST_APPP, "", "", DEFAULT_VERSION);
44 BlueprintMicroService ms2 = new BlueprintMicroService(SECOND_APPP, "", FIRST_APPP, DEFAULT_VERSION);
45 BlueprintMicroService ms3 = new BlueprintMicroService(THIRD_APPP, "", SECOND_APPP, DEFAULT_VERSION);
46 BlueprintMicroService ms4 = new BlueprintMicroService(FOURTH_APPP, "", THIRD_APPP, DEFAULT_VERSION);
48 List<BlueprintMicroService> expectedList = Arrays.asList(ms1, ms2, ms3, ms4);
49 Set<BlueprintMicroService> inputSet = new HashSet<>(expectedList);
51 List<BlueprintMicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
52 Assert.assertEquals(expectedList, actualList);
56 public void getChainOfMicroServicesTwiceNoInputTest() {
57 BlueprintMicroService ms1 = new BlueprintMicroService(FIRST_APPP, "", "", DEFAULT_VERSION);
58 BlueprintMicroService ms2 = new BlueprintMicroService(SECOND_APPP, "", "", DEFAULT_VERSION);
59 BlueprintMicroService ms3 = new BlueprintMicroService(THIRD_APPP, "", SECOND_APPP, DEFAULT_VERSION);
60 BlueprintMicroService ms4 = new BlueprintMicroService(FOURTH_APPP, "", FIRST_APPP, DEFAULT_VERSION);
62 Set<BlueprintMicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
63 List<BlueprintMicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
64 Assert.assertTrue(actualList.isEmpty());
68 public void getChainOfMicroServicesBranchingTest() {
69 BlueprintMicroService ms1 = new BlueprintMicroService(FIRST_APPP, "", "", DEFAULT_VERSION);
70 BlueprintMicroService ms2 = new BlueprintMicroService(SECOND_APPP, "", FIRST_APPP, DEFAULT_VERSION);
71 BlueprintMicroService ms3 = new BlueprintMicroService(THIRD_APPP, "", FIRST_APPP, DEFAULT_VERSION);
72 BlueprintMicroService ms4 = new BlueprintMicroService(FOURTH_APPP, "", FIRST_APPP, DEFAULT_VERSION);
74 Set<BlueprintMicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
75 List<BlueprintMicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
76 Assert.assertTrue(actualList.isEmpty());