1 8 package org.apache.avalon.excalibur.extension.test; 9 10 import java.io.InputStream ; 11 import java.util.jar.Manifest ; 12 import java.util.ArrayList ; 13 import junit.framework.TestCase; 14 import org.apache.avalon.excalibur.extension.Extension; 15 16 22 public class ExtensionTestCase 23 extends TestCase 24 { 25 private final static String MF1_NAME = "excalibur.extension"; 26 private final static String MF1_SVERSION = "1.0.1"; 27 private final static String MF1_SVENDOR = "Jakarta Apache"; 28 private final static String MF1_IVENDORID = "org.apache.jakarta"; 29 private final static String MF1_IVENDOR = "Jakarta Apache Project"; 30 private final static String MF1_IVERSION = "1.0.2"; 31 private final static String MF1_IURL = null; 32 33 private final static String MF2_NAME = "excalibur.extension"; 34 private final static String MF2_SVERSION = "1.0.1"; 35 private final static String MF2_SVENDOR = "Jakarta Apache"; 36 private final static String MF2_IVENDORID = "org.apache.jakarta"; 37 private final static String MF2_IVENDOR = "Jakarta Apache Project"; 38 private final static String MF2_IVERSION = "1.0.2"; 39 private final static String MF2_IURL = null; 40 41 private final static String MFR1_NAME = "excalibur.required1"; 42 private final static String MFR1_SVERSION = "1.0"; 43 private final static String MFR1_SVENDOR = null; 44 private final static String MFR1_IVENDORID = "org.apache.jakarta"; 45 private final static String MFR1_IVENDOR = null; 46 private final static String MFR1_IVERSION = "1.0.2"; 47 private final static String MFR1_IURL = "http://jakarta.apache.org/avalon/excalibur/required1.jar"; 48 49 private final static String MF3_NAME = "excalibur.required1"; 50 private final static String MF3_SVERSION = "1.1"; 51 private final static String MF3_SVENDOR = "Jakarta Apache"; 52 private final static String MF3_IVENDORID = "org.apache.jakarta"; 53 private final static String MF3_IVENDOR = "Jakarta Apache Project"; 54 private final static String MF3_IVERSION = "1.0.2"; 55 private final static String MF3_IURL = null; 56 57 private final static String MF4_NAME = "excalibur.required1"; 58 private final static String MF4_SVERSION = "1.0"; 59 private final static String MF4_SVENDOR = "Jakarta Apache"; 60 private final static String MF4_IVENDORID = "org.apache.jakarta"; 61 private final static String MF4_IVENDOR = "Jakarta Apache Project"; 62 private final static String MF4_IVERSION = "1.0.3"; 63 private final static String MF4_IURL = null; 64 65 public ExtensionTestCase( String name ) 66 { 67 super( name ); 68 } 69 70 private Manifest getManifest( final String name ) 71 throws Exception 72 { 73 final InputStream inputStream = getClass().getResourceAsStream( name ); 74 return new Manifest ( inputStream ); 75 } 76 77 public void testAvailable() 78 throws Exception 79 { 80 final Manifest manifest = getManifest( "manifest-1.mf" ); 81 final Extension[] available = Extension.getAvailable( manifest ); 82 83 assertEquals( "Available Count", 1, available.length ); 84 assertEquals( "Available Name", MF1_NAME, available[ 0 ].getExtensionName() ); 85 assertEquals( "Available SpecVendor", MF1_SVENDOR, available[ 0 ].getSpecificationVendor() ); 86 assertEquals( "Available SpecVersion", MF1_SVERSION, 87 available[ 0 ].getSpecificationVersion().toString() ); 88 assertEquals( "Available URL", MF1_IURL, available[ 0 ].getImplementationURL() ); 89 assertEquals( "Available ImpVendor", MF1_IVENDOR, available[ 0 ].getImplementationVendor() ); 90 assertEquals( "Available ImpVendorId", MF1_IVENDORID, available[ 0 ].getImplementationVendorId() ); 91 assertEquals( "Available ImpVersion", MF1_IVERSION, 92 available[ 0 ].getImplementationVersion().toString() ); 93 } 94 95 public void testRequired() 96 throws Exception 97 { 98 final Manifest manifest = getManifest( "manifest-2.mf" ); 99 final Extension[] available = Extension.getAvailable( manifest ); 100 101 assertEquals( "Available Count", 1, available.length ); 102 assertEquals( "Available Name", MF2_NAME, available[ 0 ].getExtensionName() ); 103 assertEquals( "Available SpecVendor", MF2_SVENDOR, available[ 0 ].getSpecificationVendor() ); 104 assertEquals( "Available SpecVersion", MF2_SVERSION, 105 available[ 0 ].getSpecificationVersion().toString() ); 106 assertEquals( "Available URL", MF2_IURL, available[ 0 ].getImplementationURL() ); 107 assertEquals( "Available ImpVendor", MF2_IVENDOR, available[ 0 ].getImplementationVendor() ); 108 assertEquals( "Available ImpVendorId", MF2_IVENDORID, available[ 0 ].getImplementationVendorId() ); 109 assertEquals( "Available ImpVersion", MF2_IVERSION, 110 available[ 0 ].getImplementationVersion().toString() ); 111 112 final Extension[] required = Extension.getRequired( manifest ); 113 assertEquals( "Available Count", 1, required.length ); 114 assertEquals( "required Name", MFR1_NAME, required[ 0 ].getExtensionName() ); 115 assertEquals( "required SpecVendor", MFR1_SVENDOR, required[ 0 ].getSpecificationVendor() ); 116 assertEquals( "required SpecVersion", MFR1_SVERSION, 117 required[ 0 ].getSpecificationVersion().toString() ); 118 assertEquals( "required URL", MFR1_IURL, required[ 0 ].getImplementationURL() ); 119 assertEquals( "required ImpVendor", MFR1_IVENDOR, required[ 0 ].getImplementationVendor() ); 120 assertEquals( "required ImpVendorId", MFR1_IVENDORID, required[ 0 ].getImplementationVendorId() ); 121 assertEquals( "required ImpVersion", MFR1_IVERSION, 122 required[ 0 ].getImplementationVersion().toString() ); 123 } 124 125 public void testManifest3() 126 throws Exception 127 { 128 final Manifest manifest = getManifest( "manifest-3.mf" ); 129 final Extension[] available = Extension.getAvailable( manifest ); 130 131 assertEquals( "Available Count", 1, available.length ); 132 assertEquals( "Available Name", MF3_NAME, available[ 0 ].getExtensionName() ); 133 assertEquals( "Available SpecVendor", MF3_SVENDOR, available[ 0 ].getSpecificationVendor() ); 134 assertEquals( "Available SpecVersion", MF3_SVERSION, 135 available[ 0 ].getSpecificationVersion().toString() ); 136 assertEquals( "Available URL", MF3_IURL, available[ 0 ].getImplementationURL() ); 137 assertEquals( "Available ImpVendor", MF3_IVENDOR, available[ 0 ].getImplementationVendor() ); 138 assertEquals( "Available ImpVendorId", MF3_IVENDORID, available[ 0 ].getImplementationVendorId() ); 139 assertEquals( "Available ImpVersion", MF3_IVERSION, 140 available[ 0 ].getImplementationVersion().toString() ); 141 142 final Extension[] required = Extension.getRequired( manifest ); 143 assertEquals( "Required Count", 1, required.length ); 144 } 145 146 public void testManifest4() 147 throws Exception 148 { 149 final Manifest manifest = getManifest( "manifest-4.mf" ); 150 final Extension[] available = Extension.getAvailable( manifest ); 151 152 assertEquals( "Available Count", 1, available.length ); 153 assertEquals( "Available Name", MF4_NAME, available[ 0 ].getExtensionName() ); 154 assertEquals( "Available SpecVendor", MF4_SVENDOR, available[ 0 ].getSpecificationVendor() ); 155 assertEquals( "Available SpecVersion", MF4_SVERSION, 156 available[ 0 ].getSpecificationVersion().toString() ); 157 assertEquals( "Available URL", MF4_IURL, available[ 0 ].getImplementationURL() ); 158 assertEquals( "Available ImpVendor", MF4_IVENDOR, available[ 0 ].getImplementationVendor() ); 159 assertEquals( "Available ImpVendorId", MF4_IVENDORID, available[ 0 ].getImplementationVendorId() ); 160 assertEquals( "Available ImpVersion", MF4_IVERSION, 161 available[ 0 ].getImplementationVersion().toString() ); 162 163 final Extension[] required = Extension.getRequired( manifest ); 164 assertEquals( "Available Count", 0, required.length ); 165 } 166 167 public void testCompatible() 168 throws Exception 169 { 170 final Manifest manifest2 = getManifest( "manifest-2.mf" ); 171 final Manifest manifest3 = getManifest( "manifest-3.mf" ); 172 final Manifest manifest4 = getManifest( "manifest-4.mf" ); 173 final Manifest manifest5 = getManifest( "manifest-5.mf" ); 174 final Manifest manifest6 = getManifest( "manifest-6.mf" ); 175 final Manifest manifest7 = getManifest( "manifest-7.mf" ); 176 177 final Extension req1 = Extension.getRequired( manifest2 )[ 0 ]; 178 final Extension req2 = Extension.getRequired( manifest5 )[ 0 ]; 179 final Extension req3 = Extension.getRequired( manifest6 )[ 0 ]; 180 final Extension req4 = Extension.getRequired( manifest7 )[ 0 ]; 181 182 final Extension avail3 = Extension.getAvailable( manifest3 )[ 0 ]; 183 final Extension avail4 = Extension.getAvailable( manifest4 )[ 0 ]; 184 185 assertTrue( "avail3.isCompatibleWith( req1 )", avail3.isCompatibleWith( req1 ) ); 186 assertTrue( "avail4.isCompatibleWith( req1 )", avail4.isCompatibleWith( req1 ) ); 187 assertTrue( "avail3.isCompatibleWith( req2 )", avail3.isCompatibleWith( req2 ) ); 188 assertTrue( "avail4.isCompatibleWith( req2 )", avail4.isCompatibleWith( req2 ) ); 189 assertTrue( "avail3.isCompatibleWith( req3 )", avail3.isCompatibleWith( req3 ) ); 190 assertTrue( "!avail4.isCompatibleWith( req3 )", !avail4.isCompatibleWith( req3 ) ); 191 assertTrue( "avail3.isCompatibleWith( req4 )", avail3.isCompatibleWith( req4 ) ); 192 assertTrue( "avail4.isCompatibleWith( req4 )", avail4.isCompatibleWith( req4 ) ); 193 } 194 195 196 public void testSpacesAfterAttributes() 197 throws Exception 198 { 199 final Manifest manifest = getManifest( "manifest-9.mf" ); 202 final Extension[] available = Extension.getAvailable( manifest ); 203 204 assertEquals( "Available Count", 1, available.length ); 205 assertEquals( "Available Name", MF1_NAME, available[ 0 ].getExtensionName() ); 206 assertEquals( "Available SpecVendor", MF1_SVENDOR, available[ 0 ].getSpecificationVendor() ); 207 assertEquals( "Available SpecVersion", MF1_SVERSION, 208 available[ 0 ].getSpecificationVersion().toString() ); 209 assertEquals( "Available URL", MF1_IURL, available[ 0 ].getImplementationURL() ); 210 assertEquals( "Available ImpVendor", MF1_IVENDOR, available[ 0 ].getImplementationVendor() ); 211 assertEquals( "Available ImpVendorId", MF1_IVENDORID, available[ 0 ].getImplementationVendorId() ); 212 assertEquals( "Available ImpVersion", MF1_IVERSION, 213 available[ 0 ].getImplementationVersion().toString() ); 214 } 215 } 216 | Popular Tags |