Issue Details (XML | Word | Printable)

Key: JCR-285
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Stefan Guggisberg
Reporter: Joseph Chen
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Jackrabbit Content Repository

Line-separator differences cause PredefinedNodeTypeTest to fail on different operating systems.

Created: 02/Dec/05 10:43 AM   Updated: 13/Oct/06 04:08 PM
Return to search
Component/s: test
Affects Version/s: 0.9, 1.0
Fix Version/s: 1.0.1

Time Tracking:
Not Specified

File Attachments:
  Size
Java Source File Licensed for inclusion in ASF works PredefinedNodeTypeTest.java 2005-12-02 10:45 AM Joseph Chen 16 kB

Resolution Date: 03/Apr/06 09:27 PM


 Description  « Hide
In testPredefinedNodeType(), the test reads in a test file from the file system and then performs a string comparison, which may fail due to line-separator differences:

    private void testPredefinedNodeType(String name)
            throws NotExecutableException {
        try {
            StringBuffer spec = new StringBuffer();
            String resource =
                "org/apache/jackrabbit/test/api/nodetype/spec/"
                + name.replace(':', '-') + ".txt";
            Reader reader = new InputStreamReader(
                    getClass().getClassLoader().getResourceAsStream(resource));
            for (int ch = reader.read(); ch != -1; ch = reader.read()) {
                spec.append((char) ch);
            }

            NodeType type = manager.getNodeType(name);

            assertEquals(
                    "Predefined node type " + name,
                    spec.toString(),
                    getNodeTypeSpec(type));
...

The above works when the file being read in has line-separators that match the operating system the test is being run on. However, if there is a mismatch, the string comparison will fail.

The fix is to replace line-separators in both strings being compared:

Helper method to replace line separators

    /** Standardize line separators around "\n". */
    public String replaceLineSeparators(String stringValue) {
        // Replace "\r\n" (Windows format) with "\n" (Unix format)
        stringValue = stringValue.replaceAll("\r\n", "\n");
        // Replace "\r" (Mac format) with "\n" (Unix format)
        stringValue = stringValue.replaceAll("\r", "\n");
        
        return stringValue;
    }
    
Updated test method:

    private void testPredefinedNodeType(String name)
            throws NotExecutableException {
        try {
            StringBuffer spec = new StringBuffer();
            String resource =
                "org/apache/jackrabbit/test/api/nodetype/spec/"
                + name.replace(':', '-') + ".txt";
            Reader reader = new InputStreamReader(
                    getClass().getClassLoader().getResourceAsStream(resource));
            for (int ch = reader.read(); ch != -1; ch = reader.read()) {
                spec.append((char) ch);
            }

            NodeType type = manager.getNodeType(name);
            
            String nodeTypeSpecValue = replaceLineSeparators(getNodeTypeSpec(type));
            String specValue = replaceLineSeparators(spec.toString());
            
            assertEquals(
                    "Predefined node type " + name,
                    specValue,
                    nodeTypeSpecValue);
...

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Joseph Chen added a comment - 02/Dec/05 10:45 AM
Proposed fix for unit test.

Joseph Chen made changes - 02/Dec/05 10:45 AM
Field Original Value New Value
Attachment PredefinedNodeTypeTest.java [ 12321090 ]
Stefan Guggisberg made changes - 02/Dec/05 07:08 PM
Component/s nodetype [ 11614 ]
Component/s TCK [ 11645 ]
Jukka Zitting added a comment - 11/Jan/06 06:13 PM
Tagged for 1.0

Jukka Zitting made changes - 11/Jan/06 06:13 PM
Affects Version/s 1.0 [ 12310154 ]
Fix Version/s 1.0 [ 12310154 ]
Jukka Zitting made changes - 07/Mar/06 03:32 PM
Fix Version/s 1.1 [ 12310346 ]
Fix Version/s 1.0 [ 12310154 ]
Jukka Zitting made changes - 21/Mar/06 06:24 AM
Affects Version/s 0.9 [ 12310719 ]
Affects Version/s 1.0 [ 12310154 ]
Repository Revision Date User Message
ASF #391041 Mon Apr 03 13:25:10 UTC 2006 stefan JCR-285: Line-separator differences cause PredefinedNodeTypeTest to fail on different operating systems.
Files Changed
MODIFY /jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java

Stefan Guggisberg made changes - 03/Apr/06 08:56 PM
Assignee Stefan Guggisberg [ stefan@jira ]
Stefan Guggisberg added a comment - 03/Apr/06 09:26 PM
fixed as suggested (svn r391041).

thanks for reporting this issue!

Stefan Guggisberg made changes - 03/Apr/06 09:27 PM
Resolution Fixed [ 1 ]
Fix Version/s 1.1 [ 12310346 ]
Fix Version/s 1.0.1 [ 12310345 ]
Status Open [ 1 ] Resolved [ 5 ]
Repository Revision Date User Message
ASF #409520 Fri May 26 00:31:28 UTC 2006 jukka 1.0: Merged revision 391041: JCR-285
Files Changed
MODIFY /jackrabbit/branches/1.0/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/nodetype/PredefinedNodeTypeTest.java

Jukka Zitting added a comment - 26/May/06 07:31 AM
Merged for 1.0.1 in revision 409520.

Jukka Zitting made changes - 13/Oct/06 04:08 PM
Status Resolved [ 5 ] Closed [ 6 ]
Jukka Zitting made changes - 07/Jul/09 01:04 PM
Workflow jira [ 12344349 ] no-reopen-closed, patch-avail [ 12469533 ]