Return-Path: Delivered-To: apmail-click-commits-archive@www.apache.org Received: (qmail 69632 invoked from network); 1 May 2010 17:34:11 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 May 2010 17:34:11 -0000 Received: (qmail 83294 invoked by uid 500); 1 May 2010 17:34:11 -0000 Delivered-To: apmail-click-commits-archive@click.apache.org Received: (qmail 83278 invoked by uid 500); 1 May 2010 17:34:11 -0000 Mailing-List: contact commits-help@click.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@click.apache.org Delivered-To: mailing list commits@click.apache.org Received: (qmail 83270 invoked by uid 99); 1 May 2010 17:34:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 May 2010 17:34:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 May 2010 17:34:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 77CC823889FA; Sat, 1 May 2010 17:33:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r940088 - in /click/trunk/click/extras: src/org/apache/click/extras/panel/TabbedPanel.java test/org/apache/click/extras/panel/TabbedPanelTest.java Date: Sat, 01 May 2010 17:33:14 -0000 To: commits@click.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100501173314.77CC823889FA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sabob Date: Sat May 1 17:33:14 2010 New Revision: 940088 URL: http://svn.apache.org/viewvc?rev=940088&view=rev Log: fix tests. CLK-666 Modified: click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java click/trunk/click/extras/test/org/apache/click/extras/panel/TabbedPanelTest.java Modified: click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java?rev=940088&r1=940087&r2=940088&view=diff ============================================================================== --- click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java (original) +++ click/trunk/click/extras/src/org/apache/click/extras/panel/TabbedPanel.java Sat May 1 17:33:14 2010 @@ -209,12 +209,19 @@ public class TabbedPanel extends Panel { */ @Override public Control insert(Control control, int index) { + Panel panel = null; + if (control instanceof Panel) { + panel = (Panel) control; + panel.setActive(false); + } + super.insert(control, index); - if (control instanceof Panel && getPanels().size() == 1) { - setActivePanel((Panel) control); + if (panel != null) { + if (getPanels().size() == 1) { + setActivePanel(panel); + } } - return control; } @@ -234,8 +241,11 @@ public class TabbedPanel extends Panel { public Control replace(Control currentControl, Control newControl) { super.replace(currentControl, newControl); - if (newControl instanceof Panel && getPanels().size() == 1) { - setActivePanel((Panel) newControl); + if (currentControl instanceof Panel) { + Panel currentPanel = (Panel) currentControl; + if (currentPanel == getActivePanel()) { + setActivePanel((Panel) newControl); + } } return newControl; } Modified: click/trunk/click/extras/test/org/apache/click/extras/panel/TabbedPanelTest.java URL: http://svn.apache.org/viewvc/click/trunk/click/extras/test/org/apache/click/extras/panel/TabbedPanelTest.java?rev=940088&r1=940087&r2=940088&view=diff ============================================================================== --- click/trunk/click/extras/test/org/apache/click/extras/panel/TabbedPanelTest.java (original) +++ click/trunk/click/extras/test/org/apache/click/extras/panel/TabbedPanelTest.java Sat May 1 17:33:14 2010 @@ -22,6 +22,7 @@ import junit.framework.TestCase; import org.apache.click.ActionListener; import org.apache.click.Control; import org.apache.click.MockContext; +import org.apache.click.Page; import org.apache.click.control.ActionLink; import org.apache.click.control.Panel; @@ -35,18 +36,18 @@ public class TabbedPanelTest extends Tes tabbedPanel.add(new Panel("panel2")); tabbedPanel.onInit(); String activePanelName = tabbedPanel.getActivePanel().getName(); - + // By default panel1 should be the active panel assertEquals("panel1", activePanelName); } - + /** * Test that the request parameter tabPanelIndex sets the new * active panel correctly. */ public void testTabPanelIndexParameter() { MockContext context = MockContext.initContext(); - + // Since tabbedPanel is zero index based, setting tabPanelIndex to 1 // should set the active panel to panel2 context.getMockRequest().setParameter("tabPanelIndex", "1"); @@ -56,17 +57,17 @@ public class TabbedPanelTest extends Tes tabbedPanel.add(new Panel("panel2")); tabbedPanel.onInit(); String activePanelName = tabbedPanel.getActivePanel().getName(); - + // By default panel2 should be the active panel assertEquals("panel2", activePanelName); } - + /** * Test that if user selects panel2, panel2 becomes the active panel. */ public void testTabLinkClicked() { MockContext context = MockContext.initContext(); - + // Simulate user selecting panel2 context.getMockRequest().setParameter(ActionLink.ACTION_LINK, "tabLink"); context.getMockRequest().setParameter(ActionLink.VALUE, "panel2"); @@ -76,11 +77,11 @@ public class TabbedPanelTest extends Tes tabbedPanel.add(new Panel("panel2")); tabbedPanel.onInit(); String activePanelName = tabbedPanel.getActivePanel().getName(); - + // By default panel2 should be the active panel assertEquals("panel2", activePanelName); } - + /** * Test that registered tab listener is fired. * @@ -111,4 +112,50 @@ public class TabbedPanelTest extends Tes // If tab listener was triggered the actionResult should be false assertFalse(actionResult); } + + /** + * Check that adding controls replace existing controls with the same name. + * + * CLK-666 + */ + public void testReplace() { + MockContext.initContext(); + + Page page = new Page(); + TabbedPanel panel = new TabbedPanel("panel"); + page.addControl(panel); + + // Add two panels named child1 and child2 + Panel child1 = new Panel("child1"); + Panel child2 = new Panel("child2"); + panel.add(child1); + panel.add(child2); + + // Execute onInit event + panel.onInit(); + + assertEquals(3, panel.getControlMap().size()); + assertEquals(3, panel.getControls().size()); + assertSame(child1, panel.getControls().get(1)); + assertSame(child2, panel.getControls().get(2)); + assertSame(child1, panel.getPanels().get(0)); + assertSame(child2, panel.getPanels().get(1)); + assertTrue(child1.isActive()); + assertFalse(child2.isActive()); + + // Add another two panels named child1 and child2 and test that these + // panels replaces the previous panels + child1 = new Panel("child1"); + child2 = new Panel("child2"); + panel.add(child1); + panel.add(child2); + assertEquals(3, panel.getControlMap().size()); + assertEquals(3, panel.getControls().size()); + assertSame(child1, panel.getControls().get(1)); + assertSame(child2, panel.getControls().get(2)); + assertSame(child1, panel.getPanels().get(0)); + assertSame(child2, panel.getPanels().get(1)); + assertTrue(child1.isActive()); + assertFalse(child2.isActive()); + } }