More testing.
This commit is contained in:
@@ -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<PersonRepository> 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<Person, Long> {
|
||||
|
||||
@Query(CUSTOM_CYPHER_QUERY)
|
||||
List<Person> annotatedQuery();
|
||||
}
|
||||
|
||||
class Person {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user