Skip to content

Commit 41f6c98

Browse files
authored
Merge pull request #555 from zhenlineo/1.7-tck
Replace TCK tests with normal unit tests
2 parents 5fbe0e0 + eaea334 commit 41f6c98

35 files changed

+737
-3753
lines changed

driver/pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@
5858
<groupId>org.junit.jupiter</groupId>
5959
<artifactId>junit-jupiter-params</artifactId>
6060
</dependency>
61-
<dependency>
62-
<groupId>org.junit.vintage</groupId>
63-
<artifactId>junit-vintage-engine</artifactId>
64-
</dependency>
6561
<dependency>
6662
<groupId>org.rauschig</groupId>
6763
<artifactId>jarchivelib</artifactId>
@@ -74,14 +70,6 @@
7470
<groupId>org.bouncycastle</groupId>
7571
<artifactId>bcpkix-jdk15on</artifactId>
7672
</dependency>
77-
<dependency>
78-
<groupId>info.cukes</groupId>
79-
<artifactId>cucumber-junit</artifactId>
80-
</dependency>
81-
<dependency>
82-
<groupId>info.cukes</groupId>
83-
<artifactId>cucumber-java</artifactId>
84-
</dependency>
8573
<dependency>
8674
<groupId>com.fasterxml.jackson.core</groupId>
8775
<artifactId>jackson-databind</artifactId>

driver/src/test/java/org/neo4j/driver/internal/DirectDriverIT.java renamed to driver/src/test/java/org/neo4j/driver/v1/integration/DirectDriverIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
package org.neo4j.driver.internal;
19+
package org.neo4j.driver.v1.integration;
2020

2121
import org.hamcrest.CoreMatchers;
2222
import org.junit.jupiter.api.AfterEach;
@@ -25,6 +25,7 @@
2525

2626
import java.net.URI;
2727

28+
import org.neo4j.driver.internal.BoltServerAddress;
2829
import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
2930
import org.neo4j.driver.v1.Driver;
3031
import org.neo4j.driver.v1.GraphDatabase;

driver/src/test/java/org/neo4j/driver/v1/integration/ScalarTypeIT.java

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@
1818
*/
1919
package org.neo4j.driver.v1.integration;
2020

21+
import org.junit.jupiter.api.Test;
2122
import org.junit.jupiter.api.extension.RegisterExtension;
2223
import org.junit.jupiter.params.ParameterizedTest;
2324
import org.junit.jupiter.params.provider.Arguments;
2425
import org.junit.jupiter.params.provider.MethodSource;
2526

27+
import java.util.Arrays;
2628
import java.util.Collections;
29+
import java.util.HashMap;
30+
import java.util.Map;
31+
import java.util.function.Function;
32+
import java.util.stream.Collectors;
2733
import java.util.stream.Stream;
2834

2935
import org.neo4j.driver.internal.value.ListValue;
3036
import org.neo4j.driver.internal.value.MapValue;
37+
import org.neo4j.driver.internal.value.NullValue;
38+
import org.neo4j.driver.internal.value.StringValue;
3139
import org.neo4j.driver.v1.StatementResult;
3240
import org.neo4j.driver.v1.Value;
3341
import org.neo4j.driver.v1.Values;
@@ -36,6 +44,7 @@
3644

3745
import static org.hamcrest.CoreMatchers.equalTo;
3846
import static org.hamcrest.MatcherAssert.assertThat;
47+
import static org.junit.jupiter.api.Assertions.assertTrue;
3948
import static org.neo4j.driver.v1.Values.parameters;
4049

4150
@ParallelizableIT
@@ -70,4 +79,175 @@ void shouldHandleType( String statement, Value expectedValue )
7079
// Then
7180
assertThat( cursor.single().get( "v" ), equalTo( expectedValue ) );
7281
}
82+
83+
static Stream<Arguments> collectionItems()
84+
{
85+
return Stream.of(
86+
Arguments.of( Values.value( (Object) null ) ),
87+
Arguments.of( Values.value( 1L ) ),
88+
Arguments.of( Values.value( 1.1d ) ),
89+
Arguments.of( Values.value( "hello" ) ),
90+
Arguments.of( Values.value( true ) )
91+
);
92+
}
93+
94+
@ParameterizedTest
95+
@MethodSource( "collectionItems" )
96+
void shouldEchoVeryLongMap( Value collectionItem )
97+
{
98+
// Given
99+
Map<String, Value> input = new HashMap<>();
100+
for ( int i = 0; i < 1000; i ++ )
101+
{
102+
input.put( String.valueOf( i ), collectionItem );
103+
}
104+
MapValue mapValue = new MapValue( input );
105+
106+
// When & Then
107+
verifyCanEncodeAndDecode( mapValue );
108+
}
109+
110+
@ParameterizedTest
111+
@MethodSource( "collectionItems" )
112+
void shouldEchoVeryLongList( Value collectionItem )
113+
{
114+
// Given
115+
Value[] input = new Value[1000];
116+
for ( int i = 0; i < 1000; i ++ )
117+
{
118+
input[i] = collectionItem;
119+
}
120+
ListValue listValue = new ListValue( input );
121+
122+
// When & Then
123+
verifyCanEncodeAndDecode( listValue );
124+
125+
}
126+
127+
@Test
128+
void shouldEchoVeryLongString()
129+
{
130+
// Given
131+
char[] chars = new char[10000];
132+
Arrays.fill( chars, '*' );
133+
String longText = new String( chars );
134+
StringValue input = new StringValue( longText );
135+
136+
// When & Then
137+
verifyCanEncodeAndDecode( input );
138+
}
139+
140+
static Stream<Arguments> scalarTypes()
141+
{
142+
return Stream.of(
143+
Arguments.of( Values.value( (Object) null ) ),
144+
Arguments.of( Values.value( true ) ),
145+
Arguments.of( Values.value( false ) ),
146+
Arguments.of( Values.value( 1L ) ),
147+
Arguments.of( Values.value( -17L ) ),
148+
Arguments.of( Values.value( -129L ) ),
149+
Arguments.of( Values.value( 129L ) ),
150+
Arguments.of( Values.value( 2147483647L ) ),
151+
Arguments.of( Values.value( -2147483648L ) ),
152+
Arguments.of( Values.value( -2147483648L ) ),
153+
Arguments.of( Values.value( 9223372036854775807L ) ),
154+
Arguments.of( Values.value( -9223372036854775808L ) ),
155+
Arguments.of( Values.value( 1.7976931348623157E+308d ) ),
156+
Arguments.of( Values.value( 2.2250738585072014e-308d ) ),
157+
Arguments.of( Values.value( 0.0d ) ),
158+
Arguments.of( Values.value( 1.1d ) ),
159+
Arguments.of( Values.value( "1" ) ),
160+
Arguments.of( Values.value( "-17∂ßå®" ) ),
161+
Arguments.of( Values.value( "String" ) ),
162+
Arguments.of( Values.value( "" ) )
163+
);
164+
}
165+
166+
@ParameterizedTest
167+
@MethodSource( "scalarTypes" )
168+
void shouldEchoScalarTypes( Value input )
169+
{
170+
// When & Then
171+
verifyCanEncodeAndDecode( input );
172+
}
173+
174+
static Stream<Arguments> listToTest()
175+
{
176+
return Stream.of(
177+
Arguments.of( Values.value( 1, 2, 3, 4 ) ),
178+
Arguments.of( Values.value( true, false ) ),
179+
Arguments.of( Values.value( 1.1, 2.2, 3.3 ) ),
180+
Arguments.of( Values.value( "a", "b", "c", "˚C" ) ),
181+
Arguments.of( Values.value( NullValue.NULL, NullValue.NULL ) ),
182+
Arguments.of( Values.value( Values.values( NullValue.NULL, true, "-17∂ßå®", 1.7976931348623157E+308d, -9223372036854775808d ) ) ),
183+
Arguments.of( new ListValue( parameters( "a", 1, "b", true, "c", 1.1, "d", "˚C", "e", null ) ) )
184+
);
185+
}
186+
187+
@ParameterizedTest
188+
@MethodSource( "listToTest" )
189+
void shouldEchoList( Value input )
190+
{
191+
// When & Then
192+
assertTrue( input instanceof ListValue );
193+
verifyCanEncodeAndDecode( input );
194+
}
195+
196+
@Test
197+
void shouldEchoNestedList() throws Throwable
198+
{
199+
Value input = Values.value( toValueStream( listToTest() ) );
200+
201+
// When & Then
202+
assertTrue( input instanceof ListValue );
203+
verifyCanEncodeAndDecode( input );
204+
}
205+
206+
static Stream<Arguments> mapToTest()
207+
{
208+
return Stream.of( Arguments.of( parameters( "a", 1, "b", 2, "c", 3, "d", 4 ) ),
209+
Arguments.of( parameters( "a", true, "b", false ) ),
210+
Arguments.of( parameters( "a", 1.1, "b", 2.2, "c", 3.3 ) ),
211+
Arguments.of( parameters( "b", "a", "c", "b", "d", "c", "e", "˚C" ) ),
212+
Arguments.of( parameters( "a", null ) ),
213+
Arguments.of( parameters( "a", 1, "b", true, "c", 1.1, "d", "˚C", "e", null ) ) );
214+
}
215+
216+
@ParameterizedTest
217+
@MethodSource( "mapToTest" )
218+
void shouldEchoMap( Value input )
219+
{
220+
assertTrue( input instanceof MapValue );
221+
// When & Then
222+
verifyCanEncodeAndDecode( input );
223+
}
224+
225+
@Test
226+
void shouldEchoNestedMap() throws Throwable
227+
{
228+
MapValue input = new MapValue(
229+
toValueStream( mapToTest() )
230+
.collect( Collectors.toMap( Object::toString, Function.identity() ) ) );
231+
232+
// When & Then
233+
verifyCanEncodeAndDecode( input );
234+
}
235+
236+
private Stream<Value> toValueStream( Stream<Arguments> arguments )
237+
{
238+
return arguments.map( arg -> {
239+
Object obj = arg.get()[0];
240+
assertTrue( obj instanceof Value );
241+
return (Value) obj;
242+
} );
243+
}
244+
245+
private void verifyCanEncodeAndDecode( Value input )
246+
{
247+
// When
248+
StatementResult cursor = session.run( "RETURN {x} as y", parameters( "x", input ) );
249+
250+
// Then
251+
assertThat( cursor.single().get( "y" ), equalTo( input ) );
252+
}
73253
}

driver/src/test/java/org/neo4j/driver/v1/integration/SummaryIT.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,14 @@ void shouldContainCorrectStatementType()
138138
void shouldContainCorrectPlan()
139139
{
140140
// When
141-
Plan plan = session.run( "EXPLAIN MATCH (n) RETURN 1" ).consume().plan();
141+
ResultSummary summary = session.run( "EXPLAIN MATCH (n) RETURN 1" ).consume();
142142

143143
// Then
144+
assertTrue( summary.hasPlan() );
145+
146+
Plan plan = summary.plan();
144147
assertThat( plan.operatorType(), notNullValue() );
148+
assertThat( plan.identifiers().size(), greaterThan( 0 ) );
145149
assertThat( plan.arguments().size(), greaterThan( 0 ) );
146150
assertThat( plan.children().size(), greaterThan( 0 ) );
147151
}
@@ -170,11 +174,24 @@ void shouldContainNotifications()
170174
ResultSummary summary = session.run( "EXPLAIN MATCH (n), (m) RETURN n, m" ).consume();
171175

172176
// Then
173-
assertTrue( summary.hasPlan() );
174177
List<Notification> notifications = summary.notifications();
175178
assertNotNull( notifications );
176179
assertThat( notifications.size(), equalTo( 1 ) );
177-
assertThat( notifications.get( 0 ).toString(), containsString("CartesianProduct") );
180+
Notification notification = notifications.get( 0 );
181+
assertThat( notification.code(), notNullValue() );
182+
assertThat( notification.title(), notNullValue() );
183+
assertThat( notification.description(), notNullValue() );
184+
assertThat( notification.severity(), notNullValue() );
185+
assertThat( notification.position(), notNullValue() );
186+
}
178187

188+
@Test
189+
void shouldContainNoNotifications() throws Throwable
190+
{
191+
// When
192+
ResultSummary summary = session.run( "RETURN 1" ).consume();
193+
194+
// Then
195+
assertThat( summary.notifications().size(), equalTo( 0 ) );
179196
}
180197
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2002-2019 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.v1.integration;
20+
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.RegisterExtension;
23+
24+
import java.io.File;
25+
import java.util.function.Supplier;
26+
27+
import org.neo4j.driver.v1.Config;
28+
import org.neo4j.driver.v1.Driver;
29+
import org.neo4j.driver.v1.GraphDatabase;
30+
import org.neo4j.driver.v1.Session;
31+
import org.neo4j.driver.v1.StatementResult;
32+
import org.neo4j.driver.v1.exceptions.SecurityException;
33+
import org.neo4j.driver.v1.util.CertificateToolUtil.CertificateKeyPair;
34+
import org.neo4j.driver.v1.util.DatabaseExtension;
35+
import org.neo4j.driver.v1.util.ParallelizableIT;
36+
37+
import static org.hamcrest.CoreMatchers.equalTo;
38+
import static org.hamcrest.MatcherAssert.assertThat;
39+
import static org.junit.jupiter.api.Assertions.assertThrows;
40+
import static org.neo4j.driver.v1.Config.TrustStrategy.trustCustomCertificateSignedBy;
41+
import static org.neo4j.driver.v1.util.CertificateToolUtil.createNewCertificateAndKey;
42+
import static org.neo4j.driver.v1.util.CertificateToolUtil.createNewCertificateAndKeySignedBy;
43+
44+
@ParallelizableIT
45+
public class TrustCustomCertificateIT
46+
{
47+
@RegisterExtension
48+
static final DatabaseExtension neo4j = new DatabaseExtension();
49+
50+
@Test
51+
void shouldAcceptServerWithCertificateSignedByDriverCertificate() throws Throwable
52+
{
53+
// Given root certificate
54+
CertificateKeyPair<File,File> root = createNewCertificateAndKey();
55+
56+
// When
57+
CertificateKeyPair<File,File> server = createNewCertificateAndKeySignedBy( root );
58+
neo4j.updateEncryptionKeyAndCert( server.key(), server.cert() );
59+
60+
// Then
61+
shouldBeAbleToRunCypher( () -> createDriverWithCustomCertificate( root.cert() ) );
62+
}
63+
64+
@Test
65+
void shouldAcceptServerWithSameCertificate() throws Throwable
66+
{
67+
shouldBeAbleToRunCypher( () -> createDriverWithCustomCertificate( neo4j.tlsCertFile() ) );
68+
}
69+
70+
@Test
71+
void shouldRejectServerWithUntrustedCertificate() throws Throwable
72+
{
73+
// Given a driver with a (random) cert
74+
CertificateKeyPair<File,File> certificateAndKey = createNewCertificateAndKey();
75+
76+
// When & Then
77+
SecurityException error = assertThrows( SecurityException.class, () -> createDriverWithCustomCertificate( certificateAndKey.cert() ) );
78+
}
79+
80+
private void shouldBeAbleToRunCypher( Supplier<Driver> driverSupplier )
81+
{
82+
try ( Driver driver = driverSupplier.get(); Session session = driver.session() )
83+
{
84+
StatementResult result = session.run( "RETURN 1 as n" );
85+
assertThat( result.single().get( "n" ).asInt(), equalTo( 1 ) );
86+
}
87+
}
88+
89+
private Driver createDriverWithCustomCertificate( File cert )
90+
{
91+
return GraphDatabase.driver( neo4j.uri(), neo4j.authToken(),
92+
Config.builder().withEncryption().withTrustStrategy( trustCustomCertificateSignedBy( cert ) ).build() );
93+
}
94+
}

0 commit comments

Comments
 (0)