Subversion Repositories DevTools

Rev

Rev 7047 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
/**
2
 *  A collection of utilities used in testing
3
 */
4
package com.erggroup.buildtool.utf;
5
 
6
import java.io.File;
7
import java.io.FileReader;
8
import java.io.FileWriter;
9
import java.io.IOException;
10
 
11
public class Utilities
12
{
13
 
14
    private Utilities() {
15
        throw new IllegalStateException("Utilities class");
16
      }
17
 
18
    /**
19
     * Check build file against golden image
20
     * Golden images are held in the 'expected' subdirectory
21
     * 
22
     * @param content
23
     *            - Generated build file
24
     * @param baseName
25
     *            - Base name used to save buildfile and for golden image
26
     * @return boolean - True if the build file matches the golden image
27
     */
28
    static public boolean checkBuildfile(String content, String baseName)
29
    {
30
        String buildFileName;
31
        String testFilename;
32
        String expected = "";
33
        String user = "";
34
        boolean rv = false;
35
 
36
        // persist the generated build file content to daemon2.xml for visibility
37
        buildFileName = new String(baseName + ".xml");
38
        testFilename = new String("work/expected/" + baseName + ".xml");
39
 
40
        try
41
        {
42
            File buildFile = new File("build", buildFileName);
43
            FileWriter buildFileWriter = new FileWriter(buildFile);
44
            buildFileWriter.write(content);
45
            buildFileWriter.close();
46
 
47
            File expectedBuildFile = new File(testFilename);
48
            FileReader expectedBuildFileReader = new FileReader(expectedBuildFile);
49
            char[] expectedBuildFileContent = new char[(int) expectedBuildFile.length()];
50
            expectedBuildFileReader.read(expectedBuildFileContent);
51
            expectedBuildFileReader.close();
52
 
53
            expected = new String(expectedBuildFileContent);
54
            expected = expected.replace("\r", "");
55
 
56
            user = content.replace("\r", "");
57
 
58
            rv = user.compareTo(expected) == 0;
59
        }
60
        catch (IOException e)
61
        {
62
            System.out.println("checkBuildFile caught IOException:" + baseName);
63
            rv = false;
64
        }
65
 
66
        return rv;
67
    }
68
 
69
    /** Compare a named file with its expected value
70
     *  Golden images are held in the 'expected' subdirectory 
71
     * 
72
     * @param file1             - test file
73
     * @return                  - True if the files match
74
     */
75
    public static boolean checkBuildfiles(String file1)
76
    {
77
        boolean rv = false;
78
        String fileG = new String("work/expected/" + file1);
79
 
80
        try
81
        {
82
 
83
            File expected1 = new File(fileG);
84
            FileReader expected1Reader = new FileReader(expected1);
85
            char[] expected1Content = new char[(int) expected1.length()];
86
            expected1Reader.read(expected1Content);
87
            expected1Reader.close();
88
            String readExpected1Content = new String(expected1Content);
89
 
90
            File buildFile1 = new File("build",file1);
91
            FileReader buildFile1Reader = new FileReader(buildFile1);
92
            char[] buildFile1Content = new char[(int) buildFile1.length()];
93
            buildFile1Reader.read(buildFile1Content);
94
            buildFile1Reader.close();
95
            String readBuildFile1Content = new String(buildFile1Content);
96
 
97
            readExpected1Content = readExpected1Content.replace("\r", "");
98
            readBuildFile1Content = readBuildFile1Content.replace("\r", "");
99
 
100
            rv = readExpected1Content.compareTo(readBuildFile1Content) == 0;
101
        }
102
        catch (IOException e)
103
        {
104
            System.out.println("checkBuildFiles caught IOException:" + fileG + ":" + file1);
105
            rv = false;
106
        }
107
 
108
        return rv;
109
 
110
    }
111
 
112
 
113
}