-
Notifications
You must be signed in to change notification settings - Fork 14
/
ReadCommittedConnectorFactoryTest.java
52 lines (43 loc) · 2.13 KB
/
ReadCommittedConnectorFactoryTest.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
package cz.cvut.kbss.ontodriver.jena.connector;
import cz.cvut.kbss.ontodriver.config.Configuration;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.lang.reflect.Field;
import static org.junit.Assert.*;
public class ReadCommittedConnectorFactoryTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void createConnectorCreatesNewChangeTrackingConnectorWrappingCentralConnector() throws Exception {
final Configuration configuration = StorageTestUtil.createConfiguration("test:uri");
final ConnectorFactory factory = new ReadCommittedConnectorFactory(configuration);
final StorageConnector connector = factory.createConnector();
assertTrue(connector instanceof ChangeTrackingStorageConnector);
assertNotNull(getCentralConnector(factory));
assertTrue(getCentralConnector(factory).isOpen());
}
private SharedStorageConnector getCentralConnector(ConnectorFactory factory) throws Exception {
final Field connectorField = ReadCommittedConnectorFactory.class.getDeclaredField("centralConnector");
connectorField.setAccessible(true);
return (SharedStorageConnector) connectorField.get(factory);
}
@Test
public void closeClosesCentralConnector() throws Exception {
final Configuration configuration = StorageTestUtil.createConfiguration("test:uri");
final ConnectorFactory factory = new ReadCommittedConnectorFactory(configuration);
assertTrue(getCentralConnector(factory).isOpen());
factory.close();
assertFalse(factory.isOpen());
assertFalse(getCentralConnector(factory).isOpen());
}
@Test
public void createConnectorOnClosedFactoryThrowsIllegalStateException() throws Exception {
thrown.expect(IllegalStateException.class);
final Configuration configuration = StorageTestUtil.createConfiguration("test:uri");
final ConnectorFactory factory = new ReadCommittedConnectorFactory(configuration);
factory.close();
assertFalse(factory.isOpen());
factory.createConnector();
}
}