Exemplo n.º 1
0
  @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());
  }
Exemplo n.º 2
0
  @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());
  }