- added test for AuthorPersistenceAdapter
- added some demo classes
This commit is contained in:
@@ -16,7 +16,7 @@ configurations {
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -31,8 +31,11 @@ dependencies {
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.0.1'
|
||||
testImplementation 'org.mockito:mockito-junit-jupiter:2.23.0'
|
||||
testImplementation 'com.tngtech.archunit:archunit:0.9.3'
|
||||
testImplementation 'de.adesso:junit-insights:1.1.0'
|
||||
testImplementation 'org.junit.platform:junit-platform-launcher:1.4.2'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
systemProperty 'de.adesso.junitinsights.enabled', 'true'
|
||||
}
|
||||
|
||||
11
src/demo/PersistenceAdapterTestConfiguration.java
Normal file
11
src/demo/PersistenceAdapterTestConfiguration.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package io.reflectoring.reviewapp.adapter.persistence;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
//@SpringBootConfiguration
|
||||
//@EnableAutoConfiguration
|
||||
//@Import(PersistenceAdapterConfiguration.class)
|
||||
public class PersistenceAdapterTestConfiguration {
|
||||
}
|
||||
4
src/demo/morepersistence/AnotherEntity.java
Normal file
4
src/demo/morepersistence/AnotherEntity.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package io.reflectoring.reviewapp.adapter.morepersistence;
|
||||
|
||||
public class AnotherEntity {
|
||||
}
|
||||
13
src/demo/morepersistence/AnotherPersistenceAdapter.java
Normal file
13
src/demo/morepersistence/AnotherPersistenceAdapter.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package io.reflectoring.reviewapp.adapter.morepersistence;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
class AnotherPersistenceAdapter {
|
||||
|
||||
private final CrudRepository<AnotherEntity, Long> anotherRepository;
|
||||
|
||||
}
|
||||
@@ -2,13 +2,14 @@ package io.reflectoring.reviewapp.adapter.persistence;
|
||||
|
||||
import io.reflectoring.reviewapp.application.port.out.FindBookByTitlePort;
|
||||
import io.reflectoring.reviewapp.application.port.out.PersistBookPort;
|
||||
import io.reflectoring.reviewapp.common.PersistenceAdapter;
|
||||
import io.reflectoring.reviewapp.domain.Book;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@PersistenceAdapter
|
||||
@RequiredArgsConstructor
|
||||
class BookPersistenceAdapter implements FindBookByTitlePort, PersistBookPort {
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
DELETE
|
||||
FROM AUTHOR
|
||||
WHERE ID = 42;
|
||||
@@ -0,0 +1,2 @@
|
||||
INSERT INTO AUTHOR (ID, NAME)
|
||||
VALUES (42, 'Tom');
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.reflectoring.reviewapp.adapter.persistence;
|
||||
|
||||
import io.reflectoring.reviewapp.domain.Author;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
|
||||
import org.springframework.test.context.jdbc.SqlGroup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
class AuthorPersistenceAdapterTest {
|
||||
|
||||
@Autowired
|
||||
private AuthorPersistenceAdapter authorPersistenceAdapter;
|
||||
|
||||
@Test
|
||||
@SqlGroup({
|
||||
@Sql(scripts = "single-author.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD),
|
||||
@Sql(scripts = "single-author-reset.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)})
|
||||
void findByAuthorId() {
|
||||
Author author = authorPersistenceAdapter.findAuthorById(42L);
|
||||
assertThat(author).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user