1 import java.io.BufferedReader;
2 import java.io.IOException;
3 import java.io.InputStream;
4 import java.io.InputStreamReader;
6 import org.junit.Before;
9 import gov.nasa.jpf.Config;
10 import gov.nasa.jpf.JPF;
11 import gov.nasa.jpf.util.test.TestJPF;
14 * This is a plain JUnit test to check whether required resource files exist on
17 * @author Jeanderson Candido
20 public class ReporterResourcesTest extends TestJPF {
26 String[] configArgs = { "+vm.class=.vm.MultiProcessVM", "+target.1=HelloWorld", "+target.2=HelloWorld" };
27 this.jpf = new JPF(new Config(configArgs));
31 public void checkResources() throws IOException {
32 assertNotNull("build.properties should exist on classpath", jpf.getClass().getResourceAsStream("build.properties"));
33 assertNotNull(".version should exist on classpath", jpf.getClass().getResourceAsStream(".version"));
37 public void hashMustMatch() {
38 InputStream stream = jpf.getClass().getResourceAsStream(".version");
39 assertEquals("Should have the same hash", fetchCurrentRevisionFromVCS().trim(), readContentFrom(stream).trim());
42 private String fetchCurrentRevisionFromVCS() {
43 String currentRevision = "";
45 Process process = Runtime.getRuntime().exec("git rev-parse HEAD");
47 InputStream output = process.getInputStream();
48 currentRevision = readContentFrom(output);
50 } catch (Exception e) {
53 return currentRevision;
56 private String readContentFrom(InputStream stream) {
57 BufferedReader buffer = new BufferedReader(new InputStreamReader(stream));
58 StringBuilder output = new StringBuilder();
60 while (buffer.ready()) {
61 output.append(buffer.readLine().trim()).append("\n");
63 } catch (IOException e) {
64 fail("Should not have failed while reading the file");
66 return output.toString();