@Test public void testGet() throws Exception { MockGeoServer.get().catalog() .workspace("foo", "http: .layer("foo").workspace().catalog() .workspace("bar", "http: .geoServer().build(geoServer); GeoServerResourceLoader resourceLoader = mock(GeoServerResourceLoader.class); when(resourceLoader.get("workspaces/foo/workspace.xml")).thenAnswer(mockResource()); when(resourceLoader.get("workspaces/bar/workspace.xml")).thenAnswer(mockResource()); Catalog catalog = geoServer.getCatalog(); when(catalog.getResourceLoader()).thenReturn(resourceLoader); MvcResult result = mvc.perform(get("/app/api/workspaces/foo")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); JSONObj obj = JSONWrapper.read(result.getResponse().getContentAsString()).toObject(); assertEquals("foo", obj.str("name")); assertEquals("http: assertTrue(obj.bool("default")); assertEquals(0, obj.integer("maps").intValue()); assertEquals(1, obj.integer("layers").intValue()); assertEquals(0, obj.integer("stores").intValue()); result = mvc.perform(get("/app/api/workspaces/bar")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); obj = JSONWrapper.read(result.getResponse().getContentAsString()).toObject(); assertEquals("bar", obj.str("name")); assertEquals("http: assertFalse(obj.bool("default")); }
@RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj get(@PathVariable String wsName) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); WorkspaceInfo def = cat.getDefaultWorkspace(); JSONObj obj = IO.workspace(new JSONObj(), ws, namespaceFor(ws), def != null && def.equals(ws)); obj.put("maps", countMaps(ws, cat)); obj.put("layers", countLayers(ws, cat)); obj.put("stores", countStores(ws, cat)); return obj; }
WorkspaceController extends ApiController { @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj get(@PathVariable String wsName) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); WorkspaceInfo def = cat.getDefaultWorkspace(); JSONObj obj = IO.workspace(new JSONObj(), ws, namespaceFor(ws), def != null && def.equals(ws)); obj.put("maps", countMaps(ws, cat)); obj.put("layers", countLayers(ws, cat)); obj.put("stores", countStores(ws, cat)); return obj; } }
WorkspaceController extends ApiController { @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj get(@PathVariable String wsName) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); WorkspaceInfo def = cat.getDefaultWorkspace(); JSONObj obj = IO.workspace(new JSONObj(), ws, namespaceFor(ws), def != null && def.equals(ws)); obj.put("maps", countMaps(ws, cat)); obj.put("layers", countLayers(ws, cat)); obj.put("stores", countStores(ws, cat)); return obj; } @Autowired  WorkspaceController(GeoServer geoServer, RecentObjectCache recentCache); }
WorkspaceController extends ApiController { @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj get(@PathVariable String wsName) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); WorkspaceInfo def = cat.getDefaultWorkspace(); JSONObj obj = IO.workspace(new JSONObj(), ws, namespaceFor(ws), def != null && def.equals(ws)); obj.put("maps", countMaps(ws, cat)); obj.put("layers", countLayers(ws, cat)); obj.put("stores", countStores(ws, cat)); return obj; } @Autowired  WorkspaceController(GeoServer geoServer, RecentObjectCache recentCache); @RequestMapping(method = RequestMethod.GET) @ResponseBody JSONArr list(); @RequestMapping(value = "/recent", method = RequestMethod.GET) @ResponseBody JSONArr recent(); @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody JSONObj create(@RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) @ResponseBody JSONObj get(@PathVariable String wsName); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PATCH) @ResponseBody JSONObj patch(@PathVariable String wsName, @RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PUT) @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.NO_CONTENT) void delete(@PathVariable String wsName, HttpServletResponse response); @RequestMapping(value = "/{wsName}/export", method = RequestMethod.POST, produces = APPLICATION_ZIP_VALUE) @ResponseStatus(value = HttpStatus.OK) void export(@PathVariable String wsName, HttpServletResponse response); @RequestMapping(value = "/{wsName}/import", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(value = HttpStatus.OK) void inport(@PathVariable String wsName, HttpServletRequest request, HttpServletResponse response); }
WorkspaceController extends ApiController { @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj get(@PathVariable String wsName) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); WorkspaceInfo def = cat.getDefaultWorkspace(); JSONObj obj = IO.workspace(new JSONObj(), ws, namespaceFor(ws), def != null && def.equals(ws)); obj.put("maps", countMaps(ws, cat)); obj.put("layers", countLayers(ws, cat)); obj.put("stores", countStores(ws, cat)); return obj; } @Autowired  WorkspaceController(GeoServer geoServer, RecentObjectCache recentCache); @RequestMapping(method = RequestMethod.GET) @ResponseBody JSONArr list(); @RequestMapping(value = "/recent", method = RequestMethod.GET) @ResponseBody JSONArr recent(); @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody JSONObj create(@RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) @ResponseBody JSONObj get(@PathVariable String wsName); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PATCH) @ResponseBody JSONObj patch(@PathVariable String wsName, @RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PUT) @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.NO_CONTENT) void delete(@PathVariable String wsName, HttpServletResponse response); @RequestMapping(value = "/{wsName}/export", method = RequestMethod.POST, produces = APPLICATION_ZIP_VALUE) @ResponseStatus(value = HttpStatus.OK) void export(@PathVariable String wsName, HttpServletResponse response); @RequestMapping(value = "/{wsName}/import", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(value = HttpStatus.OK) void inport(@PathVariable String wsName, HttpServletRequest request, HttpServletResponse response); static final String APPLICATION_ZIP_VALUE; }