/** * Dumps the source of last rendered <code>Page</code>. */ public void dumpPage() { log.info(getLastResponseAsString()); }
/** * Dumps the source of last rendered <code>Page</code>. */ public void dumpPage() { log.info(getLastResponseAsString()); }
/** * assert the content of last rendered page contains(matches) regex pattern. * * @param pattern * reqex pattern to match * @return a <code>Result</code> */ public Result ifContains(String pattern) { return isTrue("pattern '" + pattern + "' not found in:\n" + getLastResponseAsString(), getLastResponseAsString().matches("(?s).*" + pattern + ".*")); }
/** * assert the content of last rendered page contains(matches) regex pattern. * * @param pattern * reqex pattern to match * @return a <code>Result</code> */ public Result ifContains(String pattern) { return isTrue("pattern '" + pattern + "' not found in:\n" + getLastResponseAsString(), getLastResponseAsString().matches("(?s).*" + pattern + ".*")); }
/** * Retrieves a <code>TagTester</code> based on an DOM id. If more <code>Component</code>s exist * with the same id in the markup, only the first one is returned. * * @param id * the DOM id to search for. * @return the <code>TagTester</code> for the tag which has the given DOM id */ public TagTester getTagById(String id) { return TagTester.createTagByAttribute(getLastResponseAsString(), "id", id); }
/** * Retrieves a <code>TagTester</code> based on an DOM id. If more <code>Component</code>s exist * with the same id in the markup, only the first one is returned. * * @param id * the DOM id to search for. * @return the <code>TagTester</code> for the tag which has the given DOM id */ public TagTester getTagById(String id) { return TagTester.createTagByAttribute(getLastResponseAsString(), "id", id); }
/** * Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags * instead of just the first. * * @param wicketId * @return List of Tags */ public List<TagTester> getTagsByWicketId(String wicketId) { return TagTester.createTagsByAttribute(getLastResponseAsString(), "wicket:id", wicketId, false); }
/** * assert the content of last rendered page contains(matches) regex pattern. * * @param pattern * reqex pattern to match * @return a <code>Result</code> */ public Result ifContainsNot(String pattern) { return isFalse("pattern '" + pattern + "' found", getLastResponseAsString().matches("(?s).*" + pattern + ".*")); }
/** * assert the content of last rendered page contains(matches) regex pattern. * * @param pattern * reqex pattern to match * @return a <code>Result</code> */ public Result ifContainsNot(String pattern) { return isFalse("pattern '" + pattern + "' found", getLastResponseAsString().matches("(?s).*" + pattern + ".*")); }
/** * Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags * instead of just the first. * * @param wicketId * @return List of Tags */ public List<TagTester> getTagsByWicketId(String wicketId) { return TagTester.createTagsByAttribute(getLastResponseAsString(), "wicket:id", wicketId, false); }
/** * Retrieves a <code>TagTester</code> based on a <code>wicket:id</code>. If more * <code>Component</code>s exist with the same <code>wicket:id</code> in the markup, only the * first one is returned. * * @param wicketId * the <code>wicket:id</code> to search for * @return the <code>TagTester</code> for the tag which has the given <code>wicket:id</code> */ public TagTester getTagByWicketId(String wicketId) { return TagTester.createTagByAttribute(getLastResponseAsString(), "wicket:id", wicketId); }
/** * Asserts last rendered <code>Page</code> against an expected HTML document as a * <code>String</code>. * * @param expectedDocument * expected output * @return a <code>Result</code> */ public Result isResultPage(final String expectedDocument) { // Validate the document String document = getLastResponseAsString(); return isTrue("expected rendered page equals", document.equals(expectedDocument)); }
/** * Retrieves a <code>TagTester</code> based on a <code>wicket:id</code>. If more * <code>Component</code>s exist with the same <code>wicket:id</code> in the markup, only the * first one is returned. * * @param wicketId * the <code>wicket:id</code> to search for * @return the <code>TagTester</code> for the tag which has the given <code>wicket:id</code> */ public TagTester getTagByWicketId(String wicketId) { return TagTester.createTagByAttribute(getLastResponseAsString(), "wicket:id", wicketId); }
/** * Asserts last rendered <code>Page</code> against an expected HTML document as a * <code>String</code>. * * @param expectedDocument * expected output * @return a <code>Result</code> * @throws Exception */ public Result isResultPage(final String expectedDocument) throws Exception { // Validate the document String document = getLastResponseAsString(); return isTrue("expected rendered page equals", document.equals(expectedDocument)); }
/** * The same as {@link #hasTag(String)}, but uses {@link org.apache.wicket.util.tester.BaseWicketTester#getLastResponseAsString()} * to get the last response. * * @param wicketTester * the wicket tester to use * @param <T> * type of the component * @return the matcher */ @Factory public static <T extends Component> HasCorrespondingTag<T> hasTag(BaseWicketTester wicketTester) { return new HasCorrespondingTag<T>(wicketTester.getLastResponseAsString()); }
/** * Asserts last rendered <code>Page</code> against an expected HTML document. * <p> * Use <code>-Dwicket.replace.expected.results=true</code> to automatically replace the expected * output file. * </p> * * @param pageClass * used to load the <code>File</code> (relative to <code>clazz</code> package) * @param filename * expected output <code>File</code> name * @throws Exception */ public void assertResultPage(final Class<?> pageClass, final String filename) throws Exception { // Validate the document String document = getLastResponseAsString(); DiffUtil.validatePage(document, pageClass, filename, true); }
/** * Asserts last rendered <code>Page</code> against an expected HTML document. * <p> * Use <code>-Dwicket.replace.expected.results=true</code> to automatically replace the expected * output file. * </p> * * @param pageClass * used to load the <code>File</code> (relative to <code>clazz</code> package) * @param filename * expected output <code>File</code> name * @throws Exception */ public void assertResultPage(final Class<?> pageClass, final String filename) throws Exception { // Validate the document String document = getLastResponseAsString(); DiffUtil.validatePage(document, pageClass, filename, true); }
/** * This method tries to parse the last response to return the encoded base URL and will throw an * exception if there none was encoded. * * @return Wicket-Ajax-BaseURL set on last response by {@link AbstractDefaultAjaxBehavior} * @throws IOException * @throws ParseException */ public String getWicketAjaxBaseUrlEncodedInLastResponse() throws IOException, ParseException { XmlPullParser parser = new XmlPullParser(); parser.parse(getLastResponseAsString()); XmlTag tag; while ((tag = parser.nextTag()) != null) { if (tag.isOpen() && tag.getName().equals("script") && "wicket-ajax-base-url".equals(tag.getAttribute("id"))) { parser.next(); return parser.getString().toString().split("\\\"")[1]; } } fail("Last response has no AJAX base URL set by AbstractDefaultAjaxBehavior."); return null; }
/** * This method tries to parse the last response to return the encoded base URL and will throw an * exception if there none was encoded. * * @return Wicket-Ajax-BaseURL set on last response by {@link AbstractDefaultAjaxBehavior} * @throws IOException * @throws ResourceStreamNotFoundException * @throws ParseException */ public String getWicketAjaxBaseUrlEncodedInLastResponse() throws IOException, ResourceStreamNotFoundException, ParseException { XmlPullParser parser = new XmlPullParser(); parser.parse(getLastResponseAsString()); XmlTag tag; while ((tag = parser.nextTag()) != null) { if (tag.isOpen() && tag.getName().equals("script") && "wicket-ajax-base-url".equals(tag.getAttribute("id"))) { parser.next(); return parser.getString().toString().split("\\\"")[1]; } } fail("Last response has no AJAX base URL set by AbstractDefaultAjaxBehavior."); return null; }
String ajaxResponse = getLastResponseAsString();