+ AbstractJQueryBehavior behavior = new AbstractJQueryBehavior("myfunc");
+ behavior.bind(component);
+ String readyHandler = behavior.createReadyFunction();
+ assertEquals("jQuery(function(){myfunc(\"#" + component.getMarkupId() +
+ "\",null);});", readyHandler);
+ }
+
+ @Test
+ public void testCreateReadyJavaScriptWithCustomConfigJavascript() {
+ Component component = new Label("label");
+ component.setOutputMarkupId(false);
+ AbstractJQueryBehavior behavior = new AbstractJQueryBehavior("myfunc") {
+ @Override
+ protected String getConfigurationJavascript() {
+ return "bla";
+ }
+ };
+ behavior.bind(component);
+ String readyHandler = behavior.createReadyFunction();
+ assertEquals("jQuery(function(){myfunc(\"#" + component.getMarkupId() +
+ "\",bla);});", readyHandler);
+ }
+
+ public static final class X {
+ private int x = 10;
+ public int getX() {
+ return x;
+ }
+ }
+
+ @Test
+ public void testCreateReadyJavaScriptWithConfig() {
+ Component component = new Label("label");
+ component.setOutputMarkupId(false);
+ AbstractJQueryBehavior behavior = new AbstractJQueryBehavior("myfunc") {
+ @Override
+ protected Object getConfigurationObject() {
+ return new X();
+ }
+ };
+ behavior.bind(component);
+ String readyHandler = behavior.createReadyFunction();
+ String config = new JSONSerializer().serialize(new X());
+ assertEquals("jQuery(function(){myfunc(\"#" + component.getMarkupId() +
+ "\"," + config + ");});", readyHandler);