Search in sources :

Example 1 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.

the class TestODataIntegration method testEntityId.

@Test
public void testEntityId() 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/$entity?$id=" + baseURL + "/northwind/m/x('a')&$select=b").method("GET").send();
        assertEquals(200, response.getStatus());
        assertEquals("{\"@odata.context\":\"$metadata#x(b)/$entity\"," + "\"@odata.id\":\"" + baseURL + "/northwind/m/x('ABCDEFG')\"," + "\"b\":\"ABCDEFG\"}", response.getContentAsString());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 2 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory 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");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 3 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory 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");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) JsonFactory(com.fasterxml.jackson.core.JsonFactory) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) Properties(java.util.Properties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.junit.Test)

Example 4 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory 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");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) StringContentProvider(org.eclipse.jetty.client.util.StringContentProvider) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 5 with HardCodedExecutionFactory

use of org.teiid.runtime.HardCodedExecutionFactory 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");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)46 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)43 Test (org.junit.Test)40 Properties (java.util.Properties)27 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)27 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)10 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 Statement (java.sql.Statement)7 CallableStatement (java.sql.CallableStatement)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FakeServer (org.teiid.jdbc.FakeServer)4 QueryExpression (org.teiid.language.QueryExpression)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 Table (org.teiid.metadata.Table)3 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BeforeClass (org.junit.BeforeClass)2 AbstractQueryTest (org.teiid.jdbc.AbstractQueryTest)2