KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > deploy > DeploymentStatusTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.management.deploy;
24
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 import java.io.Serializable JavaDoc;
32
33 import com.sun.appserv.management.deploy.DeploymentStatus;
34
35 import com.sun.appserv.management.deploy.DeploymentStatusImpl;
36
37
38 import com.sun.enterprise.management.AMXTestBase;
39 import com.sun.enterprise.management.Capabilities;
40 import com.sun.appserv.management.util.misc.IteratorUtil;
41
42 /**
43  */

44 public final class DeploymentStatusTest extends junit.framework.TestCase
45 {
46         public
47     DeploymentStatusTest( )
48     {
49     }
50     
51     
52     
53         private DeploymentStatusImpl
54     createDeploymentStatus( final Object JavaDoc deployID )
55     {
56         final DeploymentStatusImpl ds =
57             new DeploymentStatusImpl(
58             0,
59             "success",
60             "description",
61             null );
62         
63         final Throwable JavaDoc t = new Exception JavaDoc( "test", new Throwable JavaDoc( "test2" ) );
64         
65         ds.setStageThrowable( t );
66         assert( ds.getStageThrowable() == t );
67         
68         return( ds );
69     }
70     
71         public void
72     testCreateDeploymentStatus()
73     {
74         createDeploymentStatus( "dummy" );
75     }
76     
77     /**
78         An alternative impl, to ensure the logic doesn't assume a particular impl.
79      */

80     private static final class DeploymentStatusFoo
81         implements DeploymentStatus, Serializable JavaDoc
82     {
83         public static final long serialVersionUID = 983629292;
84         
85         final ArrayList JavaDoc<DeploymentStatus> mSubStages;
86         final Map JavaDoc<String JavaDoc,Serializable JavaDoc> mMap;
87         final Exception JavaDoc mException;
88         DeploymentStatus mParent;
89         
90             public
91         DeploymentStatusFoo()
92         {
93             mSubStages = new ArrayList JavaDoc<DeploymentStatus>();
94             mException = new Exception JavaDoc();
95             mParent = null;
96             
97             mMap = new HashMap JavaDoc<String JavaDoc,Serializable JavaDoc>();
98             putField( STAGE_STATUS_KEY, new Integer JavaDoc( 0 ) );
99             putField( STAGE_STATUS_MESSAGE_KEY, "status message" );
100             // putField( STAGE_THROWABLE_KEY, mException );
101
putField( STAGE_DESCRIPTION_KEY, "description" );
102         }
103             public void
104         addSubStage( DeploymentStatus subStage )
105         {
106             mSubStages.add( subStage );
107             subStage.setParent( this );
108         }
109         
110             public String JavaDoc
111         getMapClassName()
112         {
113             return( DEPLOYMENT_STATUS_CLASS_NAME );
114         }
115         
116             public Map JavaDoc<String JavaDoc,Serializable JavaDoc>
117         asMap()
118         {
119             final Map JavaDoc<String JavaDoc,Serializable JavaDoc> m = new HashMap JavaDoc<String JavaDoc,Serializable JavaDoc>();
120             
121             m.putAll( mMap );
122             
123             if ( mSubStages.size() != 0 )
124             {
125                 final DeploymentStatus[] s = new DeploymentStatus[ mSubStages.size() ];
126                 mSubStages.toArray( s );
127                 m.put( SUB_STAGES_KEY, s );
128             }
129             
130             m.put( MAP_CAPABLE_CLASS_NAME_KEY, getMapClassName() );
131             
132             return( m );
133         }
134     
135             public void
136         putField( final String JavaDoc key, final Serializable JavaDoc value )
137         {
138             mMap.put( key, value );
139         }
140
141             public Iterator JavaDoc<Map JavaDoc<String JavaDoc,Serializable JavaDoc>>
142         getSubStages()
143         {
144             if ( mSubStages.size() == 0 )
145             {
146                 return( null );
147             }
148             
149             final List JavaDoc<Map JavaDoc<String JavaDoc,Serializable JavaDoc>> maps = new ArrayList JavaDoc<Map JavaDoc<String JavaDoc,Serializable JavaDoc>>();
150             for( final DeploymentStatus ds : mSubStages )
151             {
152                 maps.add( ds.asMap() );
153             }
154             
155             return( maps.iterator() );
156         }
157         
158             public List JavaDoc<DeploymentStatus>
159         getSubStagesList()
160         {
161             return( mSubStages );
162         }
163
164         public int getStageStatus() { return( getStatusCode() ); }
165         public String JavaDoc getStageStatusMessage() { return( "status message" ); }
166         
167         public Throwable JavaDoc getThrowable() { return( mException ); }
168         public Throwable JavaDoc getStageThrowable() { return( getThrowable() ); }
169         public int getStatusCode()
170             { return( getStageThrowable() == null ? STATUS_CODE_SUCCESS : STATUS_CODE_FAILURE ); }
171
172         public String JavaDoc getStageDescription() { return( "stage description" ); }
173
174         public DeploymentStatus getParent() { return( mParent ); }
175         
176         public Map JavaDoc<String JavaDoc,Serializable JavaDoc> getAdditionalStatus()
177         {
178             return( null );
179         }
180         
181             public void
182         setParent( DeploymentStatus parent )
183         {
184             mParent = parent;
185         }
186         
187             public boolean
188         equals( Object JavaDoc rhs )
189         {
190             return( new DeploymentStatusImpl( this ).equals( rhs ) );
191         }
192         
193             public String JavaDoc
194         toString()
195         {
196             return( new DeploymentStatusImpl( this.asMap() ).toString() );
197         }
198     }
199     
200         public void
201     testDeploymentStatusFromMap()
202     {
203         final DeploymentStatusImpl ds = createDeploymentStatus( "dummy" );
204         final DeploymentStatusFoo stage1 = new DeploymentStatusFoo();
205         ds.addSubStage( stage1 );
206         
207         final Map JavaDoc<String JavaDoc,Serializable JavaDoc> data = ds.asMap();
208         
209         final DeploymentStatusImpl ds2 = new DeploymentStatusImpl( data );
210         
211         assert( ds2.equals( ds ) );
212     }
213     
214     
215         public void
216     testDeploymentStatusAsMap()
217     {
218         final DeploymentStatusImpl ds = createDeploymentStatus( "dummy" );
219         
220         final Map JavaDoc<String JavaDoc,Serializable JavaDoc> m = ds.asMap();
221     }
222     
223     
224         public void
225     testCreateDeploymentStatusFromDeploymentStatus()
226     {
227         final DeploymentStatusFoo foo = new DeploymentStatusFoo();
228         final DeploymentStatusImpl ds = new DeploymentStatusImpl( foo );
229         
230         assert( foo.equals( ds ) );
231         assert( ds.equals( foo ) );
232     }
233     
234         public void
235     testDeploymentStatusSubStages()
236     {
237         final DeploymentStatusFoo stage1 = new DeploymentStatusFoo();
238         final DeploymentStatusFoo stage2 = new DeploymentStatusFoo();
239         final DeploymentStatusFoo stage1_1 = new DeploymentStatusFoo();
240         final DeploymentStatusFoo stage2_1 = new DeploymentStatusFoo();
241         
242         final DeploymentStatusImpl root = createDeploymentStatus( "root" );
243         assert( stage1.getParent() == null );
244         root.addSubStage( stage1 );
245         assert( stage1.getParent() == root );
246         root.addSubStage( stage2 );
247         assert( stage2.getParent() == root );
248         stage1.addSubStage( stage1_1 );
249         assert( stage1_1.getParent() == stage1 );
250         stage2.addSubStage( stage2_1 );
251         assert( stage2_1.getParent() == stage2 );
252         
253         final List JavaDoc<DeploymentStatus> subStages = root.getSubStagesList();
254         assert( subStages.get(0) == stage1 );
255         assert( subStages.get(1) == stage2 );
256     }
257     
258     private static final class MyException extends Exception JavaDoc
259     {
260         public static final long serialVersionUID = 833629292;
261         
262         public MyException( Throwable JavaDoc cause )
263         {
264             super( cause );
265         }
266         
267         public MyException( )
268         {
269         }
270     }
271     
272         public void
273     testIllegalThrowableDetected()
274     {
275         final DeploymentStatusImpl root = createDeploymentStatus( "root" );
276         
277         final Throwable JavaDoc t = new MyException( new MyException() );
278         root.setStageThrowable( t );
279         assert( root.getStageThrowable() != t );
280     }
281     
282 }
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
Popular Tags