@Override @Nonnull public String createLink (final @Nonnull ResourcePath relativeUri) { return relativeUri.asString(); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public String getPathParams (final @Nonnull SiteNode siteNode) { final String siteNodeRelativeUri = siteNode.getRelativeUri().asString(); return (relativeUri.length() <= siteNodeRelativeUri.length()) ? "" : relativeUri.substring(siteNodeRelativeUri.length()); }
@Nonnull private static String toString (final @CheckForNull Resource resource) { return (resource == null) ? "null" : resource.getFile().getPath().asString(); } }
@Override public void apply (final @Nonnull ResourceFile folder, final @Nonnull ResourcePath relativePath) { documentMapByRelativePath.put(relativePath.asString(), modelFactory.createContent().withFolder(folder).build()); } });
@Override public void apply (final @Nonnull ResourceFile file, final @Nonnull ResourcePath relativePath) { libraryMapByRelativePath.put(relativePath.asString(), modelFactory.createResource().withFile(file).build()); } });
@Override public void apply (final @Nonnull ResourceFile file, final @Nonnull ResourcePath relativePath) { mediaMapByRelativePath.put(relativePath.asString(), modelFactory.createMedia().withFile(file).build()); } });
@Override public String toString() { return "AdminContent(" + getFile().getPath().asString() + ')'; } }
@Override @Nonnull public String answer (final @Nonnull InvocationOnMock invocation) { return "/LINK" + ((ResourcePath)invocation.getArguments()[0]).asString(); // return ((ResourcePath)invocation.getArguments()[0]).prepend("LINK").asString(); } });
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_properly_create_an_empty_path() { final ResourcePath underTest = new ResourcePath(); assertThat(underTest.segments, is(not(nullValue()))); assertThat(underTest.segments.isEmpty(), is(true)); assertThat(underTest.asString(), is("/")); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "asStringProvider", dependsOnMethods = { "must_properly_create_an_empty_path", "must_properly_create_an_empty_path_from_string" }) public void must_properly_compute_asString (final @Nonnull ImmutableList<String> segments, final @Nonnull String expectedAsString) { final ResourcePath underTest = new ResourcePath(segments); assertThat(underTest.asString(), is(expectedAsString)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "segmentProvider", dependsOnMethods = "must_properly_create_an_empty_path") public void must_properly_create_an_empty_path_from_string (final @Nonnull String pathAsString, final @Nonnull String expectedAsString, final @Nonnull List<String> expectedSegments) { final ResourcePath underTest = new ResourcePath(pathAsString); assertThat(underTest.segments, is(not(nullValue()))); assertThat(underTest.segments, is(expectedSegments)); assertThat(underTest.asString(), is(expectedAsString)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull private DefaultLayout loadLayout (final @Nonnull ResourceFile layoutFile) throws IOException { log.trace(">>>> reading layout from {}...", layoutFile.getPath().asString()); final @Cleanup InputStream is = layoutFile.getInputStream(); return modelFactory.createLayout().build().as(Unmarshallable).unmarshal(is); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "urlEncodedPathProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_url_decode (final @Nonnull String plainPathAsString, final @Nonnull String encodedPathAsString) { final ResourcePath underTest = new ResourcePath(encodedPathAsString); assertThat(underTest.urlDecoded().asString(), is(plainPathAsString)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "withoutLeadingAndTrailingProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_compute_without_leading (final @Nonnull String pathAsString, final @Nonnull String expectedPathWithoutLeadingAsString, final @Nonnull String expectedPathWithoutTrailingAsString) { final ResourcePath underTest = new ResourcePath(pathAsString); assertThat(underTest.withoutLeading().asString(), is(expectedPathWithoutLeadingAsString)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "withoutLeadingAndTrailingProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_compute_without_trailing (final @Nonnull String path, final @Nonnull String expectedPathWithoutLeadingAsString, final @Nonnull String expectedPathWithoutTrailingAsString) { final ResourcePath underTest = new ResourcePath(path); assertThat(underTest.withoutTrailing().asString(), is(expectedPathWithoutTrailingAsString)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "appendPrependProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_append_string (final @Nonnull String pathAsString, final @Nonnull String secondPathAsString, final @Nonnull String expectedAppendedPathAsString, final @Nonnull String expectedPrependedPathAsString) { final ResourcePath underTest = new ResourcePath(pathAsString); assertThat(underTest.appendedWith(secondPathAsString).asString(), is(expectedAppendedPathAsString)); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "appendPrependProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_prepend_string (final @Nonnull String pathAsString, final @Nonnull String secondPathAsString, final @Nonnull String expectedAppendedPathAsString, final @Nonnull String expectedPrependedPathAsString) { final ResourcePath underTest = new ResourcePath(pathAsString); assertThat(underTest.prependedWith(secondPathAsString).asString(), is(expectedPrependedPathAsString)); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Content build (final @Nonnull Content.Builder builder) { final Content content = mock(Content.class); final String path = builder.getFolder().getPath().asString(); log.trace(">>>> creating Content for {}", path); when(content.toString()).thenReturn(String.format("Content(path=%s)", path)); return content; }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Media build (final @Nonnull Media.Builder builder) { final Media media = mock(Media.class); final String path = builder.getFile().getPath().asString(); log.trace(">>>> creating Media for {}", path); when(media.toString()).thenReturn(String.format("Media(path=%s)", path)); return media; }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "appendPrependProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_append_path (final @Nonnull String pathAsString, final @Nonnull String secondPathAsString, final @Nonnull String expectedAppendedPathAsString, final @Nonnull String expectedPrependedPathAsString) { final ResourcePath underTest = new ResourcePath(pathAsString); final ResourcePath appendingPath = new ResourcePath(secondPathAsString); assertThat(underTest.appendedWith(appendingPath).asString(), is(expectedAppendedPathAsString)); }