/
TestVDBMerge.java
141 lines (107 loc) · 5.8 KB
/
TestVDBMerge.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package org.teiid.jdbc;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.sql.SQLException;
import java.util.Arrays;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.teiid.adminapi.impl.VDBImportMetadata;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.jdbc.FakeServer.DeployVDBParameter;
import org.teiid.runtime.HardCodedExecutionFactory;
@SuppressWarnings("nls")
public class TestVDBMerge extends AbstractMMQueryTestCase {
private static final String VDB1 = "PartsSupplier"; //$NON-NLS-1$
private static final String VDB2 = "QT_Ora9DS"; //$NON-NLS-1$
private FakeServer server;
@Before public void setup() throws Exception {
server = new FakeServer(true);
server.setThrowMetadataErrors(false); //test vdb has errors
}
@After public void teardown() throws Exception {
server.stop();
}
@Test
public void testMerge() throws Throwable {
server.deployVDB(VDB1, UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
this.internalConnection = server.createConnection("jdbc:teiid:"+VDB1);
execute("select * from tables where schemaname ='PartsSupplier'"); //$NON-NLS-1$
TestMMDatabaseMetaData.compareResultSet("TestVDBMerge/merge.test", this.internalResultSet);
execute("select * from tables where schemaname='BQT1'"); //$NON-NLS-1$
TestMMDatabaseMetaData.compareResultSet("TestVDBMerge/merge.before", this.internalResultSet);
this.internalConnection.close();
server.deployVDB(VDB2, UnitTestUtil.getTestDataPath()+"/QT_Ora9DS_1.vdb");
DeployVDBParameter param = new DeployVDBParameter(null, null);
VDBImportMetadata vdbImport = new VDBImportMetadata();
vdbImport.setName(VDB2);
param.vdbImports = Arrays.asList(vdbImport);
server.removeVDB(VDB1);
server.deployVDB(VDB1, UnitTestUtil.getTestDataPath()+"/PartsSupplier.vdb", param);
this.internalConnection = server.createConnection("jdbc:teiid:"+VDB1);
execute("select * from tables where schemaname='BQT1' order by name"); //$NON-NLS-1$
TestMMDatabaseMetaData.compareResultSet("TestVDBMerge/merge.after", this.internalResultSet);
}
@Test
public void testMergeWithEmptyVDB() throws Exception {
server.deployVDB("empty", UnitTestUtil.getTestDataPath() + "/empty.vdb");
this.internalConnection = server.createConnection("jdbc:teiid:empty");
execute("select * from tables where schemaname ='BQT1'"); //$NON-NLS-1$
TestMMDatabaseMetaData.compareResultSet("TestVDBMerge/mergeEmpty.before", this.internalResultSet);
this.internalConnection.close();
server.deployVDB(VDB2, UnitTestUtil.getTestDataPath()+"/QT_Ora9DS_1.vdb");
DeployVDBParameter param = new DeployVDBParameter(null, null);
VDBImportMetadata vdbImport = new VDBImportMetadata();
vdbImport.setName(VDB2);
param.vdbImports = Arrays.asList(vdbImport);
server.undeployVDB("empty");
server.deployVDB("empty", UnitTestUtil.getTestDataPath() + "/empty.vdb", param);
this.internalConnection = server.createConnection("jdbc:teiid:empty");
execute("select * from tables where schemaname='BQT1'"); //$NON-NLS-1$
TestMMDatabaseMetaData.compareResultSet("TestVDBMerge/mergeEmpty.after", this.internalResultSet);
}
@Test public void testMergeWithPolicies() throws Exception {
server.deployVDB(new ByteArrayInputStream(new String("<vdb name=\"role-1\" version=\"1\">"
+ "<model name=\"myschema\" type=\"virtual\">"
+ "<metadata type = \"DDL\"><![CDATA[CREATE VIEW vw as select 'a' as col;]]></metadata></model>"
+ "<data-role name=\"y\" any-authenticated=\"true\"/></vdb>").getBytes()));
this.internalConnection = server.createConnection("jdbc:teiid:role-1");
try {
execute("select * from vw"); //$NON-NLS-1$
fail("should not be authorized");
} catch (SQLException e) {
}
server.deployVDB(new ByteArrayInputStream(new String("<vdb name=\"role-2\" version=\"1\">"
+ "<import-vdb name=\"role-1\" version=\"1\"/>"
+ "</vdb>").getBytes()));
this.internalConnection = server.createConnection("jdbc:teiid:role-2");
try {
execute("select * from vw"); //$NON-NLS-1$
fail("should not be authorized");
} catch (SQLException e) {
}
server.deployVDB(new ByteArrayInputStream(new String("<vdb name=\"role-3\" version=\"1\">"
+ "<import-vdb name=\"role-1\" version=\"1\" import-data-policies=\"false\"/>"
+ "</vdb>").getBytes()));
this.internalConnection = server.createConnection("jdbc:teiid:role-3");
execute("select * from vw"); //$NON-NLS-1$
}
@Test public void testMergeWithMultiSource() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
hc.addData("SELECT tbl.col FROM tbl", Arrays.asList(Arrays.asList("a")));
server.addTranslator("hc", hc);
server.deployVDB(new ByteArrayInputStream(new String("<vdb name=\"ms-base\" version=\"1\">"
+ "<model name=\"myschema\"><source name=\"a\" translator-name=\"hc\"/><source name=\"b\" translator-name=\"hc\"/>"
+ "<metadata type = \"DDL\"><![CDATA[CREATE foreign table tbl (col string);]]></metadata></model>"
+ "</vdb>").getBytes()));
this.internalConnection = server.createConnection("jdbc:teiid:ms-base");
execute("select * from tbl"); //$NON-NLS-1$
assertRowCount(2);
server.deployVDB(new ByteArrayInputStream(new String("<vdb name=\"ms-2\" version=\"1\">"
+ "<import-vdb name=\"ms-base\" version=\"1\"/>"
+ "</vdb>").getBytes()));
this.internalConnection = server.createConnection("jdbc:teiid:ms-2");
execute("select * from tbl"); //$NON-NLS-1$
assertRowCount(2);
}
}