Package com.boundlessgeo.geoserver.json

Examples of com.boundlessgeo.geoserver.json.JSONObj


        HttpStatus status = status(e);
        response.setStatus(status.value());

        // log at warning if 500, else debug
        LOG.log(status == HttpStatus.INTERNAL_SERVER_ERROR ? Level.WARNING : Level.FINE, e.getMessage(), e);
        return IO.error(new JSONObj(), e );
    }
View Full Code Here


        assertPathExists(root, "bundle.json");

        try (
            FileInputStream in =  new FileInputStream(root.resolve("bundle.json").toFile());
        ) {
            JSONObj obj = JSONWrapper.read(in).toObject();
            assertEquals("blah", obj.str("name"));
        }
    }
View Full Code Here

        MvcResult result = mvc.perform(get("/api/layers/foo/one"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andReturn();

        JSONObj obj = JSONWrapper.read(result.getResponse().getContentAsString()).toObject();

        assertEquals("one", obj.str("name"));
        assertEquals("foo", obj.str("workspace"));
        assertEquals("vector", obj.str("type"));
        assertEquals("The layer", obj.str("title"));
        assertEquals("This layer is cool!", obj.str("description"));

        assertEquals("EPSG:4326", obj.object("proj").str("srs"));

        assertEquals(-180d, obj.object("bbox").object("native").doub("west"), 0.1);
        assertEquals(-90d, obj.object("bbox").object("native").doub("south"), 0.1);
        assertEquals(180d, obj.object("bbox").object("native").doub("east"), 0.1);
        assertEquals(90d, obj.object("bbox").object("native").doub("north"), 0.1);
        assertEquals(0d, obj.object("bbox").object("native").array("center").doub(0), 0.1);
        assertEquals(0d, obj.object("bbox").object("native").array("center").doub(1), 0.1);

        assertEquals(-180d, obj.object("bbox").object("lonlat").doub("west"), 0.1);
        assertEquals(-90d, obj.object("bbox").object("lonlat").doub("south"), 0.1);
        assertEquals(180d, obj.object("bbox").object("lonlat").doub("east"), 0.1);
        assertEquals(90d, obj.object("bbox").object("lonlat").doub("north"), 0.1);
        assertEquals(0d, obj.object("bbox").object("lonlat").array("center").doub(0), 0.1);
        assertEquals(0d, obj.object("bbox").object("lonlat").array("center").doub(1), 0.1);

        assertNotNull(obj.get("modified"));
        assertNotNull(obj.get("created"));

        String mod = obj.object("modified").str("timestamp");
        //TODO: this fails for some configuraitons, like our build server, investigate
        //assertTrue(Pattern.compile(".*\\d{2}:\\d{2}").matcher(mod).matches());
    }
View Full Code Here

        MvcResult result = mvc.perform(req)
            .andExpect(status().isBadRequest())
            .andReturn();

        JSONObj obj = JSONWrapper.read(result.getResponse().getContentAsString()).toObject();
        assertNotNull(obj.get("message"));
        assertNotNull(obj.get("cause"));
        assertNotNull(obj.get("trace"));

        JSONArr arr = obj.array("errors");
        assertEquals(1, arr.size());

        assertNotNull(arr.object(0).get("problem"));
        assertNotNull(arr.object(0).get("line"));
        assertNotNull(arr.object(0).get("column"));
View Full Code Here

            .workspace("foo", "http://scratch.org", true)
                .layer("one").info("The layer", "This layer is cool!")
                .featureType().defaults().store("one")
                .geoServer().build(geoServer);

        JSONObj obj = new JSONObj().put("title", "new title");
        MockHttpServletRequestBuilder req = put("/api/layers/foo/one")
            .contentType(MediaType.APPLICATION_JSON)
            .content(obj.toString());

        mvc.perform(req).andExpect(status().isOk()).andReturn();

        LayerInfo l = gs.getCatalog().getLayerByName("foo:one");
        verify(l, times(1)).setTitle("new title");
View Full Code Here

                    .featureType().defaults().store("foo").workspace()
                .layer("layer3", "layer3")
                    .featureType().defaults().store("foo").workspace()
                .geoServer().build(geoServer);

        JSONObj obj;
        MockHttpServletRequestBuilder req;
        obj = new JSONObj().put("title", "new title");
        req = put("/api/layers/foo/layer3")
            .contentType(MediaType.APPLICATION_JSON)
            .content(obj.toString());
        mvc.perform(req).andExpect(status().isOk()).andReturn();
       
        obj = new JSONObj().put("title", "new title");
        req = put("/api/layers/foo/layer2")
            .contentType(MediaType.APPLICATION_JSON)
            .content(obj.toString());
        mvc.perform(req).andExpect(status().isOk()).andReturn();
       
        obj = new JSONObj().put("title", "new title");
        req = put("/api/layers/foo/layer1")
            .contentType(MediaType.APPLICATION_JSON)
            .content(obj.toString());
        mvc.perform(req).andExpect(status().isOk()).andReturn();

        verify(recent, times(1)).add(eq(LayerInfo.class), hasId("layer3"), eq("foo"));
        verify(recent, times(1)).add(eq(LayerInfo.class), hasId("layer2"), eq("foo"));
        verify(recent, times(1)).add(eq(LayerInfo.class), hasId("layer1"), eq("foo"));
View Full Code Here

        MockGeoServer.get().catalog()
            .workspace("foo", "http://scratch.org", true)
                .layer("one").featureType().defaults().store("sample")
            .geoServer().build(geoServer);

        JSONObj obj = new JSONObj();
        obj.put("name", "foo");
        obj.put("title", "Foo");
        obj.putObject("proj").put("srs", "EPSG:4326");
        obj.putArray("layers").addObject().put("name", "one");

        MockHttpServletRequestBuilder req = post("/api/maps/foo")
            .contentType(MediaType.APPLICATION_JSON)
            .content(obj.toString());

        mvc.perform(req)
            .andExpect(status().isCreated())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON))
            .andReturn();
View Full Code Here

        MockGeoServer.get().catalog()
            .workspace("foo", "http://scratch.org", true)
                .map("map1")
            .geoServer().build(geoServer);

        JSONObj obj = new JSONObj();
        obj.put("name", "map1");
        obj.put("title", "Map1");
        obj.putObject("proj").put("srs", "EPSG:4326");
        obj.putArray("layers").addObject().put("name", "one");

        MockHttpServletRequestBuilder reqBuilder = post("/api/maps/foo")
            .contentType(MediaType.APPLICATION_JSON)
            .content(obj.toString());

        MockHttpServletRequest req = reqBuilder.buildRequest(new MockServletContext());
        try {
            new MapController(geoServer, new RecentObjectCache())
                .create("foo", new JSONObj().put("name", "map1"), req);
            fail();
        }
        catch(BadRequestException e) {
            assertTrue(e.getMessage().contains("already exists"));
        }
View Full Code Here

        MvcResult result = mvc.perform(get("/api/maps/foo/map"))
                .andExpect(status().isOk())
                .andExpect(content().contentType(MediaType.APPLICATION_JSON))
                .andReturn();

        JSONObj obj = JSONWrapper.read(result.getResponse().getContentAsString()).toObject();
        assertEquals("map", obj.str("name"));
        assertEquals("foo", obj.str("workspace"));
        assertEquals("The map", obj.str("title"));
        assertEquals("This map is cool!", obj.str("description"));
       
        assertEquals(-180d, obj.object("bbox").doub("west"), 0.1);
        assertEquals(-90d, obj.object("bbox").doub("south"), 0.1);
        assertEquals(180d, obj.object("bbox").doub("east"), 0.1);
        assertEquals(90d, obj.object("bbox").doub("north"), 0.1);
        assertEquals(0d, obj.object("bbox").array("center").doub(0), 0.1);
        assertEquals(0d, obj.object("bbox").array("center").doub(1), 0.1);

        assertEquals(2, obj.array("layers").size());

        Iterables.find(obj.array("layers"), new Predicate<Object>() {
            @Override
            public boolean apply(@Nullable Object o) {
                return "one".equals(JSONWrapper.wrap(o).toObject().str("name"));
            }
        });
        Iterables.find(obj.array("layers"), new Predicate<Object>() {
            @Override
            public boolean apply(@Nullable Object o) {
                return "two".equals(JSONWrapper.wrap(o).toObject().str("name"));
            }
        });

        assertNotNull(obj.get("modified"));
    }
View Full Code Here

            .andReturn();

        JSONArr arr = JSONWrapper.read(result.getResponse().getContentAsString()).toArray();
        assertEquals(2, arr.size());

        JSONObj obj = arr.object(0);
        assertEquals("foo", obj.str("name"));
        assertTrue(obj.bool("default"));
        assertEquals("http://scratch.org", obj.str("uri"));
        assertTrue(obj.has("modified"));
        assertTrue(obj.object("modified").has("timestamp"));
        assertTrue(obj.object("modified").has("pretty"));

        obj = arr.object(1);
        assertEquals("bar", obj.str("name"));
        assertFalse(obj.bool("default"));
        assertEquals("http://bar.org", obj.str("uri"));
        assertTrue(obj.has("modified"));
        assertTrue(obj.object("modified").has("timestamp"));
        assertTrue(obj.object("modified").has("pretty"));
    }
View Full Code Here

TOP

Related Classes of com.boundlessgeo.geoserver.json.JSONObj

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.