1
2
3
4
5
6
7
8
9
10
11
12
13
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 Embedded";
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 }