KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > convertor > DVDConvertorTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.convertor;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.ByteArrayOutputStream JavaDoc;
24 import java.io.FileInputStream JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import org.netbeans.junit.*;
27 import junit.textui.TestRunner;
28 import org.netbeans.api.convertor.dvd.DVD;
29 import org.netbeans.modules.convertor.PropertiesConvertor;
30 import org.netbeans.spi.convertor.Convertor;
31 import org.openide.filesystems.Repository;
32 import org.openide.modules.ModuleInfo;
33 import org.openide.util.Lookup;
34 import org.w3c.dom.Document JavaDoc;
35
36
37 /**
38  *
39  * @author David Konecny
40  */

41 public class DVDConvertorTest extends NbTestCase {
42     
43
44     public DVDConvertorTest(String JavaDoc name) {
45         super (name);
46     }
47     
48     public static void main(String JavaDoc[] args) {
49         TestRunner.run(new NbTestSuite(DVDConvertorTest.class));
50     }
51     
52     protected void setUp () throws Exception JavaDoc {
53         Lookup.getDefault().lookup(ModuleInfo.class);
54         Repository.getDefault ().getDefaultFileSystem ().getRoot ();
55     }
56     
57     private static Convertor conv;
58     
59     public static void setupConvertor() throws Exception JavaDoc {
60         ModuleUtils.DEFAULT.install();
61         ModuleUtils.DEFAULT.enableDVDConvertorModule(true);
62     }
63     
64     public static void removeConvertor() throws Exception JavaDoc {
65         ModuleUtils.DEFAULT.enableDVDConvertorModule(false);
66         ModuleUtils.DEFAULT.uninstall();
67     }
68     
69     public void testDVDConvertor() throws Exception JavaDoc {
70         assertFalse(Convertors.canRead("http://www.netbeans.org/ns/dvd", "dvd"));
71         assertFalse(Convertors.canWrite(new DVD()));
72         
73         setupConvertor();
74         
75         assertTrue(Convertors.canRead("http://www.netbeans.org/ns/dvd", "dvd"));
76         assertTrue(Convertors.canWrite(new DVD()));
77
78 // assertEquals(Convertors.getConvertorDescriptor(new DVD()), new ConvertorDescriptor("http://www.netbeans.org/ns/dvd", "org.netbeans.api.convertor.dvd.DVD"));
79

80         String JavaDoc name = DVDConvertorTest.class.getResource("dvd").getFile() + "/data/DVD.xml";
81         InputStream JavaDoc is = new FileInputStream JavaDoc(name);
82         DVD d = (DVD)Convertors.read(is);
83         assertEquals(d.ID, 125);
84         assertEquals(d.title, "Tetsuo");
85         assertEquals(d.publisher, "TartanTerror");
86         assertEquals(d.price, 19);
87         is.close();
88         
89         
90         ByteArrayOutputStream JavaDoc os = new ByteArrayOutputStream JavaDoc();
91         DVD dvd = new DVD(698, "Zentropa", "TartanClassic", 65);
92         Convertors.write(os, dvd);
93         
94         byte[] ba = os.toByteArray();
95         os.close();
96         
97         ByteArrayInputStream JavaDoc bis = new ByteArrayInputStream JavaDoc(ba);
98         Object JavaDoc o = Convertors.read(bis);
99         assertEquals(dvd, o);
100         
101         removeConvertor();
102         assertFalse(Convertors.canRead("http://www.netbeans.org/ns/dvd", "dvd"));
103         assertFalse(Convertors.canWrite(new DVD()));
104     }
105     
106 }
107
Popular Tags