@Test public void testLoadPage_Quaggan_Remote() throws IOException { System.out.println("loadPage(Quaggan remote)"); // NOI18N. final int pageIndex = 1; final int pageSize = 10; final String[] urls = {"https://api.guildwars2.com/v2/quaggans"}; final Class[] classes = {Quaggan.class}; final JsonpContext instance = JsonpContext.SAX; assertEquals(urls.length, classes.length); IntStream.range(0, urls.length) .forEach( index -> { try { final String url = urls[index]; final Class aClass = classes[index]; final String path = String.format("%s?page=%d&page_size=%d", url, pageIndex, pageSize); System.out.println(path); final PageResult page = instance.loadPage(aClass, new URL(path)); assertNotNull(page); } catch (IOException ex) { fail(ex.getMessage()); } }); }
@Test public void testLoadObject_CurrencyAmount() throws IOException, InstantiationException, IllegalAccessException, NoSuchFieldException { System.out.println("loadObject(CurrencyAmount)"); // NOI18N. final URL url = getClass() .getResource("/api/web/gw2/mapping/v2/account/wallet/currency_amount1.json"); // NOI18N. final JsonpContext instance = JsonpContext.SAX; final CurrencyAmount value = instance.loadObject(CurrencyAmount.class, url); assertNotNull(value); assertEquals(1, value.getId()); assertEquals(100001, value.getValue()); }
@Test public void testLoadObject_Quaggan_Remote() throws IOException, InstantiationException, IllegalAccessException, NoSuchFieldException { System.out.println("loadObject(Quaggan remote)"); // NOI18N. final String expId = "box"; // NOI18N. final Optional<URL> expURL = Optional.of(new URL("https://static.staticwars.com/quaggans/box.jpg")); // NOI18N. final URL url = getClass().getResource("/api/web/gw2/mapping/v2/quaggans/quaggan1.json"); // NOI18N. final JsonpContext instance = JsonpContext.SAX; final Quaggan value = instance.loadObject(Quaggan.class, url); assertNotNull(value); assertEquals(expId, value.getId()); assertEquals(expURL, value.getUrl()); }
@Test public void testLoadPage_Integer_Local() throws IOException { System.out.println("loadPage(integer local)"); // NOI18N. final int expPageTotal = 1; final int expPageSize = 10; final int expResultCount = expPageSize; final int expResultTotal = expPageSize; final URL url = getClass().getResource("test_page1.json"); // NOI18N. final JsonpContext instance = JsonpContext.SAX; final PageResult<Integer> value = instance.loadPage(Integer.class, url); assertNotNull(value); assertEquals(expPageTotal, value.getPageTotal()); assertEquals(expPageSize, value.getPageSize()); assertEquals(expResultCount, value.getResultCount()); assertEquals(expResultTotal, value.getResultTotal()); final Iterator<Integer> iterator = value.iterator(); IntStream.range(0, expPageSize) .forEach( index -> { final int expResult = index; final int result = iterator.next(); assertEquals(expResult, result); }); }