@Test
  public void testSimpleEntity() {

    final SimpleEntity e1 = new SimpleEntity();
    final SimpleEntity e2 = new SimpleEntity();
    final SimpleEntity e3 = new SimpleEntity();

    String namespace = "testSetNameAndType";
    InMemoryProducer p = new InMemoryProducer(namespace);
    ODataConsumer c = new ODataConsumerAdapter(p);

    p.register(
        SimpleEntity.class,
        "entitySetName",
        "entityTypeName",
        new Func<Iterable<SimpleEntity>>() {
          @Override
          public Iterable<SimpleEntity> apply() {
            return Enumerable.create(e1, e2, e3);
          }
        },
        "Id");

    Assert.assertEquals(3, c.getEntities("entitySetName").execute().count());
    Assert.assertNotNull(c.getEntity("entitySetName", OEntityKey.create(e1.getId())).execute());

    Assert.assertNotNull(p.getMetadata().findEdmEntitySet("entitySetName"));
    Assert.assertNotNull(p.getMetadata().findEdmEntityType(namespace + ".entityTypeName"));
  }
Esempio n. 2
0
  protected void deleteEntityAndTest(ODataConsumer consumer, String customerID) {

    OEntity customer = consumer.getEntity("Customers", customerID).execute();
    Assert.assertNotNull(customer);
    Assert.assertEquals(customerID, customer.getEntityKey().asSingleValue());

    Assert.assertNotNull(
        consumer
            .getEntities("Customers")
            .execute()
            .firstOrNull(OPredicates.entityPropertyValueEquals("CustomerID", customerID)));

    consumer.deleteEntity("Customers", customer.getEntityKey()).execute();

    Assert.assertNull(
        consumer
            .getEntities("Customers")
            .execute()
            .firstOrNull(OPredicates.entityPropertyValueEquals("CustomerID", customerID)));
  }