View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.util;
17  
18  import java.util.jar.Attributes;
19  import java.util.jar.Manifest;
20  
21  import junit.framework.Assert;
22  
23  import org.apache.cxf.common.util.StringUtils;
24  import org.junit.Test;
25  
26  public class TestManifestInspector {
27  	String name = "Kuali Student Bundled with All-In-One Rice";
28  	String version = "1.1.0-M8-SNAPSHOT";
29  	String timestamp = "2010-08-10 21:35 EDT";
30  	String buildNumber = "89";
31  
32  	@Test
33  	public void testNullManifest() throws Exception {
34  		ManifestInspector mi = new ManifestInspector();
35  		BuildInformation bi = mi.getBuildInformation(null);
36  		Assert.assertNull(bi);
37  	}
38  
39  	@Test
40  	public void testEmptyManifest() throws Exception {
41  		ManifestInspector mi = new ManifestInspector();
42  		Manifest manifest = new Manifest();
43  		BuildInformation bi = mi.getBuildInformation(manifest);
44  		Assert.assertTrue(mi.isNullOrEmpty(bi));
45  		String s = mi.toString(bi);
46  		Assert.assertEquals(s, ManifestInspector.NO_BUILD_INFORMATION_AVAILABLE);
47  	}
48  
49  	@Test
50  	public void testNoBuildNumberManifest() throws Exception {
51  		ManifestInspector mi = new ManifestInspector();
52  		Manifest manifest = new Manifest();
53  		Attributes attributes = manifest.getMainAttributes();
54  		attributes.putValue(ManifestInspector.BUNDLE_NAME, name);
55  		attributes.putValue(ManifestInspector.BUNDLE_VERSION, version);
56  		attributes.putValue(ManifestInspector.BUNDLE_TIMESTAMP, timestamp);
57  		BuildInformation bi = mi.getBuildInformation(manifest);
58  		Assert.assertFalse(mi.isNullOrEmpty(bi));
59  		Assert.assertTrue(StringUtils.isEmpty(bi.getBuildNumber()));
60  		String testString = name + " :: " + version + " :: " + timestamp;
61  		String s = mi.toString(bi);
62  		Assert.assertEquals(s, testString);
63  	}
64  
65  	@Test
66  	public void testFullBuildInfo() throws Exception {
67  		ManifestInspector mi = new ManifestInspector();
68  		Manifest manifest = new Manifest();
69  		Attributes attributes = manifest.getMainAttributes();
70  		attributes.putValue(ManifestInspector.BUNDLE_NAME, name);
71  		attributes.putValue(ManifestInspector.BUNDLE_VERSION, version);
72          attributes.putValue(ManifestInspector.BUNDLE_BUILD_NUMBER, buildNumber);
73  		attributes.putValue(ManifestInspector.BUNDLE_TIMESTAMP, timestamp);
74  		BuildInformation bi = mi.getBuildInformation(manifest);
75  		Assert.assertFalse(mi.isNullOrEmpty(bi));
76  		String testString = name + " :: " + version + " :: #" + buildNumber + " :: " + timestamp;
77  		String s = mi.toString(bi);
78  		Assert.assertEquals(s, testString);
79  	}
80  
81  }