Search in sources :

Example 1 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 2 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)

Example 3 with MockNode

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

Example 4 with MockNode

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

Example 5 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)

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