-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
3,014 additions
and
0 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
59 changes: 59 additions & 0 deletions
59
reladomo/src/test/java/com/gs/fw/common/mithra/test/H2TestConnectionManager.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,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"; | ||
} | ||
} |
194 changes: 194 additions & 0 deletions
194
reladomo/src/test/java/com/gs/fw/common/mithra/test/MithraH2TestAbstract.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,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; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
reladomo/src/test/java/com/gs/fw/common/mithra/test/MithraH2TestSuite.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,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; | ||
} | ||
} |
Oops, something went wrong.