Merge branch '2.0.x'
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.actuate.flyway;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -38,6 +39,7 @@ import org.springframework.context.ApplicationContext;
|
||||
* @author Eddú Meléndez
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
* @author Artsiom Yudovin
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Endpoint(id = "flyway")
|
||||
@@ -164,15 +166,19 @@ public class FlywayEndpoint {
|
||||
this.script = info.getScript();
|
||||
this.state = info.getState();
|
||||
this.installedBy = info.getInstalledBy();
|
||||
this.installedOn = Instant.ofEpochMilli(info.getInstalledOn().getTime());
|
||||
this.installedRank = info.getInstalledRank();
|
||||
this.executionTime = info.getExecutionTime();
|
||||
this.installedOn = nullSafeToInstant(info.getInstalledOn());
|
||||
}
|
||||
|
||||
private String nullSafeToString(Object obj) {
|
||||
return (obj != null) ? obj.toString() : null;
|
||||
}
|
||||
|
||||
private Instant nullSafeToInstant(Date date) {
|
||||
return (date != null) ? Instant.ofEpochMilli(date.getTime()) : null;
|
||||
}
|
||||
|
||||
public MigrationType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,13 @@
|
||||
|
||||
package org.springframework.boot.actuate.flyway;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.actuate.flyway.FlywayEndpoint.FlywayDescriptor;
|
||||
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -40,9 +44,28 @@ public class FlywayEndpointTests {
|
||||
@Test
|
||||
public void flywayReportIsProduced() {
|
||||
new ApplicationContextRunner().withUserConfiguration(Config.class)
|
||||
.run((context) -> assertThat(
|
||||
context.getBean(FlywayEndpoint.class).flywayBeans().getContexts()
|
||||
.get(context.getId()).getFlywayBeans()).hasSize(1));
|
||||
.run((context) -> {
|
||||
Map<String, FlywayDescriptor> flywayBeans = context
|
||||
.getBean(FlywayEndpoint.class).flywayBeans().getContexts()
|
||||
.get(context.getId()).getFlywayBeans();
|
||||
assertThat(flywayBeans).hasSize(1);
|
||||
assertThat(flywayBeans.values().iterator().next().getMigrations())
|
||||
.hasSize(3);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFlywayHasBeenBaselinedFlywayReportIsProduced() {
|
||||
new ApplicationContextRunner()
|
||||
.withUserConfiguration(BaselinedFlywayConfig.class, Config.class)
|
||||
.run((context) -> {
|
||||
Map<String, FlywayDescriptor> flywayBeans = context
|
||||
.getBean(FlywayEndpoint.class).flywayBeans().getContexts()
|
||||
.get(context.getId()).getFlywayBeans();
|
||||
assertThat(flywayBeans).hasSize(1);
|
||||
assertThat(flywayBeans.values().iterator().next().getMigrations())
|
||||
.hasSize(3);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -56,4 +79,18 @@ public class FlywayEndpointTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class BaselinedFlywayConfig {
|
||||
|
||||
@Bean
|
||||
public FlywayMigrationStrategy baseliningMigrationStrategy() {
|
||||
return (flyway) -> {
|
||||
flyway.setBaselineVersionAsString("2");
|
||||
flyway.baseline();
|
||||
flyway.migrate();
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS TEST;
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS TEST;
|
||||
Reference in New Issue
Block a user