Skip to content

Commit bf2d680

Browse files
author
Zhen
committed
Remove some not needed restart of server in tests
1 parent 45e3623 commit bf2d680

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

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

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

21-
import org.junit.Rule;
21+
import org.junit.BeforeClass;
22+
import org.junit.ClassRule;
2223
import org.junit.Test;
23-
import org.junit.rules.ExpectedException;
2424
import org.junit.rules.TemporaryFolder;
2525

2626
import java.util.HashMap;
@@ -34,31 +34,29 @@
3434
import org.neo4j.driver.v1.util.Neo4jSettings;
3535
import org.neo4j.driver.v1.util.TestNeo4j;
3636

37+
import static junit.framework.TestCase.fail;
3738
import static org.hamcrest.MatcherAssert.assertThat;
39+
import static org.hamcrest.Matchers.containsString;
3840
import static org.hamcrest.Matchers.equalTo;
41+
import static org.hamcrest.Matchers.instanceOf;
3942
import static org.neo4j.driver.v1.AuthTokens.basic;
4043
import static org.neo4j.driver.v1.AuthTokens.custom;
4144
import static org.neo4j.driver.v1.Values.ofValue;
4245
import static org.neo4j.driver.v1.Values.parameters;
4346

4447
public class CredentialsIT
4548
{
46-
@Rule
47-
public TemporaryFolder tempDir = new TemporaryFolder();
49+
@ClassRule
50+
public static TemporaryFolder tempDir = new TemporaryFolder();
4851

49-
@Rule
50-
public TestNeo4j neo4j = new TestNeo4j();
52+
@ClassRule
53+
public static TestNeo4j neo4j = new TestNeo4j();
5154

52-
@Rule
53-
public ExpectedException exception = ExpectedException.none();
55+
private static String password = "secret";
5456

5557
@Test
5658
public void basicCredentialsShouldWork() throws Throwable
5759
{
58-
// Given
59-
String password = "secret";
60-
enableAuth( password );
61-
6260
// When & Then
6361
try( Driver driver = GraphDatabase.driver( neo4j.uri(),
6462
basic("neo4j", password ) );
@@ -73,28 +71,22 @@ public void basicCredentialsShouldWork() throws Throwable
7371
@Test
7472
public void shouldGetHelpfulErrorOnInvalidCredentials() throws Throwable
7573
{
76-
// Given
77-
String password = "secret";
78-
enableAuth( password );
79-
80-
// Expect
81-
exception.expect( ClientException.class );
82-
exception.expectMessage( "The client is unauthorized due to authentication failure." );
83-
8474
// When
8575
try( Driver driver = GraphDatabase.driver( neo4j.uri(), basic("thisisnotthepassword", password ) );
8676
Session ignored = driver.session() ) {
8777
//empty
78+
fail( "Should fail with an auth error already" );
79+
}
80+
catch( Throwable e )
81+
{
82+
assertThat( e, instanceOf( ClientException.class ) );
83+
assertThat( e.getMessage(), containsString( "The client is unauthorized due to authentication failure." ) );
8884
}
8985
}
9086

9187
@Test
9288
public void shouldBeAbleToProvideRealmWithBasicAuth() throws Throwable
9389
{
94-
// Given
95-
String password = "secret";
96-
enableAuth( password );
97-
9890
// When & Then
9991
try( Driver driver = GraphDatabase.driver( neo4j.uri(),
10092
basic("neo4j", password, "native") );
@@ -108,10 +100,6 @@ public void shouldBeAbleToProvideRealmWithBasicAuth() throws Throwable
108100
@Test
109101
public void shouldBeAbleToConnectWithCustomToken() throws Throwable
110102
{
111-
// Given
112-
String password = "secret";
113-
enableAuth( password );
114-
115103
// When & Then
116104
try( Driver driver = GraphDatabase.driver( neo4j.uri(),
117105
custom("neo4j", password, "native", "basic" ) );
@@ -125,9 +113,6 @@ public void shouldBeAbleToConnectWithCustomToken() throws Throwable
125113
@Test
126114
public void shouldBeAbleToConnectWithCustomTokenWithAdditionalParameters() throws Throwable
127115
{
128-
// Given
129-
String password = "secret";
130-
enableAuth( password );
131116
HashMap<String,Object> parameters = new HashMap<>();
132117
parameters.put( "secret", 16 );
133118

@@ -141,7 +126,8 @@ public void shouldBeAbleToConnectWithCustomTokenWithAdditionalParameters() throw
141126
}
142127
}
143128

144-
private void enableAuth( String password ) throws Exception
129+
@BeforeClass
130+
public static void enableAuth() throws Exception
145131
{
146132
neo4j.restart( Neo4jSettings.TEST_SETTINGS
147133
.updateWith( Neo4jSettings.AUTH_ENABLED, "true" )

0 commit comments

Comments
 (0)