Tests ok
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.6.RELEASE</version>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>me.bearns</groupId>
|
||||
|
||||
@@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableJpaRepositories("me.bearns.fias.repository")
|
||||
public class FiasApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager;
|
||||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
@@ -19,7 +18,7 @@ import javax.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories
|
||||
@EnableJpaRepositories("me.bearns.fias.repository")
|
||||
@EnableTransactionManagement
|
||||
@PropertySource("application.properties")
|
||||
class ApplicationConfig {
|
||||
@@ -31,10 +30,6 @@ class ApplicationConfig {
|
||||
//@Profile("test")
|
||||
public DataSource dataSource() {
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
/*dataSource.setDriverClassName("org.h2.Driver");
|
||||
dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1");
|
||||
dataSource.setUsername("sa");
|
||||
dataSource.setPassword("sa");*/
|
||||
dataSource.setDriverClassName(env.getProperty("spring.datasource.driverClassName"));
|
||||
dataSource.setUrl(env.getProperty("spring.datasource.url"));
|
||||
dataSource.setUsername(env.getProperty("spring.datasource.username"));
|
||||
@@ -47,15 +42,12 @@ class ApplicationConfig {
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||
|
||||
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
||||
vendorAdapter.setGenerateDdl(true);
|
||||
|
||||
//DefaultPersistenceUnitManager persistenceUnitManager = new DefaultPersistenceUnitManager();
|
||||
//persistenceUnitManager.setDefaultDataSource(dataSource());
|
||||
vendorAdapter.setGenerateDdl(false); //use liquibase
|
||||
vendorAdapter.setShowSql(true); //TODO Debug
|
||||
|
||||
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
|
||||
factory.setJpaVendorAdapter(vendorAdapter);
|
||||
factory.setPackagesToScan(new String[] {"me.bearns.fias.domain", "me.bearns.fias.repository"});
|
||||
//factory.setPersistenceUnitManager(persistenceUnitManager);
|
||||
factory.setDataSource(dataSource());
|
||||
return factory;
|
||||
}
|
||||
|
||||
@@ -2,20 +2,46 @@ package me.bearns.fias.domain;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "version")
|
||||
public class FiasVersion {
|
||||
|
||||
public FiasVersion(Long versionId, String textVersion, String fiasCompleteXmlUrl, String fiasDeltaXmlUrl) {
|
||||
this.versionId = versionId;
|
||||
this.textVersion = textVersion;
|
||||
this.fiasCompleteXmlUrl = fiasCompleteXmlUrl;
|
||||
this.fiasDeltaXmlUrl = fiasDeltaXmlUrl;
|
||||
}
|
||||
|
||||
@Id
|
||||
@Column(name = "version_id")
|
||||
protected Long versionId;
|
||||
|
||||
@Column(name = "version_txt")
|
||||
protected String textVersion;
|
||||
|
||||
@Column(name = "xml_url")
|
||||
protected String fiasCompleteXmlUrl;
|
||||
|
||||
@Column(name = "delta_xml_url")
|
||||
protected String fiasDeltaXmlUrl;
|
||||
|
||||
public Long getVersionId() {
|
||||
return versionId;
|
||||
}
|
||||
|
||||
public String getTextVersion() {
|
||||
return textVersion;
|
||||
}
|
||||
|
||||
public String getFiasCompleteXmlUrl() {
|
||||
return fiasCompleteXmlUrl;
|
||||
}
|
||||
|
||||
public String getFiasDeltaXmlUrl() {
|
||||
return fiasDeltaXmlUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 1
|
||||
author: alex@bearns.me
|
||||
changes:
|
||||
- createTable:
|
||||
tableName: version
|
||||
columns:
|
||||
- column:
|
||||
name: version_id
|
||||
type: number
|
||||
constraints:
|
||||
primaryKey: true
|
||||
nullable: false
|
||||
- column:
|
||||
name: version_txt
|
||||
type: number
|
||||
- column:
|
||||
name: xml_url
|
||||
type: varchar
|
||||
@@ -1,4 +1,4 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 1
|
||||
author: alex@bearns.me
|
||||
- include:
|
||||
- file: "000_initial_schema.yaml"
|
||||
- relativeToChangelogFile: "true"
|
||||
@@ -1,13 +0,0 @@
|
||||
package me.bearns.fias;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class FiasApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2002-2016 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
|
||||
*
|
||||
* https://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 me.bearns.fias;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import me.bearns.fias.domain.FiasVersion;
|
||||
import me.bearns.fias.repository.FiasVersionRepository;
|
||||
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;
|
||||
|
||||
@DataJpaTest
|
||||
public class VersionRepositoryTests {
|
||||
@Autowired
|
||||
private TestEntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
private FiasVersionRepository repository;
|
||||
|
||||
@Test
|
||||
public void testFindByLastName() {
|
||||
FiasVersion fiasVersion = new FiasVersion(1L, "last", "c", "d");
|
||||
entityManager.persist(fiasVersion);
|
||||
|
||||
Optional<FiasVersion> byId = repository.findById(fiasVersion.getVersionId());
|
||||
|
||||
FiasVersion version = byId.get();
|
||||
|
||||
assertThat(version).extracting(FiasVersion::getVersionId).isEqualTo(fiasVersion.getVersionId());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user