Skip to content

Fix deprecation warnings. #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.dbunit.operation.DatabaseOperation;

import java.io.IOException;
Expand Down Expand Up @@ -65,9 +66,10 @@ public void migrate(MigrationContext context) throws MigrationException
JdbcMigrationContext jdbcContext = (JdbcMigrationContext) context;
// used to close connection in finally block
Connection contextConnection = null;
FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
try
{
FlatXmlDataSet xmlDataSet = new FlatXmlDataSet(getXmlAsStream());
FlatXmlDataSet xmlDataSet = builder.build(getXmlAsStream());
// Set contextConnection so it can be accessed in the finally block.
contextConnection = jdbcContext.getConnection();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.easymock.EasyMock;
import org.easymock.MockControl;

import com.mockrunner.mock.jdbc.MockDataSource;
import org.easymock.classextension.IMocksControl;

import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createControl;
import static org.easymock.classextension.EasyMock.createStrictControl;

/**
* Test the Distributed auto patch service to make sure it configures and runs
Expand Down Expand Up @@ -315,10 +315,9 @@ protected void setReportedPatchLevel(Collection launchers, int levelToReport) th
for(Iterator it = launcher.getContexts().keySet().iterator(); it.hasNext(); )
{
MigrationContext ctx = (MigrationContext) it.next();
MockControl patchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
PatchInfoStore patchInfoStore = (PatchInfoStore) patchInfoStoreControl.getMock();
patchInfoStore.getPatchLevel();
patchInfoStoreControl.setReturnValue(levelToReport);
IMocksControl patchInfoStoreControl = createStrictControl();
PatchInfoStore patchInfoStore = patchInfoStoreControl.createMock(PatchInfoStore.class);
expect(patchInfoStore.getPatchLevel()).andReturn(levelToReport);
patchInfoStoreControl.replay();
launcher.getContexts().put(ctx, patchInfoStore);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@

import org.easymock.EasyMock;
import org.easymock.classextension.IMocksControl;
import org.easymock.MockControl;

import com.tacitknowledge.util.migration.jdbc.JdbcMigrationContext;
import com.tacitknowledge.util.migration.jdbc.JdbcMigrationLauncher;

import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createControl;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.createStrictControl;

/**
Expand Down Expand Up @@ -82,11 +80,11 @@ public void testValidateControlledSystemsWhenNodePatchLevelsAreInSync() throws E
String systemName = "system1";
JdbcMigrationLauncher launcher = new JdbcMigrationLauncher();

MockControl contextControl = MockControl.createControl(JdbcMigrationContext.class);
IMocksControl contextControl = createStrictControl();

JdbcMigrationContext context = (JdbcMigrationContext) contextControl.getMock();
MockControl patchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
PatchInfoStore patchInfoStore = (PatchInfoStore) patchInfoStoreControl.getMock();
JdbcMigrationContext context = contextControl.createMock(JdbcMigrationContext.class);
IMocksControl patchInfoStoreControl = createStrictControl();
PatchInfoStore patchInfoStore = patchInfoStoreControl.createMock(PatchInfoStore.class);

expect(migrationRunnerStrategy.isSynchronized(currentPatchInfoStore, patchInfoStore)).andReturn(true);

Expand Down Expand Up @@ -121,23 +119,21 @@ public void testValidateControlledSystemsWhenNodePatchLevelsAreOutOfSync() throw
JdbcMigrationLauncher launcher = new JdbcMigrationLauncher();

// first node is at the 'current' patch level
MockControl node1ContextControl = MockControl.createControl(JdbcMigrationContext.class);
JdbcMigrationContext node1Context = (JdbcMigrationContext) node1ContextControl.getMock();
MockControl node1PatchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
PatchInfoStore node1PatchInfoStore = (PatchInfoStore) node1PatchInfoStoreControl.getMock();
IMocksControl node1ContextControl = createStrictControl();
JdbcMigrationContext node1Context = node1ContextControl.createMock(JdbcMigrationContext.class);
IMocksControl node1PatchInfoStoreControl = createStrictControl();
PatchInfoStore node1PatchInfoStore = node1PatchInfoStoreControl.createMock(PatchInfoStore.class);
// setup mock patch info store to return the patch level we want
node1Context.getDatabaseName();
node1ContextControl.setReturnValue("node1", MockControl.ONE_OR_MORE);
expect(node1Context.getDatabaseName()).andReturn("node1").atLeastOnce();
node1ContextControl.replay();

// second node simulates a newly added database instance, it has not been patched
MockControl node2ContextControl = MockControl.createControl(JdbcMigrationContext.class);
JdbcMigrationContext node2Context = (JdbcMigrationContext) node2ContextControl.getMock();
MockControl node2PatchInfoStoreControl = MockControl.createControl(PatchInfoStore.class);
PatchInfoStore node2PatchInfoStore = (PatchInfoStore) node2PatchInfoStoreControl.getMock();
IMocksControl node2ContextControl = createStrictControl();
JdbcMigrationContext node2Context = node2ContextControl.createMock(JdbcMigrationContext.class);
IMocksControl node2PatchInfoStoreControl = createStrictControl();
PatchInfoStore node2PatchInfoStore = node2PatchInfoStoreControl.createMock(PatchInfoStore.class);
// setup mock patch info store to return the patch level we want
node2Context.getDatabaseName();
node2ContextControl.setReturnValue("node2", MockControl.ONE_OR_MORE);
expect(node2Context.getDatabaseName()).andReturn("node2").atLeastOnce();
node2ContextControl.replay();

// create the launcher's contexts collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
import com.tacitknowledge.util.migration.tasks.rollback.TestRollbackableTask4;
import com.tacitknowledge.util.migration.tasks.rollback.TestRollbackableTask5;
import org.easymock.EasyMock;
import org.easymock.MockControl;
import org.easymock.classextension.IMocksControl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createStrictControl;


/**
* This class defines unit tests for the Rollback functionality.
*
Expand All @@ -48,7 +49,7 @@ public class MigrationProcessRollbackTest extends MigrationListenerTestBase
* Test migration context
*/
private TestMigrationContext context = null;
private MockControl patchInfoStoreControl;
private IMocksControl patchInfoStoreControl;
private PatchInfoStore patchInfoStore;
private PatchInfoStore currentPatchInfoStore;
private IMocksControl mockControl;
Expand Down Expand Up @@ -80,8 +81,8 @@ protected void setUp() throws Exception
+ ".tasks.post");
runner.addListener(this);
context = new TestMigrationContext();
patchInfoStoreControl = MockControl.createStrictControl(PatchInfoStore.class);
patchInfoStore = (PatchInfoStore) patchInfoStoreControl.getMock();
patchInfoStoreControl = createStrictControl();
patchInfoStore = patchInfoStoreControl.createMock(PatchInfoStore.class);
currentPatchInfoStore = MockBuilder.getPatchInfoStore(12);

mockControl = createStrictControl();
Expand All @@ -92,8 +93,8 @@ protected void setUp() throws Exception
rollbackCandidates.add(new TestRollbackableTask4());
rollbackCandidates.add(new TestRollbackableTask3());
rollbackCandidates.add(new TestRollbackableTask2());
expect(migrationStrategy.getRollbackCandidates(EasyMock.<List<MigrationTask>>anyObject(), eq(ROLLBACK_LEVELS), eq(currentPatchInfoStore))).andReturn(rollbackCandidates);
expect(migrationStrategy.getRollbackCandidates(EasyMock.<List<MigrationTask>>anyObject(), eq(ROLLBACK_LEVELS), eq(currentPatchInfoStore))).andReturn(Collections.EMPTY_LIST);
expect(migrationStrategy.getRollbackCandidates(EasyMock.<List<MigrationTask>> anyObject(), eq(ROLLBACK_LEVELS), eq(currentPatchInfoStore))).andReturn(rollbackCandidates);
expect(migrationStrategy.getRollbackCandidates(EasyMock.<List<MigrationTask>> anyObject(), eq(ROLLBACK_LEVELS), eq(currentPatchInfoStore))).andReturn(Collections.EMPTY_LIST);

}

Expand All @@ -118,7 +119,7 @@ public void testRollbackAllTasks() throws MigrationException
List migrationTasks = runner.getMigrationTasks();
assertEquals(5, migrationTasks.size());

patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 1, MockControl.ONE_OR_MORE);
expect(patchInfoStore.getPatchLevel()).andReturn(1).atLeastOnce();
patchInfoStoreControl.replay();

int level = runner.doMigrations(patchInfoStore, context);
Expand Down Expand Up @@ -153,7 +154,7 @@ public void testRollbackPartialTasks() throws MigrationException
List l = runner.getMigrationTasks();
assertEquals(5, l.size());

patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 8, MockControl.ONE_OR_MORE);
expect(patchInfoStore.getPatchLevel()).andReturn(8).atLeastOnce();
patchInfoStoreControl.replay();

int level = runner.doMigrations(patchInfoStore, context);
Expand Down Expand Up @@ -228,7 +229,7 @@ private void doInitialMigrations() throws MigrationException
List l = runner.getMigrationTasks();
assertEquals(5, l.size());

patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 0, MockControl.ONE_OR_MORE);
expect(patchInfoStore.getPatchLevel()).andReturn(0).atLeastOnce();
patchInfoStoreControl.replay();
int level = runner.doMigrations(patchInfoStore, context);
runner.doPostPatchMigrations(context);
Expand All @@ -253,7 +254,7 @@ public void testInvalidRollbackLevel() throws MigrationException
List l = runner.getMigrationTasks();
assertEquals(5, l.size());

patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 0, MockControl.ONE_OR_MORE);
expect(patchInfoStore.getPatchLevel()).andReturn(0).atLeastOnce();
patchInfoStoreControl.replay();

int level = runner.doMigrations(patchInfoStore, context);
Expand Down Expand Up @@ -295,7 +296,7 @@ public void testMigrationTaskRollback() throws MigrationException

assertEquals(6, l.size());

patchInfoStoreControl.expectAndReturn(patchInfoStore.getPatchLevel(), 7, MockControl.ONE_OR_MORE);
expect(patchInfoStore.getPatchLevel()).andReturn(7).atLeastOnce();
patchInfoStoreControl.replay();

int level = runner.doMigrations(patchInfoStore, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
import com.tacitknowledge.util.migration.tasks.normal.TestMigrationTask2;
import com.tacitknowledge.util.migration.tasks.normal.TestMigrationTask3;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.easymock.IMocksControl;

import java.util.ArrayList;
import java.util.List;

import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.classextension.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createStrictControl;


/**
* Test the {@link MigrationProcess} class.
Expand All @@ -36,15 +40,15 @@ public class MigrationProcessTest extends TestCase

private MigrationProcess migrationProcess = null;

private MockControl migrationContextControl = null;
private IMocksControl migrationContextControl = null;

private MigrationContext migrationContextMock = null;

private MockControl migrationTaskSourceControl = null;
private IMocksControl migrationTaskSourceControl = null;

private MigrationTaskSource migrationTaskSourceMock = null;

private MockControl patchInfoStoreControl = null;
private IMocksControl patchInfoStoreControl = null;

private PatchInfoStore patchInfoStoreMock = null;
private PatchInfoStore patchInfoStore;
Expand All @@ -55,14 +59,13 @@ public void setUp() throws Exception
migrationProcess = new MigrationProcess();
migrationProcess.
setMigrationRunnerStrategy(MigrationRunnerFactory.getMigrationRunnerStrategy(null));
migrationContextControl = MockControl.createStrictControl(MigrationContext.class);
migrationContextMock =
(MigrationContext) migrationContextControl.getMock();
migrationTaskSourceControl = MockControl.createStrictControl(MigrationTaskSource.class);
migrationTaskSourceMock = (MigrationTaskSource) migrationTaskSourceControl.getMock();
migrationContextControl = createStrictControl();
migrationContextMock = migrationContextControl.createMock(MigrationContext.class);
migrationTaskSourceControl = createStrictControl();
migrationTaskSourceMock = migrationTaskSourceControl.createMock(MigrationTaskSource.class);
migrationProcess.addPatchResourcePackage("testPackageName");
patchInfoStoreControl = MockControl.createStrictControl(PatchInfoStore.class);
patchInfoStoreMock = (PatchInfoStore) patchInfoStoreControl.getMock();
patchInfoStoreControl = createStrictControl();
patchInfoStoreMock = patchInfoStoreControl.createMock(PatchInfoStore.class);
patchInfoStore = MockBuilder.getPatchInfoStore(3);
}

Expand Down Expand Up @@ -119,7 +122,7 @@ public void testDryRunWithNullMigrationList() throws MigrationException {
}

public void testDryRunWithMigrationsInOrder() throws MigrationException {
patchInfoStoreControl.expectAndReturn(patchInfoStoreMock.getPatchLevel(), 3, 2);
expect(patchInfoStoreMock.getPatchLevel()).andReturn(3).times(2);
patchInfoStoreControl.replay();
int taskCount = migrationProcess.dryRun(patchInfoStoreMock, migrationContextMock, getMigrationTasks());
assertEquals("TaskCount should be equal to 2", 2, taskCount);
Expand All @@ -142,10 +145,9 @@ public void testDoMigrationInReadOnlyWithExistingTasksThrowsError() throws Migra
try
{
migrationProcess.setReadOnly(true);
migrationTaskSourceControl.expectAndReturn(migrationTaskSourceMock.
getMigrationTasks("testPackageName"), getMigrationTasks());
expect(migrationTaskSourceMock.getMigrationTasks("testPackageName")).andReturn(getMigrationTasks());
migrationTaskSourceControl.replay();
patchInfoStoreControl.expectAndReturn(patchInfoStoreMock.getPatchLevel(), 2, 2);
expect(patchInfoStoreMock.getPatchLevel()).andReturn(2).times(2);
patchInfoStoreControl.replay();
migrationProcess.addMigrationTaskSource(migrationTaskSourceMock);
migrationProcess.doMigrations(patchInfoStoreMock, migrationContextMock);
Expand All @@ -163,23 +165,21 @@ public void testDoMigrationInReadOnlyWithExistingTasksThrowsError() throws Migra
public void testDoMigrationInReadOnlyWithZeroTasks() throws MigrationException
{
migrationProcess.setReadOnly(true);
migrationTaskSourceControl.expectAndReturn(migrationTaskSourceMock.
getMigrationTasks("testPackageName"), new ArrayList());
expect(migrationTaskSourceMock.getMigrationTasks("testPackageName")).andReturn(new ArrayList());
migrationTaskSourceControl.replay();
migrationProcess.addMigrationTaskSource(migrationTaskSourceMock);
patchInfoStoreControl.expectAndReturn(patchInfoStoreMock.getPatchLevel(), 0);
expect(patchInfoStoreMock.getPatchLevel()).andReturn(0);
patchInfoStoreControl.replay();
migrationProcess.doMigrations(patchInfoStoreMock, migrationContextMock);
}

public void testDoTwoMigrations() throws MigrationException
{
migrationProcess.setReadOnly(false);
migrationTaskSourceControl.expectAndReturn(migrationTaskSourceMock.
getMigrationTasks("testPackageName"), getMigrationTasks());
expect(migrationTaskSourceMock.getMigrationTasks("testPackageName")).andReturn(getMigrationTasks());
migrationTaskSourceControl.replay();
migrationProcess.addMigrationTaskSource(migrationTaskSourceMock);
patchInfoStoreControl.expectAndReturn(patchInfoStoreMock.getPatchLevel(), 2, 4);
expect(patchInfoStoreMock.getPatchLevel()).andReturn(2).times(4);
patchInfoStoreControl.replay();
assertEquals("We should have executed 2 migrations",
2, migrationProcess.doMigrations(patchInfoStoreMock, migrationContextMock));
Expand All @@ -188,11 +188,10 @@ public void testDoTwoMigrations() throws MigrationException
public void testDontDoMigrations() throws MigrationException
{
migrationProcess.setReadOnly(false);
migrationTaskSourceControl.expectAndReturn(migrationTaskSourceMock.
getMigrationTasks("testPackageName"), getMigrationTasks());
expect(migrationTaskSourceMock.getMigrationTasks("testPackageName")).andReturn(getMigrationTasks());
migrationTaskSourceControl.replay();
migrationProcess.addMigrationTaskSource(migrationTaskSourceMock);
patchInfoStoreControl.expectAndReturn(patchInfoStoreMock.getPatchLevel(), 100, 4);
expect(patchInfoStoreMock.getPatchLevel()).andReturn(100).times(4);
patchInfoStoreControl.replay();
assertEquals("We should have executed no migrations",
0, migrationProcess.doMigrations(patchInfoStoreMock, migrationContextMock));
Expand Down
Loading