Logger & profiles
This commit is contained in:
@@ -20,7 +20,7 @@ import javax.sql.DataSource;
|
||||
@Configuration
|
||||
@EnableJpaRepositories("me.bearns.fias.repository")
|
||||
@EnableTransactionManagement
|
||||
@PropertySource(value = "application.properties", ignoreResourceNotFound = true)
|
||||
//@PropertySource(value = "application-{profile}.properties", ignoreResourceNotFound = true)
|
||||
class ApplicationConfig {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -35,7 +35,6 @@ public class DownloaderImpl implements Downloader {
|
||||
if(feature != start) return feature;
|
||||
|
||||
pool.submit(() -> {
|
||||
//todo
|
||||
|
||||
final URL conn;
|
||||
final Path path;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/databasename
|
||||
spring.datasource.driverClassName=org.postgresql.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
|
||||
+1
-1
@@ -2,4 +2,4 @@ spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.bearns.fias;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.bearns.fias.domain.FiasVersion;
|
||||
import me.bearns.fias.exceptions.UnmarshallingException;
|
||||
import me.bearns.fias.helper.TransactionalSaveHelper;
|
||||
@@ -11,6 +12,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -19,6 +21,8 @@ import java.util.List;
|
||||
import static me.bearns.fias.helper.TransactionalSaveHelper.FIRST;
|
||||
import static me.bearns.fias.helper.TransactionalSaveHelper.NEXT;
|
||||
|
||||
@Slf4j
|
||||
@ActiveProfiles("test")
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Import(TransactionalSaveHelper.class)
|
||||
@@ -32,12 +36,14 @@ public class TransactionsTest {
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
log.info("Configure test components");
|
||||
helper.setRepository(repository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transactionTest(){
|
||||
|
||||
log.info("Run transaction test");
|
||||
helper.addFirst();
|
||||
|
||||
try {
|
||||
@@ -45,22 +51,26 @@ public class TransactionsTest {
|
||||
assert false;
|
||||
} catch (Exception e) {
|
||||
//just as plained
|
||||
log.info("Caught exception, continue");
|
||||
assert true;
|
||||
}
|
||||
|
||||
final List<FiasVersion> versions = repository.findAll();
|
||||
|
||||
versions.stream().map(FiasVersion::getVersionId).forEach(System.out::println);
|
||||
versions.stream().map(FiasVersion::toString).forEach(log::info);
|
||||
|
||||
assert versions.stream().mapToLong(FiasVersion::getVersionId).anyMatch(v -> FIRST == v);
|
||||
log.info("find {}", FIRST);
|
||||
|
||||
assert versions.stream().mapToLong(FiasVersion::getVersionId).noneMatch(v -> NEXT == v);
|
||||
log.info("not find {}", NEXT);
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void clear(){
|
||||
repository.deleteAll();
|
||||
log.info("Clear FiasVersion repo");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
@ActiveProfiles("test")
|
||||
@DataJpaTest
|
||||
public class VersionRepositoryTests {
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.bearns.fias.helper;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.bearns.fias.domain.FiasVersion;
|
||||
import me.bearns.fias.exceptions.CommonException;
|
||||
import me.bearns.fias.exceptions.UnmarshallingException;
|
||||
@@ -7,6 +8,7 @@ import me.bearns.fias.repository.FiasVersionRepository;
|
||||
import org.springframework.boot.test.context.TestComponent;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Slf4j
|
||||
@TestComponent
|
||||
public class TransactionalSaveHelper {
|
||||
|
||||
@@ -22,12 +24,12 @@ public class TransactionalSaveHelper {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addNext() throws CommonException {
|
||||
final FiasVersion nextVersion = new FiasVersion(NEXT, null, null, null);
|
||||
repository.save(nextVersion);
|
||||
log.info("Saved {}",repository.save(nextVersion));
|
||||
throw new UnmarshallingException("test");
|
||||
}
|
||||
|
||||
public void addFirst() {
|
||||
final FiasVersion version = new FiasVersion(FIRST, null, null, null);
|
||||
repository.save(version);
|
||||
log.info("Saved {}", repository.save(version));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user