Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.
20 changes: 14 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -39,11 +39,11 @@
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>playground-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>playground-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>voyager-spring-boot-starter</artifactId>
Expand Down Expand Up @@ -101,6 +101,14 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>

<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface BookRepository extends CrudRepository<Book, Long> {
List<Book> findAllBooks();

Book findBookByIsbn13(String isbn13);

Book findByTitleIgnoreCase(String title);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public Iterable<Author> findAllAuthors() {
public Book findBookByIsbn13(String isbn13) {
return bookRepository.findBookByIsbn13(isbn13);
}

public Book findByTitleIgnoreCase(String title) {
return bookRepository.findByTitleIgnoreCase(title);
}
}
1 change: 1 addition & 0 deletions src/main/resources/graphql/query.graphqls
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type Query {
findAllBooks: [Book]!
findBookByIsbn13(isbn13: String!): Book!
findByTitleIgnoreCase(title: String!): Book
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@DisplayName("BookRepository should")
class BookRepositoryTest {
private static final String ISBN = "978-3-16-148410-0";
private static final String TITLE = "Harry Potter";

private final BookRepository bookRepository;
private final AuthorRepository authorRepository;
Expand Down Expand Up @@ -106,6 +107,45 @@ private Book createBookwithISBN() {
return book;
}

@Test
void findBookByTitle() {
// given
createAndSaveAuthors();
Book book = new Book(
TITLE,
new Author[]{author1, author2},
Language.ENGLISH,
""
);
bookRepository.save(book);

// when
Book result = bookRepository.findByTitleIgnoreCase(TITLE);

// then
assertThat(result).isEqualTo(book);
}

@Test
@DisplayName("find book by title case insensitive")
void findBookByTitleCaseInsensitive() {
// given
createAndSaveAuthors();
Book book = new Book(
TITLE,
new Author[]{author1, author2},
Language.ENGLISH,
""
);
bookRepository.save(book);

// when
Book result = bookRepository.findByTitleIgnoreCase(TITLE.toLowerCase());

// then
assertThat(result).isEqualTo(book);
}

private void saveAllAuthors(Author... authors) {
Arrays.stream(authors).forEach(authorRepository::save);
}
Expand Down