(no commit message)
[utils] / wicket / components / src / test / java / org / wamblee / wicket / jquery / AbstractJQueryBehaviorTest.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */
16 package org.wamblee.wicket.jquery;
17
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;
27
28 import static junit.framework.TestCase.*;
29
30 public class AbstractJQueryBehaviorTest {
31     private WicketTester wicket;
32
33     @Before
34     public void setUp() {
35         wicket = new WicketTester();
36     }
37
38     @After
39     public void tearDown() {
40         wicket.destroy();
41     }
42     
43     @Test
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"));
54     }
55     
56     @Test
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);
62     }
63     
64     @Test(expected = IllegalStateException.class)
65     public void testCreateReadyJavascriptNoMarkupId() { 
66         Component component = new Label("label");
67         String readyHandler = AbstractJQueryBehavior.createReadyFunction("myfunc", component);
68     }
69     
70 }