[Minor] refactored tests for persistence layers to remove duplicate code

This commit is contained in:
Robert von Burg 2013-12-25 17:34:03 +01:00
parent 295a5e0063
commit 36c02bad0c
5 changed files with 38 additions and 151 deletions

View File

@ -19,6 +19,7 @@ import static li.strolch.model.ModelGenerator.createOrder;
import static li.strolch.model.ModelGenerator.createResource;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -33,14 +34,42 @@ import li.strolch.persistence.api.ModificationResult;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.observer.Observer;
import li.strolch.runtime.observer.ObserverHandler;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class ObserverUpdateTest extends AbstractDaoImplTest {
public class ObserverUpdateTest {
public static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$
public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$
public static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$
protected static RuntimeMock runtimeMock;
protected RuntimeMock getRuntimeMock() {
return runtimeMock;
}
@BeforeClass
public static void beforeClass() {
File rootPath = new File(RUNTIME_PATH);
File configSrc = new File(CONFIG_SRC);
runtimeMock = new RuntimeMock();
runtimeMock.mockRuntime(rootPath, configSrc);
new File(rootPath, DB_STORE_PATH_DIR).mkdir();
runtimeMock.startContainer(rootPath);
}
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
public final class ElementAddedObserver implements Observer {

View File

@ -1,44 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 li.strolch.persistence.postgresql.dao.test;
import li.strolch.testbase.runtime.OrderModelTestRunner;
import org.junit.Test;
public class PostgreSqlOrderDaoTest extends AbstractDaoImplTest {
@Test
public void shouldCreateOrder() {
OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock);
testRunner.runCreateOrderTest();
}
@Test
public void shouldCrud() {
OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock);
testRunner.runCrudTests();
}
@Test
public void shouldPerformBulkOperations() {
OrderModelTestRunner testRunner = new OrderModelTestRunner(runtimeMock);
testRunner.runBulkOperationTests();
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 li.strolch.persistence.postgresql.dao.test;
import li.strolch.testbase.runtime.ResourceModelTestRunner;
import org.junit.Test;
public class PostgreSqlResourceDaoTest extends AbstractDaoImplTest {
@Test
public void shouldCreateOrder() {
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock);
testRunner.runCreateResourceTest();
}
@Test
public void shouldCrud() {
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock);
testRunner.runCrudTests();
}
@Test
public void shouldPerformBulkOperations() {
ResourceModelTestRunner testRunner = new ResourceModelTestRunner(runtimeMock);
testRunner.runBulkOperationTests();
}
}

View File

@ -1,57 +0,0 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* 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 li.strolch.persistence.postgresql.dao.test;
import java.io.File;
import java.sql.SQLException;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class PostgresqlContainerTest {
private static RuntimeMock runtimeMock;
@BeforeClass
public static void beforeClass() throws SQLException {
File rootPath = new File(AbstractDaoImplTest.RUNTIME_PATH);
File configSrc = new File(AbstractDaoImplTest.CONFIG_SRC);
runtimeMock = new RuntimeMock();
runtimeMock.mockRuntime(rootPath, configSrc);
new File(rootPath, AbstractDaoImplTest.DB_STORE_PATH_DIR).mkdir();
runtimeMock.startContainer(rootPath);
}
@Test
public void shouldStartContainer() {
try (StrolchTransaction tx = runtimeMock.getPersistenceHandler().openTx()) {
tx.getOrderDao().queryKeySet();
}
}
@AfterClass
public static void afterClass() {
runtimeMock.destroyRuntime();
}
}

View File

@ -21,15 +21,13 @@ import java.sql.DriverManager;
import java.sql.SQLException;
import li.strolch.persistence.postgresql.DbSchemaVersionCheck;
import li.strolch.testbase.runtime.AbstractModelTest;
import li.strolch.testbase.runtime.RuntimeMock;
import org.junit.AfterClass;
import org.junit.BeforeClass;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AbstractDaoImplTest {
public class XmlCachedDaoTest extends AbstractModelTest {
public static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$
public static final String DB_STORE_PATH_DIR = "dbStore"; //$NON-NLS-1$
@ -40,6 +38,11 @@ public abstract class AbstractDaoImplTest {
private static final String DB_PASSWORD = "test"; //$NON-NLS-1$
protected static RuntimeMock runtimeMock;
@Override
protected RuntimeMock getRuntimeMock() {
return runtimeMock;
}
@BeforeClass
public static void beforeClass() throws SQLException {