@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()); }
@KOTest public void loadAndParseJSONSentToArray() throws InterruptedException { if (js == null) { url = Utils.prepareURL( JSONTest.class, "{'firstName': 'Sitar', 'sex': 'MALE'}", "application/json" ); js = Models.bind(new JSONik(), newContext()); js.applyBindings(); js.setFetched(null); js.fetchArray(url); } Person p = js.getFetched(); if (p == null) { throw new InterruptedException(); } assert "Sitar".equals(p.getFirstName()) : "Expecting Sitar: " + p.getFirstName(); assert Sex.MALE.equals(p.getSex()) : "Expecting MALE: " + p.getSex(); }
@KOTest public void loadAndParseJSONArray() throws InterruptedException { if (js == null) { url = Utils.prepareURL( JSONTest.class, "[{'firstName': 'Gitar', 'sex': 'FEMALE'}," + "{'firstName': 'Peter', 'sex': 'MALE'}" + "]", "application/json" ); js = Models.bind(new JSONik(), newContext()); js.applyBindings(); js.setFetched(null); js.fetchArray(url); } Person p = js.getFetched(); if (p == null) { throw new InterruptedException(); } assert js.getFetchedCount() == 2 : "We got two values: " + js.getFetchedCount(); assert "Gitar".equals(p.getFirstName()) : "Expecting Gitar: " + p.getFirstName(); assert Sex.FEMALE.equals(p.getSex()) : "Expecting FEMALE: " + p.getSex(); }
@KOTest public void loadAndParseJSONSentToArray() throws InterruptedException { if (js == null) { url = Utils.prepareURL( JSONTest.class, "{'firstName': 'Sitar', 'sex': 'MALE'}", "application/json" ); js = Models.bind(new JSONik(), newContext()); js.applyBindings(); js.setFetched(null); js.fetchArray(url); } Person p = js.getFetched(); if (p == null) { throw new InterruptedException(); } assertEquals("Sitar", p.getFirstName(), "Expecting Sitar: " + p.getFirstName()); assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex()); }
@KOTest public void loadAndParseJSONArray() throws InterruptedException { if (js == null) { url = Utils.prepareURL( JSONTest.class, "[{'firstName': 'Gitar', 'sex': 'FEMALE'}," + "{'firstName': 'Peter', 'sex': 'MALE'}" + "]", "application/json" ); js = Models.bind(new JSONik(), newContext()); js.applyBindings(); js.setFetched(null); js.fetchArray(url); } Person p = js.getFetched(); if (p == null) { throw new InterruptedException(); } assertEquals(js.getFetchedCount(), 2, "We got two values: " + js.getFetchedCount()); assertEquals("Gitar", p.getFirstName(), "Expecting Gitar: " + p.getFirstName()); assertEquals(Sex.FEMALE, p.getSex(), "Expecting FEMALE: " + p.getSex()); }