Example #1
0
  /**
   * Adds a style to the test setup.
   *
   * <p>To set up the style a file named <tt>filename</tt> is copied from the classpath relative to
   * the <tt>scope</tt> parameter.
   *
   * @param name The name of the style.
   * @param filename The filename to copy from classpath.
   * @param scope Class from which to load sld resource from.
   */
  public void addStyle(String name, String filename, Class scope, Catalog catalog)
      throws IOException {
    File styles = catalog.getResourceLoader().findOrCreateDirectory(data, "styles");

    catalog.getResourceLoader().copyFromClassPath(filename, new File(styles, filename), scope);

    StyleInfo style = catalog.getStyleByName(name);
    if (style == null) {
      style = catalog.getFactory().createStyle();
      style.setName(name);
    }
    style.setFilename(filename);
    if (style.getId() == null) {
      catalog.add(style);
    } else {
      catalog.save(style);
    }
  }
Example #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;
  }