@Override Object perform( GraphDatabaseService graphDb ) { return entity.getProperty( key ); } };
private void getAllProperties( PropertyContainer entity ) { for ( String key : entity.getPropertyKeys() ) { entity.getProperty( key ); } } };
private int readProperties( PropertyContainer entity ) { int count = 0; for ( String key : entity.getPropertyKeys() ) { entity.getProperty( key ); count++; } return count; }
@Override public String represent( PropertyContainer item ) { return (String) item.getProperty( key ); } }
PropertiesRep( PropertyContainer entity, long id ) { this.entityId = id; this.entityToString = entity.toString(); for ( String key : entity.getPropertyKeys() ) { Serializable value = (Serializable) entity.getProperty( key, null ); // We do this because the node may have changed since we did getPropertyKeys() if ( value != null ) { if ( value.getClass().isArray() ) { props.put( key, new ArrayList<>( Arrays.asList( IoPrimitiveUtils.asArray( value ) ) ) ); } else { props.put( key, value ); } } } }
private String representation( PropertyContainer entity ) { StringBuilder builder = new StringBuilder(); for ( String key : propertyKeys ) { Object value = entity.getProperty( key, null ); if ( value != null ) { if ( builder.length() > 0 ) { builder.append( "," ); } builder.append( value ); } } return builder.toString(); }
private String formatProperties( PropertyContainer pc ) { StringBuilder result = new StringBuilder(); List<String> keys = Iterables.asList( pc.getPropertyKeys() ); Collections.sort( keys ); for ( String prop : keys ) { if ( result.length() > 0 ) { result.append( ", " ); } result.append( quote( prop ) ).append( ':' ); Object value = pc.getProperty( prop ); result.append( toString( value ) ); } return "{" + result + "}"; }
private void assertHasProperties( PropertyContainer container, Map<String, Object> properties ) { for ( Map.Entry<String, Object> entry : properties.entrySet() ) { assertEquals( entry.getValue(), container.getProperty( entry.getKey() ) ); } }
static PropertyContainer container( Map<String, Object> values ) { PropertyContainer container = mock( PropertyContainer.class ); when( container.getPropertyKeys() ).thenReturn( values.keySet() ); when( container.getAllProperties() ).thenReturn( values ); for ( Map.Entry<String, Object> entry : values.entrySet() ) { when( container.getProperty( entry.getKey(), null ) ).thenReturn( entry.getValue() ); } return container; } }
public Object getProperty( final PropertyContainer entity, final String key ) throws Exception { return execute( state -> entity.getProperty( key ) ); } }
private static <T extends PropertyContainer> T mockPropertyContainer( Class<T> type, Properties properties ) { T container = mock( type ); when( container.getProperty( anyString() ) ).thenAnswer( properties ); when( container.getProperty( anyString(), any() ) ).thenAnswer( properties ); when( container.getPropertyKeys() ).thenReturn( properties ); when( container.getAllProperties() ).thenReturn( properties.getProperties() ); return container; } }
private String uniqueId( Group group, PropertyContainer entity ) { return uniqueId( group, entity.getProperty( "id" ) ); }
public static void assertProperties( Map<String, Object> properties, PropertyContainer entity ) { int count = 0; for ( String key : entity.getPropertyKeys() ) { Object expectedValue = properties.get( key ); Object entityValue = entity.getProperty( key ); if ( expectedValue.getClass().isArray() ) { assertTrue( Arrays.equals( (byte[]) expectedValue, (byte[]) entityValue ) ); } else { assertEquals( expectedValue, entityValue ); } count++; } assertEquals( properties.size(), count ); }
private void assertPropertiesEquals( InputEntity input, PropertyContainer entity ) { Object[] properties = input.properties(); for ( int i = 0; i < properties.length; i++ ) { String key = (String) properties[i++]; Object value = properties[i]; assertPropertyValueEquals( input, entity, key, value, entity.getProperty( key ) ); } }
@Override protected boolean matchesSafely( PropertyContainer propertyContainer, Description mismatchDescription ) { if ( !propertyMatcher.matchesSafely( propertyContainer, mismatchDescription ) ) { return false; } Object foundValue = propertyContainer.getProperty( propertyName ); if ( !propertyValuesEqual( expectedValue, foundValue ) ) { mismatchDescription.appendText( "found value " + formatValue( foundValue ) ); return false; } return true; }
private void assertPropertyEqual( PropertyContainer primitive, String key, String value ) { try ( Transaction tx = getGraphDb().beginTx() ) { assertEquals( value, primitive.getProperty( key ) ); } }
@Test public void shouldBeAbleToWriteNewGraphProperty() throws Exception { int prop; try ( Transaction tx = beginTransaction() ) { prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); tx.success(); } try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( testSupport.graphProperties().getProperty( "prop" ), equalTo( "hello" ) ); } }
@Test public void shouldBeAbleToReplaceExistingGraphProperty() throws Exception { int prop; try ( Transaction tx = beginTransaction() ) { prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ); assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "hello" ) ), equalTo( NO_VALUE ) ); tx.success(); } try ( Transaction tx = beginTransaction() ) { assertThat( tx.dataWrite().graphSetProperty( prop, stringValue( "good bye" ) ), equalTo( stringValue("hello") ) ); tx.success(); } try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( testSupport.graphProperties().getProperty( "prop" ), equalTo( "good bye" ) ); } }
@Test public void getNonExistentGraphPropertyWithDefaultValue() { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); PropertyContainer graphProperties = properties( db ); Transaction tx = db.beginTx(); assertEquals( "default", graphProperties.getProperty( "test", "default" ) ); tx.success(); tx.close(); db.shutdown(); }
assertEquals( "yo", graphProperties.getProperty( "test" ) ); tx.success(); tx.close(); assertNull( graphProperties.removeProperty( "something non existent" ) ); assertEquals( "yo", graphProperties.removeProperty( "test" ) ); assertNull( graphProperties.getProperty( "test", null ) ); graphProperties.setProperty( "other", 10 ); assertEquals( 10, graphProperties.getProperty( "other" ) ); graphProperties.setProperty( "new", "third" ); tx.success(); assertEquals( true, graphProperties.getProperty( "rollback" ) ); tx.close(); assertThat( graphProperties, inTx( db, not( hasProperty( "rollback" ) ) ) );