diff options
author | sebdet <sebastien.determe@intl.att.com> | 2020-05-20 18:36:43 +0200 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2020-05-27 17:39:54 +0200 |
commit | 9e25792898ae648234239403374db8bb923bc180 (patch) | |
tree | b00142fcd0f173f0af2316b7ad1d49f24611dcdc /src/test/java/org/onap/clamp/clds | |
parent | c0ec0fc448af1c5d6eacb195e95938c921ba1bce (diff) |
Create SVG in UI
Remove the SVG generation from the backend and put it in the UI. Backend removal code + clean up of test resources
Issue-ID: CLAMP-854
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: Ie9d6cd20f0135b459dbc85901b9a66f65002a85c
Diffstat (limited to 'src/test/java/org/onap/clamp/clds')
5 files changed, 0 insertions, 430 deletions
diff --git a/src/test/java/org/onap/clamp/clds/util/XmlToolsTest.java b/src/test/java/org/onap/clamp/clds/util/XmlToolsTest.java deleted file mode 100644 index a34ef3f9..00000000 --- a/src/test/java/org/onap/clamp/clds/util/XmlToolsTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util; - -import java.io.IOException; -import java.io.StringReader; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.apache.batik.anim.dom.SVGDOMImplementation; -import org.apache.batik.util.SVGConstants; -import org.junit.Assert; -import org.junit.Test; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -public class XmlToolsTest { - - @Test - public void exportXmlDocumentAsStringTest() throws IOException, ParserConfigurationException, SAXException { - String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml"); - Document document = parseStringToXmlDocument(expected); - String actual = XmlTools.exportXmlDocumentAsString(document); - Assert.assertEquals(expected.trim(), actual.trim()); - } - - @Test - public void createEmptySvgDocumentTest() { - Document doc = XmlTools.createEmptySvgDocument(); - Assert.assertEquals(SVGDOMImplementation.SVG_NAMESPACE_URI, doc.getDocumentElement().getNamespaceURI()); - Assert.assertEquals(SVGConstants.SVG_SVG_TAG, doc.getDocumentElement().getNodeName()); - Assert.assertNull(doc.getDoctype()); - } - - /** - * Method to parse String into XmlDocument. - * - * @param res - * String to parse - * @return - * XmlDocument - * @throws ParserConfigurationException - * In case of issues with parse the document - * @throws SAXException - * In case of bad format of res - * @throws IOException - * In case of issues creating the document - */ - public static Document parseStringToXmlDocument(String res) - throws ParserConfigurationException, SAXException, IOException { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setValidating(false); - dbf.setNamespaceAware(true); - dbf.setFeature("http://xml.org/sax/features/namespaces", false); - dbf.setFeature("http://xml.org/sax/features/validation", false); - dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); - dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); - DocumentBuilder db = dbf.newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(res)); - return db.parse(is); - } - -} diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java deleted file mode 100644 index 8eeba07e..00000000 --- a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * Modifications copyright (c) 2019 AT&T - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import com.google.gson.JsonObject; -import java.util.Set; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.clamp.loop.template.PolicyModel; -import org.onap.clamp.policy.microservice.MicroServicePolicy; -import org.onap.clamp.policy.operational.OperationalPolicy; - -@RunWith(MockitoJUnitRunner.class) -public class ClampGraphBuilderTest { - @Mock - private Painter mockPainter; - - @Captor - private ArgumentCaptor<String> collectorCaptor; - - @Captor - private ArgumentCaptor<Set<MicroServicePolicy>> microServicesCaptor; - - @Captor - private ArgumentCaptor<Set<OperationalPolicy>> policyCaptor; - - /** - * Do a quick test of the graphBuilder chain. - */ - @Test - public void clampGraphBuilderCompleteChainTest() { - String collector = "VES"; - MicroServicePolicy ms1 = new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0"), false, - null, null, null, null); - MicroServicePolicy ms2 = new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0"), false, - null, null, null, null); - - OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new JsonObject(), new JsonObject(), - new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"), null, null, null); - final Set<OperationalPolicy> opPolicies = Set.of(opPolicy); - final Set<MicroServicePolicy> microServices = Set.of(ms1, ms2); - - ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter); - clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).addPolicy(opPolicy).build(); - - verify(mockPainter, times(1)).doPaint(collectorCaptor.capture(), microServicesCaptor.capture(), - policyCaptor.capture()); - - Assert.assertEquals(collector, collectorCaptor.getValue()); - Assert.assertEquals(microServices, microServicesCaptor.getValue()); - Assert.assertEquals(opPolicies, policyCaptor.getValue()); - } - - /** - * Do a quick test of the graphBuilder chain when no policy is given. - */ - @Test - public void clampGraphBuilderNoPolicyGivenTest() { - String collector = "VES"; - MicroServicePolicy ms1 = - new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0"), false, null, null, null, - null); - MicroServicePolicy ms2 = - new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0"), false, null, null, null, - null); - - ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter); - assertThat(clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).build()) - .isNotNull(); - - } -} diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphTest.java deleted file mode 100644 index 4ae0a490..00000000 --- a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.clamp.clds.util.XmlToolsTest; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -@RunWith(MockitoJUnitRunner.class) -public class ClampGraphTest { - @Mock - private DocumentBuilder mockDocumentBuilder; - - @Test - public void getAsSvgTest() throws IOException, ParserConfigurationException, SAXException { - String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml"); - Document document = XmlToolsTest.parseStringToXmlDocument(expected); - - when(mockDocumentBuilder.getGroupingDocument()).thenReturn(document); - - String actual = new ClampGraph(mockDocumentBuilder).getAsSvg(); - Assert.assertEquals(expected.trim(), actual.trim()); - } - - @Test - public void getAsSvgLazyTest() throws IOException, ParserConfigurationException, SAXException { - String expected = ResourceFileUtil.getResourceAsString("clds/util/file.xml"); - Document document = XmlToolsTest.parseStringToXmlDocument(expected); - - when(mockDocumentBuilder.getGroupingDocument()).thenReturn(document); - ClampGraph cg = new ClampGraph(mockDocumentBuilder); - - String actualFirst = cg.getAsSvg(); - verify(mockDocumentBuilder, times(1)).getGroupingDocument(); - - String actualSecond = cg.getAsSvg(); - verifyNoMoreInteractions(mockDocumentBuilder); - - Assert.assertEquals(expected.trim(), actualFirst.trim()); - Assert.assertEquals(expected.trim(), actualSecond.trim()); - - } -} diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java deleted file mode 100644 index 13f8e3ad..00000000 --- a/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; - -import java.io.IOException; - -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.batik.svggen.SVGGraphics2D; -import org.apache.batik.util.SVGConstants; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.clamp.clds.util.ResourceFileUtil; -import org.onap.clamp.clds.util.XmlToolsTest; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -@RunWith(MockitoJUnitRunner.class) -public class DocumentBuilderTest { - @Mock - private SVGGraphics2D mockG2d; - - @Test - public void pushChangestoDocumentTest() throws IOException, ParserConfigurationException, SAXException { - String dataElementId = "someId"; - String newNodeTag = "tagged"; - String newNodeText = "Sample text"; - String xml = ResourceFileUtil.getResourceAsString("clds/util/file.xml"); - Document document = XmlToolsTest.parseStringToXmlDocument(xml); - Node newNode = document.createElement(newNodeTag); - newNode.appendChild(document.createTextNode(newNodeText)); - - when(mockG2d.getRoot(any(Element.class))).then(a -> a.getArgument(0, Element.class).appendChild(newNode)); - - DocumentBuilder db = new DocumentBuilder(document, document); - db.pushChangestoDocument(mockG2d, dataElementId); - Document actualDocument = db.getGroupingDocument(); - - Node addedActualNode = actualDocument.getDocumentElement().getLastChild(); - String actualDataElementId = addedActualNode.getAttributes() - .getNamedItem(DocumentBuilder.DATA_ELEMENT_ID_ATTRIBUTE).getTextContent(); - - Assert.assertEquals(dataElementId, actualDataElementId); - Assert.assertEquals(SVGConstants.SVG_G_TAG, addedActualNode.getNodeName()); - - Node addedActualNodeChild = addedActualNode.getLastChild(); - Assert.assertEquals(newNodeTag, addedActualNodeChild.getNodeName()); - Assert.assertEquals(newNodeText, addedActualNodeChild.getTextContent()); - } -}
\ No newline at end of file diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java deleted file mode 100644 index 0150af02..00000000 --- a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -package org.onap.clamp.clds.util.drawing; - -import static org.assertj.core.api.Assertions.assertThat; -import com.google.gson.JsonObject; -import java.io.IOException; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.Test; -import org.onap.clamp.loop.Loop; -import org.onap.clamp.loop.template.LoopElementModel; -import org.onap.clamp.loop.template.PolicyModel; -import org.onap.clamp.policy.microservice.MicroServicePolicy; -import org.onap.clamp.policy.operational.OperationalPolicy; -import org.xml.sax.SAXException; - -public class SvgLoopGeneratorTest { - private Loop getLoop() { - - LoopElementModel msModel = new LoopElementModel("testMs", LoopElementModel.MICRO_SERVICE_TYPE, ""); - MicroServicePolicy ms1 = - new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0", "short.ms1"), - false,null,msModel,null,null); - MicroServicePolicy ms2 = - new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0", "short.ms2"), - false, null,msModel,null,null); - LoopElementModel opModel = new LoopElementModel("testOp", LoopElementModel.OPERATIONAL_POLICY_TYPE, ""); - OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new JsonObject(),new JsonObject(), - new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy"), opModel, null, null); - Loop loop = new Loop(); - loop.addMicroServicePolicy(ms1); - loop.addMicroServicePolicy(ms2); - loop.addOperationalPolicy(opPolicy); - return loop; - } - - /** - * Test a Svg rendering with all objects. - * - * @throws IOException In case of isssues - * @throws ParserConfigurationException In case of isssues - * @throws SAXException In case of isssues - */ - @Test - public void getAsSvgTest() throws IOException, ParserConfigurationException, SAXException { - String xml = SvgLoopGenerator.getSvgImage(getLoop()); - assertThat(xml).contains("data-element-id=\"VES\""); - assertThat(xml).contains(">VES<"); - assertThat(xml).contains("data-element-id=\"ms1\""); - assertThat(xml).contains("data-element-id=\"ms2\""); - assertThat(xml).contains("data-grouping-id=\"testMs\""); - assertThat(xml).contains("data-grouping-id=\"testOp\""); - assertThat(xml).contains("data-for-ui=\"testMs\""); - assertThat(xml).contains("data-for-ui=\"testOp\""); - assertThat(xml).contains(">short.ms1<"); - assertThat(xml).contains(">short.ms2<"); - assertThat(xml).contains("data-element-id=\"OperationalPolicy\""); - assertThat(xml).contains(">short.OperationalPolicy<"); - - } -} |