Пример #1
0
  public MockCatalogBuilder layerGroup(
      String name, List<String> layerNames, List<String> styleNames) {

    final LayerGroupInfo lg = createMock(LayerGroupInfo.class);
    layerGroups.add(lg);

    expect(lg.getId()).andReturn(newId()).anyTimes();
    expect(lg.getName()).andReturn(name).anyTimes();

    List<PublishedInfo> grpLayers = new ArrayList<PublishedInfo>();
    List<StyleInfo> grpStyles = new ArrayList<StyleInfo>();
    for (int i = 0; i < layerNames.size(); i++) {
      String layerName = layerNames.get(i);
      LayerInfo l = null;
      for (LayerInfo layer : layers) {
        if (layerName.equals(layer.getName())) {
          l = layer;
          break;
        }
      }

      if (l == null) {
        throw new RuntimeException("No such layer: " + layerName);
      }

      grpLayers.add(l);

      StyleInfo s = null;
      if (styleNames != null) {
        String styleName = styleNames.get(i);
        for (StyleInfo style : styles) {
          if (styleName.equals(style.getName())) {
            s = style;
            break;
          }
        }
      }

      grpStyles.add(s);
    }
    expect(lg.getLayers()).andReturn(grpLayers).anyTimes();
    expect(lg.getStyles()).andReturn(grpStyles).anyTimes();

    lg.accept((CatalogVisitor) anyObject());
    expectLastCall()
        .andAnswer(
            new VisitAnswer() {
              @Override
              protected void doVisit(CatalogVisitor visitor) {
                visitor.visit(lg);
              }
            })
        .anyTimes();

    expect(catalog.getLayerGroupByName(name)).andReturn(lg).anyTimes();

    callback.onLayerGroup(name, lg, this);
    replay(lg);
    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()));
  }
  @Test
  public void modificationProxySerializeTest() throws Exception {
    Catalog catalog = getCatalog();

    // workspace
    WorkspaceInfo ws = catalog.getWorkspaceByName(MockData.CITE_PREFIX);
    WorkspaceInfo ws2 = serialize(ws);
    assertSame(ModificationProxy.unwrap(ws), ModificationProxy.unwrap(ws2));

    // namespace
    NamespaceInfo ns = catalog.getNamespaceByPrefix(MockData.CITE_PREFIX);
    NamespaceInfo ns2 = serialize(ns);
    assertSame(ModificationProxy.unwrap(ns), ModificationProxy.unwrap(ns2));

    // data store and related objects
    DataStoreInfo ds = catalog.getDataStoreByName(MockData.CITE_PREFIX);
    DataStoreInfo ds2 = serialize(ds);
    assertSame(ModificationProxy.unwrap(ds), ModificationProxy.unwrap(ds2));
    assertSame(
        ModificationProxy.unwrap(ds.getWorkspace()), ModificationProxy.unwrap(ds2.getWorkspace()));

    // coverage store and related objects
    CoverageStoreInfo cs = catalog.getCoverageStoreByName(MockData.TASMANIA_DEM.getLocalPart());
    CoverageStoreInfo cs2 = serialize(cs);
    assertSame(ModificationProxy.unwrap(cs), ModificationProxy.unwrap(cs2));
    assertSame(
        ModificationProxy.unwrap(cs.getWorkspace()), ModificationProxy.unwrap(cs2.getWorkspace()));

    // feature type and related objects
    FeatureTypeInfo ft = catalog.getFeatureTypeByName(getLayerId(MockData.BRIDGES));
    FeatureTypeInfo ft2 = serialize(ft);
    assertSame(ModificationProxy.unwrap(ft), ModificationProxy.unwrap(ft2));
    assertSame(ModificationProxy.unwrap(ft.getStore()), ModificationProxy.unwrap(ft2.getStore()));

    // coverage and related objects
    CoverageInfo ci = catalog.getCoverageByName(getLayerId(MockData.TASMANIA_DEM));
    CoverageInfo ci2 = serialize(ci);
    assertSame(ModificationProxy.unwrap(ci), ModificationProxy.unwrap(ci2));
    assertSame(ModificationProxy.unwrap(ci.getStore()), ModificationProxy.unwrap(ci.getStore()));

    // style
    StyleInfo streamsStyle = catalog.getStyleByName("Streams");
    StyleInfo si2 = serialize(streamsStyle);
    assertSame(ModificationProxy.unwrap(streamsStyle), ModificationProxy.unwrap(si2));

    // layer and related objects
    LayerInfo li = catalog.getLayerByName(getLayerId(MockData.BRIDGES));
    // ... let's add an extra style

    li.getStyles().add(streamsStyle);
    catalog.save(li);
    LayerInfo li2 = serialize(li);
    assertSame(ModificationProxy.unwrap(li), ModificationProxy.unwrap(li2));
    assertSame(
        ModificationProxy.unwrap(li.getResource()), ModificationProxy.unwrap(li2.getResource()));
    assertSame(
        ModificationProxy.unwrap(li.getDefaultStyle()),
        ModificationProxy.unwrap(li2.getDefaultStyle()));
    assertSame(
        ModificationProxy.unwrap(li.getStyles().iterator().next()),
        ModificationProxy.unwrap(li2.getStyles().iterator().next()));

    // try a group layer
    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.PONDS)));
    cb.calculateLayerGroupBounds(lg);
    lg.setName("test-lg");
    catalog.add(lg);
    // ... make sure we get a proxy
    lg = catalog.getLayerGroupByName("test-lg");
    if (lg instanceof SecuredLayerGroupInfo) {
      lg = ((SecuredLayerGroupInfo) lg).unwrap(LayerGroupInfo.class);
    }
    LayerGroupInfo lg2 = serialize(lg);
    assertSame(ModificationProxy.unwrap(lg), ModificationProxy.unwrap(lg2));
    assertSame(
        ModificationProxy.unwrap(lg.getLayers().get(0)),
        ModificationProxy.unwrap(lg2.getLayers().get(0)));
    assertSame(
        ModificationProxy.unwrap(lg.getLayers().get(1)),
        ModificationProxy.unwrap(lg2.getLayers().get(1)));

    // now check a half modified proxy
    LayerInfo lim = catalog.getLayerByName(getLayerId(MockData.BRIDGES));
    // ... let's add an extra style
    lim.setDefaultStyle(streamsStyle);
    lim.getStyles().add(streamsStyle);
    // clone and check
    LayerInfo lim2 = serialize(lim);
    assertSame(
        ModificationProxy.unwrap(lim.getDefaultStyle()),
        ModificationProxy.unwrap(lim2.getDefaultStyle()));
    assertSame(
        ModificationProxy.unwrap(lim.getStyles().iterator().next()),
        ModificationProxy.unwrap(lim2.getStyles().iterator().next()));

    // mess a bit with the metadata map too
    String key = "workspaceKey";
    lim.getMetadata().put(key, ws);
    LayerInfo lim3 = serialize(lim);
    assertSame(ModificationProxy.unwrap(lim), ModificationProxy.unwrap(lim3));
    assertSame(
        ModificationProxy.unwrap(lim.getMetadata().get(key)),
        ModificationProxy.unwrap(lim3.getMetadata().get(key)));
  }