use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testPutRawValue.
@Test
public void testPutRawValue() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addUpdate("UPDATE x SET c = 6 WHERE x.a = 'a'", new int[] { 1 });
hc.addUpdate("UPDATE x SET b = '6' WHERE x.a = 'a'", new int[] { 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)) 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')/c/$value").method("PUT").content(new BytesContentProvider("6".getBytes())).send();
assertEquals(204, response.getStatus());
response = http.newRequest(baseURL + "/northwind/m/x('a')/b/$value").method("PUT").content(new BytesContentProvider("6".getBytes())).send();
assertEquals(204, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testExpand.
@Test
public void testExpand() 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 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")));
hc.addData("SELECT Orders.place, Orders.customerid, Orders.id FROM Orders", Arrays.asList(Arrays.asList("town", 1, 1), Arrays.asList("state", 1, 2), Arrays.asList("country", 1, 3), Arrays.asList("abroad", 1, 4), Arrays.asList("state", 2, 5), Arrays.asList("country", 2, 6), Arrays.asList("town", 3, 7), Arrays.asList("town", 3, 8)));
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" + " 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/Customers?$expand=Orders_FK0&$count=true").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"@odata.count\":4,\"" + "value\":[" + "{\"id\":1,\"name\":\"customer1\"," + "\"Orders_FK0\":[" + "{\"id\":1,\"customerid\":1,\"place\":\"town\"}," + "{\"id\":2,\"customerid\":1,\"place\":\"state\"}," + "{\"id\":3,\"customerid\":1,\"place\":\"country\"}," + "{\"id\":4,\"customerid\":1,\"place\":\"abroad\"}" + "]}," + "{\"id\":2,\"name\":\"customer2\"," + "\"Orders_FK0\":[" + "{\"id\":5,\"customerid\":2,\"place\":\"state\"}," + "{\"id\":6,\"customerid\":2,\"place\":\"country\"}" + "]}," + "{\"id\":3,\"name\":\"customer3\"," + "\"Orders_FK0\":[" + "{\"id\":7,\"customerid\":3,\"place\":\"town\"}," + "{\"id\":8,\"customerid\":3,\"place\":\"town\"}" + "]}," + "{\"id\":4,\"name\":\"customer4\"," + "\"Orders_FK0\":[" + "]}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Customers?$expand=Orders_FK0&$count=true&$skip=3").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"@odata.count\":4,\"value\":[" + "{\"id\":4,\"name\":\"customer4\"," + "\"Orders_FK0\":[]" + "}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Customers?$expand=Orders_FK0&$skip=2").method("GET").header("Prefer", "odata.maxpagesize=1").send();
assertEquals(200, response.getStatus());
assertTrue(response.getContentAsString().startsWith("{\"@odata.context\":\"$metadata#Customers\"," + "\"value\":[{\"id\":3,\"name\":\"customer3\"," + "\"Orders_FK0\":[" + "{\"id\":7,\"customerid\":3,\"place\":\"town\"}," + "{\"id\":8,\"customerid\":3,\"place\":\"town\"}" + "]}]," + "\"@odata.nextLink\":\"http://localhost:"));
assertTrue(response.getContentAsString(), response.getContentAsString().endsWith(",1\"}"));
JsonParser parser = new JsonFactory(new ObjectMapper().configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, true)).createParser(response.getContentAsString());
JsonNode node = parser.getCodec().readTree(parser);
response = http.newRequest(node.get("@odata.nextLink").asText()).method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"value\":[" + "{\"id\":4,\"name\":\"customer4\"," + "\"Orders_FK0\":[]" + "}]}", response.getContentAsString());
// system options
response = http.newRequest(baseURL + "/northwind/m/Customers?$expand=Orders_FK0($skip=2)&$count=true").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"@odata.count\":4,\"" + "value\":[" + "{\"id\":1,\"name\":\"customer1\"," + "\"Orders_FK0\":[" + "{\"id\":3,\"customerid\":1,\"place\":\"country\"}," + "{\"id\":4,\"customerid\":1,\"place\":\"abroad\"}" + "]}," + "{\"id\":2,\"name\":\"customer2\"," + "\"Orders_FK0\":[" + "]}," + "{\"id\":3,\"name\":\"customer3\"," + "\"Orders_FK0\":[" + "]}," + "{\"id\":4,\"name\":\"customer4\"," + "\"Orders_FK0\":[" + "]}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Customers?$expand=Orders_FK0($top=2;$count=true)&$count=true").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"@odata.count\":4,\"" + "value\":[" + "{\"id\":1,\"name\":\"customer1\"," + "\"Orders_FK0@odata.count\":4," + "\"Orders_FK0\":[" + "{\"id\":1,\"customerid\":1,\"place\":\"town\"}," + "{\"id\":2,\"customerid\":1,\"place\":\"state\"}" + "]}," + "{\"id\":2,\"name\":\"customer2\"," + "\"Orders_FK0@odata.count\":2," + "\"Orders_FK0\":[" + "{\"id\":5,\"customerid\":2,\"place\":\"state\"}," + "{\"id\":6,\"customerid\":2,\"place\":\"country\"}" + "]}," + "{\"id\":3,\"name\":\"customer3\"," + "\"Orders_FK0@odata.count\":2," + "\"Orders_FK0\":[" + "{\"id\":7,\"customerid\":3,\"place\":\"town\"}," + "{\"id\":8,\"customerid\":3,\"place\":\"town\"}" + "]}," + "{\"id\":4,\"name\":\"customer4\"," + "\"Orders_FK0@odata.count\":0," + "\"Orders_FK0\":[" + "]}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Customers?$expand=Orders_FK0($top=1;$select=place)&$count=true").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers(Orders_FK0(place))\"," + "\"@odata.count\":4,\"" + "value\":[" + "{\"id\":1,\"name\":\"customer1\"," + "\"Orders_FK0\":[" + "{\"@odata.id\":\"" + baseURL + "/northwind/m/Orders(1)\",\"place\":\"town\"}" + "]}," + "{\"id\":2,\"name\":\"customer2\"," + "\"Orders_FK0\":[" + "{\"@odata.id\":\"" + baseURL + "/northwind/m/Orders(5)\",\"place\":\"state\"}" + "]}," + "{\"id\":3,\"name\":\"customer3\"," + "\"Orders_FK0\":[" + "{\"@odata.id\":\"" + baseURL + "/northwind/m/Orders(7)\",\"place\":\"town\"}" + "]}," + "{\"id\":4,\"name\":\"customer4\"," + "\"Orders_FK0\":[" + "]}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Customers?$expand=Orders_FK0($filter=" + Encoder.encode("place eq ") + "'town')").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"value\":[{\"id\":1,\"name\":\"customer1\"," + "\"Orders_FK0\":[{\"id\":1,\"customerid\":1,\"place\":\"town\"}]}," + "{\"id\":2,\"name\":\"customer2\",\"Orders_FK0\":[]}," + "{\"id\":3,\"name\":\"customer3\"," + "\"Orders_FK0\":[{\"id\":7,\"customerid\":3,\"place\":\"town\"}," + "{\"id\":8,\"customerid\":3,\"place\":\"town\"}]}," + "{\"id\":4,\"name\":\"customer4\",\"Orders_FK0\":[]}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Customers?$expand=Orders_FK0($top=0;$count=true)&$count=true").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"@odata.count\":4,\"" + "value\":[" + "{\"id\":1,\"name\":\"customer1\"," + "\"Orders_FK0@odata.count\":4," + "\"Orders_FK0\":[]}," + "{\"id\":2,\"name\":\"customer2\"," + "\"Orders_FK0@odata.count\":2," + "\"Orders_FK0\":[]}," + "{\"id\":3,\"name\":\"customer3\"," + "\"Orders_FK0@odata.count\":2," + "\"Orders_FK0\":[]}," + "{\"id\":4,\"name\":\"customer4\"," + "\"Orders_FK0@odata.count\":0," + "\"Orders_FK0\":[" + "]}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testAliasNoValue.
@Test
public void testAliasNoValue() 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"));
assertEquals(200, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testArrayInsertResults.
@Test
public void testArrayInsertResults() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addUpdate("INSERT INTO x (a, b) VALUES ('x', (1, 2, 3))", new int[] { 1 });
teiid.addTranslator("x5", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("DDL", "create foreign table x (a string primary key, b integer[], c string[][]) OPTIONS (updatable true);");
mmd.setModelType(Model.Type.PHYSICAL);
mmd.addSourceMapping("x5", "x5", 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("{\"a\":\"x\",\"b\":[1,2,3]}"), "application/json").send();
assertEquals(201, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testCrossJoin.
@Test
public void testCrossJoin() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addUpdate("UPDATE y SET b = 'a' WHERE y.a = 'a'", new int[] { 1 });
teiid.addTranslator("x9", 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)" + ") options (updatable true);");
mmd.addSourceMapping("x9", "x9", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.newRequest(baseURL + "/northwind/m/$crossjoin(x,y)").method("GET").send();
assertEquals(200, response.getStatus());
String u = baseURL + "/northwind/m/";
assertEquals("{\"@odata.context\":\"$metadata#Collection(Edm.ComplexType)\"," + "\"value\":[{\"x@odata.navigationLink\":\"" + u + "x('ABCDEFG')\"," + "\"y@odata.navigationLink\":\"" + u + "y('ABCDEFG')\"}]}", response.getContentAsString());
// TODO: OLINGO-904
/*
response = http.newRequest(baseURL + "/northwind/m/$crossjoin(x,y)?$expand=x")
.method("GET")
.send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Collection(Edm.ComplexType)\",\"value\":[{\"x\":{\"a\":\"ABCDEFG\",\"b\":\"ABCDEFG\"},\"y@odata.navigationLink\":\""+u+"y('ABCDEFG')\"}]}", response.getContentAsString());
*/
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
Aggregations