@Test public void testGetObjects() throws Exception { final int ITEM_COUNT = 3; doReturn(getAgendaProgressJson(ITEM_COUNT)).when(mockURLRequestPerformer).performURLRequest(any(), any()); DataObjectResponse<AgendaProgress> dataObjectFeed = client.getObjects(""); Assert.assertEquals(dataObjectFeed.getAll().size(), ITEM_COUNT); Assert.assertEquals(dataObjectFeed.getAll().get(0).getClass(), AgendaProgress.class); }
public DataObjectResponse<T> getObjects(String queryParams) { HttpURLConnection urlConnection = null; try { urlConnection = httpUrlConnectionFactory.getHttpURLConnection(endpointURL + queryParams); urlConnection.setRequestMethod("GET"); String result = urlRequestPerformer.performURLRequest( urlConnection, null); logger.info("Object: {}", result); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { return null; } return parseDataObjectResponse(result); } catch(IOException e) { return buildExceptionResponse(e, String.format("Failed to perform retrieve for query %1$s: %2$s", objectClass.getSimpleName(), queryParams), urlConnection); } }
HttpObjectClient implements ObjectClient<T> { public DataObjectResponse<T> getObjects(String queryParams) { HttpURLConnection urlConnection = null; try { urlConnection = httpUrlConnectionFactory.getHttpURLConnection(endpointURL + queryParams); urlConnection.setRequestMethod("GET"); String result = urlRequestPerformer.performURLRequest( urlConnection, null); logger.info("Object: {}", result); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { return null; } return parseDataObjectResponse(result); } catch(IOException e) { return buildExceptionResponse(e, String.format("Failed to perform retrieve for query %1$s: %2$s", objectClass.getSimpleName(), queryParams), urlConnection); } } }
HttpObjectClient implements ObjectClient<T> { public DataObjectResponse<T> getObjects(String queryParams) { HttpURLConnection urlConnection = null; try { urlConnection = httpUrlConnectionFactory.getHttpURLConnection(endpointURL + queryParams); urlConnection.setRequestMethod("GET"); String result = urlRequestPerformer.performURLRequest( urlConnection, null); logger.info("Object: {}", result); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { return null; } return parseDataObjectResponse(result); } catch(IOException e) { return buildExceptionResponse(e, String.format("Failed to perform retrieve for query %1$s: %2$s", objectClass.getSimpleName(), queryParams), urlConnection); } } HttpObjectClient(String endpointURL, HttpURLConnectionFactory httpUrlConnectionFactory, Class<T> clazz); }
HttpObjectClient implements ObjectClient<T> { public DataObjectResponse<T> getObjects(String queryParams) { HttpURLConnection urlConnection = null; try { urlConnection = httpUrlConnectionFactory.getHttpURLConnection(endpointURL + queryParams); urlConnection.setRequestMethod("GET"); String result = urlRequestPerformer.performURLRequest( urlConnection, null); logger.info("Object: {}", result); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { return null; } return parseDataObjectResponse(result); } catch(IOException e) { return buildExceptionResponse(e, String.format("Failed to perform retrieve for query %1$s: %2$s", objectClass.getSimpleName(), queryParams), urlConnection); } } HttpObjectClient(String endpointURL, HttpURLConnectionFactory httpUrlConnectionFactory, Class<T> clazz); DataObjectResponse<T> getObjects(String queryParams); DataObjectResponse<T> getObjects(List<Query> queries); DataObjectResponse<T> getObject(String id); DataObjectResponse<T> persistObject(T object); DataObjectResponse<T> updateObject(T object, String id); DataObjectResponse<T> deleteObject(String id); Class<T> getObjectClass(); void setUrlRequestPerformer(URLRequestPerformer urlRequestPerformer); }
HttpObjectClient implements ObjectClient<T> { public DataObjectResponse<T> getObjects(String queryParams) { HttpURLConnection urlConnection = null; try { urlConnection = httpUrlConnectionFactory.getHttpURLConnection(endpointURL + queryParams); urlConnection.setRequestMethod("GET"); String result = urlRequestPerformer.performURLRequest( urlConnection, null); logger.info("Object: {}", result); if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { return null; } return parseDataObjectResponse(result); } catch(IOException e) { return buildExceptionResponse(e, String.format("Failed to perform retrieve for query %1$s: %2$s", objectClass.getSimpleName(), queryParams), urlConnection); } } HttpObjectClient(String endpointURL, HttpURLConnectionFactory httpUrlConnectionFactory, Class<T> clazz); DataObjectResponse<T> getObjects(String queryParams); DataObjectResponse<T> getObjects(List<Query> queries); DataObjectResponse<T> getObject(String id); DataObjectResponse<T> persistObject(T object); DataObjectResponse<T> updateObject(T object, String id); DataObjectResponse<T> deleteObject(String id); Class<T> getObjectClass(); void setUrlRequestPerformer(URLRequestPerformer urlRequestPerformer); final static String DEFAULT_RESPONSE_MESSAGE; }