1 19 20 package org.netbeans.core.startup; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 import org.netbeans.CLIHandler; 26 import org.netbeans.junit.NbTestCase; 27 28 31 public class CLILookupExecTest extends NbTestCase { 32 File home, cluster2, user; 33 34 public CLILookupExecTest(String name) { 35 super(name); 36 } 37 38 protected void setUp() throws Exception { 39 clearWorkDir(); 40 41 home = new File (getWorkDir(), "nb/cluster1"); 42 cluster2 = new File (getWorkDir(), "nb/cluster2"); 43 user = new File (getWorkDir(), "testuserdir"); 44 45 home.mkdirs(); 46 cluster2.mkdirs(); 47 user.mkdirs(); 48 49 System.setProperty("netbeans.home", home.toString()); 50 System.setProperty("netbeans.dirs", cluster2.toString()); 51 } 52 53 54 protected void tearDown() throws Exception { 55 } 56 57 public void testModuleInAClusterCanBeFound() throws Exception { 58 createJAR(home, "test-module-one", One.class); 59 createJAR(cluster2, "test-module-two", Two.class); 60 createJAR(user, "test-module-user", User.class); 61 62 org.netbeans.Main.main(new String [] { "--userdir", user.toString(), "--nosplash", "--one", "--two", "--three"}); 63 org.netbeans.Main.finishInitialization(); 64 65 assertEquals("Usage one", 0, One.usageCnt); assertEquals("CLI one", 1, One.cliCnt); 66 assertEquals("Usage two", 0, Two.usageCnt); assertEquals("CLI two ", 1, Two.cliCnt); 67 assertEquals("Usage user", 0, User.usageCnt); assertEquals("CLI user", 1, User.cliCnt); 68 } 69 70 private static void createJAR(File cluster, String moduleName, Class metaInfHandler) 71 throws IOException { 72 CLILookupHelpTest.createJAR(cluster, moduleName, metaInfHandler); 73 } 74 75 private static void assertArg(String [] arr, String expected) { 76 for (int i = 0; i < arr.length; i++) { 77 if (expected.equals(arr[i])) { 78 arr[i] = null; 79 return; 80 } 81 } 82 83 fail("There should be: " + expected + " but was only: " + java.util.Arrays.asList(arr)); 84 } 85 86 public static final class One extends CLIHandler { 87 public static int cliCnt; 88 public static int usageCnt; 89 90 public One() { 91 super(WHEN_EXTRA); 92 } 93 94 protected int cli(CLIHandler.Args args) { 95 assertArg(args.getArguments(), "--one"); 96 cliCnt++; 97 return 0; 98 } 99 100 protected void usage(PrintWriter w) { 101 usageCnt++; 102 } 103 } 104 public static final class Two extends CLIHandler { 105 public static int cliCnt; 106 public static int usageCnt; 107 108 public Two() { 109 super(WHEN_EXTRA); 110 } 111 112 protected int cli(CLIHandler.Args args) { 113 assertArg(args.getArguments(), "--two"); 114 cliCnt++; 115 return 0; 116 } 117 118 protected void usage(PrintWriter w) { 119 usageCnt++; 120 } 121 } 122 public static final class User extends CLIHandler { 123 public static int cliCnt; 124 public static int usageCnt; 125 126 public User() { 127 super(WHEN_EXTRA); 128 } 129 130 protected int cli(CLIHandler.Args args) { 131 assertArg(args.getArguments(), "--three"); 132 cliCnt++; 133 return 0; 134 } 135 136 protected void usage(PrintWriter w) { 137 usageCnt++; 138 } 139 } 140 } 141 | Popular Tags |