1 17 18 package org.apache.avalon.extension.test; 19 20 import java.io.InputStream ; 21 import java.util.jar.Manifest ; 22 23 import junit.framework.TestCase; 24 25 import org.apache.avalon.extension.Specification; 26 27 33 public class SpecificationTestCase 34 extends TestCase 35 { 36 private static final String MF1_STITLE = "org.realityforge.dve"; 37 private static final String MF1_SVERSION = "1.0.2"; 38 private static final String MF1_SVENDOR = "Peter Donald"; 39 private static final String MF1_ITITLE = "DVE vi OS3P"; 40 private static final String MF1_IVENDOR = "Peter Donald"; 41 private static final String MF1_IVERSION = "1.0.2Alpha"; 42 43 private static final String MF2_STITLE = "org.apache.phoenix"; 44 private static final String MF2_SVERSION = "1.0.2"; 45 private static final String MF2_SVENDOR = "Apache"; 46 private static final String MF2_ITITLE = "Apache Phoenix"; 47 private static final String MF2_IVENDOR = "Apache"; 48 private static final String MF2_IVERSION = "1.0.2"; 49 50 public SpecificationTestCase( String name ) 51 { 52 super( name ); 53 } 54 55 private Manifest getManifest( final String name ) 56 throws Exception 57 { 58 final InputStream inputStream = getClass().getResourceAsStream( name ); 59 return new Manifest ( inputStream ); 60 } 61 62 private Specification[] getPackageSpecifcations( final String name ) 63 throws Exception 64 { 65 final Manifest manifest = getManifest( name ); 66 return Specification.getSpecifications( manifest ); 67 } 68 69 private void checkMissing( final int manifestID, final String attribute ) 70 { 71 try 72 { 73 getPackageSpecifcations( "specification-" + manifestID + ".mf" ); 74 } 75 catch( final Throwable t ) 76 { 77 return; 78 } 79 fail( "Missing " + attribute + " parsed" ); 80 } 81 82 public void testSpecifications() 83 throws Exception 84 { 85 final Specification[] specifications = getPackageSpecifcations( "specification-1.mf" ); 86 87 assertEquals( "Count", 1, specifications.length ); 88 assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() ); 89 assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() ); 90 assertEquals( "SpecVersion", MF1_SVERSION, 91 specifications[ 0 ].getSpecificationVersion().toString() ); 92 assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() ); 93 assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() ); 94 assertEquals( "ImpVersion", MF1_IVERSION, 95 specifications[ 0 ].getImplementationVersion().toString() ); 96 } 97 98 public void testSpaceAtEOL() 99 throws Exception 100 { 101 final Specification[] specifications = getPackageSpecifcations( "specification-7.mf" ); 104 105 assertEquals( "Count", 1, specifications.length ); 106 assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() ); 107 assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() ); 108 assertEquals( "SpecVersion", MF1_SVERSION, 109 specifications[ 0 ].getSpecificationVersion().toString() ); 110 assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() ); 111 assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() ); 112 assertEquals( "ImpVersion", MF1_IVERSION, 113 specifications[ 0 ].getImplementationVersion().toString() ); 114 } 115 116 public void testMultiSection() 117 throws Exception 118 { 119 final Specification[] specifications = getPackageSpecifcations( "specification-8.mf" ); 120 121 assertEquals( "Count", 1, specifications.length ); 122 assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() ); 123 assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() ); 124 assertEquals( "SpecVersion", MF1_SVERSION, 125 specifications[ 0 ].getSpecificationVersion().toString() ); 126 assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() ); 127 assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() ); 128 assertEquals( "ImpVersion", MF1_IVERSION, 129 specifications[ 0 ].getImplementationVersion().toString() ); 130 } 131 132 public void testMultiSectionMultiSpec() 133 throws Exception 134 { 135 final Specification[] specifications = getPackageSpecifcations( "specification-9.mf" ); 136 137 assertEquals( "Count", 2, specifications.length ); 138 assertEquals( "Name", MF1_STITLE, specifications[ 0 ].getSpecificationTitle() ); 139 assertEquals( "SpecVendor", MF1_SVENDOR, specifications[ 0 ].getSpecificationVendor() ); 140 assertEquals( "SpecVersion", MF1_SVERSION, 141 specifications[ 0 ].getSpecificationVersion().toString() ); 142 assertEquals( "ImpVendor", MF1_IVENDOR, specifications[ 0 ].getImplementationVendor() ); 143 assertEquals( "ImpTitle", MF1_ITITLE, specifications[ 0 ].getImplementationTitle() ); 144 assertEquals( "ImpVersion", MF1_IVERSION, 145 specifications[ 0 ].getImplementationVersion().toString() ); 146 147 assertEquals( "Name", MF2_STITLE, specifications[ 1 ].getSpecificationTitle() ); 148 assertEquals( "SpecVendor", MF2_SVENDOR, specifications[ 1 ].getSpecificationVendor() ); 149 assertEquals( "SpecVersion", MF2_SVERSION, 150 specifications[ 1 ].getSpecificationVersion().toString() ); 151 assertEquals( "ImpVendor", MF2_IVENDOR, specifications[ 1 ].getImplementationVendor() ); 152 assertEquals( "ImpTitle", MF2_ITITLE, specifications[ 1 ].getImplementationTitle() ); 153 assertEquals( "ImpVersion", MF2_IVERSION, 154 specifications[ 1 ].getImplementationVersion().toString() ); 155 } 156 157 public void testMissingSPecVersion() 158 throws Exception 159 { 160 checkMissing( 2, "SpecVersion" ); 161 } 162 163 public void testMissingSpecVendor() 164 throws Exception 165 { 166 checkMissing( 3, "SpecVendor" ); 167 } 168 169 public void testMissingImplTitle() 170 throws Exception 171 { 172 checkMissing( 4, "ImplTitle" ); 173 } 174 175 public void testMissingImplVendor() 176 throws Exception 177 { 178 checkMissing( 5, "ImplVendor" ); 179 } 180 181 public void testMissingImplVersion() 182 throws Exception 183 { 184 checkMissing( 6, "ImplVersion" ); 185 } 186 187 public void testCompatible() 188 throws Exception 189 { 190 final Specification req1 = 191 new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR, 192 MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR ); 193 final Specification req2 = 194 new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR, 195 null, null, null ); 196 final Specification req3 = 197 new Specification( MF1_STITLE, "1.0.1", MF1_SVENDOR, 198 null, null, null ); 199 final Specification req4 = 200 new Specification( MF1_STITLE, MF1_SVERSION, null, 201 null, null, null ); 202 final Specification req5 = 203 new Specification( "another title", MF1_SVERSION, MF1_SVENDOR, 204 MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR ); 205 206 final Specification avail1 = 207 new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR, 208 MF1_ITITLE, MF1_IVERSION, MF1_IVENDOR ); 209 final Specification avail2 = 210 new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR, 211 MF1_ITITLE, "another version", MF1_IVENDOR ); 212 final Specification avail3 = 213 new Specification( MF1_STITLE, MF1_SVERSION, MF1_SVENDOR, 214 MF1_ITITLE, MF1_IVERSION, "another vendor" ); 215 216 assertTrue( "avail1.isCompatibleWith( req1 )", avail1.isCompatibleWith( req1 ) ); 217 assertTrue( "avail1.isCompatibleWith( req2 )", avail1.isCompatibleWith( req2 ) ); 218 assertTrue( "avail1.isCompatibleWith( req3 )", avail1.isCompatibleWith( req3 ) ); 219 assertTrue( "avail1.isCompatibleWith( req4 )", avail1.isCompatibleWith( req4 ) ); 220 assertTrue( "!avail1.isCompatibleWith( req5 )", !avail1.isCompatibleWith( req5 ) ); 221 222 assertTrue( "!avail2.isCompatibleWith( req1 )", !avail2.isCompatibleWith( req1 ) ); 223 assertTrue( "avail2.isCompatibleWith( req2 )", avail2.isCompatibleWith( req2 ) ); 224 assertTrue( "avail2.isCompatibleWith( req3 )", avail2.isCompatibleWith( req3 ) ); 225 assertTrue( "avail2.isCompatibleWith( req4 )", avail2.isCompatibleWith( req4 ) ); 226 assertTrue( "!avail2.isCompatibleWith( req5 )", !avail2.isCompatibleWith( req5 ) ); 227 228 assertTrue( "!avail3.isCompatibleWith( req1 )", !avail3.isCompatibleWith( req1 ) ); 229 assertTrue( "avail3.isCompatibleWith( req2 )", avail3.isCompatibleWith( req2 ) ); 230 assertTrue( "avail3.isCompatibleWith( req3 )", avail3.isCompatibleWith( req3 ) ); 231 assertTrue( "avail3.isCompatibleWith( req4 )", avail3.isCompatibleWith( req4 ) ); 232 assertTrue( "!avail3.isCompatibleWith( req5 )", !avail3.isCompatibleWith( req5 ) ); 233 } 234 } 235 | Popular Tags |