@Test public void testCreateEntity() throws ODataClientException { Product product = createProduct(31, "Best book ever", BOOKS); when(endpointCaller.doPostEntity(anyMapOf(String.class, String.class), any(URL.class), eq(MARSHALLED_MOCKED_ENTITY_CONTENT), any(MediaType.class), any(MediaType.class))).thenReturn(MARSHALLED_MOCKED_ENTITY_RETURNED_CONTENT); when(componentsProvider.getUnmarshaller()).thenReturn(unmarshaller); when(unmarshaller.unmarshallEntity(eq(MARSHALLED_MOCKED_ENTITY_RETURNED_CONTENT), any(ODataClientQuery.class))) .thenReturn(product); Object savedProduct = client.createEntity(emptyMap(), product); assertNotNull(savedProduct); assertEquals(product, savedProduct); }
@Override public Object createEntity(Map<String, String> requestProperties, Object entity) { BasicODataClientQuery query = buildQueryForEntity(entity); String entitySetName = query.getEdmEntityName(); try { URL endpointUrl = new URL(getUrlToCall(entitySetName, false, null)); String marshalledEntity = componentsProvider.getMarshaller().marshallEntity(entity, query); String createdEntity = componentsProvider.getEndpointCaller() .doPostEntity(requestProperties, endpointUrl, marshalledEntity, ATOM_XML, ATOM_XML); return componentsProvider.getUnmarshaller().unmarshallEntity(createdEntity, query); } catch (ODataClientException e) { throw formFailedRequestException(e, entitySetName); } catch (MalformedURLException | UnsupportedEncodingException e) { throw formFailedUrlFormingException(e, entitySetName); } }
DefaultODataClient implements ODataClient { @Override public Object createEntity(Map<String, String> requestProperties, Object entity) { BasicODataClientQuery query = buildQueryForEntity(entity); String entitySetName = query.getEdmEntityName(); try { URL endpointUrl = new URL(getUrlToCall(entitySetName, false, null)); String marshalledEntity = componentsProvider.getMarshaller().marshallEntity(entity, query); String createdEntity = componentsProvider.getEndpointCaller() .doPostEntity(requestProperties, endpointUrl, marshalledEntity, ATOM_XML, ATOM_XML); return componentsProvider.getUnmarshaller().unmarshallEntity(createdEntity, query); } catch (ODataClientException e) { throw formFailedRequestException(e, entitySetName); } catch (MalformedURLException | UnsupportedEncodingException e) { throw formFailedUrlFormingException(e, entitySetName); } } }
DefaultODataClient implements ODataClient { @Override public Object createEntity(Map<String, String> requestProperties, Object entity) { BasicODataClientQuery query = buildQueryForEntity(entity); String entitySetName = query.getEdmEntityName(); try { URL endpointUrl = new URL(getUrlToCall(entitySetName, false, null)); String marshalledEntity = componentsProvider.getMarshaller().marshallEntity(entity, query); String createdEntity = componentsProvider.getEndpointCaller() .doPostEntity(requestProperties, endpointUrl, marshalledEntity, ATOM_XML, ATOM_XML); return componentsProvider.getUnmarshaller().unmarshallEntity(createdEntity, query); } catch (ODataClientException e) { throw formFailedRequestException(e, entitySetName); } catch (MalformedURLException | UnsupportedEncodingException e) { throw formFailedUrlFormingException(e, entitySetName); } }  }
DefaultODataClient implements ODataClient { @Override public Object createEntity(Map<String, String> requestProperties, Object entity) { BasicODataClientQuery query = buildQueryForEntity(entity); String entitySetName = query.getEdmEntityName(); try { URL endpointUrl = new URL(getUrlToCall(entitySetName, false, null)); String marshalledEntity = componentsProvider.getMarshaller().marshallEntity(entity, query); String createdEntity = componentsProvider.getEndpointCaller() .doPostEntity(requestProperties, endpointUrl, marshalledEntity, ATOM_XML, ATOM_XML); return componentsProvider.getUnmarshaller().unmarshallEntity(createdEntity, query); } catch (ODataClientException e) { throw formFailedRequestException(e, entitySetName); } catch (MalformedURLException | UnsupportedEncodingException e) { throw formFailedUrlFormingException(e, entitySetName); } }  @Override void configure(ODataClientComponentsProvider clientComponentsProvider); @Override void encodeURL(boolean encode); @Override Object getEntity(Map<String, String> requestProperties, ODataClientQuery query); @Override Object performAction(Map<String, String> properties, ODataActionClientQuery actionQuery); ODataClientComponentsProvider getComponentsProvider(); @Override List<?> getEntities(Map<String, String> requestProperties, ODataClientQuery query); @Override Object getMetaData(Map<String, String> requestProperties, ODataClientQuery builder); @Override Iterable<Object> getLinks(ODataClientQuery builder); @Override Iterable<Object> getCollections(ODataClientQuery builder); @Override Object createEntity(Map<String, String> requestProperties, Object entity); @Override Object updateEntity(Map<String, String> requestProperties, ODataIdAwareEntity entity); @Override void deleteEntity(Map<String, String> requestProperties, ODataIdAwareEntity entity); @Override InputStream getInputStream(Map<String, String> requestProperties, URL url); }
DefaultODataClient implements ODataClient { @Override public Object createEntity(Map<String, String> requestProperties, Object entity) { BasicODataClientQuery query = buildQueryForEntity(entity); String entitySetName = query.getEdmEntityName(); try { URL endpointUrl = new URL(getUrlToCall(entitySetName, false, null)); String marshalledEntity = componentsProvider.getMarshaller().marshallEntity(entity, query); String createdEntity = componentsProvider.getEndpointCaller() .doPostEntity(requestProperties, endpointUrl, marshalledEntity, ATOM_XML, ATOM_XML); return componentsProvider.getUnmarshaller().unmarshallEntity(createdEntity, query); } catch (ODataClientException e) { throw formFailedRequestException(e, entitySetName); } catch (MalformedURLException | UnsupportedEncodingException e) { throw formFailedUrlFormingException(e, entitySetName); } }  @Override void configure(ODataClientComponentsProvider clientComponentsProvider); @Override void encodeURL(boolean encode); @Override Object getEntity(Map<String, String> requestProperties, ODataClientQuery query); @Override Object performAction(Map<String, String> properties, ODataActionClientQuery actionQuery); ODataClientComponentsProvider getComponentsProvider(); @Override List<?> getEntities(Map<String, String> requestProperties, ODataClientQuery query); @Override Object getMetaData(Map<String, String> requestProperties, ODataClientQuery builder); @Override Iterable<Object> getLinks(ODataClientQuery builder); @Override Iterable<Object> getCollections(ODataClientQuery builder); @Override Object createEntity(Map<String, String> requestProperties, Object entity); @Override Object updateEntity(Map<String, String> requestProperties, ODataIdAwareEntity entity); @Override void deleteEntity(Map<String, String> requestProperties, ODataIdAwareEntity entity); @Override InputStream getInputStream(Map<String, String> requestProperties, URL url);  }