📄 msvsstest.java
字号:
tstamp.setLocation(location); tstamp.setProject(project); Tstamp.CustomFormat format = tstamp.createFormat(); format.setProperty("today"); format.setPattern("HH:mm:ss z"); format.setTimezone("GMT"); Date date = Calendar.getInstance().getTime(); format.execute(project, date, location); String today = project.getProperty("today"); // Get today's date SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); String expected = sdf.format(date); // Set up a VSSHistory task MSVSSHISTORY vssHistory = new MSVSSHISTORY(); vssHistory.setProject(project); vssHistory.setLogin(VSS_USERNAME); vssHistory.setToDate(today); vssHistory.setVsspath(VSS_PROJECT_PATH); String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + expected, MSVSS.FLAG_LOGIN + VSS_USERNAME}; commandline = vssHistory.buildCmdLine(); checkCommandLines(sTestCmdLine, commandline.getCommandline()); } /** * Tests VSSHistory required attributes. */ public void testHistoryExceptions() { configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); expectSpecificBuildException("vsshistory.1", "some cause", "vsspath attribute must be set!"); } /** Tests CheckIn commandline generation. */ public void testCheckinCommandLine() { String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CHECKIN, DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_WRITABLE, MSVSS.FLAG_LOGIN + VSS_USERNAME, MSVSS.FLAG_COMMENT + SRC_COMMENT}; // Set up a VSSCheckIn task MSVSSCHECKIN vssCheckin = new MSVSSCHECKIN(); vssCheckin.setProject(project); vssCheckin.setComment(SRC_COMMENT); vssCheckin.setLogin(VSS_USERNAME); vssCheckin.setAutoresponse("N"); vssCheckin.setVsspath(VSS_PROJECT_PATH); vssCheckin.setWritable(true); commandline = vssCheckin.buildCmdLine(); checkCommandLines(sTestCmdLine, commandline.getCommandline()); } /** * Test VSSCheckIn required attributes. */ public void testCheckinExceptions() { configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); expectSpecificBuildException("vsscheckin.1", "some cause", "vsspath attribute must be set!"); } /** Tests CheckOut commandline generation. */ public void testCheckoutCommandLine() { String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_CHECKOUT, DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION_DATE + DATE, MSVSS.FLAG_LOGIN + VSS_USERNAME, FLAG_FILETIME_MODIFIED, FLAG_NO_GET}; // Set up a VSSCheckOut task MSVSSCHECKOUT vssCheckout = new MSVSSCHECKOUT(); vssCheckout.setProject(project); vssCheckout.setLogin(VSS_USERNAME); vssCheckout.setVsspath(DS_VSS_PROJECT_PATH); vssCheckout.setRecursive(true); vssCheckout.setDate(DATE); vssCheckout.setLabel(SRC_LABEL); vssCheckout.setSsdir(SS_DIR); MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated(); cmu.setValue(TIME_MODIFIED); vssCheckout.setFileTimeStamp(cmu); vssCheckout.setGetLocalCopy(false); commandline = vssCheckout.buildCmdLine(); checkCommandLines(sTestCmdLine, commandline.getCommandline()); } /** * Test VSSCheckout required attributes. */ public void testCheckoutExceptions() { configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); expectSpecificBuildException("vsscheckout.1", "some cause", "vsspath attribute must be set!"); expectSpecificBuildException("vsscheckout.2", "some cause", "blah is not a legal value for this attribute"); } /** Tests Add commandline generation. */ public void testAddCommandLine() { String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_ADD, project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD, MSVSS.FLAG_COMMENT + "-"}; // Set up a VSSAdd task MSVSSADD vssAdd = new MSVSSADD(); vssAdd.setProject(project); vssAdd.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); vssAdd.setVsspath(DS_VSS_PROJECT_PATH); vssAdd.setRecursive(true); vssAdd.setSsdir(SS_DIR); vssAdd.setWritable(false); vssAdd.setLocalpath(new Path(project, LOCAL_PATH)); commandline = vssAdd.buildCmdLine(); checkCommandLines(sTestCmdLine, commandline.getCommandline()); } /** * Test VSSAdd required attributes. */ public void testAddExceptions() { configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); expectSpecificBuildException("vssadd.1", "some cause", "localPath attribute must be set!"); } /** Tests CP commandline generation. */ public void testCpCommandLine() { String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CP, DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_LOGIN + VSS_USERNAME}; // Set up a VSSCp task MSVSSCP vssCp = new MSVSSCP(); vssCp.setProject(project); vssCp.setLogin(VSS_USERNAME); vssCp.setVsspath(DS_VSS_PROJECT_PATH); commandline = vssCp.buildCmdLine(); checkCommandLines(sTestCmdLine, commandline.getCommandline()); } /** * Test VSSCP required attributes. */ public void testCpExceptions() { configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); expectSpecificBuildException("vsscp.1", "some cause", "vsspath attribute must be set!"); } /** Tests Create commandline generation. */ public void testCreateCommandLine() { String[] sTestCmdLine = { MSVSS.SS_EXE, MSVSS.COMMAND_CREATE, DS_VSS_PROJECT_PATH, MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_QUIET, MSVSS.FLAG_LOGIN + VSS_USERNAME}; // Set up a VSSCreate task MSVSSCREATE vssCreate = new MSVSSCREATE(); vssCreate.setProject(project); vssCreate.setComment(SRC_COMMENT); vssCreate.setLogin(VSS_USERNAME); vssCreate.setVsspath(DS_VSS_PROJECT_PATH); vssCreate.setFailOnError(true); vssCreate.setAutoresponse("N"); vssCreate.setQuiet(true); commandline = vssCreate.buildCmdLine(); checkCommandLines(sTestCmdLine, commandline.getCommandline()); } /** * Test VSSCreate required attributes. */ public void testCreateExceptions() { configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); expectSpecificBuildException("vsscreate.1", "some cause", "vsspath attribute must be set!"); } /** * Iterate through the generated command line comparing it to reference one. * @param sTestCmdLine The reference command line; * @param sGeneratedCmdLine The generated command line; */ private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) { int testLength = sTestCmdLine.length; int genLength = sGeneratedCmdLine.length; int genIndex = 0; int testIndex = 0; while (testIndex < testLength) { try { if (sGeneratedCmdLine[genIndex] == "") { genIndex++; continue; } assertEquals("arg # " + testIndex, sTestCmdLine[testIndex], sGeneratedCmdLine[genIndex]); testIndex++; genIndex++; } catch (ArrayIndexOutOfBoundsException aioob) { fail("missing arg " + sTestCmdLine[testIndex]); } } // Count the number of empty strings int cnt = 0; for (int i = 0; i < genLength; i++) { if (sGeneratedCmdLine[i] == "") { cnt++; } } if (genLength - cnt > sTestCmdLine.length) { // We have extra elements fail("extra args"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -