KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > deployment > impl > ServerRegistryTest


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.j2ee.deployment.impl;
21
22 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
23 import javax.enterprise.deploy.spi.*;
24 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
25 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
26 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
27 import org.netbeans.modules.j2ee.deployment.impl.ui.RegistryNodeProvider;
28 import org.netbeans.modules.j2ee.deployment.plugins.api.StartServer;
29 /**
30  *
31  * @author nn136682
32  */

33 public class ServerRegistryTest extends ServerRegistryTestBase {
34     
35     public ServerRegistryTest(String JavaDoc testName) {
36         super(testName);
37     }
38     
39     /**
40      * Test plugin layer file which install 1 plugin instance.
41      * @precondition: test plugin is installed
42      * @postcondition: getServer("Test") to get testplugin
43      * @postcondition: getInstance("fooservice") to get testplugin instance
44      */

45     public void testPluginLayerFile() {
46         ServerRegistry registry = ServerRegistry.getInstance();
47         System.out.println ("registry:" + registry);
48         Server testPlugin = registry.getServer("Test");
49         if (testPlugin == null || ! testPlugin.getShortName().equals("Test"))
50             fail("Could not get testPlugin: "+testPlugin);
51         
52         DeploymentFactory JavaDoc factory = testPlugin.getDeploymentFactory();
53         assertNotNull ("No DeploymentFactory for test plugin", factory);
54         
55         RegistryNodeProvider nodeProvider = testPlugin.getNodeProvider();
56         assertNotNull ("No RegistryNodeProvider for test plugin", nodeProvider);
57         
58         OptionalDeploymentManagerFactory optionalFactory = testPlugin.getOptionalFactory();
59         assertNotNull ("No OptionalDeploymentManagerFactory for test plugin", optionalFactory);
60         
61         DeploymentManager manager = null;
62         try {
63             manager = testPlugin.getDisconnectedDeploymentManager();
64             assertNotNull ("No DeploymentManager for test plugin", manager);
65         } catch (DeploymentManagerCreationException JavaDoc dce) {
66             fail(dce.getLocalizedMessage());
67         }
68         
69         IncrementalDeployment incrementalDepl = optionalFactory.getIncrementalDeployment(manager);
70         assertNotNull ("No IncrementalDeployment for test plugin", incrementalDepl);
71         
72         StartServer start = optionalFactory.getStartServer(manager);
73         assertNotNull ("No StartServer for test plugin", start);
74         
75         String JavaDoc url = "fooservice";
76         ServerInstance instance = registry.getServerInstance(url);
77         if (instance == null || ! instance.getUrl().equals(url)) {
78             fail("Failed: expected: " + url + " got: " + instance);
79         }
80     }
81     
82     public void testDeploymentFileNames() {
83         ServerRegistry registry = ServerRegistry.getInstance();
84         Server testPlugin = registry.getServer("Test");
85         if (testPlugin == null || ! testPlugin.getShortName().equals("Test")) {
86             fail("Could not get testPlugin: "+testPlugin);
87         }
88         String JavaDoc expected = "META-INF/context.xml";
89         String JavaDoc[] names = testPlugin.getDeploymentPlanFiles(ModuleType.WAR);
90         if (names == null || names.length != 1) {
91             fail("Got null or incorrect deploy plan file paths: " + names);
92         } else if (! names[0].equals(expected)) {
93             fail("Expected: "+expected+" Got: "+names[0]);
94         }
95     }
96 }
97
Popular Tags