NameValueFactory extends AbstractValueFactory<Name> implements NameFactory { @Override public Name create( String value ) { return create(value, getDecoder()); } NameValueFactory( NamespaceRegistry.Holder namespaceRegistryHolder,
                             TextDecoder decoder,
                             ValueFactories factories ); @Override NameFactory with( ValueFactories valueFactories ); @Override NameFactory with( org.modeshape.jcr.value.NamespaceRegistry.Holder namespaceRegistryHolder ); @Override Name create( String value ); @Override Name create( String value,
                        TextDecoder decoder ); @Override Name create( String namespaceUri,
                        String localName ); @Override Name create( String namespaceUri,
                        String localName,
                        TextDecoder decoder ); @Override Name create( int value ); @Override Name create( long value ); @Override Name create( boolean value ); @Override Name create( float value ); @Override Name create( double value ); @Override Name create( BigDecimal value ); @Override Name create( Calendar value ); @Override Name create( Date value ); @Override Name create( DateTime value ); @Override Name create( Name value ); @Override Name create( Path value ); @Override Name create( Path.Segment segment ); @Override Name create( Reference value ); @Override Name create( URI value ); @Override Name create( UUID value ); @Override Name create( NodeKey value ); @Override Name create( byte[] value ); @Override Name create( BinaryValue value ); @Override Name create( InputStream stream ); @Override NamespaceRegistry getNamespaceRegistry(); @Override Name[] createEmptyArray( int length );  }
@Test public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormatWithoutPrefix() { name = nameFactory.create("a"); assertThat(name.getLocalName(), is("a")); assertThat(name.getNamespaceUri(), is(this.registry.getNamespaceForPrefix(""))); }
@Test public void shouldCreateNameFromSingleStringInPrefixedNamespaceFormat() { name = nameFactory.create("dna:something"); assertThat(name.getLocalName(), is("something")); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Test public void shouldCreateNameFromSingleEncodedStringInPrefixedNamespaceFormat() { name = nameFactory.create(encoder.encode("dna") + ":" + encoder.encode("some/thing")); assertThat(name.getLocalName(), is("some/thing")); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Test public void shouldCreateNameFromSingleStringInStandardFullNamespaceFormat() { name = nameFactory.create("{http: assertThat(name.getLocalName(), is("something")); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Test public void shouldCreateNameFromSingleEncodedStringInStandardFullNamespaceFormat() { name = nameFactory.create("{" + encoder.encode("http: assertThat(name.getLocalName(), is("some/thing")); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowNullLocalName() { nameFactory.create("a", (String)null); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowNullLocalNameWithEncoder() { nameFactory.create("a", null, decoder); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowEmptyLocalName() { nameFactory.create("a", ""); }
@Test( expected = IllegalArgumentException.class ) public void shouldNotAllowEmptyLocalNameWithEncoder() { nameFactory.create("a", "", decoder); }
@Test( expected = ValueFormatException.class ) public void shouldNotCreateNameFromStringWithMultipleNonEscapedColons() { nameFactory.create("a:b:c"); }
@Test( expected = ValueFormatException.class ) public void shouldNotAllowStringWithUnclosedBrace() { nameFactory.create("{something"); }
@Test( expected = ValueFormatException.class ) public void shouldNotAllowLocalNameWithBlankPrefix() { name = nameFactory.create(":something"); }
@Test public void shouldCreateIteratorOverValuesWhenSuppliedIteratorOfUnknownObjects() { List<String> values = new ArrayList<String>(); for (int i = 0; i != 10; ++i) { values.add("dna:something" + i); } Iterator<Name> iter = nameFactory.create(values.iterator()); Iterator<String> valueIter = values.iterator(); while (iter.hasNext()) { assertThat(iter.next(), is(nameFactory.create(valueIter.next()))); } }
@Test public void shouldCreateNameWithBlankUri() { name = nameFactory.create("{}something"); assertThat(name.getNamespaceUri(), is("")); assertThat(name.getLocalName(), is("something")); assertThat(name.getString(NO_OP_ENCODER), is("something")); }
@Test public void shouldCreateNameWithBlankUriAndBlankName() { name = nameFactory.create("{}"); assertThat(name.getNamespaceUri(), is("")); assertThat(name.getLocalName(), is("")); assertThat(name.getString(NO_OP_ENCODER), is("")); }
@Test public void shouldCreateNameWithBlankPrefixAndBlankLocalName() { name = nameFactory.create(":"); assertThat(name.getNamespaceUri(), is("")); assertThat(name.getLocalName(), is("")); assertThat(name.getString(NO_OP_ENCODER), is("")); }
@Test( expected = IllegalArgumentException.class ) public void shouldFailToCreateNameWithUriAndBlankLocalName() { name = nameFactory.create("{http: }
@Test public void shouldCreateNameWithPrefixAndBlankLocalName() { name = nameFactory.create("dna:"); assertThat(name.getNamespaceUri(), is("http: assertThat(name.getLocalName(), is("")); assertThat(name.getString(NO_OP_ENCODER), is("{http: }
@Ignore @Test public void shouldCreateFromNonEncodedString() { for (int i = 0; i != 10; ++i) { name = nameFactory.create("dna:something"); } Stopwatch sw = new Stopwatch(); int count = 20000000; sw.start(); for (int i = 0; i != count; ++i) { name = nameFactory.create("dna:something"); } sw.stop(); System.out.println("Total duration for " + count + " calls: " + sw.getTotalDuration()); }