Skip to content

Commit

Permalink
Add H2 test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
motlin committed Nov 26, 2022
1 parent 948a249 commit 62cfa25
Show file tree
Hide file tree
Showing 7 changed files with 3,014 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
<mkdir dir="${root}/reladomogenutil/target/db/db2"/>
<mkdir dir="${root}/reladomogenutil/target/db/postgres"/>
<mkdir dir="${root}/reladomogenutil/target/db/oracle"/>
<mkdir dir="${root}/reladomogenutil/target/db/h2"/>
<mkdir dir="${root}/reladomogsi/target"/>
<mkdir dir="${root}/reladomogsi/target/generated-src"/>
<mkdir dir="${root}/reladomogsi/target/classes"/>
Expand Down Expand Up @@ -1360,6 +1361,10 @@
<mithraImport dir="${root}/reladomo/src/test/reladomo-xml" fileName="MithraClassListToImport.xml"/>
<mithraImport dir="${root}/reladomo/src/test/reladomo-xml/testmithraimport" fileName="MithraTestImportClassList.xml"/>
</reladomo-gen-db>
<reladomo-gen-db xml="${root}/reladomo/src/test/reladomo-xml/MithraClassList.xml" generatedDir="${root}/reladomogenutil/target/db/h2" databaseType="h2">
<mithraImport dir="${root}/reladomo/src/test/reladomo-xml" fileName="MithraClassListToImport.xml"/>
<mithraImport dir="${root}/reladomo/src/test/reladomo-xml/testmithraimport" fileName="MithraTestImportClassList.xml"/>
</reladomo-gen-db>
</target>

<target name="generate-reladomo-xml-test" depends="compile-reladomo-genutil">
Expand Down Expand Up @@ -1910,6 +1915,7 @@
<exec-test-suite mithraxmlconfig="MithraMsSqlTestConfig.xml" testclass="com.gs.fw.common.mithra.test.MithraMsSqlTestSuite" heap="onheap"/>
<exec-test-suite mithraxmlconfig="MithraSybaseTestConfig.xml" testclass="com.gs.fw.common.mithra.test.MithraSybaseTestSuite" heap="onheap"/>
<exec-test-suite mithraxmlconfig="MithraMariaTestConfig.xml" testclass="com.gs.fw.common.mithra.test.MithraMariaTestSuite" heap="onheap"/>
<exec-test-suite mithraxmlconfig="MithraH2TestConfig.xml" testclass="com.gs.fw.common.mithra.test.MithraH2TestSuite" heap="onheap"/>
</parallel>
</target>

Expand All @@ -1924,6 +1930,7 @@
<include name="TEST-*MithraPostgresTestConfig.xml"/>
<include name="TEST-*MithraOracleTestConfig.xml"/>
<include name="TEST-*MithraMariaTestConfig.xml"/>
<include name="TEST-*MithraH2TestConfig.xml"/>
</fileset>
<report format="frames" todir="${root}/reladomo/target/junit-report-vendor-test"/>
</junitreport>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2016 Goldman Sachs.
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
http://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 com.gs.fw.common.mithra.test;

import com.gs.fw.common.mithra.bulkloader.BulkLoader;
import com.gs.fw.common.mithra.bulkloader.BulkLoaderException;
import com.gs.fw.common.mithra.connectionmanager.XAConnectionManager;
import com.gs.fw.common.mithra.databasetype.H2DatabaseType;

public class H2TestConnectionManager
extends VendorTestConnectionManager
{
private static final H2TestConnectionManager INSTANCE = new H2TestConnectionManager();

public static H2TestConnectionManager getInstance()
{
return INSTANCE;
}

protected H2TestConnectionManager()
{
connectionManager = new XAConnectionManager();
connectionManager.setDriverClassName("org.h2.Driver");
connectionManager.setJdbcConnectionString("jdbc:h2:mem:testdb");
connectionManager.setJdbcUser("sa");
connectionManager.setJdbcPassword("");
connectionManager.setPoolName("h2-schema connection pool");
connectionManager.setInitialSize(1);
connectionManager.setPoolSize(100);
connectionManager.setUseStatementPooling(true);
connectionManager.initialisePool();

this.setDatabaseType(H2DatabaseType.getInstance());
}

public BulkLoader createBulkLoader()
{
return null;
}

public String getDatabaseIdentifier()
{
return "h2-schema";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@

/*
Copyright 2016 Goldman Sachs.
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
http://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 com.gs.fw.common.mithra.test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

import com.gs.fw.common.mithra.MithraList;
import com.gs.fw.common.mithra.databasetype.DatabaseType;
import com.gs.fw.common.mithra.databasetype.H2DatabaseType;
import com.gs.fw.common.mithra.finder.Operation;
import com.gs.fw.common.mithra.test.domain.AllTypes;
import com.gs.fw.common.mithra.test.domain.AllTypesList;
import com.gs.fw.common.mithra.test.domain.Product;
import com.gs.fw.common.mithra.test.domain.ProductList;
import com.gs.fw.common.mithra.util.Time;

public class MithraH2TestAbstract
extends MithraTestAbstract
{
private MithraTestResource mithraTestResource;
private String testDataFileName = "testdata/vendor/mithraH2TestData.txt";

public void setTestDataFileName(String testDataFileName)
{
this.testDataFileName = testDataFileName;
}

public String getTestDataFileName()
{
return testDataFileName;
}

protected void setUp()
throws Exception
{
setMithraTestObjectToResultSetComparator(new AllTypesResultSetComparator());
mithraTestResource = new MithraTestResource("MithraH2TestConfig.xml", H2DatabaseType.getInstance());
mithraTestResource.setRestrictedClassList(getRestrictedClassList());

H2TestConnectionManager connectionManager = H2TestConnectionManager.getInstance();
connectionManager.setDefaultSource("mithra_qa");
connectionManager.setDatabaseTimeZone(this.getDatabaseTimeZone());

mithraTestResource.createSingleDatabase(connectionManager, "mithra_qa", getTestDataFileName());
mithraTestResource.setTestConnectionsOnTearDown(true);
mithraTestResource.setUp();
}

@Override
public Connection getConnection()
{
return H2TestConnectionManager.getInstance().getConnection();
}

protected void tearDown() throws Exception
{
if (mithraTestResource != null)
{
mithraTestResource.tearDown();
}
if (!H2TestConnectionManager.getInstance().ensureAllConnectionsReturnedToPool())
{
fail("Connections were not returned to pool");
}
}

protected DatabaseType getDatabaseType()
{
return this.mithraTestResource.getDatabaseType();
}

protected void validateMithraResult(Operation op, String sql, int minSize)
{
this.validateMithraResult(new AllTypesList(op), sql, minSize);
}

protected void validateMithraResult(MithraList list, String sql, int minSize)
{
try
{
list.setBypassCache(true);
Connection con = H2TestConnectionManager.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(sql);
this.genericRetrievalTest(ps, list, con, minSize);
}
catch(SQLException e)
{
getLogger().error("SQLException on MithraH2TestAbstract.validateMithraResult()",e);
throw new RuntimeException("SQLException ",e);
}
}


protected void validateMithraResult(Operation op, String sql)
{
validateMithraResult(op, sql, 1);
}

protected AllTypesList createNewAllTypesList(int firstId, long count)
{
AllTypesList list = new AllTypesList();
for(int i = firstId; i < (firstId + count); i++)
{
AllTypes obj = this.createNewAllTypes(i, true);
list.add(obj);
}
return list;
}

protected ProductList createNewProductList(int firstId, long count)
{
ProductList list = new ProductList();
for(int i = firstId; i < (firstId + count); i++)
{
Product obj = new Product();
obj.setProductId(i);
obj.setProductCode("ABC"+i);
obj.setProductDescription("Product "+i);
obj.setManufacturerId(1);
obj.setDailyProductionRate(100.25f);
list.add(obj);
}
return list;
}

protected AllTypes createNewAllTypes(int id, boolean withNullablesNull)
{
AllTypes allTypesObj = new AllTypes();
Date date = new Date();
Timestamp timestamp = new Timestamp(date.getTime());
byte[] newData = new byte[5];
newData[0] = toByte(0xAA);
newData[1] = toByte(0xBB);
newData[2] = toByte(0x99);
newData[3] = toByte(0x11);
newData[4] = 0;

if(withNullablesNull)
{
allTypesObj.setNullablePrimitiveAttributesToNull();
}
else
{
allTypesObj.setNullableByteValue((byte)100);
allTypesObj.setNullableShortValue((short) 30000);
allTypesObj.setNullableCharValue('a');
allTypesObj.setNullableIntValue(2000000000);
allTypesObj.setNullableLongValue(9000000000000000000L);
allTypesObj.setNullableFloatValue(100.99f);
allTypesObj.setNullableDoubleValue(100.99998888777);
allTypesObj.setNullableDateValue(date);
allTypesObj.setNullableTimeValue(Time.withMillis(1, 2, 3, 4));
allTypesObj.setNullableTimestampValue(timestamp);
allTypesObj.setNullableStringValue("This is a test");
allTypesObj.setNullableByteArrayValue(newData);

}
allTypesObj.setId(id);
allTypesObj.setBooleanValue(true);
allTypesObj.setByteValue((byte)100);
allTypesObj.setShortValue((short) 30000);
allTypesObj.setCharValue('a');
allTypesObj.setIntValue(2000000000);
allTypesObj.setLongValue(9000000000000000000L);
allTypesObj.setFloatValue(100.99f);
allTypesObj.setDoubleValue(100.99998888777);
allTypesObj.setDateValue(date);
allTypesObj.setTimeValue(Time.withMillis(1, 2, 3, 4));
allTypesObj.setTimestampValue(timestamp);
allTypesObj.setStringValue("This is a test");
allTypesObj.setByteArrayValue(newData);

return allTypesObj;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

/*
Copyright 2016 Goldman Sachs.
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
http://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 com.gs.fw.common.mithra.test;

import junit.framework.Test;
import junit.framework.TestSuite;

public class MithraH2TestSuite
extends TestSuite
{

public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTestSuite(TestH2GeneralTestCases.class);
return suite;
}
}
Loading

0 comments on commit 62cfa25

Please sign in to comment.