Skip to content

Commit a89c6ab

Browse files
Kate IvanovaiText-CI
authored andcommitted
Add logmessages into unit tests
DEVSIX-2904
1 parent cfa9d76 commit a89c6ab

39 files changed

+200
-63
lines changed

styled-xml-parser/src/test/java/com/itextpdf/styledxmlparser/jsoup/JsoupXmlParserTest.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ This file is part of the iText (R) project.
4242
*/
4343
package com.itextpdf.styledxmlparser.jsoup;
4444

45+
import com.itextpdf.styledxmlparser.LogMessageConstant;
46+
import com.itextpdf.styledxmlparser.jsoup.nodes.Element;
47+
import com.itextpdf.styledxmlparser.jsoup.parser.Tag;
4548
import com.itextpdf.styledxmlparser.node.IDocumentNode;
49+
import com.itextpdf.styledxmlparser.node.INode;
4650
import com.itextpdf.styledxmlparser.node.impl.jsoup.JsoupXmlParser;
51+
import com.itextpdf.styledxmlparser.node.impl.jsoup.node.JsoupElementNode;
52+
import com.itextpdf.test.ExtendedITextTest;
53+
import com.itextpdf.test.annotations.LogMessage;
54+
import com.itextpdf.test.annotations.LogMessages;
4755
import com.itextpdf.test.annotations.type.UnitTest;
4856
import org.junit.Assert;
4957
import org.junit.Test;
@@ -54,14 +62,25 @@ This file is part of the iText (R) project.
5462
import java.io.InputStream;
5563

5664
@Category(UnitTest.class)
57-
public class JsoupXmlParserTest {
58-
@Test
59-
public void testXmlDeclarationAndComment() throws IOException {
60-
String xml = "<?xml version=\"1.0\" standalone=\"no\"?>\n" +
61-
"<!-- just declaration and comment -->";
62-
InputStream stream = new ByteArrayInputStream(xml.getBytes());
63-
IDocumentNode node = new JsoupXmlParser().parse(stream, "UTF-8");
64-
// only text (whitespace) child node shall be fetched.
65-
Assert.assertEquals(1, node.childNodes().size());
66-
}
65+
public class JsoupXmlParserTest extends ExtendedITextTest {
66+
@Test
67+
public void testXmlDeclarationAndComment() throws IOException {
68+
String xml = "<?xml version=\"1.0\" standalone=\"no\"?>\n" +
69+
"<!-- just declaration and comment -->";
70+
InputStream stream = new ByteArrayInputStream(xml.getBytes());
71+
IDocumentNode node = new JsoupXmlParser().parse(stream, "UTF-8");
72+
// only text (whitespace) child node shall be fetched.
73+
Assert.assertEquals(1, node.childNodes().size());
74+
}
75+
76+
@Test
77+
@LogMessages(messages = {
78+
@LogMessage(messageTemplate = LogMessageConstant.ERROR_ADDING_CHILD_NODE),
79+
})
80+
public void testMessageAddingChild() {
81+
Element jsoupSVGRoot = new Element(Tag.valueOf("svg"), "");
82+
INode root = new JsoupElementNode(jsoupSVGRoot);
83+
root.addChild(null);
84+
Assert.assertEquals(0, root.childNodes().size());
85+
}
6786
}

svg/src/main/java/com/itextpdf/svg/renderers/factories/DefaultSvgNodeRendererFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ public ISvgNodeRenderer createSvgNodeRendererForTag(IElementNode tag, ISvgNodeRe
114114
throw new SvgProcessingException(SvgLogMessageConstant.COULDNOTINSTANTIATE, ex).setMessageParams(tag.name());
115115
}
116116

117-
if (parent != null && !(parent instanceof NoDrawOperationSvgNodeRenderer )) {
117+
if (parent != null && !(parent instanceof NoDrawOperationSvgNodeRenderer)) {
118118
result.setParent(parent);
119119
}
120120

121121
return result;
122122
}
123123

124124
@Override
125-
public boolean isTagIgnored(IElementNode tag){
125+
public boolean isTagIgnored(IElementNode tag) {
126126
return ignoredTags.contains(tag.name());
127127
}
128-
}
128+
}

svg/src/test/java/com/itextpdf/svg/converter/SvgConverterUnitNullTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This file is part of the iText (R) project.
5353
import com.itextpdf.svg.exceptions.SvgProcessingException;
5454
import com.itextpdf.svg.processors.ISvgConverterProperties;
5555
import com.itextpdf.svg.renderers.ISvgNodeRenderer;
56+
import com.itextpdf.test.ExtendedITextTest;
5657
import com.itextpdf.test.annotations.type.UnitTest;
5758
import java.io.ByteArrayInputStream;
5859
import java.io.ByteArrayOutputStream;
@@ -75,7 +76,7 @@ This file is part of the iText (R) project.
7576
* should NOT throw an exception as this is caught in the library.
7677
*/
7778
@Category(UnitTest.class)
78-
public class SvgConverterUnitNullTest {
79+
public class SvgConverterUnitNullTest extends ExtendedITextTest {
7980

8081
// we cannot easily mock the PdfDocument, so we make do with as close to unit testing as we can
8182
private PdfDocument doc;

svg/src/test/java/com/itextpdf/svg/converter/SvgConverterUnitTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ This file is part of the iText (R) project.
5959
import com.itextpdf.svg.exceptions.SvgProcessingException;
6060
import com.itextpdf.svg.renderers.IBranchSvgNodeRenderer;
6161
import com.itextpdf.svg.renderers.impl.SvgTagSvgNodeRenderer;
62+
import com.itextpdf.test.ExtendedITextTest;
6263
import com.itextpdf.test.annotations.type.UnitTest;
6364
import java.io.ByteArrayInputStream;
6465
import java.io.ByteArrayOutputStream;
@@ -74,7 +75,7 @@ This file is part of the iText (R) project.
7475
import org.junit.rules.ExpectedException;
7576

7677
@Category(UnitTest.class)
77-
public class SvgConverterUnitTest {
78+
public class SvgConverterUnitTest extends ExtendedITextTest {
7879

7980
// we cannot easily mock the PdfDocument, so we make do with as close to unit testing as we can
8081
private PdfDocument doc;

svg/src/test/java/com/itextpdf/svg/css/SvgStyleResolverTest.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ This file is part of the iText (R) project.
5959
import com.itextpdf.svg.css.impl.SvgStyleResolver;
6060
import com.itextpdf.svg.processors.impl.SvgConverterProperties;
6161
import com.itextpdf.svg.processors.impl.SvgProcessorContext;
62+
import com.itextpdf.test.ExtendedITextTest;
6263
import com.itextpdf.test.annotations.LogMessage;
6364
import com.itextpdf.test.annotations.LogMessages;
6465
import com.itextpdf.test.annotations.type.UnitTest;
@@ -72,7 +73,7 @@ This file is part of the iText (R) project.
7273
import org.junit.experimental.categories.Category;
7374

7475
@Category(UnitTest.class)
75-
public class SvgStyleResolverTest {
76+
public class SvgStyleResolverTest extends ExtendedITextTest{
7677
private static final String baseUri = "./src/test/resources/com/itextpdf/svg/css/SvgStyleResolver/";
7778

7879
//Single element test
@@ -146,20 +147,6 @@ public void svgCssResolveHashXlinkTest() {
146147
Assert.assertEquals("#testid", attr.get("xlink:href"));
147148
}
148149

149-
@Test
150-
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.UNABLE_TO_RESOLVE_IMAGE_URL, count = 1))
151-
public void svgCssResolveMalformedXlinkTest() {
152-
Element jsoupImage = new Element(Tag.valueOf("image"), "");
153-
Attributes imageAttributes = jsoupImage.attributes();
154-
155-
imageAttributes.put(new Attribute("xlink:href", "htt://are/"));
156-
JsoupElementNode node = new JsoupElementNode(jsoupImage);
157-
158-
SvgStyleResolver sr = new SvgStyleResolver();
159-
Map<String, String> attr = sr.resolveStyles(node, new SvgCssContext());
160-
Assert.assertEquals("htt://are/", attr.get("xlink:href"));
161-
}
162-
163150
@Test
164151
public void overrideDefaultStyleTest() {
165152
ICssResolver styleResolver = new SvgStyleResolver();
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.svg.css;
44+
45+
import com.itextpdf.styledxmlparser.LogMessageConstant;
46+
import com.itextpdf.styledxmlparser.jsoup.nodes.Attribute;
47+
import com.itextpdf.styledxmlparser.jsoup.nodes.Attributes;
48+
import com.itextpdf.styledxmlparser.jsoup.nodes.Element;
49+
import com.itextpdf.styledxmlparser.jsoup.parser.Tag;
50+
import com.itextpdf.styledxmlparser.node.impl.jsoup.node.JsoupElementNode;
51+
import com.itextpdf.svg.css.impl.SvgStyleResolver;
52+
import com.itextpdf.test.ExtendedITextTest;
53+
import com.itextpdf.test.annotations.LogMessage;
54+
import com.itextpdf.test.annotations.LogMessages;
55+
import com.itextpdf.test.annotations.type.UnitTest;
56+
import org.junit.Assert;
57+
import org.junit.Test;
58+
import org.junit.experimental.categories.Category;
59+
60+
import java.util.Map;
61+
62+
@Category(UnitTest.class)
63+
public class XLinkTest extends ExtendedITextTest {
64+
65+
@Test
66+
@LogMessages(messages = @LogMessage(messageTemplate = LogMessageConstant.UNABLE_TO_RESOLVE_IMAGE_URL))
67+
public void svgCssResolveMalformedXlinkTest() {
68+
Element jsoupImage = new Element(Tag.valueOf("image"), "");
69+
Attributes imageAttributes = jsoupImage.attributes();
70+
71+
imageAttributes.put(new Attribute("xlink:href", "htt://are/"));
72+
JsoupElementNode node = new JsoupElementNode(jsoupImage);
73+
74+
SvgStyleResolver sr = new SvgStyleResolver();
75+
Map<String, String> attr = sr.resolveStyles(node, new SvgCssContext());
76+
Assert.assertEquals("htt://are/", attr.get("xlink:href"));
77+
}
78+
}

svg/src/test/java/com/itextpdf/svg/css/impl/StyleResolverUtilUnitTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ This file is part of the iText (R) project.
4242
*/
4343
package com.itextpdf.svg.css.impl;
4444

45+
import com.itextpdf.test.ExtendedITextTest;
4546
import com.itextpdf.test.annotations.type.UnitTest;
4647
import org.junit.Assert;
4748
import org.junit.Test;
@@ -51,7 +52,7 @@ This file is part of the iText (R) project.
5152
import java.util.Map;
5253

5354
@Category(UnitTest.class)
54-
public class StyleResolverUtilUnitTest {
55+
public class StyleResolverUtilUnitTest extends ExtendedITextTest {
5556

5657
@Test
5758
public void mergeParentDeclarationsFillTest(){

svg/src/test/java/com/itextpdf/svg/css/impl/SvgNodeRendererInheritanceResolverUnitTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ This file is part of the iText (R) project.
4747
import com.itextpdf.svg.renderers.impl.GroupSvgNodeRenderer;
4848
import com.itextpdf.svg.renderers.impl.RectangleSvgNodeRenderer;
4949
import com.itextpdf.svg.renderers.impl.UseSvgNodeRenderer;
50+
import com.itextpdf.test.ExtendedITextTest;
5051
import com.itextpdf.test.annotations.type.UnitTest;
5152
import org.junit.Assert;
5253
import org.junit.Test;
5354
import org.junit.experimental.categories.Category;
5455

5556
@Category(UnitTest.class)
56-
public class SvgNodeRendererInheritanceResolverUnitTest {
57+
public class SvgNodeRendererInheritanceResolverUnitTest extends ExtendedITextTest{
5758

5859
@Test
5960
public void applyInheritanceToSubTreeFillTest(){

svg/src/test/java/com/itextpdf/svg/processors/DefaultSvgProcessorIntegrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ This file is part of the iText (R) project.
4747
import com.itextpdf.svg.processors.impl.DefaultSvgProcessor;
4848
import com.itextpdf.svg.renderers.IBranchSvgNodeRenderer;
4949
import com.itextpdf.svg.renderers.ISvgNodeRenderer;
50+
import com.itextpdf.svg.renderers.SvgIntegrationTest;
5051
import com.itextpdf.svg.renderers.impl.EllipseSvgNodeRenderer;
5152
import com.itextpdf.svg.renderers.impl.SvgTagSvgNodeRenderer;
5253
import com.itextpdf.test.annotations.type.IntegrationTest;
@@ -63,7 +64,7 @@ This file is part of the iText (R) project.
6364
import java.util.Map;
6465

6566
@Category(IntegrationTest.class)
66-
public class DefaultSvgProcessorIntegrationTest {
67+
public class DefaultSvgProcessorIntegrationTest extends SvgIntegrationTest {
6768

6869
public static final String sourceFolder = "./src/test/resources/com/itextpdf/svg/processors/impl/DefaultSvgProcessorIntegrationTest/";
6970
public static final String destinationFolder = "./target/test/com/itextpdf/svg/processors/impl/DefaultSvgProcessorIntegrationTest/";

svg/src/test/java/com/itextpdf/svg/processors/ProcessorStateTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This file is part of the iText (R) project.
4545
import com.itextpdf.svg.dummy.renderers.impl.DummySvgNodeRenderer;
4646
import com.itextpdf.svg.processors.impl.ProcessorState;
4747
import com.itextpdf.svg.renderers.ISvgNodeRenderer;
48+
import com.itextpdf.test.ExtendedITextTest;
4849
import com.itextpdf.test.annotations.type.UnitTest;
4950

5051
import java.util.EmptyStackException;
@@ -56,7 +57,7 @@ This file is part of the iText (R) project.
5657
import org.junit.rules.ExpectedException;
5758

5859
@Category( UnitTest.class )
59-
public class ProcessorStateTest {
60+
public class ProcessorStateTest extends ExtendedITextTest{
6061

6162
@Rule
6263
public ExpectedException junitExpectedException = ExpectedException.none();

0 commit comments

Comments
 (0)