-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
UpgradeScriptsTest.java
118 lines (101 loc) · 4.59 KB
/
UpgradeScriptsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package org.jbpm.persistence.scripts;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import org.jbpm.persistence.scripts.util.TestsUtil;
import org.junit.Assert;
import org.junit.Test;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.internal.runtime.StatefulKnowledgeSession;
/**
* Contains tests that test database upgrade scripts.
*/
public class UpgradeScriptsTest {
private static final String TEST_PROCESS_ID = "minimalProcess";
private static final Long TEST_PROCESS_INSTANCE_ID = 1L;
private static final Integer TEST_SESSION_ID = 1;
/**
* Tests that DB schema is upgraded properly using database upgrade scripts.
* @throws IOException
*/
@Test
public void testExecutingScripts() throws IOException, SQLException {
testExecutingScripts("jbpm");
testExecutingScripts("bpms");
}
public void testExecutingScripts(String type) throws IOException, SQLException {
// Clear schema.
TestsUtil.clearSchema();
final TestPersistenceContext scriptRunnerContext = new TestPersistenceContext();
scriptRunnerContext.init(PersistenceUnit.SCRIPT_RUNNER);
try {
// Prepare 6.0. schema
scriptRunnerContext.executeScripts(new File(getClass().getResource("/ddl60").getFile()));
// Execute upgrade scripts.
scriptRunnerContext.executeScripts(new File(getClass().getResource("/upgrade-scripts").getFile()), type);
} finally {
scriptRunnerContext.clean();
}
final TestPersistenceContext dbTestingContext = new TestPersistenceContext();
dbTestingContext.init(PersistenceUnit.DB_TESTING);
try {
dbTestingContext.startAndPersistSomeProcess(TEST_PROCESS_ID);
Assert.assertTrue(dbTestingContext.getStoredProcessesCount() == 1);
} finally {
dbTestingContext.clean();
}
}
/**
* Tests that persisted process is not destroyed by upgrade scripts.
* @throws IOException
* @throws ParseException
* @throws SQLException
*/
@Test
public void testPersistedProcess() throws IOException, ParseException, SQLException {
testPersistedProcess("jbpm");
testPersistedProcess("bpms");
}
public void testPersistedProcess(String type) throws IOException, ParseException, SQLException {
// Clear schema.
TestsUtil.clearSchema();
// Prepare + upgrade schema.
final TestPersistenceContext scriptRunnerContext = new TestPersistenceContext();
scriptRunnerContext.init(PersistenceUnit.SCRIPT_RUNNER);
try {
// Prepare 6.0. schema
scriptRunnerContext.executeScripts(new File(getClass().getResource("/ddl60").getFile()));
scriptRunnerContext.persistOldProcessAndSession(TEST_SESSION_ID, TEST_PROCESS_ID, TEST_PROCESS_INSTANCE_ID);
scriptRunnerContext.createSomeTask();
// Execute upgrade scripts.
scriptRunnerContext.executeScripts(new File(getClass().getResource("/upgrade-scripts").getFile()), type);
} finally {
scriptRunnerContext.clean();
}
final TestPersistenceContext dbTestingContext = new TestPersistenceContext();
dbTestingContext.init(PersistenceUnit.DB_TESTING);
try {
Assert.assertTrue(dbTestingContext.getStoredProcessesCount() == 1);
Assert.assertTrue(dbTestingContext.getStoredSessionsCount() == 1);
final StatefulKnowledgeSession persistedSession = dbTestingContext.loadPersistedSession(
TEST_SESSION_ID.longValue(), TEST_PROCESS_ID);
Assert.assertNotNull(persistedSession);
// Start another process.
persistedSession.startProcess(TEST_PROCESS_ID);
Assert.assertTrue(dbTestingContext.getStoredProcessesCount() == 2);
// Load old process instance.
ProcessInstance processInstance = persistedSession.getProcessInstance(TEST_PROCESS_INSTANCE_ID);
Assert.assertNotNull(processInstance);
persistedSession.signalEvent("test", null);
processInstance = persistedSession.getProcessInstance(TEST_PROCESS_INSTANCE_ID);
Assert.assertNull(processInstance);
Assert.assertTrue(dbTestingContext.getStoredProcessesCount() == 0);
persistedSession.dispose();
persistedSession.destroy();
Assert.assertTrue(dbTestingContext.getStoredSessionsCount() == 0);
} finally {
dbTestingContext.clean();
}
}
}