public ImmutableList<GlobalSetting> parse(final InputStream is) { return Jsons.toObjects(is, GlobalSetting.class); } }
public static MocoEventAction post(final Resource url, final Object object) { return post(checkNotNull(url, "URL should not be null"), Jsons.toJson(checkNotNull(object, "Content should not be null"))); }
public static <T> ImmutableList<T> toObjects(final ImmutableList<InputStream> streams, final Class<T> elementClass) { final CollectionType type = DEFAULT_FACTORY.constructCollectionType(List.class, elementClass); return FluentIterable.from(streams).transformAndConcat(Jsons.<T>toObject(type)).toList(); }
public static <T> ImmutableList<T> toObjects(final InputStream stream, final Class<T> elementClass) { return toObjects(of(stream), elementClass); }
public static void assertEquals(final Object expected, final String actual) { try { JSONAssert.assertEquals(Jsons.toJson(expected), actual, JSONCompareMode.LENIENT); } catch (JSONException e) { throw new AssertionError("fail to parse entity to json"); } } }
public Object getJson() { try { return Jsons.toObject(this.request.getContent().toString(), Object.class); } catch (Exception e) { throw new IllegalArgumentException("Json content is expected", e); } } }
public static <T> ImmutableList<T> toObjects(final String value, final Class<T> elementClass) { return toObjects(new ByteArrayInputStream(value.getBytes()), elementClass); }
@Override public MessageContent readFor(final Optional<? extends Request> request) { return MessageContent.content().withContent(toJson(pojo)).build(); }
private Plain asPlain(final HttpResponse response) throws IOException { HttpEntity entity = checkJsonResponse(response); return Jsons.toObject(entity.getContent(), Plain.class); }
private ImmutableList<Session> restoreSessions(final File file) { try { InputStream inputStream = new FileInputStream(file); return Jsons.toObjects(inputStream, Session.class); } catch (MocoException me) { logger.error("exception found", me); return of(); } catch (IOException e) { throw new MocoException(e); } }
public static void assertEquals(final Object expected, final HttpResponse response) { assertEquals(Jsons.toJson(expected), response); }
private Plain asPlain(org.apache.http.HttpResponse response) throws IOException { assertThat(response.getStatusLine().getStatusCode(), is(200)); HttpEntity entity = response.getEntity(); MediaType mediaType = MediaType.parse(entity.getContentType().getValue()); assertThat(mediaType.type(), is("application")); assertThat(mediaType.subtype(), is("json")); return Jsons.toObject(entity.getContent(), Plain.class); }
public final T parseServer(final ImmutableList<InputStream> streams, final Optional<Integer> port, final MocoConfig... configs) { ImmutableList<SessionSetting> settings = Jsons.toObjects(streams, SessionSetting.class); return createServer(settings, port, configs); } }
@Override public void run() throws Exception { HttpResponse httpResponse = helper.postForResponse(remoteUrl("/targets"), Jsons.toJson(resource1)); assertThat(httpResponse.getStatusLine().getStatusCode(), is(201)); assertThat(httpResponse.getFirstHeader("Location").getValue(), is("/targets/123")); } });
private List<Plain> asPlains(final HttpResponse response) throws IOException { HttpEntity entity = checkJsonResponse(response); return Jsons.toObjects(entity.getContent(), Plain.class); }
@Override public void run() throws Exception { HttpResponse httpResponse = helper.putForResponse(remoteUrl("/targets/1"), Jsons.toJson(resource1)); assertThat(httpResponse.getStatusLine().getStatusCode(), is(200)); } });
@Test public void should_get_all_resource() throws IOException { runWithConfiguration("rest/rest.json"); org.apache.http.HttpResponse response = helper.getResponseWithHeader(remoteUrl("/all-resources"), of(HttpHeaders.CONTENT_TYPE, "application/json")); assertThat(response.getStatusLine().getStatusCode(), is(200)); HttpEntity entity = response.getEntity(); List<Plain> plains = Jsons.toObjects(entity.getContent(), Plain.class); assertThat(plains.size(), is(2)); }
@Override public void run() throws Exception { HttpResponse httpResponse1 = helper.putForResponse(remoteUrl("/targets/1"), Jsons.toJson(resource1)); assertThat(httpResponse1.getStatusLine().getStatusCode(), is(200)); HttpResponse httpResponse2 = helper.putForResponse(remoteUrl("/targets/2"), Jsons.toJson(resource1)); assertThat(httpResponse2.getStatusLine().getStatusCode(), is(200)); } });
@Override public void run() throws Exception { List<Plain> plains = Jsons.toObjects(helper.get(remoteUrl("/targets?foo=bar")), Plain.class); assertThat(plains.size(), is(2)); HttpResponse response = helper.getResponse(remoteUrl("/targets")); assertThat(response.getStatusLine().getStatusCode(), is(404)); } });
@Override public void run() throws Exception { HttpResponse httpResponse = helper.putForResponseWithHeaders(remoteUrl("/targets/1"), Jsons.toJson(resource1), of(HttpHeaders.IF_MATCH, "moco")); assertThat(httpResponse.getStatusLine().getStatusCode(), is(200)); } });