Create SVG in UI
[clamp.git] / src / test / java / org / onap / clamp / clds / util / drawing / SvgLoopGeneratorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.util.drawing;
25
26 import static org.assertj.core.api.Assertions.assertThat;
27 import com.google.gson.JsonObject;
28 import java.io.IOException;
29 import javax.xml.parsers.ParserConfigurationException;
30 import org.junit.Test;
31 import org.onap.clamp.loop.Loop;
32 import org.onap.clamp.loop.template.LoopElementModel;
33 import org.onap.clamp.loop.template.PolicyModel;
34 import org.onap.clamp.policy.microservice.MicroServicePolicy;
35 import org.onap.clamp.policy.operational.OperationalPolicy;
36 import org.xml.sax.SAXException;
37
38 public class SvgLoopGeneratorTest {
39     private Loop getLoop() {
40
41         LoopElementModel msModel = new LoopElementModel("testMs", LoopElementModel.MICRO_SERVICE_TYPE, "");
42         MicroServicePolicy ms1 =
43                 new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0", "short.ms1"),
44                         false,null,msModel,null,null);
45         MicroServicePolicy ms2 =
46                 new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0", "short.ms2"),
47                         false, null,msModel,null,null);
48         LoopElementModel opModel = new LoopElementModel("testOp", LoopElementModel.OPERATIONAL_POLICY_TYPE, "");
49         OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new JsonObject(),new JsonObject(),
50                 new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy"), opModel, null, null);
51         Loop loop = new Loop();
52         loop.addMicroServicePolicy(ms1);
53         loop.addMicroServicePolicy(ms2);
54         loop.addOperationalPolicy(opPolicy);
55         return loop;
56     }
57
58     /**
59      * Test a Svg rendering with all objects.
60      *
61      * @throws IOException In case of isssues
62      * @throws ParserConfigurationException In case of isssues
63      * @throws SAXException In case of isssues
64      */
65     @Test
66     public void getAsSvgTest() throws IOException, ParserConfigurationException, SAXException {
67         String xml = SvgLoopGenerator.getSvgImage(getLoop());
68         assertThat(xml).contains("data-element-id=\"VES\"");
69         assertThat(xml).contains(">VES<");
70         assertThat(xml).contains("data-element-id=\"ms1\"");
71         assertThat(xml).contains("data-element-id=\"ms2\"");
72         assertThat(xml).contains("data-grouping-id=\"testMs\"");
73         assertThat(xml).contains("data-grouping-id=\"testOp\"");
74         assertThat(xml).contains("data-for-ui=\"testMs\"");
75         assertThat(xml).contains("data-for-ui=\"testOp\"");
76         assertThat(xml).contains(">short.ms1<");
77         assertThat(xml).contains(">short.ms2<");
78         assertThat(xml).contains("data-element-id=\"OperationalPolicy\"");
79         assertThat(xml).contains(">short.OperationalPolicy<");
80
81     }
82 }