예제 #1
0
 private boolean isValidLinkPathName(String linkPath) throws Exception {
   if (isFilePath(linkPath) && !isValidDirectoryPath(linkPath)) {
     String message =
         "Cannot create link to the file system path '"
             + linkPath
             + "'."
             + " The canonical file system path used was ;"
             + createFileFromPath(linkPath).getCanonicalPath()
             + "'."
             + " Either it doesn't exist or it's not a directory.";
     response = new ErrorResponder(message).makeResponse(context, null);
     response.setStatus(404);
     return false;
   } else if (!isFilePath(linkPath) && isInternalPageThatDoesntExist(linkPath)) {
     response =
         new ErrorResponder(
                 "The page to which you are attempting to link, "
                     + HtmlUtil.escapeHTML(linkPath)
                     + ", doesn't exist.")
             .makeResponse(context, null);
     response.setStatus(404);
     return false;
   }
   return true;
 }
  @Test
  public void testRenameFailWhenNonSym() throws Exception {
    prepareSymlinkOnPageOne();
    request.addInput("newname", "ChildOne");
    Response response = invokeResponder();

    assertEquals(412, response.getStatus());
  }
  public void testSuccess() throws Exception {
    int ticket = dealer.seekingSocket(seeker);
    request.addInput("ticket", ticket + "");
    Response response = responder.makeResponse(context, request);
    response.sendTo(sender);

    assertEquals("", sender.sentData());
  }
  public void testMissingSeeker() throws Exception {
    request.addInput("ticket", "123");
    Response response = responder.makeResponse(context, request);
    response.sendTo(sender);

    assertHasRegexp(
        "There are no clients waiting for a socket with ticketNumber 123", sender.sentData());
    assertTrue(sender.isClosed());
    assertEquals(404, response.getStatus());
  }
  @Test
  public void linkNameShouldBeAValidWikiWordWhenRenaming() throws Exception {
    prepareSymlinkOnPageOne();
    request.addInput("newname", "New+link");
    Response response = invokeResponder();

    assertEquals(412, response.getStatus());
    String content = ((SimpleResponse) response).getContent();
    assertSubString("WikiWord", content);
  }
  @Test
  public void linkNameShouldBeAValidWikiWord() throws Exception {
    request.addInput("linkName", "Sym+link");
    request.addInput("linkPath", "PageTwo");
    Response response = invokeResponder();

    assertEquals(412, response.getStatus());
    String content = ((SimpleResponse) response).getContent();
    assertSubString("WikiWord", content);
  }
  @Test
  public void testNoPageAtPath() throws Exception {
    request.addInput("linkName", "SymLink");
    request.addInput("linkPath", "NonExistingPage");
    Response response = invokeResponder();

    assertEquals(404, response.getStatus());
    String content = ((SimpleResponse) response).getContent();
    assertSubString("doesn't exist", content);
    assertSubString("Error Occurred", content);
  }
  @Test
  public void testAddFailWhenLinkPathIsInvalid() throws Exception {
    request.addInput("linkName", "SymLink");
    request.addInput("linkPath", "PageOne PageTwo");
    Response response = invokeResponder();

    assertEquals(404, response.getStatus());
    String content = ((SimpleResponse) response).getContent();
    assertSubString("doesn't exist", content);
    assertSubString("Error Occurred", content);
  }
  @Test
  public void testSubmitFormForLinkToExternalRootThatsMissing() throws Exception {
    request.addInput("linkName", "SymLink");
    request.addInput("linkPath", "file:/testDir/ExternalRoot");
    Response response = invokeResponder();

    assertEquals(404, response.getStatus());
    String content = ((SimpleResponse) response).getContent();
    assertSubString(
        "Cannot create link to the file system path 'file:/testDir/ExternalRoot'.", content);
    assertSubString("Error Occurred", content);
  }
  @Test
  public void testAddFailWhenPageAlreadyHasNonSymChild() throws Exception {
    WikiPageUtil.addPage(pageOne, PathParser.parse("SymLink"), "");

    request.addInput("linkName", "SymLink");
    request.addInput("linkPath", "PageTwo");
    Response response = invokeResponder();

    assertEquals(412, response.getStatus());
    String content = ((SimpleResponse) response).getContent();
    assertSubString("already has a child named SymLink", content);
    assertSubString("Error Occurred", content);
  }
예제 #11
0
 private boolean isValidWikiPageName(String linkName, WikiPageProperty symLinks) throws Exception {
   if (page.hasChildPage(linkName) && !symLinks.has(linkName)) {
     response =
         new ErrorResponder(resource + " already has a child named " + linkName + ".")
             .makeResponse(context, null);
     response.setStatus(412);
     return false;
   } else if (!PathParser.isSingleWikiWord(linkName)) {
     response =
         new ErrorResponder(linkName + " is not a valid WikiWord.").makeResponse(context, null);
     response.setStatus(412);
     return false;
   }
   return true;
 }
예제 #12
0
  @Test
  public void testResponse() throws Exception {
    MockRequest request = new MockRequest();
    request.setResource("PageOne");
    WhereUsedResponder responder =
        new WhereUsedResponder(htmlPageFactory, root, runningTestingTracker, isChunkingEnabled());

    Response response = responder.makeResponse(request);
    MockResponseSender sender = new MockResponseSender();
    response.readyToSend(sender);
    sender.waitForClose(5000);

    String content = sender.sentData();
    assertEquals(200, response.getStatus());
    assertHasRegexp("Where Used", content);
    assertHasRegexp(">PageOne<", content);
    assertHasRegexp(">PageTwo<", content);
    assertHasRegexp(">PageTwo\\.ChildPage<", content);
  }
 private void checkChildTwoRedirectToProperties(Response response) {
   assertEquals(303, response.getStatus());
   assertEquals(response.getHeader("Location"), "/PageTwo.ChildTwo?properties#symbolics");
 }
예제 #14
0
 @Test
 public void defaultFormat() throws Exception {
   Response response = new MockResponse("");
   assertTrue(response.isHtmlFormat());
 }
예제 #15
0
 private void setRedirect(String resource) {
   response.redirect(context.contextRoot, resource + "?properties#symbolics");
 }
 @Test
 public void shouldMakeErrorResponseWhenItGetsInvalidTypeForNumberOfDays() throws Exception {
   request.addInput("days", "bob");
   Response response = responder.makeResponse(context, request);
   assertEquals(400, response.getStatus());
 }
예제 #17
0
 @Test
 public void shouldHaveHeadersIfXml() throws Exception {
   Response response = new MockResponse("xml");
   assertTrue(response.makeHttpHeaders().contains("HTTP/1.1 200 OK"));
 }
예제 #18
0
 private void checkPhrase(int reasonCode, String reasonPhrase) {
   assertEquals(reasonPhrase, Response.getReasonPhrase(reasonCode));
 }
예제 #19
0
 @Test
 public void xmlFormat() throws Exception {
   Response response = new MockResponse("xml");
   assertTrue(response.isXmlFormat());
 }
예제 #20
0
 @Test
 public void textFormat() throws Exception {
   Response response = new MockResponse("text");
   assertTrue(response.isTextFormat());
 }
예제 #21
0
 @Test
 public void shouldNotHaveHeadersIfText() throws Exception {
   Response response = new MockResponse("text");
   assertEquals("", response.makeHttpHeaders());
 }