Skip to content

Commit

Permalink
juni5 fitst step
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Bischof <[email protected]>
  • Loading branch information
stbischof committed Dec 9, 2021
1 parent b9f0309 commit 8204931
Show file tree
Hide file tree
Showing 50 changed files with 16,130 additions and 427 deletions.
35 changes: 30 additions & 5 deletions mondrian/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<guava.version>17.0</guava.version>
<driver.version.major>${project.version.major}</driver.version.major>
<maven-failsafe-plugin.argLine>-Duser.language=en -Duser.country=US</maven-failsafe-plugin.argLine>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -132,9 +133,21 @@
<version>${jsp-api.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -145,8 +158,20 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito-all.version}</version>
<artifactId>mockito-core</artifactId>
<version>4.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>1.16.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>1.16.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
4 changes: 0 additions & 4 deletions mondrian/src/it/java/mondrian/test/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ public static Test suite() throws Exception {
addTest( suite, PartialCacheVCTest.class, "suite" );
addTest( suite, QueryAllTest.class, "suite" );
addTest( suite, QueryAllVCTest.class, "suite" );
addTest( suite, Base64Test.class );
addTest( suite, CodeComplianceTest.class );
return suite;
}
Expand Down Expand Up @@ -328,7 +327,6 @@ public static Test suite() throws Exception {
addTest( suite, HierarchyBugTest.class );
addTest( suite, ScheduleTest.class );
addTest( suite, UtilTestCase.class );
addTest( suite, CancellationCheckerTest.class );
addTest( suite, PartiallyOrderedSetTest.class );
addTest( suite, ConcatenableListTest.class );
addTest( suite, ExpiringReferenceTest.class );
Expand Down Expand Up @@ -375,7 +373,6 @@ public static Test suite() throws Exception {
addTest( suite, PropertiesTest.class );
addTest( suite, MultipleHierarchyTest.class );
addTest( suite, I18nTest.class );
addTest( suite, FormatTest.class );
addTest( suite, ParallelTest.class );
addTest( suite, SchemaVersionTest.class );
addTest( suite, SchemaTest.class );
Expand All @@ -394,7 +391,6 @@ public static Test suite() throws Exception {
if ( Bug.BugMondrian503Fixed ) {
addTest( suite, RolapResultTest.class );
}
addTest( suite, ConstantCalcTest.class );
addTest( suite, SharedDimensionTest.class );
addTest( suite, CellPropertyTest.class );
addTest( suite, QueryTest.class );
Expand Down
14 changes: 7 additions & 7 deletions mondrian/src/it/java/mondrian/test/MondrianTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public MondrianTestRunner(MondrianResultPrinter printer) {
fPrinter = printer;
}

/**
* Always use the StandardTestSuiteLoader. Overridden from
* BaseTestRunner.
*/
public TestSuiteLoader getLoader() {
return new StandardTestSuiteLoader();
}
// /**
// * Always use the StandardTestSuiteLoader. Overridden from
// * BaseTestRunner.
// */
// public TestSuiteLoader getLoader() {
// return new StandardTestSuiteLoader();
// }

public void testFailed(int status, Test test, Throwable t) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,36 @@

package mondrian.calc.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import mondrian.olap.Member;
import mondrian.olap.MondrianProperties;
import mondrian.olap.ResourceLimitExceededException;
import mondrian.test.FoodMartTestCase;
import mondrian.test.PropertySaver5;

import static org.mockito.Mockito.mock;

@SuppressWarnings( "java:S2187" ) // suppressing "no-tests" warning. Mondrian still uses junit 3
public class ArrayTupleListTest extends FoodMartTestCase {
public class ArrayTupleListTest {

/**
* Access properties via this object and their values will be reset.
*/
protected final PropertySaver5 propSaver = new PropertySaver5();

@AfterEach
public void afterEach() {
propSaver.reset();
}
private Member member1 = mock( Member.class );
private Member member2 = mock( Member.class );
private ArrayTupleList list;

@Test
public void testGrowListBeyondInitialCapacity() {
propSaver.set( MondrianProperties.instance().ResultLimit, 0 );
list = new ArrayTupleList( 2, 10 );
Expand All @@ -35,15 +51,16 @@ public void testGrowListBeyondInitialCapacity() {
}
}

@Test
public void testAttemptToGrowBeyondResultLimit() {
propSaver.set( MondrianProperties.instance().ResultLimit, 30 );
list = new ArrayTupleList( 2, 10 );
try {
addMockTuplesToList( list, 32 );
fail( "Expected exception." );
} catch ( ResourceLimitExceededException e ) {
assertTrue( "Actual message: " + e.getMessage() + " \ndid not match expected",
e.getMessage().contains( "result (31) exceeded limit (30)" ) );
assertTrue( e.getMessage().contains( "result (31) exceeded limit (30)" ),
"Actual message: " + e.getMessage() + " \ndid not match expected");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@

package mondrian.calc.impl;

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

import org.junit.jupiter.api.Test;

import mondrian.olap.fun.FunUtil;
import mondrian.olap.type.NullType;

import junit.framework.TestCase;

/**
* Test for <code>ConstantCalc</code>
* @author Matt
* @author stbischof
*/
public class ConstantCalcTest extends TestCase {
public class ConstantCalcTest{

@Test
public void testNullEvaluatesToConstantDoubleNull() {
ConstantCalc constantCalc = new ConstantCalc(new NullType(), null);
assertEquals(FunUtil.DoubleNull, constantCalc.evaluateDouble(null));
}


@Test
public void testNullEvaluatesToConstantIntegerNull() {
ConstantCalc constantCalc = new ConstantCalc(new NullType(), null);
assertEquals(FunUtil.IntegerNull, constantCalc.evaluateInteger(null));
Expand Down
15 changes: 15 additions & 0 deletions mondrian/src/test/java/mondrian/example/MyTest.java
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 mondrian/src/test/java/mondrian/junit5/MondrianRuntimeExtension.java
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 mondrian/src/test/java/mondrian/junit5/MondrianRuntimeSupport.java
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 {

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,38 @@

package mondrian.olap;

import junit.framework.TestCase;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Test for <code>Cell Property<code>.
*
* @author Shishir
* @since 08 May, 2007
*/
public class CellPropertyTest extends TestCase {
public class CellPropertyTest{
private CellProperty cellProperty;

@BeforeEach
protected void setUp() throws Exception {
super.setUp();

cellProperty = new CellProperty(Id.Segment.toList("Format_String"));
}

@Test
public void testIsNameEquals() {
assertTrue(cellProperty.isNameEquals("Format_String"));
}

@Test
public void testIsNameEqualsDoesCaseInsensitiveMatch() {
assertTrue(cellProperty.isNameEquals("format_string"));
}

@Test
public void testIsNameEqualsParameterShouldNotBeQuoted() {
assertFalse(cellProperty.isNameEquals("[Format_String]"));
}
Expand Down
Loading

0 comments on commit 8204931

Please sign in to comment.