2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.wicket.jquery;
18 import org.apache.wicket.Component;
19 import org.apache.wicket.markup.html.basic.Label;
20 import org.apache.wicket.markup.html.form.Form;
21 import org.apache.wicket.util.tester.TagTester;
22 import org.apache.wicket.util.tester.WicketTester;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.wamblee.wicket.MyPage;
28 import static junit.framework.TestCase.*;
30 public class AbstractJQueryBehaviorTest {
31 private WicketTester wicket;
35 wicket = new WicketTester();
39 public void tearDown() {
44 public void testVerifyBasicFunc() {
45 MyPage page = new MyPage();
46 page.getLabel().add(new AbstractJQueryBehavior("initfunc"));
47 wicket.startPage(page);
48 wicket.assertRenderedPage(MyPage.class);
49 TagTester tag = wicket.getTagByWicketId("label");
50 assertNotNull(tag.getAttribute("id"));
51 String doc = wicket.getServletResponse().getDocument();
52 assertTrue(doc.contains("jquery-noconflict"));
53 assertTrue(doc.contains("initfunc"));
57 public void testCreateReadyJavascript() {
58 Component component = new Label("label");
59 component.setOutputMarkupId(true);
60 String readyHandler = AbstractJQueryBehavior.createReadyFunction("myfunc", component);
61 assertEquals("jQuery(function(){org.wamblee.myfunc(\"#" + component.getMarkupId() + "\");});", readyHandler);
64 @Test(expected = IllegalStateException.class)
65 public void testCreateReadyJavascriptNoMarkupId() {
66 Component component = new Label("label");
67 String readyHandler = AbstractJQueryBehavior.createReadyFunction("myfunc", component);