@Test
  public void testOdata() throws Exception {
    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"Loopy\" version=\"1\">\n"
            + "    <model name=\"MarketData\">\n"
            + "        <source name=\"text-connector2\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE G1 (e1 string, e2 integer PRIMARY KEY);\n"
            + "                CREATE FOREIGN TABLE G2 (e1 string, e2 integer PRIMARY KEY) OPTIONS (UPDATABLE 'true');\n"
            + "        ]]> </metadata>\n"
            + "    </model>\n"
            + "</vdb>";

    admin.deploy(
        "loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));

    assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

    WebClient client =
        WebClient.create("http://*****:*****@mm://localhost:31000;user=user;password=user", null);

    PreparedStatement ps =
        conn.prepareCall(
            "select t.* from xmltable('/*:Edmx/*:DataServices/*:Schema[@Alias=\"MarketData\"]' passing xmlparse(document cast(? as clob))) as t");
    ps.setAsciiStream(1, (InputStream) response.getEntity());

    ResultSet rs = ps.executeQuery();
    rs.next();

    assertEquals(
        ObjectConverterUtil.convertFileToString(
            UnitTestUtil.getTestDataFile("loopy-metadata4-results.txt")),
        rs.getString(1));

    conn.close();

    // try an invalid url
    client = WebClient.create("http://localhost:8080/odata/x/y$metadata");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    response = client.invoke("GET", null);
    assertEquals(500, response.getStatus());

    admin.undeploy("loopy-vdb.xml");
  }
  @Test
  public void testProjectedColumns() throws Exception {
    TransformationMetadata metadata =
        RealMetadataFactory.fromDDL(
            ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")),
            "northwind",
            "nw");
    EdmDataServices eds = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
    Client client = mock(Client.class);
    stub(client.getMetadataStore()).toReturn(metadata.getMetadataStore());
    stub(client.getMetadata()).toReturn(eds);
    MockProvider.CLIENT = client;
    ArgumentCaptor<String> sql = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<EdmEntitySet> entitySet = ArgumentCaptor.forClass(EdmEntitySet.class);

    OEntity entity = createCustomersEntity(eds);
    List<OEntity> result = new ArrayList<OEntity>();
    result.add(entity);

    when(client.sqlExecute(
            anyString(),
            anyListOf(SQLParam.class),
            any(EdmEntitySet.class),
            anyMapOf(String.class, Boolean.class)))
        .thenReturn(result);

    ClientRequest request =
        new ClientRequest(
            TestPortProvider.generateURL(
                "/odata/northwind/Customers?$select=CustomerID,CompanyName,Address"));
    ClientResponse<String> response = request.get(String.class);
    verify(client)
        .sqlExecute(
            sql.capture(),
            anyListOf(SQLParam.class),
            entitySet.capture(),
            anyMapOf(String.class, Boolean.class));

    Assert.assertEquals(
        "SELECT g0.Address, g0.CustomerID, g0.CompanyName FROM Customers AS g0", sql.getValue());
    Assert.assertEquals(200, response.getStatus());
    // Assert.assertEquals("", response.getEntity());
  }
  @Test
  public void testMetadata() throws Exception {
    TransformationMetadata metadata =
        RealMetadataFactory.fromDDL(
            ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")),
            "northwind",
            "nw");
    EdmDataServices eds = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
    Client client = mock(Client.class);
    stub(client.getMetadataStore()).toReturn(metadata.getMetadataStore());
    stub(client.getMetadata()).toReturn(eds);
    MockProvider.CLIENT = client;

    StringWriter sw = new StringWriter();

    EdmxFormatWriter.write(eds, sw);

    ClientRequest request =
        new ClientRequest(TestPortProvider.generateURL("/odata/northwind/$metadata"));
    ClientResponse<String> response = request.get(String.class);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(sw.toString(), response.getEntity());
  }