1 19 20 package org.netbeans; 21 22 import java.util.Arrays ; 23 import java.util.HashSet ; 24 import java.util.Set ; 25 import java.util.jar.Manifest ; 26 import org.netbeans.junit.NbTestCase; 27 28 31 public class ConsistencyVerifierTest extends NbTestCase { 32 33 public ConsistencyVerifierTest(String n) { 34 super(n); 35 } 36 37 private Set <Manifest > modules(String ... descs) { 38 Set <Manifest > modules = new HashSet <Manifest >(); 39 for (String desc : descs) { 40 Manifest m = new Manifest (); 41 for (String piece : desc.split("; ")) { 42 String [] lhsRhs = piece.split("="); 43 assert lhsRhs.length == 2 : "'" + piece + "' in '" + desc + "'"; 44 m.getMainAttributes().putValue( 45 lhsRhs[0].length() == 0 ? "OpenIDE-Module" : "OpenIDE-Module-" + lhsRhs[0], 46 lhsRhs[1]); 47 } 48 modules.add(m); 49 } 50 return modules; 51 } 52 53 private void assertProblems(String problems, String ... descs) { 54 assertEquals("for " + Arrays.toString(descs), 55 problems, ConsistencyVerifier.findInconsistencies(modules(descs)).toString()); 56 } 57 58 public void testBasicFunctionality() throws Exception { 59 assertProblems("{}", 60 "=foo", 61 "=bar; Module-Dependencies=foo"); 62 assertProblems("{foo=[module bar]}", 63 "=foo; Module-Dependencies=bar"); 64 assertProblems("{foo=[requires svc]}", 65 "=foo; Requires=svc"); 66 assertProblems("{}", 67 "=foo; Requires=svc", 68 "=bar; Provides=svc"); 69 assertProblems("{bar=[requires svc], foo=[requires svc]}", 70 "=foo; Requires=svc", 71 "=bar; Requires=svc"); 72 assertProblems("{foo=[module bar > 2.0, requires svc]}", 73 "=foo; Requires=svc; Module-Dependencies=bar > 2.0", 74 "=bar; Specification-Version=1.5"); 75 } 76 77 public void testStandardProvides() throws Exception { 78 assertProblems("{}", 79 "=foo; Requires=org.openide.modules.ModuleFormat1"); 80 assertProblems("{foo=[requires org.openide.modules.ModuleFormat2]}", 81 "=foo; Requires=org.openide.modules.ModuleFormat2"); 82 assertProblems("{}", 83 "=foo; Requires=org.openide.modules.os.Unix"); 84 assertProblems("{}", 85 "=foo; Requires=org.openide.modules.os.PlainUnix"); 86 assertProblems("{}", 87 "=foo; Requires=org.openide.modules.os.Windows"); 88 assertProblems("{}", 89 "=foo; Requires=org.openide.modules.os.MacOSX"); 90 assertProblems("{}", 91 "=foo; Requires=org.openide.modules.os.OS2"); 92 assertProblems("{foo=[requires org.openide.modules.os.Windoze]}", 93 "=foo; Requires=org.openide.modules.os.Windoze"); 94 } 95 96 public void testIAE() throws Exception { 97 try { 98 ConsistencyVerifier.findInconsistencies(modules("=foo; Whatever=1", "=foo; Whatever=2")); 99 fail(); 100 } catch (IllegalArgumentException x) {} 101 try { 102 ConsistencyVerifier.findInconsistencies(modules("Whatever=17")); 103 fail(); 104 } catch (IllegalArgumentException x) {} 105 try { 106 ConsistencyVerifier.findInconsistencies(modules("=11")); 107 fail(); 108 } catch (IllegalArgumentException x) {} 109 } 110 111 } 112 | Popular Tags |