Skip to content

Commit bbc04c3

Browse files
committed
initial junit5
1 parent ed1d28b commit bbc04c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+16516
-447
lines changed

mondrian/pom.xml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<guava.version>17.0</guava.version>
2424
<driver.version.major>${project.version.major}</driver.version.major>
2525
<maven-failsafe-plugin.argLine>-Duser.language=en -Duser.country=US</maven-failsafe-plugin.argLine>
26+
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
2627
</properties>
2728
<dependencies>
2829
<dependency>
@@ -132,9 +133,21 @@
132133
<version>${jsp-api.version}</version>
133134
</dependency>
134135
<dependency>
135-
<groupId>junit</groupId>
136-
<artifactId>junit</artifactId>
137-
<version>${junit.version}</version>
136+
<groupId>org.junit.jupiter</groupId>
137+
<artifactId>junit-jupiter-api</artifactId>
138+
<version>${junit5.version}</version>
139+
<scope>test</scope>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.junit.jupiter</groupId>
143+
<artifactId>junit-jupiter-engine</artifactId>
144+
<version>${junit5.version}</version>
145+
<scope>test</scope>
146+
</dependency>
147+
<dependency>
148+
<groupId>org.junit.jupiter</groupId>
149+
<artifactId>junit-jupiter-params</artifactId>
150+
<version>${junit5.version}</version>
138151
<scope>test</scope>
139152
</dependency>
140153
<dependency>
@@ -145,8 +158,20 @@
145158
</dependency>
146159
<dependency>
147160
<groupId>org.mockito</groupId>
148-
<artifactId>mockito-all</artifactId>
149-
<version>${mockito-all.version}</version>
161+
<artifactId>mockito-core</artifactId>
162+
<version>4.1.0</version>
163+
<scope>test</scope>
164+
</dependency>
165+
<dependency>
166+
<groupId>org.testcontainers</groupId>
167+
<artifactId>mysql</artifactId>
168+
<version>1.16.2</version>
169+
<scope>test</scope>
170+
</dependency>
171+
<dependency>
172+
<groupId>org.testcontainers</groupId>
173+
<artifactId>mysql</artifactId>
174+
<version>1.16.2</version>
150175
<scope>test</scope>
151176
</dependency>
152177
<dependency>

mondrian/src/it/java/mondrian/test/Main.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ public static Test suite() throws Exception {
279279
addTest( suite, PartialCacheVCTest.class, "suite" );
280280
addTest( suite, QueryAllTest.class, "suite" );
281281
addTest( suite, QueryAllVCTest.class, "suite" );
282-
addTest( suite, Base64Test.class );
283282
addTest( suite, CodeComplianceTest.class );
284283
return suite;
285284
}
@@ -330,7 +329,6 @@ public static Test suite() throws Exception {
330329
addTest( suite, HierarchyBugTest.class );
331330
addTest( suite, ScheduleTest.class );
332331
addTest( suite, UtilTestCase.class );
333-
addTest( suite, CancellationCheckerTest.class );
334332
addTest( suite, PartiallyOrderedSetTest.class );
335333
addTest( suite, ConcatenableListTest.class );
336334
addTest( suite, ExpiringReferenceTest.class );
@@ -377,7 +375,6 @@ public static Test suite() throws Exception {
377375
addTest( suite, PropertiesTest.class );
378376
addTest( suite, MultipleHierarchyTest.class );
379377
addTest( suite, I18nTest.class );
380-
addTest( suite, FormatTest.class );
381378
addTest( suite, ParallelTest.class );
382379
addTest( suite, SchemaVersionTest.class );
383380
addTest( suite, SchemaTest.class );
@@ -396,7 +393,6 @@ public static Test suite() throws Exception {
396393
if ( Bug.BugMondrian503Fixed ) {
397394
addTest( suite, RolapResultTest.class );
398395
}
399-
addTest( suite, ConstantCalcTest.class );
400396
addTest( suite, SharedDimensionTest.class );
401397
addTest( suite, CellPropertyTest.class );
402398
addTest( suite, QueryTest.class );

mondrian/src/it/java/mondrian/test/MondrianTestRunner.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public MondrianTestRunner(MondrianResultPrinter printer) {
5757
fPrinter = printer;
5858
}
5959

60-
/**
61-
* Always use the StandardTestSuiteLoader. Overridden from
62-
* BaseTestRunner.
63-
*/
64-
public TestSuiteLoader getLoader() {
65-
return new StandardTestSuiteLoader();
66-
}
60+
// /**
61+
// * Always use the StandardTestSuiteLoader. Overridden from
62+
// * BaseTestRunner.
63+
// */
64+
// public TestSuiteLoader getLoader() {
65+
// return new StandardTestSuiteLoader();
66+
// }
6767

6868
public void testFailed(int status, Test test, Throwable t) {
6969
}

mondrian/src/it/java/mondrian/calc/impl/ArrayTupleListTest.java renamed to mondrian/src/test/java/mondrian/calc/impl/ArrayTupleListTest.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,36 @@
99

1010
package mondrian.calc.impl;
1111

12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
import static org.junit.jupiter.api.Assertions.fail;
15+
import static org.mockito.Mockito.mock;
16+
17+
import org.junit.jupiter.api.AfterEach;
18+
import org.junit.jupiter.api.Test;
19+
1220
import mondrian.olap.Member;
1321
import mondrian.olap.MondrianProperties;
1422
import mondrian.olap.ResourceLimitExceededException;
15-
import mondrian.test.FoodMartTestCase;
23+
import mondrian.test.PropertySaver5;
1624

17-
import static org.mockito.Mockito.mock;
1825

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

28+
/**
29+
* Access properties via this object and their values will be reset.
30+
*/
31+
protected final PropertySaver5 propSaver = new PropertySaver5();
32+
33+
@AfterEach
34+
public void afterEach() {
35+
propSaver.reset();
36+
}
2237
private Member member1 = mock( Member.class );
2338
private Member member2 = mock( Member.class );
2439
private ArrayTupleList list;
2540

41+
@Test
2642
public void testGrowListBeyondInitialCapacity() {
2743
propSaver.set( MondrianProperties.instance().ResultLimit, 0 );
2844
list = new ArrayTupleList( 2, 10 );
@@ -35,15 +51,16 @@ public void testGrowListBeyondInitialCapacity() {
3551
}
3652
}
3753

54+
@Test
3855
public void testAttemptToGrowBeyondResultLimit() {
3956
propSaver.set( MondrianProperties.instance().ResultLimit, 30 );
4057
list = new ArrayTupleList( 2, 10 );
4158
try {
4259
addMockTuplesToList( list, 32 );
4360
fail( "Expected exception." );
4461
} catch ( ResourceLimitExceededException e ) {
45-
assertTrue( "Actual message: " + e.getMessage() + " \ndid not match expected",
46-
e.getMessage().contains( "result (31) exceeded limit (30)" ) );
62+
assertTrue( e.getMessage().contains( "result (31) exceeded limit (30)" ),
63+
"Actual message: " + e.getMessage() + " \ndid not match expected");
4764
}
4865
}
4966

mondrian/src/it/java/mondrian/calc/impl/ConstantCalcTest.java renamed to mondrian/src/test/java/mondrian/calc/impl/ConstantCalcTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111

1212
package mondrian.calc.impl;
1313

14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
16+
import org.junit.jupiter.api.Test;
17+
1418
import mondrian.olap.fun.FunUtil;
1519
import mondrian.olap.type.NullType;
1620

17-
import junit.framework.TestCase;
18-
1921
/**
2022
* Test for <code>ConstantCalc</code>
2123
* @author Matt
24+
* @author stbischof
2225
*/
23-
public class ConstantCalcTest extends TestCase {
26+
public class ConstantCalcTest{
27+
28+
@Test
2429
public void testNullEvaluatesToConstantDoubleNull() {
2530
ConstantCalc constantCalc = new ConstantCalc(new NullType(), null);
2631
assertEquals(FunUtil.DoubleNull, constantCalc.evaluateDouble(null));
2732
}
28-
33+
34+
@Test
2935
public void testNullEvaluatesToConstantIntegerNull() {
3036
ConstantCalc constantCalc = new ConstantCalc(new NullType(), null);
3137
assertEquals(FunUtil.IntegerNull, constantCalc.evaluateInteger(null));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package mondrian.example;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
6+
import mondrian.junit5.MondrianRuntimeExtension;
7+
8+
@ExtendWith(MondrianRuntimeExtension.class)
9+
public class MyTest {
10+
11+
@Test
12+
void testName() throws Exception {
13+
System.out.println(1);
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package mondrian.junit5;
2+
3+
public interface DataLoader {
4+
/**
5+
* @param jdbcConnectionUrl - jdbcConnectionUrl
6+
* @return jdbc connection String
7+
*/
8+
boolean loadDataData(String jdbcConnectionUrl);
9+
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package mondrian.junit5;
2+
3+
import java.io.Closeable;
4+
import java.util.Map;
5+
6+
public interface DatabaseHandler extends Closeable {
7+
8+
/**
9+
*
10+
* @param props - properties
11+
* @return jdbc connection String
12+
*/
13+
String setUpDatabase(Map<String,Object> props);
14+
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package mondrian.junit5;
2+
3+
import mondrian.test.loader.MondrianFoodMartLoaderX;
4+
5+
public class FoodmardDataLoader implements DataLoader{
6+
7+
@Override
8+
public boolean loadDataData(String jdbcUrl) {
9+
String[] args=new String[]{
10+
"-verbose",
11+
"-tables",
12+
"-data",
13+
"-indexes",
14+
"-outputJdbcURL="+jdbcUrl,
15+
// "-outputJdbcUser="+mySQLContainer.getUsername(),
16+
// "-outputJdbcPassword="+mySQLContainer.getPassword(),
17+
"-outputJdbcBatchSize=50",
18+
"-jdbcDrivers=com.mysql.cl.jdbc.Driver"
19+
};
20+
MondrianFoodMartLoaderX.main(args);
21+
return true;
22+
}
23+
24+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package mondrian.junit5;
2+
3+
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;
4+
5+
import java.sql.SQLException;
6+
import java.util.Locale;
7+
8+
import org.junit.jupiter.api.extension.BeforeAllCallback;
9+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
10+
import org.junit.jupiter.api.extension.ExecutionCondition;
11+
import org.junit.jupiter.api.extension.ExtensionContext;
12+
import org.testcontainers.DockerClientFactory;
13+
14+
import mondrian.resource.MondrianResource;
15+
16+
public class MondrianRuntimeExtension
17+
implements ExecutionCondition, BeforeAllCallback, ExtensionContext.Store.CloseableResource {
18+
19+
20+
private static boolean started = false;
21+
22+
@Override
23+
public void beforeAll(ExtensionContext context) {
24+
if (!started) {
25+
26+
started = true;
27+
// registers a callback hook when the root test context is shut down
28+
context.getRoot().getStore(GLOBAL).put("MondrianRuntimeExtensionClosableCallbackHook", this);
29+
defineLocale();
30+
31+
System.out.println("##############################################################");
32+
}
33+
}
34+
35+
private void defineLocale() {
36+
MondrianResource.setThreadLocale( Locale.US );
37+
}
38+
39+
40+
@Override
41+
public void close() {
42+
// Your "after all tests" logic goes here
43+
44+
}
45+
46+
@Override
47+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
48+
49+
try {
50+
DockerClientFactory.instance().client();
51+
return ConditionEvaluationResult.enabled("Docker is available");
52+
} catch (Throwable ex) {
53+
return ConditionEvaluationResult.disabled("Docker is not available", ex.getMessage());
54+
}
55+
56+
}
57+
58+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package mondrian.junit5;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Inherited;
6+
import java.lang.annotation.Retention;
7+
import java.lang.annotation.RetentionPolicy;
8+
import java.lang.annotation.Target;
9+
10+
import org.junit.jupiter.api.extension.ExtendWith;
11+
12+
@Inherited
13+
@Target({
14+
ElementType.TYPE,ElementType.METHOD
15+
})
16+
@Retention(RetentionPolicy.RUNTIME)
17+
@Documented
18+
@ExtendWith(MondrianRuntimeExtension.class)
19+
public @interface MondrianRuntimeSupport {
20+
Class<? extends DatabaseHandler> database() default MySQLDatabaseHandler.class;
21+
Class<? extends DataLoader> dataLoader() default FoodmardDataLoader.class;
22+
23+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package mondrian.junit5;
2+
3+
import java.io.IOException;
4+
import java.sql.DriverManager;
5+
import java.util.Map;
6+
import java.util.UUID;
7+
import java.util.function.Consumer;
8+
9+
import org.testcontainers.containers.MySQLContainer;
10+
import org.testcontainers.containers.output.OutputFrame;
11+
12+
public class MySQLDatabaseHandler implements DatabaseHandler {
13+
14+
private static MySQLContainer<?> mySQLContainer;
15+
static Consumer<OutputFrame> x = t -> System.out.println(t.getUtf8String());
16+
17+
@Override
18+
public void close() throws IOException {
19+
if (mySQLContainer != null) {
20+
mySQLContainer.stop();
21+
mySQLContainer.close();
22+
}
23+
}
24+
25+
@Override
26+
public String setUpDatabase(Map<String, Object> props) {
27+
String user=props.getOrDefault("username", UUID.randomUUID().toString().replace("-","")).toString();
28+
String pass=props.getOrDefault("password", UUID.randomUUID().toString().replace("-","")).toString();
29+
30+
31+
mySQLContainer = new MySQLContainer<>("mysql:5.7.34").withDatabaseName(user).withUsername(pass)
32+
.withPassword("pass").withEnv("MYSQL_ROOT_HOST", "%").withLogConsumer(x);
33+
34+
mySQLContainer.start();
35+
36+
return mySQLContainer.getJdbcUrl()+"?user="+user+"&password="+pass;
37+
// Connection con = DriverManager.getConnection(url, "user", "pass");
38+
39+
}
40+
41+
42+
43+
44+
45+
}

0 commit comments

Comments
 (0)