private void assertContainsInOrder( Iterable<NodeWithPropertyValues> iterable, NodeWithPropertyValues... expected ) { if ( expected.length == 0 ) { assertThat( iterable, emptyIterable() ); } else { assertThat( iterable, contains( expected ) ); } }
@Test public void emptyCacheConfiguration() throws Exception { WebContentInterceptor interceptor = new WebContentInterceptor(); interceptor.setCacheSeconds(-1); interceptor.preHandle(request, response, null); Iterable<String> expiresHeaders = response.getHeaders("Expires"); assertThat(expiresHeaders, Matchers.emptyIterable()); Iterable<String> cacheControlHeaders = response.getHeaders("Cache-Control"); assertThat(cacheControlHeaders, Matchers.emptyIterable()); }
@Test public void shouldNotLoadPropertyForLabelsAndNoPropertyChanges() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).build(); // Then assertThat( updates.forIndexKeys( singleton( index1 ), assertNoLoading(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdatesForEmptyNodeUpdates() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).build(); // Then assertThat( updates.forIndexKeys( indexes, assertNoLoading(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdateWhenRemovingOneTokenForNonSchemaIndex() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( allLabels ).withTokensAfter( label ).build(); // Then assertThat( updates.forIndexKeys( singleton( nonSchemaIndex ), propertyLoader( property1, property2, property3 ), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdateWhenAddingAnotherTokenForNonSchemaIndex() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).withTokensAfter( allLabels ).build(); // Then assertThat( updates.forIndexKeys( singleton( nonSchemaIndex ), propertyLoader( property1, property2, property3 ), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdateWhenAddingAnotherUselessTokenForNonSchemaIndex() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).withTokensAfter( labelId1, unusedLabelId ).build(); // Then assertThat( updates.forIndexKeys( singleton( nonSchemaIndex ), propertyLoader( property1, property2, property3 ), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldCreateFunctionFromListToListWithZeroLimit() { final Function<List<String>, List<Integer>> function = functionFromListOf(String.class) .limit(0) .thenMap(new StringLength()); assertThat(function.apply(INPUT_LIST), Matchers.<Integer>emptyIterable()); }
@Test public void mappedCacheConfigurationOverridesGlobal() throws Exception { Properties mappings = new Properties(); mappings.setProperty("*/*handle.vm", "-1"); // was **/*handle.vm WebContentInterceptor interceptor = new WebContentInterceptor(); interceptor.setCacheSeconds(10); interceptor.setCacheMappings(mappings); // request.setRequestURI("http://localhost:7070/example/adminhandle.vm"); request.setRequestURI("example/adminhandle.vm"); interceptor.preHandle(request, response, null); Iterable<String> cacheControlHeaders = response.getHeaders("Cache-Control"); assertThat(cacheControlHeaders, Matchers.emptyIterable()); // request.setRequestURI("http://localhost:7070/example/bingo.html"); request.setRequestURI("example/bingo.html"); interceptor.preHandle(request, response, null); cacheControlHeaders = response.getHeaders("Cache-Control"); assertThat(cacheControlHeaders, Matchers.hasItem("max-age=10")); }
@Test public void shouldNotLoadPropertyForNoLabelsAndButPropertyAddition() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( empty ) .added( property1.propertyKeyId(), property1.value() ) .build(); // Then assertThat( updates.forIndexKeys( singleton( index1 ), assertNoLoading(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdatesForLabelRemovalWithNoProperties() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).withTokensAfter( empty ).build(); // Then assertThat( updates.forIndexKeys( indexes, propertyLoader(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdatesForLabelAdditionWithNoProperties() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( empty ).withTokensAfter( label ).build(); // Then assertThat( updates.forIndexKeys( indexes, propertyLoader(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdatesForPropertyAdditionWithNoLabels() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ) .added( property1.propertyKeyId(), property1.value() ) .build(); // Then assertThat( updates.forIndexKeys( indexes, assertNoLoading(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdateForPartialCompositeSchemaIndexUpdate() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).withTokensAfter( label ) .added( propertyKeyId1, Values.of( "Neo" ) ) .added( propertyKeyId3, Values.pointValue( CoordinateReferenceSystem.WGS84, 12.3, 45.6 ) ) .build(); // Then assertThat( updates.forIndexKeys( singleton( index123 ), propertyLoader(), EntityType.NODE ), emptyIterable() ); }
@Test public void makeSureFulltextIndexCanBeCaseSensitive() { Index<Node> index = nodeIndex( MapUtil.stringMap( new HashMap<>( LuceneIndexImplementation.FULLTEXT_CONFIG ), "to_lower_case", "false" ) ); Node node = graphDb.createNode(); String key = "name"; String value = "Mattias Persson"; index.add( node, key, value ); for ( int i = 0; i < 2; i++ ) { assertThat( index.query( "name", "[A TO Z]" ), Contains.contains( node ) ); assertThat( index.query( "name", "[a TO z]" ), emptyIterable() ); assertThat( index.query( "name", "Matt*" ), Contains.contains( node ) ); assertThat( index.query( "name", "matt*" ), emptyIterable() ); assertThat( index.query( "name", "Persson" ), Contains.contains( node ) ); assertThat( index.query( "name", "persson" ), emptyIterable() ); restartTx(); } }
@Test public void shouldNotGenerateUpdateForMultipleExistingPropertiesAndLabels() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ) .existing( propertyKeyId1, Values.of( "Neo" ) ) .existing( propertyKeyId2, Values.of( 100L ) ) .existing( propertyKeyId3, Values.pointValue( CoordinateReferenceSystem.WGS84, 12.3, 45.6 ) ) .build(); // Then assertThat( updates.forIndexKeys( indexes, assertNoLoading(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGenerateUpdatesForLabelAddAndPropertyRemove() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( empty ).withTokensAfter( label ) .removed( property1.propertyKeyId(), property1.value() ) .removed( property2.propertyKeyId(), property2.value() ) .removed( property3.propertyKeyId(), property3.value() ) .build(); // Then assertThat( updates.forIndexKeys( indexes, assertNoLoading(), EntityType.NODE ), emptyIterable() ); }
@Test public void shouldNotGetLatestTxModificationsWhenChoosingSpeedQueries() { Index<Node> index = nodeIndex( LuceneIndexImplementation.EXACT_CONFIG ); Node node = graphDb.createNode(); index.add( node, "key", "value" ); QueryContext queryContext = new QueryContext( "value" ).tradeCorrectnessForSpeed(); assertThat( index.query( "key", queryContext ), emptyIterable() ); assertThat( index.query( "key", "value" ), Contains.contains( node ) ); }
@Test public void shouldNotGenerateUpdatesForLabelRemoveAndPropertyAdd() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).withTokensAfter( empty ) .added( property1.propertyKeyId(), property1.value() ) .added( property2.propertyKeyId(), property2.value() ) .added( property3.propertyKeyId(), property3.value() ) .build(); // Then assertThat( updates.forIndexKeys( indexes, assertNoLoading(), EntityType.NODE ), emptyIterable() ); }
@Test public void makeSureYouCanRemoveFromRelationshipIndex() { Node n1 = graphDb.createNode(); Node n2 = graphDb.createNode(); Relationship r = n1.createRelationshipTo( n2, withName( "foo" ) ); RelationshipIndex index = graphDb.index().forRelationships( "rel-index" ); String key = "bar"; index.remove( r, key, "value" ); index.add( r, key, "otherValue" ); for ( int i = 0; i < 2; i++ ) { assertThat( index.get( key, "value" ), emptyIterable() ); assertThat( index.get( key, "otherValue" ), Contains.contains( r ) ); restartTx(); } }