use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testExpandSimple2.
@Test
public void testExpandSimple2() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
hc.addData("SELECT x.a, x.b FROM x", Arrays.asList(Arrays.asList("xa1", "xb"), Arrays.asList("xa2", "xb2")));
hc.addData("SELECT y.b, y.a FROM y", Arrays.asList(Arrays.asList("xa1", "ya1"), Arrays.asList("xa1", "ya2")));
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=" + Encoder.encode("y_FKX($filter=b eq 'xa1')")).method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\"," + "\"value\":[" + "{\"a\":\"xa1\",\"b\":\"xb\"," + "\"y_FKX\":[{\"a\":\"ya1\",\"b\":\"xa1\"}," + "{\"a\":\"ya2\",\"b\":\"xa1\"}]}," + "{\"a\":\"xa2\",\"b\":\"xb2\"," + "\"y_FKX\":[]}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testBasicTypes.
@Test
public void testBasicTypes() throws Exception {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMapping("x3", "x3", null);
MetadataStore ms = RealMetadataFactory.exampleBQTStore();
Schema s = ms.getSchema("BQT1");
KeyRecord pk = new KeyRecord(KeyRecord.Type.Primary);
Table smalla = s.getTable("SmallA");
pk.setName("pk");
pk.addColumn(smalla.getColumnByName("IntKey"));
smalla.setPrimaryKey(pk);
String ddl = DDLStringVisitor.getDDLString(s, EnumSet.allOf(SchemaObjectType.class), "SmallA");
mmd.addSourceMetadata("DDL", ddl);
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
teiid.addTranslator("x3", hc);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.GET(baseURL + "/northwind/m/SmallA?$format=json&$select=TimeValue");
assertEquals(200, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testInsert.
@Test
public void testInsert() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addUpdate("INSERT INTO x (a, b) VALUES ('teiid', 'dv')", new int[] { 1 });
teiid.addTranslator("x10", 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);");
mmd.addSourceMapping("x10", "x10", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
String payload = "{\n" + " \"a\":\"teiid\",\n" + " \"b\":\"dv\"\n" + "}";
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider(payload)).header("Content-Type", "application/json").header("Prefer", "return=minimal").send();
assertEquals(204, response.getStatus());
assertTrue(response.getHeaders().get("OData-EntityId").endsWith("northwind/m/x('ABCDEFG')"));
// assertEquals("ABCDEFGHIJ",response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testDeepInsert.
@Test
public void testDeepInsert() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
hc.addUpdate("INSERT INTO x (a, b) VALUES ('teiid', 'dv')", new int[] { 1 });
hc.addUpdate("INSERT INTO y (a, b) VALUES ('odata', 'teiid')", new int[] { 1 });
hc.addUpdate("INSERT INTO y (a, b) VALUES ('odata4', 'teiid')", new int[] { 1 });
hc.addUpdate("INSERT INTO z (a, b) VALUES ('odata', 'teiid')", new int[] { 1 });
hc.addUpdate("INSERT INTO z (a, b) VALUES ('odata4', 'olingo4')", new int[] { 1 });
hc.addData("SELECT x.a, x.b FROM x", Arrays.asList(Arrays.asList("teiid", "dv")));
hc.addData("SELECT y.b, y.a FROM y", Arrays.asList(Arrays.asList("teiid", "odata"), Arrays.asList("teiid", "odata4")));
hc.addData("SELECT z.b, z.a FROM z", Arrays.asList(Arrays.asList("teiid", "odata"), Arrays.asList("olingo4", "odata4")));
teiid.addTranslator("x10", 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 (b) REFERENCES x(a)" + ") options (updatable true);");
mmd.addSourceMapping("x10", "x10", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
// update to collection based reference
String payload = "{\n" + " \"a\":\"teiid\",\n" + " \"b\":\"dv\",\n" + " \"y_FKX\": [\n" + " {" + " \"a\":\"odata\",\n" + " \"b\":\"teiid\"\n" + " },\n" + " {\n" + " \"a\":\"odata4\",\n" + " \"b\":\"teiid\"\n" + " }\n" + " ]\n" + "}";
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider(payload), ContentType.APPLICATION_JSON.toString()).header("Prefer", "return=representation").send();
assertEquals(201, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"a\":\"teiid\",\"b\":\"dv\"}", response.getContentAsString());
// update to collection based reference
payload = "{\n" + " \"a\":\"teiid\",\n" + " \"b\":\"dv\",\n" + " \"y_FKX\": [\n" + " {" + " \"a\":\"odata\",\n" + " \"b\":\"teiid\"\n" + " },\n" + " {\n" + " \"a\":\"odata4\",\n" + " \"b\":\"teiid\"\n" + " }\n" + " ],\n" + " \"z_FKX\": [\n" + " {" + " \"a\":\"odata\",\n" + " \"b\":\"teiid\"\n" + " },\n" + " {\n" + " \"a\":\"odata4\",\n" + " \"b\":\"olingo4\"\n" + " }\n" + " ]\n" + "}";
response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider(payload), ContentType.APPLICATION_JSON.toString()).header("Prefer", "return=representation").send();
assertEquals(201, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"a\":\"teiid\",\"b\":\"dv\"}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method test$ItFilter.
@Test
public void test$ItFilter() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
hc.addData("SELECT x.c, x.a FROM x WHERE x.a = 'x'", Arrays.asList(Arrays.asList(new String[] { "google.net", "google.com" }, 'x')));
hc.addData("SELECT x.c, x.a FROM x WHERE x.a = 'y'", Arrays.asList(Arrays.asList(new String[] { "example.net", "example.com" }, 'y')));
teiid.addTranslator("x8", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("vw");
mmd.addSourceMetadata("DDL", "create foreign table x (a string primary key, b integer[], c string[]);");
mmd.setModelType(Model.Type.PHYSICAL);
mmd.addSourceMapping("x8", "x8", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.GET(baseURL + "/northwind/vw/x('x')/c?$filter=endswith($it,'com')");
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x('x')/c\",\"value\":[\"google.com\"]}", response.getContentAsString());
response = http.GET(baseURL + "/northwind/vw/x('y')/c?$filter=startswith($it,'example')");
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x('y')/c\",\"value\":[\"example.net\",\"example.com\"]}", response.getContentAsString());
response = http.GET(baseURL + "/northwind/vw/x('y')/c?$filter=startswith($it,'example')&$orderby=$it");
assertEquals(501, response.getStatus());
response = http.GET(baseURL + "/northwind/vw/x('x')/c?$filter=endswith($it,'com')%20or%20endswith($it,'net')");
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x('x')/c\",\"value\":[\"google.net\",\"google.com\"]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
Aggregations