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
55
56 public class SiteMapVirtualUriMappingTest extends SiteMapTestUtil {
57
58 private SiteMapVirtualUriMapping uriMapping;
59 private String prefix = "sitemaps";
60
61 @Override
62 @Before
63 public void setUp() throws Exception {
64 super.setUp();
65
66 uriMapping = new SiteMapVirtualUriMapping(MgnlContext.getSystemContext());
67 uriMapping.setPrefix(prefix);
68
69
70 File sitemapFile = new File(getClass().getResource("/googleSitemaps.xml").getFile());
71 InputStream inputStream = new FileInputStream(sitemapFile);
72 DataTransporter.importXmlStream(inputStream, GoogleSiteMapConfiguration.WORKSPACE, "/", "test-stream", false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, false);
73
74
75 assertTrue(googleSiteMapSession.nodeExists("/test1"));
76 assertTrue(googleSiteMapSession.nodeExists("/test2"));
77 }
78
79
80 @Test
81 public void testSitemapPublished() throws InterruptedException {
82
83 Thread.sleep(300);
84
85 MappingResult result = uriMapping.mapURI("/test1Uri");
86 MappingResult noResult = uriMapping.mapURI("/test1");
87
88
89 assertNotNull("A virtual URI was entered. This is now used to map", result);
90 assertEquals(prefix + "/test1.xml", result.getToURI());
91 assertNull("'test1' is the display name and 'test1Uri' is the virtual URI. No mapping has to be defined for the display name.", noResult);
92 }
93
94 @Test
95 public void testSitemapNotPublished() throws InterruptedException {
96
97 Thread.sleep(300);
98
99 MappingResult result = uriMapping.mapURI("/test2");
100
101
102 assertNull("'test2' is not published and should not be part of the URI map", result);
103 }
104
105 }