Skip to content

Commit

Permalink
refactor: Address code quality issues. (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-simons authored Mar 12, 2024
1 parent 303b2c0 commit d85a767
Show file tree
Hide file tree
Showing 53 changed files with 557 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,27 @@
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class ConnectionIT extends IntegrationTestBase {

@Test
void shouldCheckTXStateBeforeCommit() throws SQLException {
try (var connection = getConnection()) {
assertThatExceptionOfType(SQLException.class).isThrownBy(connection::commit)
.withMessage("There is no transaction to commit");
}
}

@Test
void shouldCheckTXStateBeforeRollback() throws SQLException {
try (var connection = getConnection()) {
assertThatExceptionOfType(SQLException.class).isThrownBy(connection::rollback)
.withMessage("There is no transaction to rollback");
}
}

@Test
void shouldBeginNewTransactionAfterFailureInAutoCommit() throws SQLException {
try (var connection = getConnection(); var statement = connection.createStatement()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,40 @@ else if ("i".equals(columnName)) {
}
}

@Test
void shouldBeAbleToMapAllV5CypherTypes() throws Exception {

var query = """
CREATE (n:CypherTypes)
SET
n.aBoolean = true,
n.aLong = 9223372036854775807, n.aDouble = 1.7976931348, n.aString = 'Hallo, Cypher',
n.aByteArray = ?, n.aLocalDate = date('2015-07-21'),
n.anOffsetTime = time({ hour:12, minute:31, timezone: '+01:00' }),
n.aLocalTime = localtime({ hour:12, minute:31, second:14 }),
n.aZoneDateTime = datetime('2015-07-21T21:40:32-04[America/New_York]'),
n.aLocalDateTime = localdatetime('2015202T21'), n.anIsoDuration = duration('P14DT16H12M'),
n.aPoint = point({x:47, y:11})
""";
try (var stmt = this.connection.prepareStatement(query)) {
stmt.setBytes(1, new byte[] { 6 });
stmt.execute();

}
var meta = this.connection.getMetaData();
int cnt = 0;
var types = new HashSet<String>();
try (var results = meta.getColumns(null, null, "CypherTypes", null)) {
while (results.next()) {
types.add(results.getString("TYPE_NAME"));
++cnt;
}
assertThat(cnt).isEqualTo(12);
assertThat(types).hasSize(cnt);
assertThat(types).doesNotContain("OTHER");
}
}

@Test
void getIndexInfoWithIndex() throws Exception {
String indexName = "bar_uuid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.neo4j.jdbc.values.Path;
import org.neo4j.jdbc.values.Value;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -433,4 +434,18 @@ void noSurpriseGetString() throws SQLException {
}
}

@Test
void pathsShouldBeAccessible() throws SQLException {
try (var connection = getConnection();
var stmt = connection.createStatement();
var result = stmt.executeQuery(
"CREATE p = (:Show {name: 'The Last Of Us'}) <-[:WATCHED_BY]- (:Person {name: 'Michael'}) RETURN p")) {

assertThat(result.next()).isTrue();
var path = result.getObject("p", Path.class);
assertThat(path.start().get("name").asString()).isEqualTo("The Last Of Us");
assertThat(path.end().get("name").asString()).isEqualTo("Michael");
}
}

}
4 changes: 4 additions & 0 deletions neo4j-jdbc-test-results/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-jdbc-translator-impl</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Loading

0 comments on commit d85a767

Please sign in to comment.