use of org.teiid.adminapi.impl.ModelMetaData 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");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testReverseNavigation.
@Test
public void testReverseNavigation() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
hc.addData("SELECT Customers.id, Customers.name FROM Customers", Arrays.asList(Arrays.asList(1, "customer1"), Arrays.asList(2, "customer2"), Arrays.asList(3, "customer3"), Arrays.asList(4, "customer4")));
hc.addData("SELECT Customers.id FROM Customers", Arrays.asList(Arrays.asList(1), Arrays.asList(2), Arrays.asList(3), Arrays.asList(4)));
hc.addData("SELECT Orders.id, Orders.customerid FROM Orders", Arrays.asList(Arrays.asList(1, 1), Arrays.asList(2, 1), Arrays.asList(3, 1), Arrays.asList(4, 1), Arrays.asList(5, 2), Arrays.asList(6, 2), Arrays.asList(7, 3), Arrays.asList(8, 3)));
hc.addData("SELECT Orders.id, Orders.customerid, Orders.place FROM Orders", Arrays.asList(Arrays.asList(1, 1, "town"), Arrays.asList(2, 1, "state"), Arrays.asList(3, 1, "country"), Arrays.asList(4, 1, "abroad"), Arrays.asList(5, 2, "state"), Arrays.asList(6, 2, "country"), Arrays.asList(7, 3, "town"), Arrays.asList(8, 3, "town")));
hc.addData("SELECT Orders.customerid, Orders.id, Orders.place FROM Orders", Arrays.asList(Arrays.asList(1, 1, "town"), Arrays.asList(1, 2, "state"), Arrays.asList(1, 3, "country"), Arrays.asList(1, 4, "abroad"), Arrays.asList(2, 5, "state"), Arrays.asList(2, 6, "country"), Arrays.asList(3, 7, "town"), Arrays.asList(3, 8, "town")));
teiid.addTranslator("x12", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "CREATE FOREIGN TABLE Customers (\n" + " id integer PRIMARY KEY OPTIONS (NAMEINSOURCE 'id'),\n" + " name varchar(10));\n" + "CREATE FOREIGN TABLE Orders (\n" + " id integer PRIMARY KEY OPTIONS (NAMEINSOURCE 'id'),\n" + " customerid integer,\n" + " place varchar(10),\n" + " CONSTRAINT Customer FOREIGN KEY (customerid) REFERENCES Customers(id));");
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/Orders(1)/Customer").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers/$entity\"," + "\"id\":1,\"name\":\"customer1\"}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Orders(1)?$expand=Customer").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Orders/$entity\"," + "\"id\":1,\"customerid\":1,\"place\":\"town\"," + "\"Customer\":{\"id\":1,\"name\":\"customer1\"}}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Orders(1)/Customer/Orders_Customer").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"value\":[{\"id\":1,\"customerid\":1,\"place\":\"town\"}," + "{\"id\":2,\"customerid\":1,\"place\":\"state\"}," + "{\"id\":3,\"customerid\":1,\"place\":\"country\"}," + "{\"id\":4,\"customerid\":1,\"place\":\"abroad\"}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testAlias.
@Test
public void testAlias() throws Exception {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("vw");
mmd.addSourceMetadata("ddl", "create view x (a string primary key, b integer) " + "as select 'xyz', 123 union all select 'abc', 456;");
mmd.setModelType(Model.Type.VIRTUAL);
teiid.deployVDB("northwind", mmd);
Properties props = new Properties();
localClient = getClient(teiid.getDriver(), "northwind", props);
ContentResponse response = http.GET(baseURL + "/northwind/vw/x?$filter=" + Encoder.encode("a eq @a") + "&" + Encoder.encode("@a") + "=" + Encoder.encode("'xyz'"));
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"xyz\",\"b\":123}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testSkipTokenWithPageSize.
@Test
public void testSkipTokenWithPageSize() throws Exception {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("vw");
mmd.addSourceMetadata("ddl", "create view x (a string primary key, b integer) as " + "select 'xyz', 123 union all select 'abc', 456;");
mmd.setModelType(Model.Type.VIRTUAL);
teiid.deployVDB("northwind", mmd);
ContentResponse response = http.newRequest(baseURL + "/northwind/vw/x?$format=json").header("Prefer", "odata.maxpagesize=1").send();
assertEquals(200, response.getStatus());
String starts = "{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"abc\",\"b\":456}]," + "\"@odata.nextLink\":\"" + baseURL + "/northwind/vw/x?$format=json&$skiptoken=";
String ends = ",1\"}";
assertTrue(response.getContentAsString(), response.getContentAsString().startsWith(starts));
assertTrue(response.getContentAsString(), response.getContentAsString().endsWith(ends));
assertEquals("odata.maxpagesize=1", getHeader(response, "Preference-Applied"));
JsonNode node = getJSONNode(response);
String nextLink = node.get("@odata.nextLink").asText();
response = http.GET(nextLink);
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"xyz\",\"b\":123}]}", response.getContentAsString());
} finally {
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testCheckGeneratedColumns.
@Test
public void testCheckGeneratedColumns() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
@Override
public UpdateExecution createUpdateExecution(org.teiid.language.Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
GeneratedKeys keys = executionContext.getCommandContext().returnGeneratedKeys(new String[] { "a" }, new Class[] { String.class });
keys.addKey(Arrays.asList("ax"));
return super.createUpdateExecution(command, executionContext, metadata, connection);
}
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
hc.addUpdate("INSERT INTO x (b, c) VALUES ('b', 5)", new int[] { 1 });
// this gets called right after insert.
hc.addData("SELECT x.a, x.b, x.c FROM x WHERE x.a = 'ax'", Arrays.asList(Arrays.asList("a", "b", 2)));
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)) options (updatable true);");
mmd.addSourceMapping("x", "x", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider("{\"b\":\"b\", \"c\":5}"), "application/json").send();
assertEquals(201, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
Aggregations