use of info.magnolia.test.mock.jcr.MockNode in project magnolia-vanity-url by aperto.
the class SimplePublicUrlServiceTest method testInternalTarget.
@Test
public void testInternalTarget() throws Exception {
MockNode mockNode = new MockNode("node");
mockNode.setProperty(PN_VANITY_URL, "/aperto");
mockNode.setProperty(PN_LINK, "123-456-789");
assertThat(_service.createTargetUrl(mockNode), equalTo("http://www.demo-project.com/context/internal/page.html"));
assertThat(_service.createVanityUrl(mockNode), equalTo("http://www.demo-project.com/context/aperto"));
}
use of info.magnolia.test.mock.jcr.MockNode in project magnolia-vanity-url by aperto.
the class VirtualVanityUriMappingTest method setUp.
@Before
public void setUp() throws Exception {
_uriMapping = new VirtualVanityUriMapping();
Provider moduleProvider = mock(Provider.class);
VanityUrlModule module = new VanityUrlModule();
Map<String, String> excludes = new HashMap<>();
excludes.put("pages", ".*\\..*");
module.setExcludes(excludes);
when(moduleProvider.get()).thenReturn(module);
_uriMapping.setVanityUrlModule(moduleProvider);
Provider serviceProvider = mock(Provider.class);
VanityUrlService vanityUrlService = mock(VanityUrlService.class);
when(vanityUrlService.queryForVanityUrlNode("/home", "default")).thenReturn(null);
MockNode mockNode = new MockNode("xmas");
when(vanityUrlService.queryForVanityUrlNode("/xmas", "default")).thenReturn(mockNode);
when(vanityUrlService.createRedirectUrl(mockNode)).thenReturn("redirect:/internal/page.html");
when(serviceProvider.get()).thenReturn(vanityUrlService);
_uriMapping.setVanityUrlService(serviceProvider);
Provider registryProvider = mock(Provider.class);
ModuleRegistry moduleRegistry = mock(ModuleRegistry.class);
when(registryProvider.get()).thenReturn(moduleRegistry);
_uriMapping.setModuleRegistry(registryProvider);
initWebContext();
initComponentProvider();
}
use of info.magnolia.test.mock.jcr.MockNode in project magnolia-vanity-url by aperto.
the class DefaultPublicUrlServiceTest method testExternalTargetWithConfiguredTargetContextPath.
@Test
public void testExternalTargetWithConfiguredTargetContextPath() throws Exception {
MockNode mockNode = new MockNode("node");
mockNode.setProperty(PN_VANITY_URL, "/aperto");
mockNode.setProperty(PN_LINK, "http://www.aperto.de");
_service.setTargetContextPath("/public");
assertThat(_service.createTargetUrl(mockNode), equalTo("http://www.aperto.de"));
assertThat(_service.createVanityUrl(mockNode), equalTo("http://www.aperto.de/public/aperto"));
}
use of info.magnolia.test.mock.jcr.MockNode in project magnolia-vanity-url by aperto.
the class DefaultPublicUrlServiceTest method testExternalTarget.
@Test
public void testExternalTarget() throws Exception {
MockNode mockNode = new MockNode("node");
mockNode.setProperty(PN_VANITY_URL, "/aperto");
mockNode.setProperty(PN_LINK, "http://www.aperto.de");
assertThat(_service.createTargetUrl(mockNode), equalTo("http://www.aperto.de"));
assertThat(_service.createVanityUrl(mockNode), equalTo("http://www.aperto.de/aperto"));
}
use of info.magnolia.test.mock.jcr.MockNode in project magnolia-vanity-url by aperto.
the class VanityUrlServiceTest method createNode.
private MockNode createNode(MockSession session, String path) throws Exception {
MockNode current = (MockNode) session.getRootNode();
String[] parts = path.split("/");
for (String part : parts) {
MockNode child;
if (current.hasNode(part)) {
child = (MockNode) current.getNode(part);
} else {
child = new MockNode(part);
current.addNode(child);
}
current = child;
}
return current;
}