Add test that uses AbstractPersistable
See gh-161
This commit is contained in:
committed by
Andy Wilkinson
parent
0db7058714
commit
bd2d9b54ce
@@ -88,4 +88,12 @@ class DataJpaApplicationAotTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void abstractPersistable(AssertableOutput output) {
|
||||
|
||||
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
|
||||
assertThat(output).hasLineMatching(".*Publisher\\{name='independently published', id=\\d.*\\}");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.stream.Stream;
|
||||
import com.example.data.jpa.model.Author;
|
||||
import com.example.data.jpa.model.Book;
|
||||
|
||||
import com.example.data.jpa.model.Publisher;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -20,9 +21,12 @@ class CLR implements CommandLineRunner {
|
||||
|
||||
private final BookRepository bookRepository;
|
||||
|
||||
CLR(AuthorRepository authorRepository, BookRepository bookRepository) {
|
||||
private final PublisherRepository publisherRepository;
|
||||
|
||||
CLR(AuthorRepository authorRepository, BookRepository bookRepository, PublisherRepository publisherRepository) {
|
||||
this.authorRepository = authorRepository;
|
||||
this.bookRepository = bookRepository;
|
||||
this.publisherRepository = publisherRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,6 +40,7 @@ class CLR implements CommandLineRunner {
|
||||
streamAuthors();
|
||||
deleteAll();
|
||||
entityGraph();
|
||||
insertPublishers(); // uses AbstractPersistable
|
||||
}
|
||||
|
||||
private void deleteAll() {
|
||||
@@ -107,4 +112,10 @@ class CLR implements CommandLineRunner {
|
||||
return Arrays.asList(author1, author2);
|
||||
}
|
||||
|
||||
private List<Publisher> insertPublishers() {
|
||||
Publisher publisher1 = this.publisherRepository.save(new Publisher("independently published"));
|
||||
System.out.printf("insertPublishers(): publisher1 - %s%n", publisher1);
|
||||
return List.of(publisher1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.data.jpa;
|
||||
|
||||
import com.example.data.jpa.model.Publisher;
|
||||
import org.springframework.data.repository.ListCrudRepository;
|
||||
|
||||
public interface PublisherRepository extends ListCrudRepository<Publisher, Long> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2022 the original author or authors.
|
||||
*
|
||||
* 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 com.example.data.jpa.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
public class Publisher extends AbstractPersistable<Long> {
|
||||
|
||||
private String name;
|
||||
|
||||
protected Publisher() {
|
||||
}
|
||||
|
||||
public Publisher(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Publisher{name='" + name + "', id=" + getId() + '}';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user