@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")); }
@Test public void testEntitySetsQuery() { final SimpleEntity e1 = 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); } }, "Id"); Assert.assertEquals(1, c.getEntitySets().count()); Assert.assertEquals("entitySetName", c.getEntitySets().first().getTitle()); Assert.assertEquals("entitySetName", c.getEntitySets().first().getHref()); }
@Test public void Test500InvalidKey() { thrown.expect(RuntimeException.class); thrown.expectMessage(JUnitMatchers.containsString("found 500")); ODataConsumer consumer = ODataConsumer.create(endpointUri); consumer.getEntity("Customers", 1).execute(); }
@Test public void Test404NoEntity() { ODataConsumer consumer = ODataConsumer.create(endpointUri); OEntity customer = null; try { customer = consumer.getEntity("Customers", "NOUSER").execute(); } catch (Exception e) { Assert.fail(e.getMessage()); } Assert.assertNull(customer); }
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))); }