You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/07/25 05:48:11 UTC
svn commit: r978972 -
/click/trunk/click/framework/test/org/apache/click/ControlRegistryTest.java
Author: sabob
Date: Sun Jul 25 03:48:10 2010
New Revision: 978972
URL: http://svn.apache.org/viewvc?rev=978972&view=rev
Log:
added control registry tests
Added:
click/trunk/click/framework/test/org/apache/click/ControlRegistryTest.java
Added: click/trunk/click/framework/test/org/apache/click/ControlRegistryTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/ControlRegistryTest.java?rev=978972&view=auto
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/ControlRegistryTest.java (added)
+++ click/trunk/click/framework/test/org/apache/click/ControlRegistryTest.java Sun Jul 25 03:48:10 2010
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click;
+
+import junit.framework.TestCase;
+import org.apache.click.ajax.AjaxBehavior;
+import org.apache.click.control.TextField;
+
+/**
+ * Provides tests for ControlRegistry.
+ */
+public class ControlRegistryTest extends TestCase {
+
+ /**
+ * Check that AbstractControl#addBehavior registers the control as an Ajax
+ * target.
+ */
+ public void testRegisterAsAjaxTarget() {
+ MockContext.initContext();
+ ControlRegistry registry = ControlRegistry.getThreadLocalRegistry();
+
+ TextField field = new TextField("field");
+ assertFalse(registry.hasAjaxTargetControls());
+ field.addBehavior(new AjaxBehavior());
+ assertTrue(registry.hasAjaxTargetControls());
+ }
+
+ /**
+ * Check that multiple calls to AbstractControl#addBehavior registers the
+ * control as an Ajax target only once.
+ */
+ public void testRegisterAsAjaxTargetMultipleTimes() {
+ MockContext.initContext();
+ ControlRegistry registry = ControlRegistry.getThreadLocalRegistry();
+
+ TextField field = new TextField("field");
+
+ // Test that adding behavior registers control as ajax target
+ assertFalse(registry.hasAjaxTargetControls());
+ field.addBehavior(new AjaxBehavior());
+ assertTrue(registry.hasAjaxTargetControls());
+ assertEquals(1, registry.getAjaxTargetControls().size());
+
+ // Test that adding another behavior does not register the control twice
+ field.addBehavior(new AjaxBehavior());
+ assertEquals(1, registry.getAjaxTargetControls().size());
+
+ // Test that invoking onInit does not register the control twice
+ field.onInit();
+ assertEquals(1, registry.getAjaxTargetControls().size());
+ }
+
+ /**
+ * Check that ControlRegistry.registerInterceptor registers the control and
+ * behavior as interceptor.
+ */
+ public void testRegisterInterceptorMethods() {
+ MockContext.initContext();
+ ControlRegistry registry = ControlRegistry.getThreadLocalRegistry();
+
+ TextField field = new TextField("field");
+
+ Behavior interceptor = new AjaxBehavior();
+
+ // Check interceptor is registered with registry
+ assertFalse(registry.hasInterceptors());
+ ControlRegistry.registerInterceptor(field, interceptor);
+ assertTrue(registry.hasInterceptors());
+
+ assertFalse(registry.hasAjaxTargetControls());
+ }
+
+ /**
+ * Check that multiple calls to AbstractControl#registerInterceptor registers the
+ * control as an Ajax target only once.
+ */
+ public void testRegisterInterceptorMultipleTimes() {
+ MockContext.initContext();
+ ControlRegistry registry = ControlRegistry.getThreadLocalRegistry();
+
+ TextField field = new TextField("field");
+
+ Behavior interceptor = new AjaxBehavior();
+
+ // Check interceptor is registered with registry
+ assertFalse(registry.hasInterceptors());
+ ControlRegistry.registerInterceptor(field, interceptor);
+ assertTrue(registry.hasInterceptors());
+ assertEquals(1, registry.getInterceptors().size());
+
+ // Test that adding another interceptor does not register the interceptor twice
+ ControlRegistry.registerInterceptor(field, interceptor);
+ assertEquals(1, registry.getInterceptors().size());
+ }
+}