protected ReadableVisitor append( Path path ) { sb.append(SINGLE_QUOTE); sb.append(path.getString(registry)); sb.append(SINGLE_QUOTE); return this; }
@Override public String toString() { StringBuilder buff = new StringBuilder(); buff.append(path.getString(TO_STRING_ENCODER)).append('(').append(properties.keySet()).append(')'); return buff.toString(); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowNullNamespaceRegistryWithNonNullTextEncoder() { TextEncoder encoder = mock(TextEncoder.class); path.getString((NamespaceRegistry)null, encoder); }
@Test public void shouldAlwaysReturnPathWithSingleSlashForGetString() { NamespaceRegistry registry = mock(NamespaceRegistry.class); TextEncoder encoder = mock(TextEncoder.class); when(encoder.encode("/")).thenReturn("/"); assertThat(root.getString(), is("/")); assertThat(root.getString(registry), is("/")); assertThat(root.getString(registry, encoder), is("/")); assertThat(root.getString(registry, encoder, encoder), is("/")); assertThat(root.getString(encoder), is("/")); }
@Test public void shouldNotAllowNullTextEncoderForDelimiterWithNonNullNamespaceRegistry() { NamespaceRegistry registry = mock(NamespaceRegistry.class); TextEncoder encoder = mock(TextEncoder.class); assertThat(root.getString(registry, encoder, (TextEncoder)null), is("/")); }
@Test public void shouldNotAllowNullTextEncoderWithNonNullNamespaceRegistry() { NamespaceRegistry registry = mock(NamespaceRegistry.class); assertThat(root.getString(registry, (TextEncoder)null), is("/")); }
@Test public void shouldAllowNullNamespaceRegistryWithNonNullTextEncodersSinceRegistryIsNotNeeded() { TextEncoder encoder = mock(TextEncoder.class); when(encoder.encode("/")).thenReturn("/"); assertThat(root.getString((NamespaceRegistry)null, encoder, encoder), is("/")); }
@Test public void shouldAllowNullTextEncoder() { assertThat(root.getString((TextEncoder)null), is("/")); }
@Test public void shouldGetStringWithNamespacePrefixesForAllNamesIfNamespaceRegistryIsProvided() { path = pathFactory.create("/mode:a/b/mode:c/../d/./mode:e/../.."); assertThat(path.getString(namespaceRegistry, NO_OP_ENCODER), is("/mode:a/b/mode:c/../d/./mode:e/../..")); namespaceRegistry.register("dna2", validNamespaceUri); assertThat(path.getString(namespaceRegistry, NO_OP_ENCODER), is("/dna2:a/b/dna2:c/../d/./dna2:e/../..")); }
@Override public String toString() { return getPath().getString(context.getNamespaceRegistry()); } }
@Test public void shouldGetStringWithNamespacePrefixesForAllNamesIfNamespaceRegistryIsProvided() { path = pathFactory.create("/mode:a/b/mode:c/../d/./mode:e/../.."); assertThat(path.getString(namespaceRegistry, NO_OP_ENCODER), is("/mode:a/b/mode:c/../d/./mode:e/../..")); namespaceRegistry.register("dna2", validNamespaceUri); assertThat(path.getString(namespaceRegistry, NO_OP_ENCODER), is("/dna2:a/b/dna2:c/../d/./dna2:e/../..")); }
@Test public void shouldGetStringWithNamespaceUrisIfNoNamespaceRegistryIsProvided() { path = pathFactory.create("/mode:a/b/mode:c/../d/./mode:e/../.."); assertThat(path.getString(NO_OP_ENCODER), is("/{http://www.modeshape.org/1.0}a/{}b/{http://www.modeshape.org/1.0}c/../{}d/./{http://www.modeshape.org/1.0}e/../..")); }
@Test public void shouldGetStringWithNamespaceUrisIfNoNamespaceRegistryIsProvided() { path = pathFactory.create("/mode:a/b/mode:c/../d/./mode:e/../.."); assertThat(path.getString(NO_OP_ENCODER), is("/{http://www.modeshape.org/1.0}a/{}b/{http://www.modeshape.org/1.0}c/../{}d/./{http://www.modeshape.org/1.0}e/../..")); }
@Test public void shouldAlwaysReturnNonNullStringForGetString() { assertThat(path.getString(), is(notNullValue())); }
@Test public void shouldConstructRelativePath() { assertThat(pathFactory.create("a/b/c").isAbsolute(), is(false)); assertThat(pathFactory.create("a/b/c").isNormalized(), is(true)); assertThat(pathFactory.create("a/b/c").size(), is(3)); assertThat(pathFactory.create("a/b/c").getString(namespaceRegistry), is("a/b/c")); }
@Test public void shouldConstructRelativePath() { assertThat(pathFactory.create("a/b/c").isAbsolute(), is(false)); assertThat(pathFactory.create("a/b/c").isNormalized(), is(true)); assertThat(pathFactory.create("a/b/c").size(), is(3)); assertThat(pathFactory.create("a/b/c").getString(namespaceRegistry), is("a/b/c")); }
@Test public void shouldReturnSameSegmentsInIteratorAndArrayAndList() { testSegmentsByIteratorAndListAndArray("/a/b/c/../d/./e/../..", "a", "b", "c", "..", "d", ".", "e", "..", ".."); testSegmentsByIteratorAndListAndArray("/a/b/c", "a", "b", "c"); testSegmentsByIteratorAndListAndArray("a/b/c/../d/./e/../..", "a", "b", "c", "..", "d", ".", "e", "..", ".."); testSegmentsByIteratorAndListAndArray("a/b/c", "a", "b", "c"); testSegmentsByIteratorAndListAndArray(""); testSegmentsByIteratorAndListAndArray(ROOT.getString()); }
@Test public void shouldReturnSameSegmentsInIteratorAndArrayAndList() { testSegmentsByIteratorAndListAndArray("/a/b/c/../d/./e/../..", "a", "b", "c", "..", "d", ".", "e", "..", ".."); testSegmentsByIteratorAndListAndArray("/a/b/c", "a", "b", "c"); testSegmentsByIteratorAndListAndArray("a/b/c/../d/./e/../..", "a", "b", "c", "..", "d", ".", "e", "..", ".."); testSegmentsByIteratorAndListAndArray("a/b/c", "a", "b", "c"); testSegmentsByIteratorAndListAndArray(""); testSegmentsByIteratorAndListAndArray(ROOT.getString()); }