use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testBatch.
@Test
public void testBatch() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addUpdate("DELETE FROM x WHERE x.a = 'a' AND x.b = 'b'", new int[] { 1 });
teiid.addTranslator("x", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (a string, b string, c integer, " + "primary key (a, b)) options (updatable true);");
mmd.addSourceMapping("x", "x", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
final String batch = "" + "--batch_8194-cf13-1f56" + CRLF + MIME_HEADERS + CRLF + "GET " + baseURL + "/northwind/m/x HTTP/1.1" + CRLF + "Accept: application/json" + CRLF + "MaxDataServiceVersion: 4.0" + CRLF + CRLF + CRLF + "--batch_8194-cf13-1f56" + CRLF + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF + CRLF + "--changeset_f980-1cb6-94dd" + CRLF + "content-type: Application/http" + CRLF + "content-transfer-encoding: Binary" + CRLF + "Content-ID: 1" + CRLF + CRLF + "DELETE " + baseURL + "/northwind/m/x(a='a',b='b') HTTP/1.1" + CRLF + "Content-type: application/json" + CRLF + CRLF + CRLF + "--changeset_f980-1cb6-94dd--" + CRLF + "--batch_8194-cf13-1f56--";
ContentResponse response = http.newRequest(baseURL + "/northwind/m/$batch").method("POST").content(new StringContentProvider(batch), "multipart/mixed;boundary=batch_8194-cf13-1f56").send();
assertEquals(202, response.getStatus());
/*
String expected = "--batch_d06279e4-c510-46ed-a778-e4e941dfd6f1\n" +
"Content-Type: application/http\n" +
"Content-Transfer-Encoding: binary\n" +
"\n" +
"HTTP/1.1 200 OK\n" +
"Content-Type: application/json;odata.metadata=minimal\n" +
"Content-Length: 78\n" +
"\n" +
"{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"ABCDEFG\",\"b\":\"ABCDEFG\",\"c\":0}]}\n" +
"--batch_d06279e4-c510-46ed-a778-e4e941dfd6f1\n" +
"Content-Type: multipart/mixed; boundary=changeset_5a1cba47-b51f-46c2-b0ac-ead23fa7706d\n" +
"\n" +
"--changeset_5a1cba47-b51f-46c2-b0ac-ead23fa7706d\n" +
"Content-Type: application/http\n" +
"Content-Transfer-Encoding: binary\n" +
"Content-Id: 1\n" +
"\n" +
"HTTP/1.1 204 No Content\n" +
"Content-Length: 0\n" +
"\n" +
"\n" +
"--changeset_5a1cba47-b51f-46c2-b0ac-ead23fa7706d--\n" +
"--batch_d06279e4-c510-46ed-a778-e4e941dfd6f1--";
assertEquals(expected, response.getContentAsString());
*/
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testReverseBidirectionalNavigation.
@Test
public void testReverseBidirectionalNavigation() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
hc.addData("SELECT EmployeeMasterEntity.EmployeeID, EmployeeMasterEntity.Department FROM EmployeeMasterEntity", Arrays.asList(Arrays.asList(3, 10000001)));
hc.addData("SELECT OrganizationalUnitEntity.OrganizationaUnitID, OrganizationalUnitEntity.UnitManager FROM OrganizationalUnitEntity", Arrays.asList(Arrays.asList(10000001, 1)));
teiid.addTranslator("x12", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "CREATE FOREIGN TABLE EmployeeMasterEntity (\n" + " EmployeeID integer primary key,\n" + " Department integer," + "CONSTRAINT Departments FOREIGN KEY (Department) REFERENCES OrganizationalUnitEntity(OrganizationaUnitID));\n" + "CREATE FOREIGN TABLE OrganizationalUnitEntity (\n" + " OrganizationaUnitID integer PRIMARY KEY,\n" + " UnitManager integer,\n" + " CONSTRAINT Managers FOREIGN KEY (UnitManager) REFERENCES EmployeeMasterEntity(EmployeeID));");
mmd.addSourceMapping("x12", "x12", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = null;
response = http.newRequest(baseURL + "/northwind/m/EmployeeMasterEntity(3)/Departments?$format=json").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#OrganizationalUnitEntity/$entity\",\"OrganizationaUnitID\":10000001,\"UnitManager\":1}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testCompositeKeyUpdates.
@Test
public void testCompositeKeyUpdates() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addUpdate("DELETE FROM x WHERE x.a = 'a' AND x.b = 'b'", new int[] { 1 });
hc.addUpdate("INSERT INTO x (a, b, c) VALUES ('a', 'b', 5)", new int[] { 1 });
hc.addUpdate("UPDATE x SET c = 10 WHERE x.a = 'a' AND x.b = 'b'", new int[] { 1 });
hc.addData("SELECT x.a, x.b, x.c FROM x WHERE x.a = 'a' AND x.b = 'b'", Arrays.asList(Arrays.asList("a", "b", 1)));
teiid.addTranslator("x1", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (a string, b string, c integer, " + "primary key (a, b)) options (updatable true);");
mmd.addSourceMapping("x1", "x1", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x(a='a',b='b')").method("DELETE").send();
assertEquals(204, response.getStatus());
// partial key
response = http.newRequest(baseURL + "/northwind/m/x('a')").method("DELETE").send();
assertEquals(400, response.getStatus());
// partial key
response = http.newRequest(baseURL + "/northwind/m/x(a='a',a='b')").method("DELETE").send();
assertEquals(400, response.getStatus());
// not supported
// request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/x(a='a',b='b')/c/$value"));
// request.body("text/plain", "5");
// response = request.put(String.class);
response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider("{\"a\":\"a\", \"b\":\"b\", \"c\":5}"), "application/json").send();
assertEquals(201, response.getStatus());
response = http.newRequest(baseURL + "/northwind/m/x(a='a',b='b')").method("PATCH").content(new StringContentProvider("{\"c\":10}"), "application/json").send();
assertEquals(204, response.getStatus());
response = http.newRequest(baseURL + "/northwind/m/x(a='a',b='b')").method("PUT").content(new StringContentProvider("{\"a\":\"a\", \"b\":\"b\", \"c\":5}"), "application/json").send();
assertEquals(204, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testExpandSimple.
@Test
public void testExpandSimple() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
teiid.addTranslator("x7", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (" + " a string, " + " b string, " + " primary key (a)" + ") options (updatable true);" + "create foreign table y (" + " a string, " + " b string, " + " primary key (a)," + " CONSTRAINT FKX FOREIGN KEY (b) REFERENCES x(a)" + ") options (updatable true);" + "create foreign table z (" + " a string, " + " b string, " + " primary key (a)," + " CONSTRAINT FKX FOREIGN KEY (a) REFERENCES x(a)" + ") options (updatable true);");
mmd.addSourceMapping("x7", "x7", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = null;
response = http.newRequest(baseURL + "/northwind/m/x?$expand=y_FKX").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"ABCDEFG\"," + "\"b\":\"ABCDEFG\",\"y_FKX\":[{\"a\":\"ABCDEFG\",\"b\":\"ABCDEFG\"}]}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/z?$expand=FKX&$select=a").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#z(a)\",\"value\":[{\"a\":\"ABCDEFG\"," + "\"FKX\":{\"a\":\"ABCDEFG\",\"b\":\"ABCDEFG\"}}]}", response.getContentAsString());
// explictly selecting and expanding
response = http.newRequest(baseURL + "/northwind/m/z?$expand=FKX&$select=a").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#z(a)\",\"value\":[{\"a\":\"ABCDEFG\"," + "\"FKX\":{\"a\":\"ABCDEFG\",\"b\":\"ABCDEFG\"}}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/z?$expand=FKX($select=a)").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#z(FKX(a))\",\"value\":[{\"a\":\"ABCDEFG\"," + "\"b\":\"ABCDEFG\",\"FKX\":{\"a\":\"ABCDEFG\"}}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/z?$expand=FKX").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#z\",\"value\":[{\"a\":\"ABCDEFG\"," + "\"b\":\"ABCDEFG\",\"FKX\":{\"a\":\"ABCDEFG\",\"b\":\"ABCDEFG\"}}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/z?$expand=FKX($top=1)").method("GET").send();
assertEquals(200, response.getStatus());
/* TODO
response = http.newRequest(baseURL + "/northwind/m/z?$expand=FKX/a&$select=a")
.method("GET")
.send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#z(a,FKX/a)\",\"value\":[{\"a\":\"ABCDEFG\",\"FKX\":{\"a\":\"ABCDEFG\",\"b\":\"ABCDEFG\"}}]}", response.getContentAsString());
*/
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestVDBMerge method testMergeWithMultiSource.
@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");
// $NON-NLS-1$
execute("select * from tbl");
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");
// $NON-NLS-1$
execute("select * from tbl");
assertRowCount(2);
}
Aggregations