KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > module > TestCmsModuleVersion


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/module/TestCmsModuleVersion.java,v $
3  * Date : $Date: 2005/06/26 11:23:00 $
4  * Version: $Revision: 1.8 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31  
32 package org.opencms.module;
33
34 import org.opencms.main.CmsIllegalArgumentException;
35
36 import junit.framework.TestCase;
37
38 /**
39  * Tests the module version.<p>
40  *
41  * @author Alexander Kandzior
42  *
43  * @version $Revision: 1.8 $
44  */

45 public class TestCmsModuleVersion extends TestCase {
46     
47     /**
48      * Default JUnit constructor.<p>
49      *
50      * @param arg0 JUnit parameters
51      */

52     public TestCmsModuleVersion(String JavaDoc arg0) {
53         super(arg0);
54     }
55
56     /**
57      * Tests version increment.<p>
58      */

59     public void testVersionIncrement() {
60         
61         CmsModuleVersion v1 = new CmsModuleVersion("1.2.5");
62         v1.increment();
63         assertEquals("1.2.6", v1.getVersion());
64         
65         v1 = new CmsModuleVersion("1.02.05");
66         v1.increment();
67         assertEquals("1.2.6", v1.getVersion());
68
69         v1 = new CmsModuleVersion("1.02.999");
70         v1.increment();
71         assertEquals("1.3.0", v1.getVersion());
72
73         v1 = new CmsModuleVersion("0.999");
74         v1.increment();
75         assertEquals("1.0", v1.getVersion());
76         
77         boolean gotError = false;
78         try {
79             v1 = new CmsModuleVersion("999.999.999.999");
80             v1.increment();
81         } catch (RuntimeException JavaDoc e) {
82             gotError = true;
83         }
84         if (! gotError) {
85             fail("Invalid version increment allowed");
86         }
87     }
88     
89     /**
90      * Tests version generation.<p>
91      */

92     public void testVersionGeneration() {
93         
94         CmsModuleVersion v1 = new CmsModuleVersion("1.2.5");
95         CmsModuleVersion v2 = new CmsModuleVersion("1.12");
96         
97         if (v1.compareTo(v2) > 0) {
98             fail("Module version comparison error");
99         }
100         
101         v1 = new CmsModuleVersion("5");
102         v2 = new CmsModuleVersion("1.0.0.1");
103         
104         if (v1.compareTo(v2) <= 0) {
105             fail("Module version comparison error");
106         }
107
108         v1 = new CmsModuleVersion("1.2.5.7");
109         v2 = new CmsModuleVersion("1.2.45");
110         
111         if (v1.compareTo(v2) > 0) {
112             fail("Module version comparison error");
113         }
114
115         v1 = new CmsModuleVersion("2.45.6");
116         v2 = new CmsModuleVersion("2.45.06");
117         
118         if (v1.compareTo(v2) != 0) {
119             fail("Module version comparison error");
120         }
121         
122         v1 = new CmsModuleVersion("1.0.0.0");
123         v2 = new CmsModuleVersion("1");
124         
125         if (v1.compareTo(v2) != 0) {
126             fail("Module version comparison error");
127         }
128         
129         v1 = new CmsModuleVersion("0.1");
130         v2 = new CmsModuleVersion("0.0.0.1");
131         
132         if (v1.compareTo(v2) <= 0) {
133             fail("Module version comparison error");
134         }
135         
136         v1 = new CmsModuleVersion("0.08");
137         assertEquals("0.8", v1.getVersion());
138         
139         v1 = new CmsModuleVersion("00.00");
140         assertEquals("0.0", v1.getVersion());
141
142         v1 = new CmsModuleVersion("999.999.999.999");
143         assertEquals("999.999.999.999", v1.getVersion());
144         
145         boolean gotError = false;
146         try {
147             v1 = new CmsModuleVersion("2..45.6");
148         } catch (CmsIllegalArgumentException e) {
149             gotError = true;
150         }
151         if (! gotError) {
152             fail("Invalid version generation allowed");
153         }
154         
155         gotError = false;
156         try {
157             v1 = new CmsModuleVersion(".2.45.6");
158         } catch (CmsIllegalArgumentException e) {
159             gotError = true;
160         }
161         if (! gotError) {
162             fail("Invalid version generation allowed");
163         }
164
165         gotError = false;
166         try {
167             v1 = new CmsModuleVersion("2.45.6.");
168         } catch (CmsIllegalArgumentException e) {
169             gotError = true;
170         }
171         if (! gotError) {
172             fail("Invalid version generation allowed");
173         }
174
175         gotError = false;
176         try {
177             v1 = new CmsModuleVersion("wurst");
178         } catch (CmsIllegalArgumentException e) {
179             gotError = true;
180         }
181         if (! gotError) {
182             fail("Invalid version generation allowed");
183         }
184
185         gotError = false;
186         try {
187             v1 = new CmsModuleVersion("2222.45.6");
188         } catch (CmsIllegalArgumentException e) {
189             gotError = true;
190         }
191         if (! gotError) {
192             fail("Invalid version generation allowed");
193         }
194         
195         gotError = false;
196         try {
197             v1 = new CmsModuleVersion("1.2.3.4.5");
198         } catch (CmsIllegalArgumentException e) {
199             gotError = true;
200         }
201         if (! gotError) {
202             fail("Invalid version generation allowed");
203         }
204     }
205
206 }
207
Popular Tags