Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
248 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...ity/bolt/src/test/java/org/neo4j/bolt/v1/messaging/encoder/FailureMessageEncoderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,82 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.v1.messaging.encoder; | |||
|
|||
import org.junit.jupiter.api.Test; | |||
|
|||
import org.neo4j.bolt.logging.BoltMessageLogger; | |||
import org.neo4j.bolt.messaging.Neo4jPack; | |||
import org.neo4j.bolt.v1.messaging.response.FailureMessage; | |||
import org.neo4j.bolt.v1.messaging.response.FatalFailureMessage; | |||
import org.neo4j.cypher.result.QueryResult; | |||
import org.neo4j.kernel.api.exceptions.Status; | |||
import org.neo4j.values.AnyValue; | |||
|
|||
import static org.mockito.ArgumentMatchers.any; | |||
import static org.mockito.ArgumentMatchers.anyInt; | |||
import static org.mockito.ArgumentMatchers.anyString; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.never; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.when; | |||
|
|||
class FailureMessageEncoderTest | |||
{ | |||
@Test | |||
void shouldEncodeFailureMessage() throws Throwable | |||
{ | |||
// Given | |||
Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); | |||
BoltMessageLogger logger = mock( BoltMessageLogger.class ); | |||
FailureMessageEncoder encoder = new FailureMessageEncoder( logger ); | |||
|
|||
// When | |||
QueryResult.Record value = mock( QueryResult.Record.class ); | |||
when( value.fields() ).thenReturn( new AnyValue[0] ); | |||
encoder.encode( packer, new FailureMessage( Status.General.UnknownError, "I am an error message" ) ); | |||
|
|||
// Then | |||
verify( logger, never() ).serverError( anyString(), any( Status.class ) ); | |||
verify( logger ).logFailure( Status.General.UnknownError ); | |||
|
|||
verify( packer ).packStructHeader( anyInt(), eq( FailureMessage.SIGNATURE ) ); | |||
verify( packer ).packMapHeader( 2 ); | |||
verify( packer ).pack( "code" ); | |||
verify( packer ).pack( "message" ); | |||
} | |||
|
|||
@Test | |||
void shouldLogErrorIfIsFatalError() throws Throwable | |||
{ | |||
Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); | |||
BoltMessageLogger logger = mock( BoltMessageLogger.class ); | |||
FailureMessageEncoder encoder = new FailureMessageEncoder( logger ); | |||
|
|||
// When | |||
QueryResult.Record value = mock( QueryResult.Record.class ); | |||
when( value.fields() ).thenReturn( new AnyValue[0] ); | |||
encoder.encode( packer, new FatalFailureMessage( Status.General.UnknownError, "I am an error message" ) ); | |||
|
|||
// Then | |||
verify( logger ).serverError( "FATAL", Status.General.UnknownError ); | |||
verify( logger ).logFailure( Status.General.UnknownError ); | |||
} | |||
} |
49 changes: 49 additions & 0 deletions
49
...ity/bolt/src/test/java/org/neo4j/bolt/v1/messaging/encoder/IgnoredMessageEncoderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.v1.messaging.encoder; | |||
|
|||
import org.junit.jupiter.api.Test; | |||
|
|||
import org.neo4j.bolt.logging.BoltMessageLogger; | |||
import org.neo4j.bolt.messaging.Neo4jPack; | |||
import org.neo4j.bolt.v1.messaging.response.IgnoredMessage; | |||
|
|||
import static org.mockito.ArgumentMatchers.anyInt; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.neo4j.bolt.v1.messaging.response.IgnoredMessage.IGNORED_MESSAGE; | |||
|
|||
class IgnoredMessageEncoderTest | |||
{ | |||
@Test | |||
void shouldEncodeIgnoredMessage() throws Throwable | |||
{ | |||
// Given | |||
Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); | |||
IgnoredMessageEncoder encoder = new IgnoredMessageEncoder( mock( BoltMessageLogger.class ) ); | |||
|
|||
// When | |||
encoder.encode( packer, IGNORED_MESSAGE ); | |||
|
|||
// Then | |||
verify( packer ).packStructHeader( anyInt(), eq( IgnoredMessage.SIGNATURE ) ); | |||
} | |||
} |
53 changes: 53 additions & 0 deletions
53
...nity/bolt/src/test/java/org/neo4j/bolt/v1/messaging/encoder/RecordMessageEncoderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.v1.messaging.encoder; | |||
|
|||
import org.junit.jupiter.api.Test; | |||
|
|||
import org.neo4j.bolt.messaging.Neo4jPack; | |||
import org.neo4j.bolt.v1.messaging.response.RecordMessage; | |||
import org.neo4j.cypher.result.QueryResult; | |||
import org.neo4j.values.AnyValue; | |||
|
|||
import static org.mockito.ArgumentMatchers.anyInt; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.when; | |||
|
|||
class RecordMessageEncoderTest | |||
{ | |||
@Test | |||
void shouldEncodeRecordMessage() throws Throwable | |||
{ | |||
// Given | |||
Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); | |||
RecordMessageEncoder encoder = new RecordMessageEncoder(); | |||
|
|||
// When | |||
QueryResult.Record value = mock( QueryResult.Record.class ); | |||
when( value.fields() ).thenReturn( new AnyValue[0] ); | |||
encoder.encode( packer, new RecordMessage( value ) ); | |||
|
|||
// Then | |||
verify( packer ).packStructHeader( anyInt(), eq( RecordMessage.SIGNATURE ) ); | |||
verify( packer ).packListHeader( 0 ); | |||
} | |||
} |
51 changes: 51 additions & 0 deletions
51
...ity/bolt/src/test/java/org/neo4j/bolt/v1/messaging/encoder/SuccessMessageEncoderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
/* | |||
* Copyright (c) 2002-2018 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.v1.messaging.encoder; | |||
|
|||
import org.junit.jupiter.api.Test; | |||
|
|||
import org.neo4j.bolt.logging.BoltMessageLogger; | |||
import org.neo4j.bolt.messaging.Neo4jPack; | |||
import org.neo4j.bolt.v1.messaging.response.SuccessMessage; | |||
import org.neo4j.values.virtual.MapValue; | |||
|
|||
import static org.mockito.ArgumentMatchers.anyInt; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
|
|||
class SuccessMessageEncoderTest | |||
{ | |||
@Test | |||
void shouldEncodeSuccessMessage() throws Throwable | |||
{ | |||
// Given | |||
Neo4jPack.Packer packer = mock( Neo4jPack.Packer.class ); | |||
SuccessMessageEncoder encoder = new SuccessMessageEncoder( mock( BoltMessageLogger.class ) ); | |||
|
|||
// When | |||
MapValue meta = mock( MapValue.class ); | |||
encoder.encode( packer, new SuccessMessage( meta ) ); | |||
|
|||
// Then | |||
verify( packer ).packStructHeader( anyInt(), eq( SuccessMessage.SIGNATURE ) ); | |||
verify( packer ).pack( meta ); | |||
} | |||
} |