@Test public final void testHandle() { try { testInstance.setTargetInstanceManager(tim); testInstance.setHarvestCoordinator(hc); HttpServletRequest aReq = new MockHttpServletRequest(); HttpServletResponse aResp = new MockHttpServletResponse(); LogReaderCommand aCmd = new LogReaderCommand(); TargetInstance ti = tim.getTargetInstance(5000L); aCmd.setTargetInstanceOid(ti.getOid()); aCmd.setLogFileName("aqa-report(1).xml"); BindException aErrors = new BindException(aCmd, "LogReaderCommand"); ModelAndView mav = testInstance.handle(aReq, aResp, aCmd, aErrors); assertTrue(mav != null); assertNotNull((List<AQAReaderController.AQAElement>)mav.getModel().get(LogReaderCommand.MDL_MISSINGELEMENTS)); List<AQAReaderController.AQAElement> result = (List<AQAReaderController.AQAElement>)mav.getModel().get(LogReaderCommand.MDL_MISSINGELEMENTS); assertEquals(result.get(0).getUrl(), "http: assertEquals(result.get(0).getContentFile(), "100077.txt"); assertTrue(Constants.VIEW_AQA_READER.equals(mav.getViewName())); assertFalse(aErrors.hasErrors()); } catch(Exception e) { fail(e.getMessage()); } }
@Override protected ModelAndView handle(HttpServletRequest aReq, HttpServletResponse aResp, Object aCommand, BindException aErrors) throws Exception { LogReaderCommand cmd = (LogReaderCommand) aCommand; String messageText = ""; int firstLine = 0; List<AQAElement> missingElements = new ArrayList<AQAElement>(); if(aErrors.hasErrors()) { Iterator it = aErrors.getAllErrors().iterator(); while(it.hasNext()) { org.springframework.validation.ObjectError err = (org.springframework.validation.ObjectError)it.next(); if(messageText.length()>0) messageText += "; "; messageText += err.getDefaultMessage(); } } else if(cmd.getTargetInstanceOid() != null) { TargetInstance ti = targetInstanceManager.getTargetInstance(cmd.getTargetInstanceOid()); cmd.setTargetName(ti.getTarget().getName()); File f = harvestCoordinator.getLogfile(ti, cmd.getLogFileName()); Document aqaResult = readXMLDocument(f); NodeList missingElementsNodes = aqaResult.getElementsByTagName("missingElements"); if(missingElementsNodes.getLength() > 0) { NodeList missingElementNodes = ((Element)missingElementsNodes.item(0)).getElementsByTagName("element"); for(int i = 0; i < missingElementNodes.getLength(); i++) { Element elementNode = (Element)missingElementNodes.item(i); if (elementNode.getAttribute("statuscode").equals("200")) { missingElements.add(new AQAElement(elementNode.getAttribute("url"), elementNode.getAttribute("contentfile"), elementNode.getAttribute("contentType"), Long.parseLong(elementNode.getAttribute("contentLength")))); } } } } ModelAndView mav = new ModelAndView(); mav.setViewName(Constants.VIEW_AQA_READER); mav.addObject(Constants.GBL_CMD_DATA, cmd); mav.addObject(Constants.MESSAGE_TEXT, messageText); mav.addObject(LogReaderCommand.MDL_MISSINGELEMENTS, missingElements); return mav; }
AQAReaderController extends AbstractCommandController { @Override protected ModelAndView handle(HttpServletRequest aReq, HttpServletResponse aResp, Object aCommand, BindException aErrors) throws Exception { LogReaderCommand cmd = (LogReaderCommand) aCommand; String messageText = ""; int firstLine = 0; List<AQAElement> missingElements = new ArrayList<AQAElement>(); if(aErrors.hasErrors()) { Iterator it = aErrors.getAllErrors().iterator(); while(it.hasNext()) { org.springframework.validation.ObjectError err = (org.springframework.validation.ObjectError)it.next(); if(messageText.length()>0) messageText += "; "; messageText += err.getDefaultMessage(); } } else if(cmd.getTargetInstanceOid() != null) { TargetInstance ti = targetInstanceManager.getTargetInstance(cmd.getTargetInstanceOid()); cmd.setTargetName(ti.getTarget().getName()); File f = harvestCoordinator.getLogfile(ti, cmd.getLogFileName()); Document aqaResult = readXMLDocument(f); NodeList missingElementsNodes = aqaResult.getElementsByTagName("missingElements"); if(missingElementsNodes.getLength() > 0) { NodeList missingElementNodes = ((Element)missingElementsNodes.item(0)).getElementsByTagName("element"); for(int i = 0; i < missingElementNodes.getLength(); i++) { Element elementNode = (Element)missingElementNodes.item(i); if (elementNode.getAttribute("statuscode").equals("200")) { missingElements.add(new AQAElement(elementNode.getAttribute("url"), elementNode.getAttribute("contentfile"), elementNode.getAttribute("contentType"), Long.parseLong(elementNode.getAttribute("contentLength")))); } } } } ModelAndView mav = new ModelAndView(); mav.setViewName(Constants.VIEW_AQA_READER); mav.addObject(Constants.GBL_CMD_DATA, cmd); mav.addObject(Constants.MESSAGE_TEXT, messageText); mav.addObject(LogReaderCommand.MDL_MISSINGELEMENTS, missingElements); return mav; } }
AQAReaderController extends AbstractCommandController { @Override protected ModelAndView handle(HttpServletRequest aReq, HttpServletResponse aResp, Object aCommand, BindException aErrors) throws Exception { LogReaderCommand cmd = (LogReaderCommand) aCommand; String messageText = ""; int firstLine = 0; List<AQAElement> missingElements = new ArrayList<AQAElement>(); if(aErrors.hasErrors()) { Iterator it = aErrors.getAllErrors().iterator(); while(it.hasNext()) { org.springframework.validation.ObjectError err = (org.springframework.validation.ObjectError)it.next(); if(messageText.length()>0) messageText += "; "; messageText += err.getDefaultMessage(); } } else if(cmd.getTargetInstanceOid() != null) { TargetInstance ti = targetInstanceManager.getTargetInstance(cmd.getTargetInstanceOid()); cmd.setTargetName(ti.getTarget().getName()); File f = harvestCoordinator.getLogfile(ti, cmd.getLogFileName()); Document aqaResult = readXMLDocument(f); NodeList missingElementsNodes = aqaResult.getElementsByTagName("missingElements"); if(missingElementsNodes.getLength() > 0) { NodeList missingElementNodes = ((Element)missingElementsNodes.item(0)).getElementsByTagName("element"); for(int i = 0; i < missingElementNodes.getLength(); i++) { Element elementNode = (Element)missingElementNodes.item(i); if (elementNode.getAttribute("statuscode").equals("200")) { missingElements.add(new AQAElement(elementNode.getAttribute("url"), elementNode.getAttribute("contentfile"), elementNode.getAttribute("contentType"), Long.parseLong(elementNode.getAttribute("contentLength")))); } } } } ModelAndView mav = new ModelAndView(); mav.setViewName(Constants.VIEW_AQA_READER); mav.addObject(Constants.GBL_CMD_DATA, cmd); mav.addObject(Constants.MESSAGE_TEXT, messageText); mav.addObject(LogReaderCommand.MDL_MISSINGELEMENTS, missingElements); return mav; } AQAReaderController(); }
AQAReaderController extends AbstractCommandController { @Override protected ModelAndView handle(HttpServletRequest aReq, HttpServletResponse aResp, Object aCommand, BindException aErrors) throws Exception { LogReaderCommand cmd = (LogReaderCommand) aCommand; String messageText = ""; int firstLine = 0; List<AQAElement> missingElements = new ArrayList<AQAElement>(); if(aErrors.hasErrors()) { Iterator it = aErrors.getAllErrors().iterator(); while(it.hasNext()) { org.springframework.validation.ObjectError err = (org.springframework.validation.ObjectError)it.next(); if(messageText.length()>0) messageText += "; "; messageText += err.getDefaultMessage(); } } else if(cmd.getTargetInstanceOid() != null) { TargetInstance ti = targetInstanceManager.getTargetInstance(cmd.getTargetInstanceOid()); cmd.setTargetName(ti.getTarget().getName()); File f = harvestCoordinator.getLogfile(ti, cmd.getLogFileName()); Document aqaResult = readXMLDocument(f); NodeList missingElementsNodes = aqaResult.getElementsByTagName("missingElements"); if(missingElementsNodes.getLength() > 0) { NodeList missingElementNodes = ((Element)missingElementsNodes.item(0)).getElementsByTagName("element"); for(int i = 0; i < missingElementNodes.getLength(); i++) { Element elementNode = (Element)missingElementNodes.item(i); if (elementNode.getAttribute("statuscode").equals("200")) { missingElements.add(new AQAElement(elementNode.getAttribute("url"), elementNode.getAttribute("contentfile"), elementNode.getAttribute("contentType"), Long.parseLong(elementNode.getAttribute("contentLength")))); } } } } ModelAndView mav = new ModelAndView(); mav.setViewName(Constants.VIEW_AQA_READER); mav.addObject(Constants.GBL_CMD_DATA, cmd); mav.addObject(Constants.MESSAGE_TEXT, messageText); mav.addObject(LogReaderCommand.MDL_MISSINGELEMENTS, missingElements); return mav; } AQAReaderController(); void setHarvestCoordinator(HarvestCoordinator harvestCoordinator); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); }
AQAReaderController extends AbstractCommandController { @Override protected ModelAndView handle(HttpServletRequest aReq, HttpServletResponse aResp, Object aCommand, BindException aErrors) throws Exception { LogReaderCommand cmd = (LogReaderCommand) aCommand; String messageText = ""; int firstLine = 0; List<AQAElement> missingElements = new ArrayList<AQAElement>(); if(aErrors.hasErrors()) { Iterator it = aErrors.getAllErrors().iterator(); while(it.hasNext()) { org.springframework.validation.ObjectError err = (org.springframework.validation.ObjectError)it.next(); if(messageText.length()>0) messageText += "; "; messageText += err.getDefaultMessage(); } } else if(cmd.getTargetInstanceOid() != null) { TargetInstance ti = targetInstanceManager.getTargetInstance(cmd.getTargetInstanceOid()); cmd.setTargetName(ti.getTarget().getName()); File f = harvestCoordinator.getLogfile(ti, cmd.getLogFileName()); Document aqaResult = readXMLDocument(f); NodeList missingElementsNodes = aqaResult.getElementsByTagName("missingElements"); if(missingElementsNodes.getLength() > 0) { NodeList missingElementNodes = ((Element)missingElementsNodes.item(0)).getElementsByTagName("element"); for(int i = 0; i < missingElementNodes.getLength(); i++) { Element elementNode = (Element)missingElementNodes.item(i); if (elementNode.getAttribute("statuscode").equals("200")) { missingElements.add(new AQAElement(elementNode.getAttribute("url"), elementNode.getAttribute("contentfile"), elementNode.getAttribute("contentType"), Long.parseLong(elementNode.getAttribute("contentLength")))); } } } } ModelAndView mav = new ModelAndView(); mav.setViewName(Constants.VIEW_AQA_READER); mav.addObject(Constants.GBL_CMD_DATA, cmd); mav.addObject(Constants.MESSAGE_TEXT, messageText); mav.addObject(LogReaderCommand.MDL_MISSINGELEMENTS, missingElements); return mav; } AQAReaderController(); void setHarvestCoordinator(HarvestCoordinator harvestCoordinator); void setTargetInstanceManager(TargetInstanceManager targetInstanceManager);  }