public SimpleResponse asResponse() throws Exception { byte[] bytes = toByteArray(document); SimpleResponse response = new SimpleResponse(); response.setContent(bytes); response.setContentType("text/xml"); return response; }
@Test public void testHeadersAndFooters() throws Exception { WikiPageUtil.addPage(root, PathParser.parse("NormalPage"), "normal"); WikiPageUtil.addPage(root, PathParser.parse("TestPage"), "test page"); WikiPageUtil.addPage(root, PathParser.parse("PageHeader"), "header"); WikiPageUtil.addPage(root, PathParser.parse("PageFooter"), "footer"); WikiPageUtil.addPage(root, PathParser.parse("SetUp"), "setup"); WikiPageUtil.addPage(root, PathParser.parse("TearDown"), "teardown"); WikiPageUtil.addPage(root, PathParser.parse("SuiteSetUp"), "suite setup"); WikiPageUtil.addPage(root, PathParser.parse("SuiteTearDown"), "suite teardown"); SimpleResponse response = requestPage("NormalPage"); String content = response.getContent(); assertHasRegexp("header", content); assertHasRegexp("normal", content); assertHasRegexp("footer", content); assertDoesntHaveRegexp("setup", content); assertDoesntHaveRegexp("teardown", content); assertDoesntHaveRegexp("suite setup", content); assertDoesntHaveRegexp("suite teardown", content); response = requestPage("TestPage"); content = response.getContent(); assertHasRegexp("header", content); assertHasRegexp("test page", content); assertHasRegexp("footer", content); assertHasRegexp("setup", content); assertHasRegexp("teardown", content); assertHasRegexp("suite setup", content); assertHasRegexp("suite teardown", content); }
private void getContentForSimpleRename() throws Exception { request.setResource("files"); request.addInput("filename", "MyFile.txt"); Responder responder = new RenameFileConfirmationResponder(htmlPageFactory); SimpleResponse response = (SimpleResponse) responder.makeResponse(request); content = response.getContent(); }
public Response makeResponse(FitNesseContext context, Request request) throws Exception { SimpleResponse response = new SimpleResponse(); resource = request.getResource(); String filename = (String) request.getInput("filename"); response.setContent(makePageContent(filename, context)); return response; }
@Test public void testResponse() throws Exception { WikiPage page = WikiPageUtil.addPage(root, PathParser.parse("ChildPage"), "child content"); PageData data = page.getData(); WikiPageProperties properties = data.getProperties(); properties.set(PageData.PropertySUITES, "Wiki Page tags"); page.commit(data); final MockRequest request = new MockRequest(); request.setResource("ChildPage"); final Responder responder = new WikiPageResponder(); final SimpleResponse response = (SimpleResponse) responder.makeResponse(context, request); assertEquals(200, response.getStatus()); final String body = response.getContent(); assertSubString("<html>", body); assertSubString("<body", body); assertSubString("child content", body); assertSubString("href=\"ChildPage?whereUsed\"", body); assertSubString("Cache-Control: max-age=0", response.makeHttpHeaders()); assertSubString("<h5> Wiki Page tags</h5>", body); }
public Response makeResponse(FitNesseContext context, Request request) throws Exception { if (!getAndValidateRefactoredPage(context, request)) { return new NotFoundResponder().makeResponse(context, request); } if (!getAndValidateNewParentPage(context, request)) { return makeErrorMessageResponder(newParentPath.toString() + " does not exist.") .makeResponse(context, request); } if (!getAndValidateRefactoringParameters(request)) { return makeErrorMessageResponder("").makeResponse(context, request); } if (targetPageExists()) { return makeErrorMessageResponder(makeLink(getNewPageName()) + " already exists") .makeResponse(context, request); } if (request.hasInput("refactorReferences")) { getReferenceRenamer(context).renameReferences(); } execute(); SimpleResponse response = new SimpleResponse(); response.redirect(createRedirectionUrl(newParentPage, getNewPageName())); return response; }
private Response makePageHistoryXmlResponse(Request request) { VelocityContext velocityContext = new VelocityContext(); velocityContext.put("pageHistory", pageHistory); response.setContentType("text/xml"); response.setContent(context.pageFactory.render(velocityContext, "pageHistoryXML.vm")); return response; }
@Test public void testFitnesseLook() throws Exception { Responder responder = new RenameFileConfirmationResponder(htmlPageFactory); SimpleResponse response = (SimpleResponse) responder.makeResponse(request); String content = response.getContent(); assertSubString( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/files/css/fitnesse.css\" media=\"screen\"/>", content); }
private Response makeBannedContentResponse(FitNesseContext context, String resource) { SimpleResponse response = new SimpleResponse(); HtmlPage html = context.pageFactory.newPage(); html.setTitle("Edit " + resource); html.setPageTitle(new PageTitle("Banned Content", PathParser.parse(resource))); html.setMainTemplate("bannedPage.vm"); response.setContent(html.html()); return response; }
@Test public void shouldDeleteHistoryFromRequestAndRedirect() throws Exception { StubbedPurgeHistoryResponder responder = new StubbedPurgeHistoryResponder(); request.addInput("days", "30"); SimpleResponse response = (SimpleResponse) responder.makeResponse(context, request); assertEquals(30, responder.daysDeleted); assertEquals(303, response.getStatus()); assertEquals("?testHistory", response.getHeader("Location")); }
private void makeContent(FitNesseContext context, Request request) throws Exception { if ("json".equals(request.getInput("format"))) { JSONObject jsonObject = makeJson(); response.setContent(jsonObject.toString(1)); } else { String html = makeHtml(context); response.setContent(html); } }
private Response generateXMLResponse(File file) { try { response.setContent(FileUtil.getFileContent(file)); } catch (IOException e) { response.setContent("Error: Unable to read file '" + file.getName() + "'\n"); } response.setContentType(Format.XML); return response; }
private WikiPage getPropertiesContentFromPage(WikiPage page) throws Exception { request = new MockRequest(); request.setResource(page.getName()); responder = new PropertiesResponder(); SimpleResponse response = (SimpleResponse) responder.makeResponse(new FitNesseContext(root), request); content = response.getContent(); return page; }
public void testHasEditLinkForWikiWords() throws Exception { MockRequest request = new MockRequest(); request.setResource("PageOne.PageTwo"); WikiPage root = InMemoryPage.makeRoot("RooT"); Responder responder = new NotFoundResponder(); SimpleResponse response = (SimpleResponse) responder.makeResponse(FitNesseUtil.makeTestContext(root), request); assertHasRegexp("\"PageOne[.]PageTwo[?]edit\"", response.getContent()); }
public Response makeResponse(Request request) throws Exception { SimpleResponse response = new SimpleResponse(); resource = this.request.getResource(); WikiPagePath path = PathParser.parse(resource); WikiPage page = root.getPageCrawler().getPage(root, path); existingContent = page.getData().getContent(); newContent = (String) this.request.getInput(EditResponder.CONTENT_INPUT_NAME); response.setContent(makePageHtml()); return response; }
private SimpleResponse makeResponse( SuiteOverviewTree treeview, WikiPagePath path, Request request) { SimpleResponse response = new SimpleResponse(); HtmlPage page = context.pageFactory.newPage(); page.setTitle("Suite Overview"); page.setPageTitle(new PageTitle("Suite Overview", path)); page.put("treeRoot", treeview.getTreeRoot()); page.put("viewLocation", request.getResource()); page.setMainTemplate("suiteOverview"); response.setContent(page.html()); return response; }
private void makeContent(FitNesseContext context, Request request) { if ("json".equals(request.getInput("format"))) { JSONObject jsonObject = makeJson(); try { response.setContent(jsonObject.toString(1)); } catch (JSONException e) { throw new RuntimeException(e); } } else { String html = makeHtml(context, request); response.setContent(html); } }
public Response makeResponse(FitNesseContext context, Request request) { SimpleResponse response = new SimpleResponse(); String resource = request.getResource(); WikiPagePath path = PathParser.parse(resource); WikiPage page = context.root.getPageCrawler().getPage(path); if (page == null) return new NotFoundResponder().makeResponse(context, request); PageData data = page.getData(); saveAttributes(request, data); VersionInfo commitRecord = page.commit(data); response.addHeader("Current-Version", commitRecord.getName()); context.recentChanges.updateRecentChanges(data); response.redirect(resource); return response; }
public void testResponse() throws Exception { MockRequest request = new MockRequest(); request.setResource("some page"); Responder responder = new NotFoundResponder(); SimpleResponse response = (SimpleResponse) responder.makeResponse(context, request); assertEquals(404, response.getStatus()); String body = response.getContent(); assertHasRegexp("<html>", body); assertHasRegexp("<body", body); assertHasRegexp("some page", body); assertHasRegexp("Not Found", body); }
public void testUsernameDisplayed() throws Exception { WikiPage page = getContentFromSimplePropertiesPage(); assertSubString("Last modified anonymously", content); PageData data = page.getData(); data.setAttribute(WikiPage.LAST_MODIFYING_USER, "Bill"); page.commit(data); request.setResource("SomePage"); SimpleResponse response = (SimpleResponse) responder.makeResponse(new FitNesseContext(root), request); content = response.getContent(); assertSubString("Last modified by Bill", content); }
public void testMakeReponder() throws Exception { MockRequest request = new MockRequest(); request.setResource("PageOne"); Responder responder = new VersionSelectionResponder(); SimpleResponse response = (SimpleResponse) responder.makeResponse(new FitNesseContext(root), request); String content = response.getContent(); assertSubString("<input", content); assertSubString("name=\"version\"", content); assertSubString("<form", content); assertSubString("action=\"PageOne\"", content); assertSubString("name=\"responder\"", content); assertSubString(" value=\"viewVersion\"", content); }
private JSONObject makeJson() { response.setContentType("text/json"); JSONObject jsonObject = new JSONObject(); String attributes[] = new String[] { TEST.toString(), PropertySEARCH, PropertyEDIT, PropertyPROPERTIES, PropertyVERSIONS, PropertyREFACTOR, PropertyWHERE_USED, PropertyRECENT_CHANGES, SUITE.toString(), PropertyPRUNE, PropertySECURE_READ, PropertySECURE_WRITE, PropertySECURE_TEST, PropertyFILES }; for (String attribute : attributes) addJsonAttribute(jsonObject, attribute); if (pageData.hasAttribute(PropertyHELP)) { jsonObject.put(PropertyHELP, pageData.getAttribute(PropertyHELP)); } if (pageData.hasAttribute(PropertySUITES)) { JSONArray tags = new JSONArray(); for (String tag : pageData.getAttribute(PropertySUITES).split(",")) { if (StringUtils.isNotBlank(tag)) { tags.put(tag.trim()); } } jsonObject.put(PropertySUITES, tags); } return jsonObject; }
public void testResponse() throws Exception { WikiPage page = crawler.addPage(root, PathParser.parse("PageOne")); PageData data = page.getData(); data.setContent("some content"); WikiPageProperties properties = data.getProperties(); properties.set("Test", "true"); properties.set(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE, "http://www.fitnesse.org"); page.commit(data); MockRequest request = new MockRequest(); request.setResource("PageOne"); Responder responder = new PropertiesResponder(); SimpleResponse response = (SimpleResponse) responder.makeResponse(new FitNesseContext(root), request); assertEquals("max-age=0", response.getHeader("Cache-Control")); String content = response.getContent(); assertSubString("PageOne", content); assertSubString("value=\"http://www.fitnesse.org\"", content); assertDoesntHaveRegexp("textarea name=\"extensionXml\"", content); assertHasRegexp("<input.*value=\"Save Properties\".*>", content); assertHasRegexp("<input.*value=\"saveProperties\"", content); assertSubString("<input type=\"checkbox\" name=\"Test\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Search\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Edit\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Properties\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Suite\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Prune\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Versions\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"Refactor\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"WhereUsed\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"RecentChanges\" checked=\"true\"/>", content); assertSubString("<input type=\"checkbox\" name=\"" + WikiPage.SECURE_READ + "\"/>", content); assertSubString("<input type=\"checkbox\" name=\"" + WikiPage.SECURE_WRITE + "\"/>", content); assertSubString("<input type=\"checkbox\" name=\"" + WikiPage.SECURE_TEST + "\"/>", content); }
public Response makeResponse(FitNesseContext context, Request request) { response = new SimpleResponse(); resource = request.getResource(); path = PathParser.parse(resource); PageCrawler crawler = context.root.getPageCrawler(); page = crawler.getPage(path, new MockingPageCrawler()); if (page == null) return new NotFoundResponder().makeResponse(context, request); pageData = page.getData(); makeContent(context, request); response.setMaxAge(0); return response; }
protected Response doMakeResponse( FitNesseContext context, Request request, boolean firstTimeForNewPage) throws Exception { initializeResponder(context.root, request); SimpleResponse response = new SimpleResponse(); String resource = request.getResource(); WikiPagePath path = PathParser.parse(resource); PageCrawler crawler = context.root.getPageCrawler(); if (!crawler.pageExists(root, path)) { crawler.setDeadEndStrategy(new MockingPageCrawler()); page = crawler.getPage(root, path); } else page = crawler.getPage(root, path); pageData = page.getData(); content = createPageContent(); String html = doMakeHtml(resource, context, firstTimeForNewPage); response.setContent(html); response.setMaxAge(0); return response; }
public Response makeResponse(FitNesseContext context, Request request) throws Exception { response = new SimpleResponse(); resource = request.getResource(); path = PathParser.parse(resource); PageCrawler crawler = context.root.getPageCrawler(); if (!crawler.pageExists(context.root, path)) crawler.setDeadEndStrategy(new MockingPageCrawler()); page = crawler.getPage(context.root, path); if (page == null) return new NotFoundResponder().makeResponse(context, request); pageData = page.getData(); makeContent(context, request); response.setMaxAge(0); return response; }
@Test public void testAttributeButtons() throws Exception { WikiPageUtil.addPage(root, PathParser.parse("NormalPage"), ""); final WikiPage noButtonsPage = WikiPageUtil.addPage(root, PathParser.parse("NoButtonPage"), ""); for (final String attribute : PageData.NON_SECURITY_ATTRIBUTES) { final PageData data = noButtonsPage.getData(); data.removeAttribute(attribute); noButtonsPage.commit(data); } SimpleResponse response = requestPage("NormalPage"); assertSubString(">Edit</a>", response.getContent()); assertSubString(">Search</a>", response.getContent()); assertSubString(">Versions</a>", response.getContent()); assertNotSubString(">Suite</a>", response.getContent()); assertNotSubString(">Test</a>", response.getContent()); response = requestPage("NoButtonPage"); assertNotSubString(">Edit</a>", response.getContent()); assertNotSubString(">Search</a>", response.getContent()); assertNotSubString(">Versions</a>", response.getContent()); assertNotSubString(">Suite</a>", response.getContent()); assertNotSubString(">Test</a>", response.getContent()); }
private JSONObject makeJson() { response.setContentType("text/json"); JSONObject jsonObject = new JSONObject(); String attributes[] = new String[] { TEST.toString(), PropertySEARCH, PropertyEDIT, PropertyPROPERTIES, PropertyVERSIONS, PropertyREFACTOR, PropertyWHERE_USED, PropertyRECENT_CHANGES, SUITE.toString(), PropertyPRUNE, PropertySECURE_READ, PropertySECURE_WRITE, PropertySECURE_TEST }; for (String attribute : attributes) addJsonAttribute(jsonObject, attribute); return jsonObject; }
private Response makeResponse() { response.setContent(page.html()); return response; }