1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.googlesitemap.config; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
|
38 |
|
import info.magnolia.cms.beans.config.VirtualURIMapping.MappingResult; |
39 |
|
import info.magnolia.context.MgnlContext; |
40 |
|
import info.magnolia.importexport.DataTransporter; |
41 |
|
import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration; |
42 |
|
import info.magnolia.module.googlesitemap.SiteMapTestUtil; |
43 |
|
|
44 |
|
import java.io.File; |
45 |
|
import java.io.FileInputStream; |
46 |
|
import java.io.InputStream; |
47 |
|
|
48 |
|
import javax.jcr.ImportUUIDBehavior; |
49 |
|
|
50 |
|
import org.junit.Before; |
51 |
|
import org.junit.Test; |
52 |
|
|
53 |
|
|
54 |
|
@link |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 3 |
Complexity Density: 0.16 |
|
56 |
|
public class SiteMapVirtualUriMappingTest extends SiteMapTestUtil { |
57 |
|
|
58 |
|
private SiteMapVirtualUriMapping uriMapping; |
59 |
|
private String prefix = "sitemaps"; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
61 |
2 |
@Override... |
62 |
|
@Before |
63 |
|
public void setUp() throws Exception { |
64 |
2 |
super.setUp(); |
65 |
|
|
66 |
2 |
uriMapping = new SiteMapVirtualUriMapping(MgnlContext.getSystemContext()); |
67 |
2 |
uriMapping.setPrefix(prefix); |
68 |
|
|
69 |
|
|
70 |
2 |
File sitemapFile = new File(getClass().getResource("/googleSitemaps.xml").getFile()); |
71 |
2 |
InputStream inputStream = new FileInputStream(sitemapFile); |
72 |
2 |
DataTransporter.importXmlStream(inputStream, GoogleSiteMapConfiguration.WORKSPACE, "/", "test-stream", false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, false); |
73 |
|
|
74 |
|
|
75 |
2 |
assertTrue(googleSiteMapSession.nodeExists("/test1")); |
76 |
2 |
assertTrue(googleSiteMapSession.nodeExists("/test2")); |
77 |
|
} |
78 |
|
|
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void testSitemapPublished() throws InterruptedException { |
82 |
|
|
83 |
1 |
Thread.sleep(300); |
84 |
|
|
85 |
1 |
MappingResult result = uriMapping.mapURI("/test1Uri"); |
86 |
1 |
MappingResult noResult = uriMapping.mapURI("/test1"); |
87 |
|
|
88 |
|
|
89 |
1 |
assertTrue(uriMapping.isValid()); |
90 |
1 |
assertEquals("/test1Uri".length(), result.getLevel()); |
91 |
1 |
assertNotNull("A virtual URI was entered. This is now used to map", result); |
92 |
1 |
assertEquals(prefix + "/test1.xml", result.getToURI()); |
93 |
1 |
assertNull("'test1' is the display name and 'test1Uri' is the virtual URI. No mapping has to be defined for the display name.", noResult); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
96 |
1 |
@Test... |
97 |
|
public void testSitemapNotPublished() throws InterruptedException { |
98 |
|
|
99 |
1 |
Thread.sleep(300); |
100 |
|
|
101 |
1 |
MappingResult result = uriMapping.mapURI("/test2"); |
102 |
|
|
103 |
|
|
104 |
1 |
assertNull("'test2' is not published and should not be part of the URI map", result); |
105 |
|
} |
106 |
|
|
107 |
|
} |