Esempio n. 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;
  }
Esempio n. 2
0
  public MockCatalogBuilder style(String name) {
    String filename = name + ".sld";
    if (getClass().getResourceAsStream(filename) == null) {
      return this;
    }

    String sId = newId();
    Version version = Styles.Handler.SLD_10.getVersion();

    final StyleInfo s = createNiceMock(StyleInfo.class);
    styles.add(s);

    expect(s.getId()).andReturn(sId);
    expect(s.getName()).andReturn(name).anyTimes();
    expect(s.getFilename()).andReturn(filename).anyTimes();
    expect(s.getSLDVersion()).andReturn(version).anyTimes();
    try {
      expect(s.getStyle())
          .andReturn(
              Styles.style(Styles.parse(getClass().getResourceAsStream(filename), null, version)))
          .anyTimes();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    expect(catalog.getStyle(sId)).andReturn(s).anyTimes();
    expect(catalog.getStyleByName(name)).andReturn(s).anyTimes();

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

    callback.onStyle(name, s, this);
    replay(s);
    return this;
  }