From 649c8fff2b3a0c9592a2b4a8e572e27e31a05cb8 Mon Sep 17 00:00:00 2001 From: Gerrit Meier Date: Fri, 1 Mar 2019 17:03:30 +0100 Subject: [PATCH] More testing. --- .../query/Neo4jQueryMethodTest.java | 68 +++++++++ .../support/SimpleNeo4jRepositoryTest.java | 136 ++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/query/Neo4jQueryMethodTest.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepositoryTest.java diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/query/Neo4jQueryMethodTest.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/query/Neo4jQueryMethodTest.java new file mode 100644 index 000000000..1e62a1b24 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/query/Neo4jQueryMethodTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.repository.query; + +import static org.assertj.core.api.Assertions.*; + +import java.lang.reflect.Method; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.springframework.data.projection.ProjectionFactory; +import org.springframework.data.projection.SpelAwareProxyProjectionFactory; +import org.springframework.data.repository.Repository; +import org.springframework.data.repository.core.support.DefaultRepositoryMetadata; + +/** + * @author Gerrit Meier + **/ +class Neo4jQueryMethodTest { + + private static final String CUSTOM_CYPHER_QUERY = "MATCH (n) return n"; + + @Test + void shouldFindAnnotatedQuery() throws Exception { + Neo4jQueryMethod queryMethod = queryMethod("annotatedQuery"); + assertThat(queryMethod.getAnnotatedQuery()).isEqualTo(CUSTOM_CYPHER_QUERY); + } + + @Test + void findQueryAnnotation() throws Exception { + Neo4jQueryMethod queryMethod = queryMethod("annotatedQuery"); + assertThat(queryMethod.hasAnnotatedQuery()).isTrue(); + } + + private Neo4jQueryMethod queryMethod(String name, Class... parameters) throws Exception { + Class repositoryClass = PersonRepository.class; + + Method method = repositoryClass.getMethod(name, parameters); + ProjectionFactory factory = new SpelAwareProxyProjectionFactory(); + return Neo4jQueryMethod.of(method, new DefaultRepositoryMetadata(repositoryClass), factory); + } + + interface PersonRepository extends Repository { + + @Query(CUSTOM_CYPHER_QUERY) + List annotatedQuery(); + } + + class Person { + } + +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepositoryTest.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepositoryTest.java new file mode 100644 index 000000000..c8113e9a7 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/support/SimpleNeo4jRepositoryTest.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2019 "Neo4j," + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.repository.support; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; + +/** + * @author Gerrit Meier + **/ +class SimpleNeo4jRepositoryTest { + + private SimpleNeo4jRepository repository = new SimpleNeo4jRepository(null); + + @Test + void saveNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.save(null)); + } + + @Test + void saveAllNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.saveAll(null)); + } + + @Test + void findByIdNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.findById(null)); + } + + @Test + void existsByIdNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.existsById(null)); + } + + @Test + void findAllByIdNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.findAllById(null)); + } + + @Test + void deleteByIdNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.deleteById(null)); + } + + @Test + void deleteNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.delete(null)); + } + + @Test + void deleteAllNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.deleteAll()); + } + + @Test + void deleteAll1NotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.deleteAll(null)); + } + + @Test + void findOneNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.findOne(null)); + } + + @Test + void findAllNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.findAll()); + } + + @Test + void findAllExampleNotImplemented() { + Example example = Example.of(""); + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.findAll(example)); + } + + @Test + void findAllPageableNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> repository.findAll(Pageable.unpaged())); + } + + @Test + void findAllSortByNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> repository.findAll(Sort.by("property"))); + } + + @Test + void findAllExampleAndSortNotImplemented() { + Example example = Example.of(""); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> repository.findAll(example, Sort.by("property"))); + } + + @Test + void findAllExampleAndPageableNotImplemented() { + Example example = Example.of(""); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> repository.findAll(example, Pageable.unpaged())); + } + + @Test + void countNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.count()); + } + + @Test + void countWithExampleNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.count(null)); + } + + @Test + void existsNotImplemented() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> repository.findAll()); + } +}