1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.tools.plugin.generator;
20
21 import java.io.File;
22 import java.io.InputStream;
23 import java.util.Locale;
24
25 import org.codehaus.plexus.util.ReaderFactory;
26 import org.codehaus.plexus.util.xml.Xpp3Dom;
27 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
28 import org.junit.jupiter.api.Assertions;
29 import org.junit.jupiter.api.Test;
30
31 import static org.junit.jupiter.api.Assertions.assertEquals;
32
33
34
35
36
37 public class PluginXdocGeneratorTest extends AbstractGeneratorTestCase {
38
39
40
41 @Override
42 protected void validate(File destinationDirectory) throws Exception {
43 File docFile = new File(destinationDirectory, "testGoal-mojo.xml");
44 Xpp3Dom actual = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(docFile));
45
46 InputStream expectedAsStream = getClass().getResourceAsStream("/expected-testGoal-mojo.xml");
47
48 Xpp3Dom expected = Xpp3DomBuilder.build(ReaderFactory.newXmlReader(expectedAsStream));
49
50 Assertions.assertEquals(expected, actual);
51 }
52
53 @Test
54 void testGetShortType() {
55 assertEquals("String", PluginXdocGenerator.getShortType("java.lang.String"));
56 assertEquals("List<String>", PluginXdocGenerator.getShortType("java.util.List<java.lang.String>"));
57 assertEquals(
58 "Map<String,Integer>",
59 PluginXdocGenerator.getShortType("java.util.Map<java.lang.String,java.lang.Integer>"));
60 assertEquals("List<...>", PluginXdocGenerator.getShortType("java.util.List<java.util.List<java.lang.String>>"));
61 }
62
63 @Test
64 void testGetXhtmlWithValidatedLinks() {
65 File baseDir = new File(this.getClass().getResource("").getFile());
66 PluginXdocGenerator xdocGenerator = new PluginXdocGenerator(null, Locale.ROOT, baseDir, false);
67 PluginXdocGenerator xdocGeneratorWithDisabledLinkValidator =
68 new PluginXdocGenerator(null, Locale.ROOT, baseDir, true);
69 String externalLink =
70 "test<a href=\"http://example.com/test\">External Link</a>..and a second<a href=\"http://localhost/example\">link</a>end";
71 assertEquals(externalLink, xdocGenerator.getXhtmlWithValidatedLinks(externalLink, "test"));
72 assertEquals(
73 externalLink, xdocGeneratorWithDisabledLinkValidator.getXhtmlWithValidatedLinks(externalLink, "test"));
74 String validInternalLink =
75 "test<a href=\"PluginXdocGeneratorTest.class\">Internal Link</a>..and a second<a href=\"http://localhost/example\">link</a>end";
76 assertEquals(validInternalLink, xdocGenerator.getXhtmlWithValidatedLinks(validInternalLink, "test"));
77 assertEquals(
78 validInternalLink,
79 xdocGeneratorWithDisabledLinkValidator.getXhtmlWithValidatedLinks(validInternalLink, "test"));
80 String invalidInternalLink =
81 "test<a href=\"PluginXdocGeneratorTestinvalid.class\">Internal Link</a>..and a second<a href=\"http://localhost/example\">link</a>end";
82 String sanitizedInvalidInternalLink =
83 "testInternal Link..and a second<a href=\"http://localhost/example\">link</a>end";
84 assertEquals(
85 sanitizedInvalidInternalLink, xdocGenerator.getXhtmlWithValidatedLinks(invalidInternalLink, "test"));
86 assertEquals(
87 invalidInternalLink,
88 xdocGeneratorWithDisabledLinkValidator.getXhtmlWithValidatedLinks(invalidInternalLink, "test"));
89 }
90 }