@Test
  public final void testHandleRequestInternalHttpServletRequestHttpServletResponse() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();

    final ImageSizeDefinition sizea =
        new ImageSizeDefinition() {
          {
            setCode("a");
            setLabel("Size A");
          }
        };
    final ImageSizeDefinition sizeb =
        new ImageSizeDefinition() {
          {
            setCode("b");
            setLabel("Size B");
          }
        };

    try {
      context.checking(
          new Expectations() {
            {
              one(defmgr).getAllImageSizes();
              will(returnValue(Arrays.asList(new ImageSizeDefinition[] {sizea, sizeb})));
            }
          });

      ModelAndView mav = cut.handleRequest(request, response);

      Document result = (Document) mav.getModel().get("result");
      assertNotNull(result);
      log.info("Document is " + PSXmlDocumentBuilder.toString(result));

      PSXmlTreeWalker walker = new PSXmlTreeWalker(result.getDocumentElement());
      walker.getNextElement("PSXEntry", PSXmlTreeWalker.GET_NEXT_ALLOW_CHILDREN);
      log.info("current element " + walker.getCurrentNodeName());
      walker.getNextElement("PSXDisplayText", PSXmlTreeWalker.GET_NEXT_ALLOW_CHILDREN);
      String display = walker.getElementData();
      assertEquals("Size A", display);
      walker.getNextElement("Value", PSXmlTreeWalker.GET_NEXT_ALLOW_SIBLINGS);
      String value = walker.getElementData();
      assertEquals("a", value);

    } catch (Exception ex) {
      log.error("Unexpected Exception " + ex, ex);
      fail("Exception Caught");
    }
  }
コード例 #2
0
 /**
  * @see
  *     com.percussion.extension.IPSResultDocumentProcessor#processResultDocument(java.lang.Object[],
  *     com.percussion.server.IPSRequestContext, org.w3c.dom.Document)
  */
 public Document processResultDocument(
     Object[] params, IPSRequestContext request, Document resultDoc)
     throws PSParameterMismatchException, PSExtensionProcessingException {
   //      if(log.isTraceEnabled())
   //      {
   //         String idoc = PSXmlDocumentBuilder.toString(resultDoc);
   //         log.trace("result doc is " + idoc);
   //      }
   Document errorDoc = PSXmlDocumentBuilder.createXmlDocument();
   try {
     validateDocs(resultDoc, errorDoc, request, params);
   } catch (Exception ex) {
     log.error("Unexpected Exception " + ex, ex);
     throw new PSExtensionProcessingException(getClass().getName(), ex);
   }
   if (hasErrors(errorDoc)) {
     log.debug("validation errors found");
     return errorDoc;
   }
   log.debug("validation successful");
   return null;
 }