Search in sources :

Example 6 with MockNode

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;
}
Also used : MockNode(info.magnolia.test.mock.jcr.MockNode)

Example 7 with MockNode

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(""));
}
Also used : MockNode(info.magnolia.test.mock.jcr.MockNode) Test(org.junit.Test)

Example 8 with MockNode

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"));
}
Also used : MockNode(info.magnolia.test.mock.jcr.MockNode) Test(org.junit.Test)

Example 9 with MockNode

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"));
}
Also used : MockNode(info.magnolia.test.mock.jcr.MockNode) Test(org.junit.Test)

Example 10 with MockNode

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();
}
Also used : HashMap(java.util.HashMap) ModuleRegistry(info.magnolia.module.ModuleRegistry) MockNode(info.magnolia.test.mock.jcr.MockNode) Provider(javax.inject.Provider) Before(org.junit.Before)

Aggregations

MockNode (info.magnolia.test.mock.jcr.MockNode)18 Test (org.junit.Test)16 ModuleRegistry (info.magnolia.module.ModuleRegistry)1 HashMap (java.util.HashMap)1 Provider (javax.inject.Provider)1 Before (org.junit.Before)1