Example #1
0
  /**
   * POST Test: specify an option.
   *
   * @throws IOException I/O exception
   */
  @Test
  public void postOption() throws IOException {
    assertEquals(
        "2",
        post(
            "",
            "<query xmlns=\""
                + URI
                + "\">"
                + "<text>2, delete node &lt;a/&gt;</text>"
                + "<option name='"
                + MainOptions.MIXUPDATES.name()
                + "' value='true'/></query>",
            APP_XML));

    try {
      post(
          "",
          "<query xmlns=\""
              + URI
              + "\">"
              + "<text>1, delete node &lt;a/&gt;</text>"
              + "<option name='"
              + MainOptions.MIXUPDATES.name()
              + "' value='false'/></query>",
          APP_XML);
      fail("Error expected.");
    } catch (final IOException ex) {
      assertContains(ex.getMessage(), "[XUST0001]");
    }
  }
Example #2
0
 /** POST Test: execute buggy query. */
 @Test
 public void postErr() {
   try {
     assertEquals("", post("", "<query xmlns=\"" + URI + "\"><text>(</text></query>", APP_XML));
   } catch (final IOException ex) {
     assertContains(ex.getMessage(), "[XPST0003]");
   }
 }
  @Before
  public void setUp() {
    try {
      URL res = this.getClass().getClassLoader().getResource("toolspecs");
      // use the file toolspec xml as the input file too (for this test)
      toolspecsDir = res.getFile();
      repo = new LocalToolRepository(res.getFile());

    } catch (IOException ex) {
      fail(ex.getMessage());
    }
  }
Example #4
0
 public static void writeFile(String dir, String fileName, String content) {
   try {
     File f = new File(dir, fileName);
     FileWriter w = new FileWriter(f);
     BufferedWriter bw = new BufferedWriter(w);
     bw.write(content);
     bw.close();
     w.close();
   } catch (IOException ioe) {
     System.err.println("can't write file");
     ioe.printStackTrace(System.err);
   }
 }
Example #5
0
 private static ModuleImpl newModuleImpl(String name, String version, ModuleState state)
     throws CoreException {
   ModuleImpl module = null;
   String resource = "xml/" + name + ".xml";
   try {
     module = loadModule(resource);
   } catch (IOException e) {
     e.printStackTrace();
     Assert.fail(resource + ": " + e.getMessage());
   }
   module.setVersion(Version.parseVersion(version));
   module.setState(state);
   return module;
 }
Example #6
0
  /**
   * Wow! much faster than compiling outside of VM. Finicky though. Had rules called r and modulo.
   * Wouldn't compile til I changed to 'a'.
   */
  protected boolean compile(String fileName) {
    String classpathOption = "-classpath";

    String[] args =
        new String[] {
          "javac",
          "-d",
          tmpdir,
          classpathOption,
          tmpdir + pathSep + CLASSPATH,
          tmpdir + "/" + fileName
        };
    String cmdLine =
        "javac"
            + " -d "
            + tmpdir
            + " "
            + classpathOption
            + " "
            + tmpdir
            + pathSep
            + CLASSPATH
            + " "
            + fileName;
    // System.out.println("compile: "+cmdLine);

    File f = new File(tmpdir, fileName);
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    //		DiagnosticCollector<JavaFileObject> diagnostics =
    //			new DiagnosticCollector<JavaFileObject>();

    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

    Iterable<? extends JavaFileObject> compilationUnits =
        fileManager.getJavaFileObjectsFromFiles(Arrays.asList(f));

    Iterable<String> compileOptions =
        Arrays.asList(new String[] {"-d", tmpdir, "-cp", tmpdir + pathSep + CLASSPATH});

    JavaCompiler.CompilationTask task =
        compiler.getTask(null, fileManager, null, compileOptions, null, compilationUnits);
    boolean ok = task.call();

    try {
      fileManager.close();
    } catch (IOException ioe) {
      ioe.printStackTrace(System.err);
    }

    //		List<String> errors = new ArrayList<String>();
    //		for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
    //			errors.add(
    //				String.valueOf(diagnostic.getLineNumber())+
    //				": " + diagnostic.getMessage(null));
    //		}
    //		if ( errors.size()>0 ) {
    //			System.err.println("compile stderr from: "+cmdLine);
    //			System.err.println(errors);
    //			return false;
    //		}
    return ok;

    /*
    File outputDir = new File(tmpdir);
    try {
    	Process process =
    		Runtime.getRuntime().exec(args, null, outputDir);
    	StreamVacuum stdout = new StreamVacuum(process.getInputStream());
    	StreamVacuum stderr = new StreamVacuum(process.getErrorStream());
    	stdout.start();
    	stderr.start();
    	process.waitFor();
              stdout.join();
              stderr.join();
    	if ( stdout.toString().length()>0 ) {
    		System.err.println("compile stdout from: "+cmdLine);
    		System.err.println(stdout);
    	}
    	if ( stderr.toString().length()>0 ) {
    		System.err.println("compile stderr from: "+cmdLine);
    		System.err.println(stderr);
    	}
    	int ret = process.exitValue();
    	return ret==0;
    }
    catch (Exception e) {
    	System.err.println("can't exec compilation");
    	e.printStackTrace(System.err);
    	return false;
    }
    */
  }