add simple liquibase setup tests

This commit is contained in:
f43nd1r 2018-06-26 00:10:02 +02:00
parent e3a256221e
commit 68f655613b
9 changed files with 162 additions and 4 deletions

View file

@ -116,6 +116,10 @@ dependencies {
compile 'com.faendir.proguard:retrace:1.3' compile 'com.faendir.proguard:retrace:1.3'
compile 'javax.xml.bind:jaxb-api:2.3.0' compile 'javax.xml.bind:jaxb-api:2.3.0'
compile 'com.github.ziplet:ziplet:2.3.0' compile 'com.github.ziplet:ziplet:2.3.0'
//testing
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'com.h2database:h2'
testCompile files('libs/ojdbc6.jar')
} }
compileJava.dependsOn(processResources) compileJava.dependsOn(processResources)

BIN
libs/ojdbc6.jar Normal file

Binary file not shown.

View file

@ -23,8 +23,6 @@ import liquibase.changelog.visitor.AbstractChangeExecListener;
import liquibase.database.Database; import liquibase.database.Database;
import liquibase.exception.LiquibaseException; import liquibase.exception.LiquibaseException;
import liquibase.integration.spring.SpringLiquibase; import liquibase.integration.spring.SpringLiquibase;
import liquibase.logging.LogFactory;
import liquibase.logging.LogLevel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties; import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -67,7 +65,6 @@ public class ChangeAwareSpringLiquibase extends SpringLiquibase {
processors.forEach(processor -> processor.handle(changeSet)); processors.forEach(processor -> processor.handle(changeSet));
} }
}); });
LogFactory.getInstance().getLog().setLogLevel(LogLevel.DEBUG);
return liquibase; return liquibase;
} }
} }

View file

@ -60,7 +60,7 @@ public abstract class BaseChange implements LiquibaseChangePostProcessor {
@Nullable @Nullable
protected String quote(@Nullable String s) { protected String quote(@Nullable String s) {
return getDialect().quote(s); return getDialect().openQuote() + s + getDialect().closeQuote();
} }
@Transactional @Transactional

View file

@ -0,0 +1,67 @@
/*
* (C) Copyright 2018 Lukas Morawietz (https://github.com/F43nd1r)
*
* 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.faendir.acra;
import com.faendir.acra.liquibase.ChangeAwareSpringLiquibase;
import com.faendir.acra.liquibase.LiquibaseChangePostProcessor;
import liquibase.exception.LiquibaseException;
import liquibase.integration.spring.SpringLiquibase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import javax.sql.DataSource;
import java.util.List;
/**
* @author lukas
* @since 25.06.18
*/
@DataJpaTest
@RunWith(SpringRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ComponentScan(basePackageClasses = BackendApplication.class, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = SpringLiquibase.class))
@ImportAutoConfiguration(exclude = {LiquibaseAutoConfiguration.class, EmbeddedDataSourceConfiguration.class})
public abstract class LiquibaseTest {
@Autowired ResourceLoader resourceLoader;
@Autowired DataSource dataSource;
@Autowired List<LiquibaseChangePostProcessor> processors;
@Test
public void setupTest() throws LiquibaseException {
SpringLiquibase liquibase = new ChangeAwareSpringLiquibase(new LiquibaseProperties(), dataSource, processors);
liquibase.setResourceLoader(resourceLoader);
liquibase.afterPropertiesSet();
}
@Configuration
@ComponentScan("com.faendir.acra.liquibase.change")
public static class Config {
}
}

View file

@ -0,0 +1,26 @@
/*
* (C) Copyright 2018 Lukas Morawietz (https://github.com/F43nd1r)
*
* 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.faendir.acra;
import org.springframework.test.context.TestPropertySource;
/**
* @author lukas
* @since 25.06.18
*/
@TestPropertySource("classpath:application-mysql.properties")
public class MySQLTest extends LiquibaseTest{
}

View file

@ -0,0 +1,26 @@
/*
* (C) Copyright 2018 Lukas Morawietz (https://github.com/F43nd1r)
*
* 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.faendir.acra;
import org.springframework.test.context.TestPropertySource;
/**
* @author lukas
* @since 25.06.18
*/
@TestPropertySource("classpath:application-oracle.properties")
public class OracleTest extends LiquibaseTest {
}

View file

@ -0,0 +1,19 @@
#
# (C) Copyright 2018 Lukas Morawietz (https://github.com/F43nd1r)
#
# 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.
#
spring.datasource.url=jdbc:h2:mem:testdb-mysql;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false
spring.jpa.database-platform=org.hibernate.dialect.MySQL57Dialect
spring.datasource.driver-class-name=org.h2.Driver

View file

@ -0,0 +1,19 @@
#
# (C) Copyright 2018 Lukas Morawietz (https://github.com/F43nd1r)
#
# 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.
#
spring.datasource.url=jdbc:h2:mem:testdb-oracle;MODE=Oracle;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.datasource.driver-class-name=org.h2.Driver