Skip to content

Commit

Permalink
Parameterize bolt ITs with Neo4jPack versions
Browse files Browse the repository at this point in the history
  • Loading branch information
lutovich committed Feb 21, 2018
1 parent c477338 commit e513f5c
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 362 deletions.
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.bolt;

import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.neo4j.bolt.v1.messaging.Neo4jPack;
import org.neo4j.bolt.v1.messaging.Neo4jPackV1;
import org.neo4j.bolt.v1.transport.integration.TransportTestUtil;
import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
import org.neo4j.bolt.v2.messaging.Neo4jPackV2;
import org.neo4j.helpers.HostnamePort;

import static org.junit.runners.Parameterized.Parameter;
import static org.junit.runners.Parameterized.Parameters;

@RunWith( Parameterized.class )
public abstract class AbstractBoltTransportsTest
{
private static final List<Class<? extends TransportConnection>> CONNECTION_CLASSES = Arrays.asList(
SocketConnection.class,
WebSocketConnection.class,
SecureSocketConnection.class,
SecureWebSocketConnection.class );

private static final List<Neo4jPack> NEO4J_PACK_VERSIONS = Arrays.asList(
new Neo4jPackV1(),
new Neo4jPackV2() );

@Parameter( 0 )
public Class<? extends TransportConnection> connectionClass;

@Parameter( 1 )
public Neo4jPack neo4jPack;

@Parameter( 2 )
public String name;

protected HostnamePort address;
protected TransportConnection connection;
protected TransportTestUtil util;

@Before
public void initializeConnectionAndUtil() throws Exception
{
connection = connectionClass.newInstance();
util = new TransportTestUtil( neo4jPack );
}

@After
public void disconnectFromDatabase() throws Exception
{
if ( connection != null )
{
connection.disconnect();
}
}

@Parameters( name = "{2}" )
public static List<Object[]> parameters()
{
List<Object[]> result = new ArrayList<>();
for ( Class<? extends TransportConnection> connectionClass : CONNECTION_CLASSES )
{
for ( Neo4jPack neo4jPack : NEO4J_PACK_VERSIONS )
{
result.add( new Object[]{connectionClass, neo4jPack, newName( connectionClass, neo4jPack )} );
}
}
return result;
}

protected TransportConnection newConnection() throws Exception
{
return connectionClass.newInstance();
}

protected void reconnect() throws Exception
{
if ( connection != null )
{
connection.disconnect();
}
connection = newConnection();
}

private static String newName( Class<? extends TransportConnection> connectionClass, Neo4jPack neo4jPack )
{
return connectionClass.getSimpleName() + " & " + neo4jPack.getClass().getSimpleName();
}
}
Expand Up @@ -22,15 +22,10 @@
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


import org.neo4j.bolt.v1.messaging.Neo4jPackV1; import org.neo4j.bolt.AbstractBoltTransportsTest;
import org.neo4j.bolt.v1.messaging.message.InitMessage; import org.neo4j.bolt.v1.messaging.message.InitMessage;
import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket; import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket;
import org.neo4j.bolt.v1.transport.integration.TransportTestUtil;
import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.TransportConnection; import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
import org.neo4j.helpers.HostnamePort; import org.neo4j.helpers.HostnamePort;
import org.neo4j.kernel.configuration.BoltConnector; import org.neo4j.kernel.configuration.BoltConnector;
import org.neo4j.test.rule.SuppressOutput; import org.neo4j.test.rule.SuppressOutput;
Expand All @@ -42,7 +37,7 @@
import static org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyReceives; import static org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyReceives;
import static org.neo4j.kernel.configuration.BoltConnector.EncryptionLevel.REQUIRED; import static org.neo4j.kernel.configuration.BoltConnector.EncryptionLevel.REQUIRED;


public class BoltConfigIT public class BoltConfigIT extends AbstractBoltTransportsTest
{ {
private static final String ANOTHER_CONNECTOR_KEY = "1"; private static final String ANOTHER_CONNECTOR_KEY = "1";


Expand All @@ -61,27 +56,14 @@ public class BoltConfigIT
@Rule @Rule
public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); public SuppressOutput suppressOutput = SuppressOutput.suppressAll();


private final TransportTestUtil util = new TransportTestUtil( new Neo4jPackV1() );

@Test @Test
public void shouldSupportMultipleConnectors() throws Throwable public void shouldSupportMultipleConnectors() throws Throwable
{ {
// Given
// When

// Then
HostnamePort address0 = server.lookupConnector( DEFAULT_CONNECTOR_KEY ); HostnamePort address0 = server.lookupConnector( DEFAULT_CONNECTOR_KEY );
assertConnectionAccepted( address0, new WebSocketConnection() ); assertConnectionAccepted( address0, newConnection() );
assertConnectionAccepted( address0, new SecureWebSocketConnection() );
assertConnectionAccepted( address0, new SocketConnection() );
assertConnectionAccepted( address0, new SecureSocketConnection() );


HostnamePort address1 = server.lookupConnector( ANOTHER_CONNECTOR_KEY ); HostnamePort address1 = server.lookupConnector( ANOTHER_CONNECTOR_KEY );
assertConnectionRejected( address1, new WebSocketConnection() ); assertConnectionRejected( address1, newConnection() );
assertConnectionAccepted( address1, new SecureWebSocketConnection() );
assertConnectionRejected( address1, new SocketConnection() );
assertConnectionAccepted( address1, new SecureSocketConnection() );

} }


private void assertConnectionRejected( HostnamePort address, TransportConnection client ) throws Exception private void assertConnectionRejected( HostnamePort address, TransportConnection client ) throws Exception
Expand Down

0 comments on commit e513f5c

Please sign in to comment.