Пример #1
0
  private void RoundTrip(String iniFilename, String serviceName)
      throws IOException, ParserConfigurationException, SAXException, URISyntaxException {

    StringSource ini = StringSourcePersistence.inferFromSystemResource(iniFilename);
    String newline = EncodingUtil.detectNewline(ini.getString());
    List<String> iniText = ini.getLines(newline);

    List<IniSection> iniSections = IniSection.parse(iniText, false);

    Generator g = new Generator(serviceName);
    StringSource config = g.genXmlInstance(iniSections);
    StringSource schema = g.genXsdSchema(iniSections);
    StringSource template = g.genVelocityTemplate(ini, iniSections, newline);

    // save(template, serviceName, "vm");
    // save(config, serviceName, "xml");
    // save(schema, serviceName, "xsd");
    // save(ini, serviceName, "ini");

    XmlUtil.validateXml(
        StringSourceUriPair.inputSource(schema, "schema"),
        StringSourceUriPair.inputSource(config, "config"));

    ts.createService(serviceName);

    ts.setSchema(serviceName, "main.xsd", schema.getData(), schema.getContentType("xml"));
    ts.setTemplate(serviceName, template.getData(), template.getContentType("plain"));
    ts.setConfig(serviceName, "default.xml", config.getData(), config.getContentType("xml"));

    Response processResponse = ts.processDefaultTemplate(serviceName);
    StringSource roundTrip = StringSourceConverters.fromResponse(processResponse);
    // save(roundTrip, serviceName, "rt.ini");
    assertEquals(ini.getString(), roundTrip.getString());
  }
Пример #2
0
 @SuppressWarnings("unused")
 private void save(StringSource ss, String serviceName, String suffix) throws IOException {
   (new File(dir)).mkdirs();
   File f = new File(dir, serviceName + "." + suffix);
   f.delete();
   f.delete();
   StringSourcePersistence.save(ss, f);
 }