-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stefan Bischof <[email protected]>
- Loading branch information
Showing
50 changed files
with
16,130 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package mondrian.example; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import mondrian.junit5.MondrianRuntimeExtension; | ||
|
||
@ExtendWith(MondrianRuntimeExtension.class) | ||
public class MyTest { | ||
|
||
@Test | ||
void testName() throws Exception { | ||
System.out.println(1); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
mondrian/src/test/java/mondrian/junit5/MondrianRuntimeExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package mondrian.junit5; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.util.function.Consumer; | ||
|
||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
import org.junit.jupiter.api.extension.ExecutionCondition; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.testcontainers.DockerClientFactory; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.containers.output.OutputFrame; | ||
|
||
import mondrian.test.loader.MondrianFoodMartLoaderX; | ||
|
||
public class MondrianRuntimeExtension | ||
implements ExecutionCondition, BeforeAllCallback, ExtensionContext.Store.CloseableResource { | ||
static Consumer<OutputFrame> x = t -> System.out.println(t.getUtf8String()); | ||
|
||
private static boolean started = false; | ||
private static MySQLContainer<?> mySQLContainer; | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext context) { | ||
if (!started) { | ||
|
||
started = true; | ||
// registers a callback hook when the root test context is shut down | ||
context.getRoot().getStore(GLOBAL).put("MondrianRuntimeExtensionClosableCallbackHook", this); | ||
|
||
try { | ||
initDB(); | ||
loadFootMart(); | ||
} catch (SQLException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
System.out.println("##############################################################"); | ||
} | ||
} | ||
|
||
private void loadFootMart() { | ||
|
||
String[] args=new String[]{ | ||
"-verbose", | ||
"-tables", | ||
"-data", | ||
"-indexes", | ||
"-outputJdbcURL="+mySQLContainer.getJdbcUrl(), | ||
"-outputJdbcUser="+mySQLContainer.getUsername(), | ||
"-outputJdbcPassword="+mySQLContainer.getPassword(), | ||
"-outputJdbcBatchSize=50", | ||
"-jdbcDrivers=com.mysql.cl.jdbc.Driver" | ||
}; | ||
MondrianFoodMartLoaderX.main(args); | ||
|
||
} | ||
|
||
private void initDB() throws SQLException { | ||
|
||
mySQLContainer = new MySQLContainer<>("mysql:5.7.34").withDatabaseName("TEST") | ||
.withUsername("user") | ||
.withPassword("pass") | ||
.withEnv("MYSQL_ROOT_HOST", "%").withLogConsumer(x); | ||
System.out.println("11##############################################################"); | ||
|
||
mySQLContainer.start(); | ||
System.out.println("21##############################################################"); | ||
|
||
String url = mySQLContainer.getJdbcUrl(); | ||
System.out.println(url); | ||
Connection con = DriverManager.getConnection(url, "user", "pass"); | ||
// Statement stmt = con.createStatement(); | ||
// ResultSet rs = stmt.executeQuery("SELECT version() "); | ||
// rs.next(); | ||
// String resultSetString = rs.getString(1); | ||
|
||
//assertTrue(resultSetString.startsWith("8"), "The database version can be set using a container rule parameter"); | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
// Your "after all tests" logic goes here | ||
if(mySQLContainer!=null) { | ||
mySQLContainer.stop(); | ||
mySQLContainer.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
|
||
try { | ||
DockerClientFactory.instance().client(); | ||
return ConditionEvaluationResult.enabled("Docker is available"); | ||
} catch (Throwable ex) { | ||
return ConditionEvaluationResult.disabled("Docker is not available", ex.getMessage()); | ||
} | ||
|
||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
mondrian/src/test/java/mondrian/junit5/MondrianRuntimeSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package mondrian.junit5; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@Inherited | ||
@Target({ | ||
ElementType.TYPE,ElementType.METHOD | ||
}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@ExtendWith(MondrianRuntimeExtension.class) | ||
public @interface MondrianRuntimeSupport { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.