This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 138076
Collapse All | Expand All

(-)a/core.startup/src/org/netbeans/core/startup/layers/BinaryFS.java (+4 lines)
Lines 81-86 import org.openide.util.Enumerations; Link Here
81
import org.openide.util.Enumerations;
81
import org.openide.util.Enumerations;
82
import org.openide.util.Exceptions;
82
import org.openide.util.Exceptions;
83
import org.openide.util.Lookup;
83
import org.openide.util.Lookup;
84
import org.openide.util.NbBundle;
84
import org.openide.util.SharedClassObject;
85
import org.openide.util.SharedClassObject;
85
import org.openide.util.Union2;
86
import org.openide.util.Union2;
86
import org.openide.util.actions.SystemAction;
87
import org.openide.util.actions.SystemAction;
Lines 494-499 public class BinaryFS extends FileSystem Link Here
494
495
495
                    case 12: // serialvalue
496
                    case 12: // serialvalue
496
                        return decodeValue(value);
497
                        return decodeValue(value);
498
                    case 13: // bundle value
499
                        String[] arr = value.split("#");
500
                        return NbBundle.getBundle(arr[0]).getObject(arr[1]);
497
                    default:
501
                    default:
498
                        throw new IllegalStateException("Bad index: " + index); // NOI18N
502
                        throw new IllegalStateException("Bad index: " + index); // NOI18N
499
                }
503
                }
(-)a/core.startup/src/org/netbeans/core/startup/layers/ParsingLayerCacheManager.java (-1 / +2 lines)
Lines 80-85 abstract class ParsingLayerCacheManager Link Here
80
    
80
    
81
    private final static String[] ATTR_TYPES = {
81
    private final static String[] ATTR_TYPES = {
82
        "boolvalue",
82
        "boolvalue",
83
        "bundlevalue",
83
        "bytevalue",
84
        "bytevalue",
84
        "charvalue",
85
        "charvalue",
85
        "doublevalue",
86
        "doublevalue",
Lines 91-97 abstract class ParsingLayerCacheManager Link Here
91
        "serialvalue",
92
        "serialvalue",
92
        "shortvalue",
93
        "shortvalue",
93
        "stringvalue",
94
        "stringvalue",
94
        "urlvalue"
95
        "urlvalue",
95
    };
96
    };
96
    
97
    
97
    private final static String DTD_1_0 = "-//NetBeans//DTD Filesystem 1.0//EN";
98
    private final static String DTD_1_0 = "-//NetBeans//DTD Filesystem 1.0//EN";
(-)a/core.startup/test/unit/src/org/netbeans/core/startup/layers/BinaryFSTest.java (-4 / +14 lines)
Lines 41-51 Link Here
41
41
42
package org.netbeans.core.startup.layers;
42
package org.netbeans.core.startup.layers;
43
43
44
import java.io.ByteArrayOutputStream;
45
import java.io.File;
44
import java.io.File;
46
import java.io.IOException;
45
import java.io.IOException;
47
import java.net.URL;
46
import java.net.URL;
48
import java.nio.ByteBuffer;
49
import java.util.Arrays;
47
import java.util.Arrays;
50
import junit.framework.Test;
48
import junit.framework.Test;
51
import org.netbeans.junit.NbTestSuite;
49
import org.netbeans.junit.NbTestSuite;
Lines 56-67 import org.openide.filesystems.FileSyste Link Here
56
import org.openide.filesystems.FileSystemTestHid;
54
import org.openide.filesystems.FileSystemTestHid;
57
import org.openide.filesystems.TestUtilHid;
55
import org.openide.filesystems.TestUtilHid;
58
import org.openide.filesystems.XMLFileSystem;
56
import org.openide.filesystems.XMLFileSystem;
57
import org.openide.filesystems.XMLFileSystemTestHid;
59
58
60
/**
59
/**
61
 *
60
 *
62
 * @author Radek Matous
61
 * @author Radek Matous
63
 */
62
 */
64
public class BinaryFSTest extends FileSystemFactoryHid {  
63
public class BinaryFSTest extends FileSystemFactoryHid
64
implements XMLFileSystemTestHid.Factory {
65
    public BinaryFSTest(Test test) {
65
    public BinaryFSTest(Test test) {
66
        super(test);
66
        super(test);
67
    }
67
    }
Lines 71-76 public class BinaryFSTest extends FileSy Link Here
71
        suite.addTestSuite(FileSystemTestHid.class);
71
        suite.addTestSuite(FileSystemTestHid.class);
72
        suite.addTestSuite(FileObjectTestHid.class);
72
        suite.addTestSuite(FileObjectTestHid.class);
73
        suite.addTestSuite(AttributesTestHidden.class);
73
        suite.addTestSuite(AttributesTestHidden.class);
74
        suite.addTestSuite(XMLFileSystemTestHid.class);
74
         
75
         
75
        return new BinaryFSTest(suite);
76
        return new BinaryFSTest(suite);
76
    }
77
    }
Lines 88-92 public class BinaryFSTest extends FileSy Link Here
88
        String workDirProperty = System.getProperty("workdir");//NOI18N
89
        String workDirProperty = System.getProperty("workdir");//NOI18N
89
        workDirProperty = (workDirProperty != null) ? workDirProperty : System.getProperty("java.io.tmpdir");//NOI18N                 
90
        workDirProperty = (workDirProperty != null) ? workDirProperty : System.getProperty("java.io.tmpdir");//NOI18N                 
90
        return new File(workDirProperty);
91
        return new File(workDirProperty);
91
    }    
92
    }
93
94
    public FileSystem createLayerSystem(String testName, URL[] layers) throws IOException {
95
        LayerCacheManager bm = LayerCacheManager.manager(true);
96
        return BinaryCacheManagerTest.store(bm, Arrays.asList(layers));
97
    }
98
99
    public boolean setXmlUrl(FileSystem fs, URL[] layers) throws IOException {
100
        return false;
101
    }
92
}
102
}
(-)a/openide.filesystems/src/org/openide/filesystems/XMLMapAttr.java (-1 / +4 lines)
Lines 388-394 final class XMLMapAttr implements Map { Link Here
388
        // static final long serialVersionUID = -62733358015297232L;
388
        // static final long serialVersionUID = -62733358015297232L;
389
        private static final String[] ALLOWED_ATTR_KEYS = {
389
        private static final String[] ALLOWED_ATTR_KEYS = {
390
            "bytevalue", "shortvalue", "intvalue", "longvalue", "floatvalue", "doublevalue", "boolvalue", "charvalue",
390
            "bytevalue", "shortvalue", "intvalue", "longvalue", "floatvalue", "doublevalue", "boolvalue", "charvalue",
391
            "stringvalue", "methodvalue", "serialvalue", "urlvalue", "newvalue"
391
            "stringvalue", "methodvalue", "serialvalue", "urlvalue", "newvalue", "bundlevalue"
392
        }; // NOI18N
392
        }; // NOI18N
393
        private String value;
393
        private String value;
394
        private int keyIndex;
394
        private int keyIndex;
Lines 865-870 final class XMLMapAttr implements Map { Link Here
865
                        } else {
865
                        } else {
866
                            return cls.newInstance();
866
                            return cls.newInstance();
867
                        }
867
                        }
868
                    case 13:
869
                        String[] arr = value.split("#");
870
                        return NbBundle.getBundle(arr[0]).getObject(arr[1]);
868
                    }
871
                    }
869
                } catch (Exception exc) {
872
                } catch (Exception exc) {
870
                    ExternalUtil.annotate(exc, "value = " + value); //NOI18N
873
                    ExternalUtil.annotate(exc, "value = " + value); //NOI18N
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/AttributesTestHidden.java (-147 / +1 lines)
Lines 41-52 Link Here
41
41
42
package org.openide.filesystems;
42
package org.openide.filesystems;
43
43
44
import junit.framework.*;
45
//import org.openide.filesystems.hidden.*;
46
44
47
import java.util.*;
45
import java.util.*;
48
import java.io.*;
46
import java.io.*;
49
import java.net.URL;
50
47
51
/**
48
/**
52
 *
49
 *
Lines 55-60 import java.net.URL; Link Here
55
 *
52
 *
56
 */
53
 */
57
public class AttributesTestHidden extends TestBaseHid {
54
public class AttributesTestHidden extends TestBaseHid {
55
58
    static final String TEST_ERR = "Not the tested code, but this test contains errors";
56
    static final String TEST_ERR = "Not the tested code, but this test contains errors";
59
    static final String COMMON_ATTR_STRING = "testAttribute";
57
    static final String COMMON_ATTR_STRING = "testAttribute";
60
58
Lines 245-299 public class AttributesTestHidden extend Link Here
245
        assertTrue ("There was not found expected key: " + COMMON_ATTR_STRING +" in .nbattrs",content.indexOf("name=\""+COMMON_ATTR_STRING) != -1 );//        
243
        assertTrue ("There was not found expected key: " + COMMON_ATTR_STRING +" in .nbattrs",content.indexOf("name=\""+COMMON_ATTR_STRING) != -1 );//        
246
    }
244
    }
247
    
245
    
248
    
249
    public void testAttribute08 () throws Exception {
250
      URL fsURLDef = this.getClass().getResource ("data/Attributes.xml");
251
      assertTrue ("Cannot create XML FS for testing purposes", fsURLDef != null);  
252
      FileSystem fs = new XMLFileSystem (fsURLDef);
253
      FileObject fo = fs.findResource("testMethodValue");
254
      assertTrue ("Cannot acces  FileObject named testMethodValue", fo != null);  
255
256
      String testName = "test1";
257
      Object obj = fo.getAttribute(testName);
258
      assertTrue ("methodValue failed", obj != null);          
259
      assertTrue ("methodValue doesn't keep order ", 
260
      obj.equals(getObjectViaMethodValue1 (fo, testName)));                
261
      
262
      testName = "test2";
263
      obj = fo.getAttribute(testName);
264
      assertTrue ("methodValue failed", obj != null);          
265
      assertTrue ("methodValue doesn't keep order ", 
266
      obj.equals(getObjectViaMethodValue2 (testName, fo)));                
267
268
      testName = "test3";
269
      obj = fo.getAttribute(testName);
270
      assertTrue ("methodValue failed", obj != null);          
271
      assertTrue ("methodValue doesn't keep order ", 
272
      obj.equals(getObjectViaMethodValue3 (fo)));                
273
274
      testName = "test4";
275
      obj = fo.getAttribute(testName);
276
      assertTrue ("methodValue failed", obj != null);          
277
      assertTrue ("methodValue doesn't keep order ", 
278
      obj.equals(getObjectViaMethodValue4 (testName)));                
279
280
      testName = "test5";
281
      obj = fo.getAttribute(testName);
282
      assertTrue ("methodValue failed", obj != null);          
283
      assertTrue ("methodValue doesn't keep order ", 
284
      obj.equals(getObjectViaMethodValue5 ()));                     
285
286
      testName = "test6";
287
      obj = fo.getAttribute(testName);
288
      assertTrue ("methodValue failed", obj != null);          
289
      assertEquals("even works for java.util.Map", "Ahoj1", obj);
290
291
      testName = "test7";
292
      obj = fo.getAttribute(testName);
293
      assertTrue ("methodValue failed", obj != null);          
294
      assertEquals("works for map and string", "Ahoj1test7", obj);  
295
    }
296
297
    public void testAttribute09 () throws IOException {
246
    public void testAttribute09 () throws IOException {
298
        assertTrue (TEST_ERR,testedFS != null);
247
        assertTrue (TEST_ERR,testedFS != null);
299
        if (testedFS.isReadOnly ()) return;                
248
        if (testedFS.isReadOnly ()) return;                
Lines 322-422 public class AttributesTestHidden extend Link Here
322
        }                        
271
        }                        
323
    }
272
    }
324
    
273
    
325
    private static String getObjectViaMethodValue1 (FileObject fo, String testName) {
326
        return fo.getPath()+testName;
327
    }
328
329
    private static String getObjectViaMethodValue1 (String testName, FileObject fo) {
330
        return testName+fo.getPath();
331
    }
332
333
    private static String getObjectViaMethodValue1 (FileObject fo) {
334
        return fo.getPath();        
335
    }
336
    
337
    private static String getObjectViaMethodValue1 (String testName) {
338
        return testName;
339
    }
340
341
    private static String getObjectViaMethodValue1 () {
342
        return "";        
343
    }
344
///
345
    private static String getObjectViaMethodValue2 (String testName, FileObject fo) {
346
        return testName+fo.getPath();
347
    }
348
349
    private static String getObjectViaMethodValue2 (FileObject fo) {
350
        return fo.getPath();        
351
    }
352
    
353
    private static String getObjectViaMethodValue2 (String testName) {
354
        return testName;
355
    }
356
357
    private static String getObjectViaMethodValue2 () {
358
        return "";        
359
    }
360
///
361
    private static String getObjectViaMethodValue3 (FileObject fo) {
362
        return fo.getPath();        
363
    }
364
365
    private static String getObjectViaMethodValue3 (String testName) {
366
        return testName;
367
    }
368
369
    private static String getObjectViaMethodValue3 () {
370
        return "";        
371
    }
372
///
373
    private static String getObjectViaMethodValue4 (String testName) {
374
        return testName;
375
    }
376
377
    private static String getObjectViaMethodValue4 () {
378
        return "";        
379
    }
380
///
381
    private static String getObjectViaMethodValue5 () {
382
        return "";        
383
    }
384
            
385
    private static Object getObjectViaMethodValue6 (Map attrs) {
386
        try {
387
            attrs.keySet().iterator().remove();
388
            return "UnsupportedOperationException";
389
        } catch (UnsupportedOperationException ex) {
390
            // ok
391
        }
392
        try {
393
            attrs.put("value1", "nothing");
394
            return "UnsupportedOperationException";
395
        } catch (UnsupportedOperationException ex) {
396
            // ok
397
        }
398
        try {
399
            attrs.remove("value1");
400
            return "UnsupportedOperationException";
401
        } catch (UnsupportedOperationException ex) {
402
            // ok
403
        }
404
        
405
        
406
        return attrs.get("value1");
407
    }
408
    private static Object getObjectViaMethodValue7 (Map<String,Object> attrs, String attrName) {
409
        assertEquals(8, attrs.keySet().size());
410
        try {
411
            attrs.entrySet().remove(null);
412
            return "UnsupportedOperationException";
413
        } catch (UnsupportedOperationException ex) {
414
            // ok
415
        }
416
        
417
        
418
        return attrs.get("value1") + attrName;
419
    }
420
            
274
            
421
    private String basicAttributeTest (String attrName, String attrValue) throws IOException {
275
    private String basicAttributeTest (String attrName, String attrValue) throws IOException {
422
        FileObject foTested = testedFS.getRoot ();        
276
        FileObject foTested = testedFS.getRoot ();        
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/FileSystemFactoryHid.java (-1 / +22 lines)
Lines 45-53 import org.netbeans.junit.*; Link Here
45
import org.netbeans.junit.*;
45
import org.netbeans.junit.*;
46
46
47
import java.io.*;
47
import java.io.*;
48
import java.net.URL;
48
import java.util.*;
49
import java.util.*;
49
50
50
import org.openide.filesystems.*;
51
51
52
52
53
/**
53
/**
Lines 77-82 public abstract class FileSystemFactoryH Link Here
77
     * @return  array of FileSystems that should be tested in test named: "testName"*/    
77
     * @return  array of FileSystems that should be tested in test named: "testName"*/    
78
    final static FileSystem[] createFileSystem (String testName,String[] resources, Test test) throws IOException {
78
    final static FileSystem[] createFileSystem (String testName,String[] resources, Test test) throws IOException {
79
         return getInstance (test,true).createFileSystem(testName, resources);
79
         return getInstance (test,true).createFileSystem(testName, resources);
80
    }
81
82
    /**
83
     * Intended to allow prepare tested environment for each individual test.
84
     * @param testName name of test
85
     * @return  array of FileSystems that should be tested in test named: "testName"*/
86
    final static FileSystem createXMLSystem (String testName, Test test, URL... layers) throws IOException {
87
        FileSystemFactoryHid factory = getInstance(test, false);
88
        if (factory instanceof XMLFileSystemTestHid.Factory) {
89
            XMLFileSystemTestHid.Factory f = (XMLFileSystemTestHid.Factory) factory;
90
            return f.createLayerSystem(testName, layers);
91
        }
92
        throw new IllegalStateException("You need to implement XMLFileSystemTestHid.Factory to use the AttributesTestHidden!");
93
    }
94
    final static boolean switchXMLSystem (FileSystem fs, Test test, URL... layers) throws IOException {
95
        FileSystemFactoryHid factory = getInstance(test, false);
96
        if (factory instanceof XMLFileSystemTestHid.Factory) {
97
            XMLFileSystemTestHid.Factory f = (XMLFileSystemTestHid.Factory) factory;
98
            return f.setXmlUrl(fs, layers);
99
        }
100
        throw new IllegalStateException("You need to implement XMLFileSystemTestHid.Factory to use the AttributesTestHidden!");
80
    }
101
    }
81
      
102
      
82
    final static void destroyFileSystem (String testName, Test test)  throws IOException  {
103
    final static void destroyFileSystem (String testName, Test test)  throws IOException  {
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/LocalFileSystemTest.java (-7 lines)
Lines 57-69 public class LocalFileSystemTest extends Link Here
57
        super(test);
57
        super(test);
58
    }
58
    }
59
59
60
61
    public static void main(String args[]) {
62
        junit.textui.TestRunner.run(suite());
63
    }
64
65
66
67
    public static Test suite() {
60
    public static Test suite() {
68
        NbTestSuite suite = new NbTestSuite();
61
        NbTestSuite suite = new NbTestSuite();
69
62
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/TestBaseHid.java (-1 / +3 lines)
Lines 97-103 public abstract class TestBaseHid extend Link Here
97
        clearWorkDir();
97
        clearWorkDir();
98
        String[] resources = getResources (getName());        
98
        String[] resources = getResources (getName());        
99
        resourcePrefix = FileSystemFactoryHid.getResourcePrefix(this.getName(),this, resources);
99
        resourcePrefix = FileSystemFactoryHid.getResourcePrefix(this.getName(),this, resources);
100
        allTestedFS = FileSystemFactoryHid.createFileSystem(getName(),resources,this);        
100
        if (allTestedFS == null) {
101
            allTestedFS = FileSystemFactoryHid.createFileSystem(getName(),resources,this);
102
        }
101
        if (allTestedFS != null) testedFS = allTestedFS[0];
103
        if (allTestedFS != null) testedFS = allTestedFS[0];
102
        // If not null, file accesses are counted through custom SecurityManager.
104
        // If not null, file accesses are counted through custom SecurityManager.
103
        if(accessMonitor != null) {
105
        if(accessMonitor != null) {
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTest.java (-11 / +26 lines)
Lines 41-70 Link Here
41
41
42
package org.openide.filesystems;
42
package org.openide.filesystems;
43
43
44
import java.beans.PropertyVetoException;
45
import java.net.URL;
44
import junit.framework.*;
46
import junit.framework.*;
45
import java.io.*;
47
import java.io.*;
46
import java.util.*;
47
import java.util.jar.*;
48
import java.util.zip.*;
49
import java.net.*;
50
import org.netbeans.junit.*;
48
import org.netbeans.junit.*;
51
49
import org.openide.util.Exceptions;
52
//import org.openide.filesystems.hidden.*;
53
50
54
/**
51
/**
55
 *
52
 *
56
 * @author  rm111737
53
 * @author  rm111737
57
 * @version
54
 * @version
58
 */
55
 */
59
public class XMLFileSystemTest extends FileSystemFactoryHid {
56
public class XMLFileSystemTest extends FileSystemFactoryHid
57
implements XMLFileSystemTestHid.Factory {
60
58
61
    /** Creates new XMLFileSystemTest */
59
    /** Creates new XMLFileSystemTest */
62
    public XMLFileSystemTest(Test test) {
60
    public XMLFileSystemTest(Test test) {
63
        super(test);
61
        super(test);
64
    }
65
66
    public static void main(String args[]) {
67
        junit.textui.TestRunner.run(suite());
68
    }
62
    }
69
63
70
    public static Test suite() {
64
    public static Test suite() {
Lines 75-85 public class XMLFileSystemTest extends F Link Here
75
                
69
                
76
        return new XMLFileSystemTest(suite);
70
        return new XMLFileSystemTest(suite);
77
    }
71
    }
72
78
    protected void destroyFileSystem(String testName) throws IOException {}
73
    protected void destroyFileSystem(String testName) throws IOException {}
79
    
74
    
80
    protected FileSystem[] createFileSystem(String testName, String[] resources) throws IOException{
75
    protected FileSystem[] createFileSystem(String testName, String[] resources) throws IOException{
81
        return new FileSystem[] {TestUtilHid.createXMLFileSystem(testName, resources)};
76
        return new FileSystem[] {TestUtilHid.createXMLFileSystem(testName, resources)};
82
    }
77
    }
78
79
    public FileSystem createLayerSystem(String testName, URL[] layers) throws IOException {
80
        XMLFileSystem xfs = new XMLFileSystem();
81
        try {
82
            xfs.setXmlUrls(layers);
83
        } catch (PropertyVetoException ex) {
84
            throw (IOException)new IOException().initCause(ex);
85
        }
86
        return xfs;
87
    }
88
89
    public boolean setXmlUrl(org.openide.filesystems.FileSystem fs, URL[] layers) throws IOException {
90
        XMLFileSystem xfs = (XMLFileSystem)fs;
91
        try {
92
            xfs.setXmlUrls(layers);
93
        } catch (PropertyVetoException ex) {
94
            throw (IOException)new IOException().initCause(ex);
95
        }
96
        return true;
97
    }
83
    
98
    
84
99
85
    
100
    
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/XMLFileSystemTestHid.java (-17 / +208 lines)
Lines 47-57 import java.net.URL; Link Here
47
import java.net.URL;
47
import java.net.URL;
48
import java.util.ArrayList;
48
import java.util.ArrayList;
49
import java.util.List;
49
import java.util.List;
50
import java.util.Map;
50
51
51
public class XMLFileSystemTestHid extends TestBaseHid {
52
public class XMLFileSystemTestHid extends TestBaseHid {
53
    /** Factory for all filesystems that want to use TCK in this class.
54
     */
55
    public static interface Factory {
56
        /** Creates a filesystem representing XML files at given URLs
57
         *
58
         * @param testName name of the test
59
         * @param layers URLs of layers to parse
60
         * @return new filesystem that represents those layers
61
         */
62
        public FileSystem createLayerSystem(String testName, URL[] layers) throws IOException;
63
64
        /** Assigns new URLs to existing filesystem.
65
         *
66
         * @param fs the filesystem produced by {@link #createLayerSystem(java.lang.String, java.net.URL[])}
67
         * @param layers new URLs that the filesystem shall switch to
68
         * @return true if successful, false if this operation is not supported
69
         */
70
        public boolean setXmlUrl(FileSystem fs, URL[] layers) throws IOException;
71
    }
52
72
53
    private String[] resources = new String[] {"a/b/c"};
73
    private String[] resources = new String[] {"a/b/c"};
54
    XMLFileSystem xfs = null;
74
    FileSystem xfs = null;
55
75
56
    public XMLFileSystemTestHid(String testName) {
76
    public XMLFileSystemTestHid(String testName) {
57
        super(testName);
77
        super(testName);
Lines 70-90 public class XMLFileSystemTestHid extend Link Here
70
        FileChangeAdapter fcl = new FileChangeAdapter();
90
        FileChangeAdapter fcl = new FileChangeAdapter();
71
        a.addFileChangeListener(fcl);
91
        a.addFileChangeListener(fcl);
72
        
92
        
73
        resources = new String[] {"a/b/c","a/b1/c"};        
93
        resources = new String[] {"a/b/c","a/b1/c"};
74
        xfs.setXmlUrl(createXMLLayer().toURL());
94
95
        if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, createXMLLayer().toURL())) {
96
            // OK, unsupported
97
            return;
98
        }
75
        
99
        
76
        FileObject b1 = xfs.findResource("a/b1");
100
        FileObject b1 = xfs.findResource("a/b1");
77
        assertNotNull(b1);                
101
        assertNotNull(b1);                
78
        assertTrue(b1.isFolder());        
102
        assertTrue(b1.isFolder());        
79
    }
103
    }
80
    
104
    
105
    @Override
81
    protected void setUp() throws Exception {
106
    protected void setUp() throws Exception {
107
        File f = createXMLLayer();
108
        xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL());
109
        this.testedFS = xfs;
110
        this.allTestedFS = new FileSystem[] { xfs };
82
        super.setUp();
111
        super.setUp();
83
        
84
        File f = createXMLLayer();
85
        xfs = new XMLFileSystem ();
86
        xfs.setXmlUrl(f.toURL());
87
        this.testedFS = xfs;
88
    }
112
    }
89
113
90
    private File createXMLLayer() throws IOException {
114
    private File createXMLLayer() throws IOException {
Lines 113-125 public class XMLFileSystemTestHid extend Link Here
113
        
137
        
114
        
138
        
115
        
139
        
116
        xfs = new XMLFileSystem (f.toURL());
140
        xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL());
117
        
141
        
118
        FileObject fo = xfs.findResource ("TestModule/sample.txt");
142
        FileObject fo = xfs.findResource ("TestModule/sample.txt");
119
        assertEquals ("Four bytes there", 4, fo.getSize ());
143
        assertEquals ("Four bytes there", 4, fo.getSize ());
120
        registerDefaultListener (fo);
144
        registerDefaultListener (fo);
121
        
145
        
122
        xfs.setXmlUrl (f2.toURL ());
146
        if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) {
147
            // OK, unsupported
148
            return;
149
        }
123
        
150
        
124
        assertEquals ("Six bytes there", 6, fo.getSize ());
151
        assertEquals ("Six bytes there", 6, fo.getSize ());
125
        
152
        
Lines 149-161 public class XMLFileSystemTestHid extend Link Here
149
        
176
        
150
        
177
        
151
        
178
        
152
        xfs = new XMLFileSystem (f.toURL());
179
        xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL());
153
        
180
        
154
        FileObject fo = xfs.findResource ("TestModule/sample.txt");
181
        FileObject fo = xfs.findResource ("TestModule/sample.txt");
155
        assertEquals ("Four bytes there", 4, fo.getSize ());
182
        assertEquals ("Four bytes there", 4, fo.getSize ());
156
        registerDefaultListener (fo);
183
        registerDefaultListener (fo);
157
        
184
        
158
        xfs.setXmlUrl (f2.toURL ());
185
        if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) {
186
            // OK, unsupported
187
            return;
188
        }
159
        
189
        
160
        assertEquals ("Six bytes there", 6, fo.getSize ());
190
        assertEquals ("Six bytes there", 6, fo.getSize ());
161
        
191
        
Lines 186-198 public class XMLFileSystemTestHid extend Link Here
186
        
216
        
187
        
217
        
188
        
218
        
189
        xfs = new XMLFileSystem (f.toURL());
219
        xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL());
190
        
220
        
191
        FileObject fo = xfs.findResource ("TestModule/sample.txt");
221
        FileObject fo = xfs.findResource ("TestModule/sample.txt");
192
        assertEquals("Old value is in the attribute", "old", fo.getAttribute("value"));
222
        assertEquals("Old value is in the attribute", "old", fo.getAttribute("value"));
193
        registerDefaultListener (fo);
223
        registerDefaultListener (fo);
194
        
224
        
195
        xfs.setXmlUrl (f2.toURL ());
225
        if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) {
226
            // OK, unsupported
227
            return;
228
        }
196
229
197
        assertEquals("New value is in the attribute", "new", fo.getAttribute("value"));
230
        assertEquals("New value is in the attribute", "new", fo.getAttribute("value"));
198
        fileAttributeChangedAssert("Change in the content", 1);
231
        fileAttributeChangedAssert("Change in the content", 1);
Lines 217-229 public class XMLFileSystemTestHid extend Link Here
217
        
250
        
218
        
251
        
219
        
252
        
220
        xfs = new XMLFileSystem(f.toURL());
253
        xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL());
221
        
254
        
222
        FileObject fo = xfs.findResource("TestModule/sample.txt");
255
        FileObject fo = xfs.findResource("TestModule/sample.txt");
223
        assertEquals("Four bytes there", 4, fo.getSize());
256
        assertEquals("Four bytes there", 4, fo.getSize());
224
        registerDefaultListener(fo);
257
        registerDefaultListener(fo);
225
        
258
        
226
        xfs.setXmlUrl(f2.toURL());
259
        if (!FileSystemFactoryHid.switchXMLSystem(xfs, this, f2.toURL())) {
260
            // OK, unsupported
261
            return;
262
        }
227
        
263
        
228
        assertFalse("Valid no more", fo.isValid());
264
        assertFalse("Valid no more", fo.isValid());
229
        assertEquals("Empty now", 0, fo.getSize());
265
        assertEquals("Empty now", 0, fo.getSize());
Lines 246-252 public class XMLFileSystemTestHid extend Link Here
246
            Thread.sleep(3000);
282
            Thread.sleep(3000);
247
            assertTrue(f2.createNewFile());
283
            assertTrue(f2.createNewFile());
248
        }
284
        }
249
        xfs = new XMLFileSystem(f.toURL());
285
        xfs = FileSystemFactoryHid.createXMLSystem(getName(), this, f.toURL());
250
        FileObject fo = xfs.findResource ("TestModule/sample.txt");
286
        FileObject fo = xfs.findResource ("TestModule/sample.txt");
251
        assertNotNull(fo);
287
        assertNotNull(fo);
252
        assertEquals(fo.lastModified().getTime(), f.lastModified());        
288
        assertEquals(fo.lastModified().getTime(), f.lastModified());        
Lines 268-273 public class XMLFileSystemTestHid extend Link Here
268
        return f;
304
        return f;
269
    }
305
    }
270
    
306
    
307
308
    public void testAttribute08 () throws Exception {
309
      URL fsURLDef = this.getClass().getResource ("data/Attributes.xml");
310
      assertTrue ("Cannot create XML FS for testing purposes", fsURLDef != null);
311
      FileSystem fs = FileSystemFactoryHid.createXMLSystem(getName(), this, fsURLDef);
312
      FileObject fo = fs.findResource("testMethodValue");
313
      assertTrue ("Cannot acces  FileObject named testMethodValue", fo != null);
314
315
      String testName = "test1";
316
      Object obj = fo.getAttribute(testName);
317
      assertTrue ("methodValue failed", obj != null);
318
      assertTrue ("methodValue doesn't keep order ",
319
      obj.equals(getObjectViaMethodValue1 (fo, testName)));
320
321
      testName = "test2";
322
      obj = fo.getAttribute(testName);
323
      assertTrue ("methodValue failed", obj != null);
324
      assertTrue ("methodValue doesn't keep order ",
325
      obj.equals(getObjectViaMethodValue2 (testName, fo)));
326
327
      testName = "test3";
328
      obj = fo.getAttribute(testName);
329
      assertTrue ("methodValue failed", obj != null);
330
      assertTrue ("methodValue doesn't keep order ",
331
      obj.equals(getObjectViaMethodValue3 (fo)));
332
333
      testName = "test4";
334
      obj = fo.getAttribute(testName);
335
      assertTrue ("methodValue failed", obj != null);
336
      assertTrue ("methodValue doesn't keep order ",
337
      obj.equals(getObjectViaMethodValue4 (testName)));
338
339
      testName = "test5";
340
      obj = fo.getAttribute(testName);
341
      assertTrue ("methodValue failed", obj != null);
342
      assertTrue ("methodValue doesn't keep order ",
343
      obj.equals(getObjectViaMethodValue5 ()));
344
345
      testName = "test6";
346
      obj = fo.getAttribute(testName);
347
      assertTrue ("methodValue failed", obj != null);
348
      assertEquals("even works for java.util.Map", "Ahoj1", obj);
349
350
      testName = "test7";
351
      obj = fo.getAttribute(testName);
352
      assertTrue ("methodValue failed", obj != null);
353
      assertEquals("works for map and string", "Ahoj1test7", obj);
354
355
      testName = "testLoc";
356
      obj = fo.getAttribute(testName);
357
      assertNotNull("Value returned", obj);
358
      assertEquals("works for bundle key", "Hello World!", obj);
359
    }
360
271
    
361
    
272
    public void testChangeOfAnAttributeInLayerIsFiredIfThereIsRealChange() throws Exception {
362
    public void testChangeOfAnAttributeInLayerIsFiredIfThereIsRealChange() throws Exception {
273
        XMLFileSystem fs = new XMLFileSystem();
363
        XMLFileSystem fs = new XMLFileSystem();
Lines 333-362 public class XMLFileSystemTestHid extend Link Here
333
        public List<FileEvent> change = new ArrayList<FileEvent>();
423
        public List<FileEvent> change = new ArrayList<FileEvent>();
334
        
424
        
335
        
425
        
426
        @Override
336
        public void fileRenamed(FileRenameEvent fe) {
427
        public void fileRenamed(FileRenameEvent fe) {
337
            events.add(fe);
428
            events.add(fe);
338
        }
429
        }
339
430
431
        @Override
340
        public void fileAttributeChanged(FileAttributeEvent fe) {
432
        public void fileAttributeChanged(FileAttributeEvent fe) {
341
            events.add(fe);
433
            events.add(fe);
342
        }
434
        }
343
435
436
        @Override
344
        public void fileFolderCreated(FileEvent fe) {
437
        public void fileFolderCreated(FileEvent fe) {
345
            events.add(fe);
438
            events.add(fe);
346
        }
439
        }
347
440
441
        @Override
348
        public void fileDeleted(FileEvent fe) {
442
        public void fileDeleted(FileEvent fe) {
349
            events.add(fe);
443
            events.add(fe);
350
        }
444
        }
351
445
446
        @Override
352
        public void fileDataCreated(FileEvent fe) {
447
        public void fileDataCreated(FileEvent fe) {
353
            events.add(fe);
448
            events.add(fe);
354
        }
449
        }
355
450
451
        @Override
356
        public void fileChanged(FileEvent fe) {
452
        public void fileChanged(FileEvent fe) {
357
            change.add(fe);
453
            change.add(fe);
358
        }
454
        }
359
        
455
        
360
    }
456
    }
457
    private static String getObjectViaMethodValue1 (FileObject fo, String testName) {
458
        return fo.getPath()+testName;
459
    }
460
461
    private static String getObjectViaMethodValue1 (String testName, FileObject fo) {
462
        return testName+fo.getPath();
463
    }
464
465
    private static String getObjectViaMethodValue1 (FileObject fo) {
466
        return fo.getPath();
467
    }
468
469
    private static String getObjectViaMethodValue1 (String testName) {
470
        return testName;
471
    }
472
473
    private static String getObjectViaMethodValue1 () {
474
        return "";
475
    }
476
///
477
    private static String getObjectViaMethodValue2 (String testName, FileObject fo) {
478
        return testName+fo.getPath();
479
    }
480
481
    private static String getObjectViaMethodValue2 (FileObject fo) {
482
        return fo.getPath();
483
    }
484
485
    private static String getObjectViaMethodValue2 (String testName) {
486
        return testName;
487
    }
488
489
    private static String getObjectViaMethodValue2 () {
490
        return "";
491
    }
492
///
493
    private static String getObjectViaMethodValue3 (FileObject fo) {
494
        return fo.getPath();
495
    }
496
497
    private static String getObjectViaMethodValue3 (String testName) {
498
        return testName;
499
    }
500
501
    private static String getObjectViaMethodValue3 () {
502
        return "";
503
    }
504
///
505
    private static String getObjectViaMethodValue4 (String testName) {
506
        return testName;
507
    }
508
509
    private static String getObjectViaMethodValue4 () {
510
        return "";
511
    }
512
///
513
    private static String getObjectViaMethodValue5 () {
514
        return "";
515
    }
516
517
    private static Object getObjectViaMethodValue6 (Map attrs) {
518
        try {
519
            attrs.keySet().iterator().remove();
520
            return "UnsupportedOperationException";
521
        } catch (UnsupportedOperationException ex) {
522
            // ok
523
        }
524
        try {
525
            attrs.put("value1", "nothing");
526
            return "UnsupportedOperationException";
527
        } catch (UnsupportedOperationException ex) {
528
            // ok
529
        }
530
        try {
531
            attrs.remove("value1");
532
            return "UnsupportedOperationException";
533
        } catch (UnsupportedOperationException ex) {
534
            // ok
535
        }
536
537
538
        return attrs.get("value1");
539
    }
540
    private static Object getObjectViaMethodValue7 (Map<String,Object> attrs, String attrName) {
541
        assertEquals(9, attrs.keySet().size());
542
        try {
543
            attrs.entrySet().remove(null);
544
            return "UnsupportedOperationException";
545
        } catch (UnsupportedOperationException ex) {
546
            // ok
547
        }
548
549
550
        return attrs.get("value1") + attrName;
551
    }
361
    
552
    
362
}
553
}
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/data/Attributes.xml (-8 / +8 lines)
Lines 11-24 Link Here
11
<!DOCTYPE filesystem PUBLIC '-//NetBeans//DTD Filesystem 1.1//EN' 'http://www.netbeans.org/dtds/filesystem-1_1.dtd'>
11
<!DOCTYPE filesystem PUBLIC '-//NetBeans//DTD Filesystem 1.1//EN' 'http://www.netbeans.org/dtds/filesystem-1_1.dtd'>
12
<filesystem>
12
<filesystem>
13
    <folder name="testMethodValue"> 
13
    <folder name="testMethodValue"> 
14
        <attr name="test1" methodvalue="org.openide.filesystems.AttributesTestHidden.getObjectViaMethodValue1"/>
14
        <attr name="test1" methodvalue="org.openide.filesystems.XMLFileSystemTestHid.getObjectViaMethodValue1"/>
15
        <attr name="test2" methodvalue="org.openide.filesystems.AttributesTestHidden.getObjectViaMethodValue2"/>        
15
        <attr name="test2" methodvalue="org.openide.filesystems.XMLFileSystemTestHid.getObjectViaMethodValue2"/>
16
        <attr name="test3" methodvalue="org.openide.filesystems.AttributesTestHidden.getObjectViaMethodValue3"/>                
16
        <attr name="test3" methodvalue="org.openide.filesystems.XMLFileSystemTestHid.getObjectViaMethodValue3"/>
17
        <attr name="test4" methodvalue="org.openide.filesystems.AttributesTestHidden.getObjectViaMethodValue4"/>                
17
        <attr name="test4" methodvalue="org.openide.filesystems.XMLFileSystemTestHid.getObjectViaMethodValue4"/>
18
        <attr name="test5" methodvalue="org.openide.filesystems.AttributesTestHidden.getObjectViaMethodValue5"/>                
18
        <attr name="test5" methodvalue="org.openide.filesystems.XMLFileSystemTestHid.getObjectViaMethodValue5"/>
19
        <attr name="test6" methodvalue="org.openide.filesystems.AttributesTestHidden.getObjectViaMethodValue6"/>                
19
        <attr name="test6" methodvalue="org.openide.filesystems.XMLFileSystemTestHid.getObjectViaMethodValue6"/>
20
        <attr name="test7" methodvalue="org.openide.filesystems.AttributesTestHidden.getObjectViaMethodValue7"/>
20
        <attr name="test7" methodvalue="org.openide.filesystems.XMLFileSystemTestHid.getObjectViaMethodValue7"/>
21
                
22
        <attr name="value1" stringvalue="Ahoj1"/>
21
        <attr name="value1" stringvalue="Ahoj1"/>
22
        <attr name="testLoc" bundlevalue="org.openide.filesystems.data.TestBundle#AHOJ"/>
23
    </folder>
23
    </folder>
24
</filesystem>
24
</filesystem>
(-)c06fe6e89701 (+39 lines)
Added Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
# 
3
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4
# 
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
# 
23
# If you wish your version of this file to be governed by only the CDDL
24
# or only the GPL Version 2, indicate your decision by adding
25
# "[Contributor] elects to include this software in this distribution
26
# under the [CDDL or GPL Version 2] license." If you do not indicate a
27
# single choice of license, a recipient has the option to distribute
28
# your version of this file under either the CDDL, the GPL Version 2 or
29
# to extend the choice of license to its licensees as provided above.
30
# However, if you add GPL Version 2 code and therefore, elected the GPL
31
# Version 2 license, then the option applies only if the new code is
32
# made subject to such option by the copyright holder.
33
# 
34
# Contributor(s):
35
# 
36
# Portions Copyrighted 2008 Sun Microsystems, Inc.
37
38
AHOJ=Hello World!
39

Return to bug 138076