public MockCatalogBuilder coverageStore(String name, String filename, String format) { String csId = newId(); WorkspaceInfo ws = workspaces.peekLast(); NamespaceInfo ns = namespaces.peekLast(); final CoverageStoreInfo cs = createNiceMock(CoverageStoreInfo.class); coverageStores.add(cs); initStore(cs, CoverageStoreInfo.class, csId, name, ws); File covDir = new File(dataDirRoot, name); final File covFile = new File(covDir, filename); expect(cs.getURL()).andReturn(DataUtilities.fileToURL(covFile).toString()).anyTimes(); expect(cs.getType()) .andAnswer( new IAnswer<String>() { @Override public String answer() throws Throwable { return lookupGridFormat(covFile).getName(); } }) .anyTimes(); expect(cs.getFormat()) .andAnswer( new IAnswer<AbstractGridFormat>() { @Override public AbstractGridFormat answer() throws Throwable { return lookupGridFormat(covFile); } }) .anyTimes(); expect(cs.getConnectionParameters()).andReturn(new HashMap()).anyTimes(); expect(catalog.getCoverageStore(csId)).andReturn(cs).anyTimes(); expect(catalog.getCoverageStoreByName(name)).andReturn(cs).anyTimes(); expect(catalog.getCoverageStoreByName(ws.getName(), name)).andReturn(cs).anyTimes(); expect(catalog.getCoverageStoreByName(ws, name)).andReturn(cs).anyTimes(); cs.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(cs); } }) .anyTimes(); callback.onStore(name, cs, ws, this); replay(cs); return this; }
public MockCatalogBuilder workspace(String name, String uri) { String wsId = newId(); String nsId = newId(); final WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); workspaces.add(ws); expect(ws.getId()).andReturn(wsId).anyTimes(); expect(ws.getName()).andReturn(name).anyTimes(); expect(ws.getMetadata()).andReturn(new MetadataMap()).anyTimes(); expect(catalog.getWorkspace(wsId)).andReturn(ws).anyTimes(); expect(catalog.getWorkspaceByName(name)).andReturn(ws).anyTimes(); final NamespaceInfo ns = createNiceMock(NamespaceInfo.class); namespaces.add(ns); expect(ns.getId()).andReturn(nsId).anyTimes(); expect(ns.getName()).andReturn(name).anyTimes(); expect(ns.getPrefix()).andReturn(name).anyTimes(); expect(ns.getMetadata()).andReturn(new MetadataMap()).anyTimes(); expect(catalog.getNamespace(nsId)).andReturn(ns).anyTimes(); expect(catalog.getNamespaceByPrefix(name)).andReturn(ns).anyTimes(); expect(catalog.getNamespaceByURI(uri)).andReturn(ns).anyTimes(); ws.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ws); } }) .anyTimes(); ns.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ns); } }) .anyTimes(); callback.onWorkspace(name, ws, this); replay(ws, ns); return this; }
public MockCatalogBuilder dataStore(String name) { String dsId = newId(); final WorkspaceInfo ws = workspaces.peekLast(); final NamespaceInfo ns = namespaces.peekLast(); final DataStoreInfo ds = createNiceMock(DataStoreInfo.class); dataStores.add(ds); initStore(ds, DataStoreInfo.class, dsId, name, ws); // setup the property data store final File propDir = new File(dataDirRoot, name); HashMap cxParams = new HashMap(); cxParams.put(PropertyDataStoreFactory.DIRECTORY.key, propDir); cxParams.put(PropertyDataStoreFactory.NAMESPACE.key, ns.getURI()); expect(ds.getConnectionParameters()).andReturn(cxParams).anyTimes(); try { expect(ds.getDataStore(null)) .andAnswer( (IAnswer) new IAnswer<DataAccess>() { @Override public DataAccess answer() throws Throwable { return new PropertyDataStore(propDir, ns.getURI()); } }) .anyTimes(); } catch (IOException e) { } expect(catalog.getDataStore(dsId)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(name)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(ws.getName(), name)).andReturn(ds).anyTimes(); expect(catalog.getDataStoreByName(ws, name)).andReturn(ds).anyTimes(); ds.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override protected void doVisit(CatalogVisitor visitor) { visitor.visit(ds); } }) .anyTimes(); callback.onStore(name, ds, ws, this); replay(ds); return this; }
@Test public void testCascadeDeleteWorkspaceSpecific() throws Exception { Catalog catalog = getCatalog(); WorkspaceInfo ws = catalog.getWorkspaceByName(MockData.ROAD_SEGMENTS.getPrefix()); // create a workspace specific group CatalogBuilder cb = new CatalogBuilder(catalog); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.getLayers().add(catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS))); lg.getLayers().add(catalog.getLayerByName(getLayerId(MockData.STREAMS))); cb.calculateLayerGroupBounds(lg); lg.setName("test-lg"); lg.setWorkspace(ws); catalog.add(lg); // make a style a workspace specific StyleInfo style = catalog.getStyleByName(MockData.ROAD_SEGMENTS.getLocalPart()); style.setWorkspace(ws); catalog.save(style); // check we are getting the groups and styles reported properly CascadeRemovalReporter reporter = new CascadeRemovalReporter(catalog); ws.accept(reporter); List<StyleInfo> styles = reporter.getObjects(StyleInfo.class, ModificationType.DELETE); assertEquals(1, styles.size()); assertEquals(style, styles.get(0)); List<LayerGroupInfo> groups = reporter.getObjects(LayerGroupInfo.class, ModificationType.DELETE); assertEquals(1, groups.size()); assertEquals(lg, groups.get(0)); // now remove for real CascadeDeleteVisitor remover = new CascadeDeleteVisitor(catalog); ws.accept(remover); assertNull(catalog.getWorkspaceByName(ws.getName())); assertNull(catalog.getStyleByName(style.getName())); assertNull(catalog.getLayerGroupByName(lg.getName())); }
public void visit(WorkspaceInfo workspace) { // remove owned stores for (StoreInfo s : catalog.getStoresByWorkspace(workspace, StoreInfo.class)) { s.accept(this); } // remove any linked namespaces NamespaceInfo ns = catalog.getNamespaceByPrefix(workspace.getName()); if (ns != null) { ns.accept(this); } catalog.remove(workspace); }
<T extends StoreInfo> void initStore( T s, Class<T> clazz, String sId, String name, WorkspaceInfo ws) { expect(s.getId()).andReturn(sId).anyTimes(); expect(s.getName()).andReturn(name).anyTimes(); expect(s.getWorkspace()).andReturn(ws).anyTimes(); expect(s.getCatalog()).andReturn(catalog).anyTimes(); expect(s.isEnabled()).andReturn(true).anyTimes(); expect(catalog.getStore(sId, clazz)).andReturn(s).anyTimes(); expect(catalog.getStore(sId, StoreInfo.class)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(name, clazz)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(name, StoreInfo.class)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(ws.getName(), name, clazz)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(ws.getName(), name, StoreInfo.class)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(ws, name, clazz)).andReturn(s).anyTimes(); expect(catalog.getStoreByName(ws, name, StoreInfo.class)).andReturn(s).anyTimes(); }
public MockCatalogBuilder commit() { if (!featureTypes.isEmpty() || !coverages.isEmpty()) { if (!featureTypes.isEmpty()) { DataStoreInfo ds = dataStores.peekLast(); expect(catalog.getResourcesByStore(ds, FeatureTypeInfo.class)) .andReturn(featureTypes) .anyTimes(); expect(catalog.getResourcesByStore(ds, ResourceInfo.class)) .andReturn((List) featureTypes) .anyTimes(); expect(catalog.getFeatureTypesByDataStore(ds)).andReturn(featureTypes).anyTimes(); } if (!coverages.isEmpty()) { CoverageStoreInfo cs = coverageStores.peekLast(); expect(catalog.getResourcesByStore(cs, CoverageInfo.class)).andReturn(coverages).anyTimes(); expect(catalog.getResourcesByStore(cs, ResourceInfo.class)) .andReturn((List) coverages) .anyTimes(); expect(catalog.getCoveragesByCoverageStore(cs)).andReturn(coverages).anyTimes(); } // clear out local lists but push up to be included when this workspace is complete featureTypesByNamespace.addAll(featureTypes); featureTypes = new LinkedList<FeatureTypeInfo>(); coveragesByNamespace.addAll(coverages); coverages = new LinkedList<CoverageInfo>(); } else if (!dataStores.isEmpty() || !coverageStores.isEmpty()) { WorkspaceInfo ws = workspaces.peekLast(); NamespaceInfo ns = namespaces.peekLast(); expect(catalog.getStoresByWorkspace(ws.getName(), DataStoreInfo.class)) .andReturn(dataStores) .anyTimes(); expect(catalog.getStoresByWorkspace(ws, DataStoreInfo.class)) .andReturn(dataStores) .anyTimes(); expect(catalog.getDataStoresByWorkspace(ws.getName())).andReturn(dataStores).anyTimes(); expect(catalog.getDataStoresByWorkspace(ws)).andReturn(dataStores).anyTimes(); expect(catalog.getStoresByWorkspace(ws.getName(), CoverageStoreInfo.class)) .andReturn(coverageStores) .anyTimes(); expect(catalog.getStoresByWorkspace(ws, CoverageStoreInfo.class)) .andReturn(coverageStores) .anyTimes(); expect(catalog.getCoverageStoresByWorkspace(ws.getName())) .andReturn(coverageStores) .anyTimes(); expect(catalog.getCoverageStoresByWorkspace(ws)).andReturn(coverageStores).anyTimes(); List<StoreInfo> l = new LinkedList<StoreInfo>(dataStores); l.addAll(coverageStores); expect(catalog.getStoresByWorkspace(ws.getName(), StoreInfo.class)).andReturn(l).anyTimes(); expect(catalog.getStoresByWorkspace(ws, StoreInfo.class)).andReturn(l).anyTimes(); // add all the resources for this workspace List<ResourceInfo> m = new LinkedList(featureTypesByNamespace); m.addAll(coveragesByNamespace); expect(catalog.getResourcesByNamespace(ns, ResourceInfo.class)).andReturn(m).anyTimes(); // expect(catalog.getResourcesByNamespace(ns.getPrefix(), // ResourceInfo.class)).andReturn(m).anyTimes(); expect(catalog.getResourcesByNamespace(ns, FeatureTypeInfo.class)) .andReturn(featureTypesByNamespace) .anyTimes(); // expect(catalog.getResourcesByNamespace(ns.getPrefix(), FeatureTypeInfo.class)) // .andReturn(featureTypesByNamespace).anyTimes(); expect(catalog.getResourcesByNamespace(ns, CoverageInfo.class)) .andReturn(coveragesByNamespace) .anyTimes(); // expect(catalog.getResourcesByNamespace(ns.getPrefix(), CoverageInfo.class)) // .andReturn(coveragesByNamespace).anyTimes(); dataStoresAll.addAll(dataStores); dataStores = new LinkedList(); coverageStoresAll.addAll(coverageStores); coverageStores = new LinkedList(); featureTypesAll.addAll(featureTypesByNamespace); featureTypesByNamespace = new LinkedList(); coveragesAll.addAll(coveragesByNamespace); coveragesByNamespace = new LinkedList(); } else if (!workspaces.isEmpty()) { // all the resources List<ResourceInfo> l = new LinkedList<ResourceInfo>(featureTypesAll); l.addAll(coveragesAll); expect(catalog.getResources(ResourceInfo.class)).andReturn(l).anyTimes(); expect(catalog.getResources(FeatureTypeInfo.class)).andReturn(featureTypesAll).anyTimes(); expect(catalog.getResources(CoverageInfo.class)).andReturn(coverages).anyTimes(); expect(catalog.getFeatureTypes()).andReturn(featureTypesAll).anyTimes(); expect(catalog.getCoverages()).andReturn(coveragesAll).anyTimes(); // add all the stores List<StoreInfo> m = new LinkedList<StoreInfo>(dataStoresAll); m.addAll(coverageStoresAll); expect(catalog.getStores(StoreInfo.class)).andReturn(m).anyTimes(); expect(catalog.getStores(DataStoreInfo.class)).andReturn(dataStoresAll).anyTimes(); expect(catalog.getStores(CoverageStoreInfo.class)).andReturn(coverageStoresAll).anyTimes(); // add all the styles expect(catalog.getStyles()).andReturn(styles).anyTimes(); // add all the layer groups expect(catalog.getLayerGroups()).andReturn(layerGroups).anyTimes(); // add all the workspaces/namespaces expect(catalog.getWorkspaces()).andReturn(workspaces).anyTimes(); expect(catalog.getNamespaces()).andReturn(namespaces).anyTimes(); // default workspace/namespace expect(catalog.getDefaultWorkspace()).andReturn(workspaces.peekFirst()).anyTimes(); expect(catalog.getDefaultNamespace()).andReturn(namespaces.peekFirst()).anyTimes(); replay(catalog); featureTypesAll = new LinkedList(); coveragesAll = new LinkedList(); dataStoresAll = new LinkedList(); coverageStoresAll = new LinkedList(); styles = new LinkedList(); workspaces = new LinkedList(); namespaces = new LinkedList(); } return this; }