2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. 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.util.drawing;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.verifyNoMoreInteractions;
29 import static org.mockito.Mockito.when;
31 import java.io.IOException;
32 import javax.xml.parsers.ParserConfigurationException;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.runners.MockitoJUnitRunner;
38 import org.onap.clamp.clds.util.ResourceFileUtil;
39 import org.onap.clamp.clds.util.XmlToolsTest;
40 import org.w3c.dom.Document;
41 import org.xml.sax.SAXException;
43 @RunWith(MockitoJUnitRunner.class)
44 public class ClampGraphTest {
46 private DocumentBuilder mockDocumentBuilder;
49 public void getAsSvgTest() throws IOException, ParserConfigurationException, SAXException {
50 String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml");
51 Document document = XmlToolsTest.parseStringToXmlDocument(expected);
53 when(mockDocumentBuilder.getGroupingDocument()).thenReturn(document);
55 String actual = new ClampGraph(mockDocumentBuilder).getAsSvg();
56 Assert.assertEquals(expected.trim(), actual.trim());
60 public void getAsSvgLazyTest() throws IOException, ParserConfigurationException, SAXException {
61 String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml");
62 Document document = XmlToolsTest.parseStringToXmlDocument(expected);
64 when(mockDocumentBuilder.getGroupingDocument()).thenReturn(document);
65 ClampGraph cg = new ClampGraph(mockDocumentBuilder);
67 String actualFirst = cg.getAsSvg();
68 verify(mockDocumentBuilder, times(1)).getGroupingDocument();
70 String actualSecond = cg.getAsSvg();
71 verifyNoMoreInteractions(mockDocumentBuilder);
73 Assert.assertEquals(expected.trim(), actualFirst.trim());
74 Assert.assertEquals(expected.trim(), actualSecond.trim());