@Test public void testToStringListWithNullElement() { List<AuthorityURLInfo> list = new ArrayList<AuthorityURLInfo>(); AuthorityURLInfo auth1 = new AuthorityURL(); auth1.setName("auth1"); auth1.setHref("http://geoserver.org/auth1?"); list.add(auth1); list.add(null); String actual = AuthorityURLInfoInfoListConverter.toString(list); String expected = "[{\"name\":\"auth1\",\"href\":\"http://geoserver.org/auth1?\"}]"; assertEquals(expected, actual); }
/** * @param str a JSON array representation of a list of {@link AuthorityURLInfo} objects * @return the list of parsed authrority URL from the argument JSON array * @throws IllegalArgumentException if {@code str} can't be parsed to a JSONArray */ public static List<AuthorityURLInfo> fromString(String str) throws IllegalArgumentException { try { final JSONArray array; array = JSONArray.fromObject(str); final int size = array.size(); List<AuthorityURLInfo> list = new ArrayList<AuthorityURLInfo>(size); JSONObject jsonAuth; for (int i = 0; i < size; i++) { jsonAuth = array.getJSONObject(i); AuthorityURL auth = new AuthorityURL(); auth.setName(jsonAuth.getString(NAME)); auth.setHref(jsonAuth.getString(HREF)); list.add(auth); } return list; } catch (JSONException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
@Test public void testToString() { List<AuthorityURLInfo> list = new ArrayList<AuthorityURLInfo>(); AuthorityURLInfo auth1 = new AuthorityURL(); auth1.setName("auth1"); auth1.setHref("http://geoserver.org/auth1?"); list.add(auth1); AuthorityURLInfo auth2 = new AuthorityURL(); auth2.setName("auth2"); auth2.setHref("http://geoserver.org/auth2;someparam=somevalue&"); list.add(auth2); String actual = AuthorityURLInfoInfoListConverter.toString(list); String expected = "[{\"name\":\"auth1\",\"href\":\"http://geoserver.org/auth1?\"},{\"name\":\"auth2\",\"href\":\"http://geoserver.org/auth2;someparam=somevalue&\"}]"; assertEquals(expected, actual); }
private boolean forceServiceRootLayerHaveGeogigAuthURL() { LOGGER.fine("Checking for root layer geogig auth URL"); WMSInfo serviceInfo = geoserver.getService(WMSInfo.class); if (serviceInfo == null) { LOGGER.info("No WMSInfo available in GeoServer. This is strange but can happen"); return false; } List<AuthorityURLInfo> authorityURLs = serviceInfo.getAuthorityURLs(); for (AuthorityURLInfo urlInfo : authorityURLs) { if (AUTHORITY_URL_NAME.equals(urlInfo.getName())) { LOGGER.fine("geogig root layer auth URL already exists"); return true; } } AuthorityURL geogigAuthURL = new AuthorityURL(); geogigAuthURL.setName(AUTHORITY_URL_NAME); geogigAuthURL.setHref(AUTHORITY_URL); serviceInfo.getAuthorityURLs().add(geogigAuthURL); LOGGER.fine("Saving geogig root layer auth URL"); geoserver.save(serviceInfo); LOGGER.info("geogig root layer auth URL saved"); return true; }
@Test public void testFromString() { final String serialized = "[{\"name\":\"auth1\",\"href\":\"http://geoserver.org/auth1?\"},{\"name\":\"auth2\",\"href\":\"http://geoserver.org/auth2;someparam=somevalue&\"}]"; List<AuthorityURLInfo> expected = new ArrayList<AuthorityURLInfo>(); AuthorityURLInfo auth1 = new AuthorityURL(); auth1.setName("auth1"); auth1.setHref("http://geoserver.org/auth1?"); expected.add(auth1); AuthorityURLInfo auth2 = new AuthorityURL(); auth2.setName("auth2"); auth2.setHref("http://geoserver.org/auth2;someparam=somevalue&"); expected.add(auth2); List<AuthorityURLInfo> actual; actual = AuthorityURLInfoInfoListConverter.fromString(serialized); assertEquals(expected, actual); }
@Test public void testPropertyEqualsIndexed() { AuthorityURLInfo aurl1 = new AuthorityURL(); aurl1.setName("url1"); AuthorityURLInfo aurl2 = new AuthorityURL(); aurl2.setName("url2"); AuthorityURLInfo aurl3 = new AuthorityURL(); aurl3.setName("url3"); vectorLayer.setAuthorityURLs(Arrays.asList(aurl1, aurl2, aurl3)); assertTrue(equal("authorityURLs[1]", aurl1).evaluate(vectorLayer)); assertTrue(equal("authorityURLs[1].name", aurl1.getName()).evaluate(vectorLayer)); assertTrue(equal("authorityURLs[2]", aurl2).evaluate(vectorLayer)); assertTrue(equal("authorityURLs[2].name", aurl2.getName()).evaluate(vectorLayer)); assertTrue(equal("authorityURLs[3]", aurl3).evaluate(vectorLayer)); assertTrue(equal("authorityURLs[3].name", aurl3.getName()).evaluate(vectorLayer)); }
@Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { List<AuthorityURLInfo> list = authorityURLs.getModelObject(); AuthorityURLInfo authorityURL = new AuthorityURL(); list.add(authorityURL); authorityURLs.setModelObject(list); AuthorityURLListEditor.this.convertInput(); updateLinksVisibility(); target.addComponent(container); }
@Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { List<AuthorityURLInfo> list = authorityURLs.getModelObject(); AuthorityURLInfo authorityURL = new AuthorityURL(); list.add(authorityURL); authorityURLs.setModelObject(list); AuthorityURLListEditor.this.convertInput(); updateLinksVisibility(); target.add(container); } };
private void addAuthUrl(final String name, final String url, List<AuthorityURLInfo> target) { AuthorityURLInfo auth = new AuthorityURL(); auth.setName(name); auth.setHref(url); target.add(auth); }
private void addAuthUrl(final String name, final String url, List<AuthorityURLInfo> target) { AuthorityURLInfo auth = new AuthorityURL(); auth.setName(name); auth.setHref(url); target.add(auth); }