4ae0a4908f4ce6c2ee3dbe6eedc98b7b1e12394f
[clamp.git] / src / test / java / org / onap / clamp / clds / util / drawing / ClampGraphTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. 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.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.verifyNoMoreInteractions;
29 import static org.mockito.Mockito.when;
30
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;
42
43 @RunWith(MockitoJUnitRunner.class)
44 public class ClampGraphTest {
45     @Mock
46     private DocumentBuilder mockDocumentBuilder;
47
48     @Test
49     public void getAsSvgTest() throws IOException, ParserConfigurationException, SAXException {
50         String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml");
51         Document document = XmlToolsTest.parseStringToXmlDocument(expected);
52
53         when(mockDocumentBuilder.getGroupingDocument()).thenReturn(document);
54
55         String actual = new ClampGraph(mockDocumentBuilder).getAsSvg();
56         Assert.assertEquals(expected.trim(), actual.trim());
57     }
58
59     @Test
60     public void getAsSvgLazyTest() throws IOException, ParserConfigurationException, SAXException {
61         String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml");
62         Document document = XmlToolsTest.parseStringToXmlDocument(expected);
63
64         when(mockDocumentBuilder.getGroupingDocument()).thenReturn(document);
65         ClampGraph cg = new ClampGraph(mockDocumentBuilder);
66
67         String actualFirst = cg.getAsSvg();
68         verify(mockDocumentBuilder, times(1)).getGroupingDocument();
69
70         String actualSecond = cg.getAsSvg();
71         verifyNoMoreInteractions(mockDocumentBuilder);
72
73         Assert.assertEquals(expected.trim(), actualFirst.trim());
74         Assert.assertEquals(expected.trim(), actualSecond.trim());
75
76     }
77 }