KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > metainf > ServiceTest


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.modules.apisupport.project.metainf;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28 import org.netbeans.modules.apisupport.project.NbModuleProject;
29 import org.netbeans.modules.apisupport.project.TestBase;
30 import org.openide.filesystems.FileUtil;
31
32 /**
33  * @author pzajac
34  */

35 public class ServiceTest extends TestBase {
36     
37     public ServiceTest(String JavaDoc testName) {
38         super(testName);
39     }
40     
41     public static Test suite() {
42         return new TestSuite(ServiceTest.class);
43     }
44     
45     public void testReadServices() {
46         File JavaDoc jarFile = new File JavaDoc(getDataDir(),"ServiceTest.jar");
47         List JavaDoc /*Service*/ services = Service.readServices(jarFile);
48         
49         Iterator JavaDoc it = services.iterator() ;
50         
51         Service service = (Service) it.next();
52         assertEquals("testicek", service.getCodebase() );
53         assertEquals("java.io.InputStream", service.getFileName());
54         Iterator JavaDoc cIt = service.getClasses().iterator() ;
55         assertEquals("java.io.FileInputStream",cIt.next());
56         assertEquals("java.io.BufferedInputStream",cIt.next());
57         assertFalse(cIt.hasNext());
58         
59         service = (Service) it.next();
60         assertEquals("testicek", service.getCodebase() );
61         assertEquals("java.util.Collection", service.getFileName());
62         cIt = service.getClasses().iterator() ;
63         assertEquals("java.util.ArrayList",cIt.next());
64         assertEquals("java.util.Stack",cIt.next());
65         assertFalse(cIt.hasNext());
66     }
67     
68     public void testGetOnlyProjectServices() throws IOException JavaDoc {
69         NbModuleProject module = generateStandaloneModule("module");
70         FileUtil.createData(module.getSourceDirectory(), "META-INF/services/some.test.MyService");
71         FileUtil.createData(module.getSourceDirectory(), "META-INF/services/.#some.test.MyService.1.2");
72         assertEquals("one service", 1, Service.getOnlyProjectServices(module).size());
73     }
74     
75 }
76
Popular Tags