Skip to content

Commit

Permalink
fix: flyway endpoint should be serde compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Nov 8, 2024
1 parent d260fec commit b9468bb
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2017-2024 original 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 io.micronaut.flyway.endpoint;

import io.micronaut.core.annotation.Internal;
import io.micronaut.serde.annotation.SerdeImport;
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.internal.info.MigrationInfoImpl;
import org.flywaydb.core.internal.resolver.ResolvedMigrationImpl;
import org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor;
import org.flywaydb.core.internal.schemahistory.BaseAppliedMigration;

/**
* Serde imports for the flyway endpoint.
*/
@Internal
@SerdeImport(ResolvedMigrationImpl.class)
@SerdeImport(BaseAppliedMigration.class)
@SerdeImport(SqlMigrationExecutor.class)
@SerdeImport(MigrationVersion.class)
@SerdeImport(MigrationInfoImpl.class)
class FlywayEndpointSerdeImports {
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rootProject.name = 'flyway-parent'
include 'flyway'
include 'flyway-bom'
include 'test-suite-java'
include 'test-suite-serde'

enableFeaturePreview('TYPESAFE_PROJECT_ACCESSORS')

Expand Down
17 changes: 17 additions & 0 deletions test-suite-serde/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
`java-library`
id("io.micronaut.build.internal.flyway-tests")
}

dependencies {
testAnnotationProcessor(mn.micronaut.inject.java)
testAnnotationProcessor(mnSerde.micronaut.serde.processor)
testImplementation(mnSerde.micronaut.serde.jackson)
testImplementation(mnTest.micronaut.test.junit5)
testImplementation(mn.micronaut.http.server.netty)
testImplementation(mn.micronaut.http.client)
testImplementation(projects.micronautFlyway)
testRuntimeOnly(mnSql.h2)
testRuntimeOnly(mnSql.micronaut.jdbc.hikari)
testRuntimeOnly(mnLogging.logback.classic)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.micronaut.flyway.serde;

import io.micronaut.http.HttpRequest;
import io.micronaut.http.client.BlockingHttpClient;
import io.micronaut.http.client.HttpClient;
import io.micronaut.http.client.annotation.Client;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

@MicronautTest
class EndpointSerdeTest {

@Test
void testFlywayEndpointWithSerde(@Client("/") HttpClient httpClient) {
BlockingHttpClient client = httpClient.toBlocking();
HttpRequest<?> request = HttpRequest.GET("/flyway");
String json = assertDoesNotThrow(() -> client.retrieve(request));
System.out.println(json);
assertNotNull(json);
}
}
8 changes: 8 additions & 0 deletions test-suite-serde/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
endpoints.flyway.enabled=true
endpoints.flyway.sensitive=false
flyway.datasources.default.enabled=true
datasources.default.password=
datasources.default.dialect=H2
datasources.default.url=jdbc\:h2\:mem\:devDb;LOCK_TIMEOUT\=10000;DB_CLOSE_ON_EXIT\=FALSE
datasources.default.username=sa
datasources.default.driver-class-name=org.h2.Driver
6 changes: 6 additions & 0 deletions test-suite-serde/src/test/resources/db/migration/V1__init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE tutorials_tbl (
id INT NOT NULL,
title VARCHAR(50) NOT NULL,
author VARCHAR(20) NOT NULL,
submission_date DATE
);
10 changes: 10 additions & 0 deletions test-suite-serde/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

0 comments on commit b9468bb

Please sign in to comment.