2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. All rights
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
27 package org.onap.clamp.clds.util.drawing;
29 import static org.assertj.core.api.Assertions.assertThat;
30 import static org.mockito.Mockito.times;
31 import static org.mockito.Mockito.verify;
33 import com.google.gson.JsonObject;
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.Loop;
43 import org.onap.clamp.loop.template.PolicyModel;
44 import org.onap.clamp.policy.microservice.MicroServicePolicy;
45 import org.onap.clamp.policy.operational.OperationalPolicy;
47 @RunWith(MockitoJUnitRunner.class)
48 public class ClampGraphBuilderTest {
50 private Painter mockPainter;
53 private ArgumentCaptor<String> collectorCaptor;
56 private ArgumentCaptor<Set<MicroServicePolicy>> microServicesCaptor;
59 private ArgumentCaptor<Set<OperationalPolicy>> policyCaptor;
62 * Do a quick test of the graphBuilder chain.
65 public void clampGraphBuilderCompleteChainTest() {
66 String collector = "VES";
67 MicroServicePolicy ms1 = new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0"), false,
69 MicroServicePolicy ms2 = new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0"), false,
72 OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(),
73 new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"));
74 final Set<OperationalPolicy> opPolicies = Set.of(opPolicy);
75 final Set<MicroServicePolicy> microServices = Set.of(ms1, ms2);
77 ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
78 clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).addPolicy(opPolicy).build();
80 verify(mockPainter, times(1)).doPaint(collectorCaptor.capture(), microServicesCaptor.capture(),
81 policyCaptor.capture());
83 Assert.assertEquals(collector, collectorCaptor.getValue());
84 Assert.assertEquals(microServices, microServicesCaptor.getValue());
85 Assert.assertEquals(opPolicies, policyCaptor.getValue());
89 * Do a quick test of the graphBuilder chain when no policy is given.
92 public void clampGraphBuilderNoPolicyGivenTest() {
93 String collector = "VES";
94 MicroServicePolicy ms1 =
95 new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0"), false, null);
96 MicroServicePolicy ms2 =
97 new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0"), false, null);
99 ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
100 assertThat(clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).build())