📄 staxtestcaseactionfactory.java
字号:
tcMap.put("testcaseName", testcase.getName()); tcMap.put("numPasses", "" + numPass); tcMap.put("numFails", "" + numFail); tcMap.put("elapsedTime", testcase.getElapsedTime()); tcMap.put("numStarts", "" + testcase.getNumStarts()); tcOutputList.add(tcMap); } } } mc.setRootObject(tcOutputList); return new STAFResult(STAFResult.Ok, mc.marshall()); } else return new STAFResult(STAFResult.DoesNotExist, type); } public STAFResult handleQueryRequest(String type, String key, STAXJob job, STAXRequestSettings settings) { String lineSep = settings.getLineSeparator(); if (type.equalsIgnoreCase("testcase")) { // QUERY JOB <Job ID> TESTCASE <Testcase Name> // Create the marshalling context and set its map class definition STAFMarshallingContext mc = new STAFMarshallingContext(); mc.setMapClassDefinition(fQueryTestcaseMapClass); TreeMap testcaseMap = (TreeMap)job.getData("testcaseMap"); synchronized (testcaseMap) { if (!testcaseMap.containsKey(key)) return new STAFResult(STAFResult.DoesNotExist, key); else { STAXTestcase testcase = (STAXTestcase)testcaseMap.get(key); Map tcMap = fQueryTestcaseMapClass.createInstance(); tcMap.put("testcaseName", testcase.getName()); tcMap.put("numPasses", "" + testcase.getNumPass()); tcMap.put("numFails", "" + testcase.getNumFail()); if (!testcase.getLastStatus().equals("")) tcMap.put("lastStatus", testcase.getLastStatus()); STAXTimestamp lastStatusTimestamp = testcase.getLastStatusTimestamp(); if (lastStatusTimestamp != null) { tcMap.put("lastStatusTimestamp", lastStatusTimestamp.getTimestampString()); } tcMap.put("elapsedTime", testcase.getElapsedTime()); tcMap.put("numStarts", "" + testcase.getNumStarts()); mc.setRootObject(tcMap); return new STAFResult(STAFResult.Ok, mc.marshall()); } } } else return new STAFResult(STAFResult.DoesNotExist, type); } public STAFResult handleQueryJobRequest(STAXJob job, STAXRequestSettings settings) { return new STAFResult(STAFResult.Ok, ""); } public STAXAction parseAction(STAX staxService, STAXJob job, org.w3c.dom.Node root) throws STAXException { String testName = new String(); STAXAction testcaseAction = null; String testMode = new String(); NamedNodeMap attrs = root.getAttributes(); for (int i = 0; i < attrs.getLength(); ++i) { Node thisAttr = attrs.item(i); String errorInfo = "\n Element: " + root.getNodeName() + " Attribute: " + thisAttr.getNodeName(); if (thisAttr.getNodeName().equals("name")) { testName = STAXUtil.parseAndCompileForPython( thisAttr.getNodeValue(), errorInfo); } else if (thisAttr.getNodeName().equals("mode")) { testMode = STAXUtil.parseAndCompileForPython( thisAttr.getNodeValue(), errorInfo); } else { throw new STAXInvalidXMLAttributeException( root.getNodeName() + ": " + thisAttr.getNodeName()); } } NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node thisChild = children.item(i); if (thisChild.getNodeType() == Node.COMMENT_NODE) { /* Do nothing */ } else if (thisChild.getNodeType() == Node.ELEMENT_NODE) { if (testcaseAction != null) { throw new STAXInvalidXMLElementCountException( thisChild.getNodeName()); } STAXActionFactory factory = staxService.getActionFactory(thisChild.getNodeName()); if (factory == null) { throw new STAXInvalidXMLElementException( thisChild.getNodeName()); } testcaseAction = factory.parseAction(staxService, job, thisChild); } else { throw new STAXInvalidXMLNodeTypeException( Integer.toString(thisChild.getNodeType())); } } return new STAXTestcaseAction(testName, testcaseAction, testMode); } // STAXGenericRequestHandler Interface Methods public STAFResult handleRequest(Object infoObject, STAX staxService) { STAFServiceInterfaceLevel30.RequestInfo info = (STAFServiceInterfaceLevel30.RequestInfo)infoObject; String lowerRequest = info.request.toLowerCase(); if (lowerRequest.startsWith("update")) return handleUpdateRequest(info, staxService); else if (lowerRequest.startsWith("start")) return handleStartRequest(info, staxService); else if (lowerRequest.startsWith("stop")) return handleStopRequest(info, staxService); else { // Returning nothing in the result indicates that this parser // does not support this request. return new STAFResult(STAFResult.InvalidRequestString, ""); } } private STAFResult handleUpdateRequest( STAFServiceInterfaceLevel30.RequestInfo info, STAX staxService) { // Verify the requesting machine/user has at least trust level 3 STAFResult trustResult = STAFUtil.validateTrust( 3, staxService.getServiceName(), "UPDATE", staxService.getLocalMachineName(), info); if (trustResult.rc != STAFResult.Ok) return trustResult; // Parse the request STAFCommandParseResult parseResult= fUpdateParser.parse(info.request); if (parseResult.rc != STAFResult.Ok) { return new STAFResult(STAFResult.InvalidRequestString, parseResult.errorBuffer); } // Resolve the value specified for JOB and get its integer value STAFResult res = STAFUtil.resolveRequestVarAndCheckInt( "JOB", parseResult.optionValue("JOB"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; Integer jobID = new Integer(res.result); // Verify that the JOB ID is a currently active job STAXJob job = null; job = (STAXJob)staxService.getJobMap().get(jobID); if (job == null) { return new STAFResult( STAFResult.DoesNotExist, "Job " + jobID + " is not currently running."); } // Resolve the value specified for Testcase name res = STAFUtil.resolveRequestVar( parseResult.optionValue("TESTCASE"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; String testcaseName = res.result; // Resolve the value specified for the Status res = STAFUtil.resolveRequestVar( parseResult.optionValue("STATUS"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; String status = res.result; // Make sure that the status is either pass or fail if (!status.equalsIgnoreCase("pass") && !status.equalsIgnoreCase("fail")) { return new STAFResult(STAFResult.InvalidValue, status); } String message = new String(""); if (parseResult.optionTimes("MESSAGE") != 0) { // Resolve the value specified for Message res = STAFUtil.resolveRequestVar( parseResult.optionValue("MESSAGE"), staxService.getSTAFHandle(), info.requestNumber); if (res.rc != 0) return res; message = res.result; } boolean force = false; if (parseResult.optionTimes("FORCE") != 0) { force = true; } // Check if the testcase exists. If not, and force is not specified, // return an error message. If not, and force is specified, add it // to the testcaseMap. TreeMap testcaseMap = (TreeMap)job.getData("testcaseMap"); STAXTestcase theTest; synchronized (testcaseMap) { theTest = (STAXTestcase)testcaseMap.get(testcaseName); if (theTest == null) { if (! force) { return new STAFResult( STAFResult.DoesNotExist, "Testcase " + testcaseName + " does not exist."); } else { theTest = new STAXTestcase(testcaseName, STAXTestcase.STRICT_MODE); synchronized(testcaseMap) { testcaseMap.put(testcaseName, theTest); } } } } // Check if the testcase name is in the activeTestcaseMap. // If not, add it to the activeTestcaseMap, storing its start // timestamp, and start the testcase. HashMap activeTestcaseMap = (HashMap)job.getData("activeTestcaseMap"); synchronized (activeTestcaseMap)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -