@KOTest public void loadError() throws InterruptedException { if (js == null) { js = Models.bind(new JSONik(), newContext()); js.applyBindings(); js.setFetched(null); js.fetchArray("http://127.0.0.1:54253/does/not/exist.txt"); } if (js.getFetchedResponse() == null) { throw new InterruptedException(); } assert "Exception".equals(js.getFetchedResponse()) : js.getFetchedResponse(); }
@KOTest public void loadError() throws InterruptedException { if (js == null) { js = Models.bind(new JSONik(), newContext()); js.applyBindings(); js.setFetched(null); js.fetchArray("http://127.0.0.1:54253/does/not/exist.txt"); } if (js.getFetchedResponse() == null) { throw new InterruptedException(); } assertEquals("Exception", js.getFetchedResponse(), "Response " + js.getFetchedResponse()); }
throw new InterruptedException(); String res = js.getFetchedResponse(); int line = res.indexOf('\n'); String msg; assert "PUT".equals(res) : "Server was queried with PUT method: " + js.getFetchedResponse();
throw new InterruptedException(); String res = js.getFetchedResponse(); int line = res.indexOf('\n'); String msg; assertEquals("PUT", res, "Server was queried with PUT method: " + js.getFetchedResponse());
@KOTest public void loadAndParsePlainText() throws Exception { if (js == null) { url = Utils.prepareURL( JSONTest.class, "{'firstName': 'Sitar', 'sex': 'MALE'}", "text/plain" ); js = Models.bind(new JSONik(), ctx = newContext()); js.applyBindings(); js.setFetched(null); js.fetchPlain(url); } String s = js.getFetchedResponse(); if (s == null) { throw new InterruptedException(); } assertTrue(s.contains("Sitar"), "The text contains Sitar value: " + s); assertTrue(s.contains("MALE"), "The text contains MALE value: " + s); Person p = Models.parse(ctx, Person.class, new ByteArrayInputStream(s.getBytes())); assertEquals("Sitar", p.getFirstName(), "Expecting Sitar: " + p.getFirstName()); assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex()); assertEquals(ctx, onCallback, "Same context"); }
@KOTest public void loadAndParsePlainTextOnArray() throws Exception { if (js == null) { url = Utils.prepareURL( JSONTest.class, "[ {'firstName': 'Sitar', 'sex': 'MALE'} ]", "text/plain" ); js = Models.bind(new JSONik(), ctx = newContext()); js.applyBindings(); js.setFetched(null); js.fetchPlain(url); } String s = js.getFetchedResponse(); if (s == null) { throw new InterruptedException(); } assertTrue(s.contains("Sitar"), "The text contains Sitar value: " + s); assertTrue(s.contains("MALE"), "The text contains MALE value: " + s); Person p = Models.parse(ctx, Person.class, new ByteArrayInputStream(s.getBytes())); assertEquals("Sitar", p.getFirstName(), "Expecting Sitar: " + p.getFirstName()); assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex()); assertEquals(ctx, onCallback, "Same context"); }