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.mapping;
35
36 import static org.junit.Assert.*;
37
38 import info.magnolia.context.SystemContext;
39 import info.magnolia.importexport.DataTransporter;
40 import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration;
41 import info.magnolia.module.googlesitemap.SiteMapTestUtil;
42 import info.magnolia.objectfactory.Components;
43 import info.magnolia.virtualuri.VirtualUriMapping;
44
45 import java.io.FileInputStream;
46 import java.net.URI;
47 import java.util.Optional;
48
49 import javax.jcr.ImportUUIDBehavior;
50
51 import org.junit.Before;
52 import org.junit.Test;
53
54 public class SiteMapVirtualUriMappingTest extends SiteMapTestUtil {
55
56 private String prefix = "sitemaps";
57 private SiteMapVirtualUriMapping mapping;
58
59 @Before
60 @Override
61 public void setUp() throws Exception {
62 super.setUp();
63 mapping = new SiteMapVirtualUriMapping(Components.getComponent(SystemContext.class));
64 mapping.setPrefix(prefix);
65
66 FileInputStream fis = new FileInputStream(getClass().getResource("/googleSitemaps.xml").getFile());
67 DataTransporter.importXmlStream(fis, GoogleSiteMapConfiguration.WORKSPACE, "/", "test-stream", false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, false);
68
69
70 assertTrue(googleSiteMapSession.nodeExists("/test1"));
71 assertTrue(googleSiteMapSession.nodeExists("/test2"));
72 }
73
74 @Test
75 public void sitemapCanPublish() throws InterruptedException {
76
77 Thread.sleep(300);
78
79 Optional<VirtualUriMapping.Result> result = mapping.mapUri(URI.create("/test1Uri"));
80 Optional<VirtualUriMapping.Result> noResult = mapping.mapUri(URI.create("/test1"));
81
82
83 assertEquals(prefix + "/test1.xml", result.get().getToUri());
84 assertEquals("/test1Uri".length(), result.get().getWeight());
85 assertTrue(mapping.isValid());
86 assertFalse("'test1' is the display name and 'test1Uri' is the virtual URI. No mapping has to be defined for the display name.", noResult.isPresent());
87 }
88
89 @Test
90 public void sitemapCanNotPublish() throws InterruptedException {
91
92 Thread.sleep(300);
93
94 Optional<VirtualUriMapping.Result> result = mapping.mapUri(URI.create("/test2"));
95
96
97 assertFalse("'test2' is not published and should not be part of the URI map", result.isPresent());
98 }
99
100 }