8eeba07ed83f47d2947d9ac0ce712de26d559e36
[clamp.git] / src / test / java / org / onap / clamp / clds / util / drawing / ClampGraphBuilderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights
6  *                             reserved.
7  * ================================================================================
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END============================================
22  * Modifications copyright (c) 2019 AT&T
23  * ===================================================================
24  *
25  */
26
27 package org.onap.clamp.clds.util.drawing;
28
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.mockito.Mockito.times;
31 import static org.mockito.Mockito.verify;
32
33 import com.google.gson.JsonObject;
34 import java.util.Set;
35 import org.junit.Assert;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.ArgumentCaptor;
39 import org.mockito.Captor;
40 import org.mockito.Mock;
41 import org.mockito.runners.MockitoJUnitRunner;
42 import org.onap.clamp.loop.template.PolicyModel;
43 import org.onap.clamp.policy.microservice.MicroServicePolicy;
44 import org.onap.clamp.policy.operational.OperationalPolicy;
45
46 @RunWith(MockitoJUnitRunner.class)
47 public class ClampGraphBuilderTest {
48     @Mock
49     private Painter mockPainter;
50
51     @Captor
52     private ArgumentCaptor<String> collectorCaptor;
53
54     @Captor
55     private ArgumentCaptor<Set<MicroServicePolicy>> microServicesCaptor;
56
57     @Captor
58     private ArgumentCaptor<Set<OperationalPolicy>> policyCaptor;
59
60     /**
61      * Do a quick test of the graphBuilder chain.
62      */
63     @Test
64     public void clampGraphBuilderCompleteChainTest() {
65         String collector = "VES";
66         MicroServicePolicy ms1 = new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0"), false,
67                 null, null, null, null);
68         MicroServicePolicy ms2 = new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0"), false,
69                 null, null, null, null);
70
71         OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new JsonObject(), new JsonObject(),
72                 new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"), null, null, null);
73         final Set<OperationalPolicy> opPolicies = Set.of(opPolicy);
74         final Set<MicroServicePolicy> microServices = Set.of(ms1, ms2);
75
76         ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
77         clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).addPolicy(opPolicy).build();
78
79         verify(mockPainter, times(1)).doPaint(collectorCaptor.capture(), microServicesCaptor.capture(),
80                 policyCaptor.capture());
81
82         Assert.assertEquals(collector, collectorCaptor.getValue());
83         Assert.assertEquals(microServices, microServicesCaptor.getValue());
84         Assert.assertEquals(opPolicies, policyCaptor.getValue());
85     }
86
87     /**
88      * Do a quick test of the graphBuilder chain when no policy is given.
89      */
90     @Test
91     public void clampGraphBuilderNoPolicyGivenTest() {
92         String collector = "VES";
93         MicroServicePolicy ms1 =
94                 new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0"), false, null, null, null,
95                         null);
96         MicroServicePolicy ms2 =
97                 new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0"), false, null, null, null,
98                         null);
99
100         ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
101         assertThat(clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).build())
102                 .isNotNull();
103
104     }
105 }