Example #1
0
  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;
  }
Example #2
0
  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;
  }