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;
}
use of info.magnolia.test.mock.jcr.MockNode in project magnolia-vanity-url by aperto.
the class VanityUrlServiceTest method testImageLinkWithMissingImage.
@Test
public void testImageLinkWithMissingImage() throws Exception {
MockNode mockNode = new MockNode("node");
assertThat(_service.createImageLink(mockNode), equalTo(""));
}
use of info.magnolia.test.mock.jcr.MockNode in project magnolia-vanity-url by aperto.
the class VanityUrlServiceTest method testTargetUrlExternal.
@Test
public void testTargetUrlExternal() throws Exception {
MockNode mockNode = new MockNode("node");
mockNode.setProperty("link", "http://www.aperto.de");
assertThat(_service.createRedirectUrl(mockNode), equalTo("redirect:http://www.aperto.de"));
assertThat(_service.createPreviewUrl(mockNode), equalTo("http://www.aperto.de"));
}
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();
}