Author: ldywicki
Date: Fri Sep  9 14:44:53 2011
New Revision: 1167227

URL: http://svn.apache.org/viewvc?rev=1167227&view=rev
Log:
Sidebar tests

Signed-off-by: Lukasz Dywicki <l...@code-house.org>

Added:
    
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SidebarPageTest.java
Modified:
    
karaf/webconsole/trunk/core/src/main/java/org/apache/karaf/webconsole/core/page/SidebarPage.java
    
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/WebConsoleTest.java
    
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SecuredPageTest.java

Modified: 
karaf/webconsole/trunk/core/src/main/java/org/apache/karaf/webconsole/core/page/SidebarPage.java
URL: 
http://svn.apache.org/viewvc/karaf/webconsole/trunk/core/src/main/java/org/apache/karaf/webconsole/core/page/SidebarPage.java?rev=1167227&r1=1167226&r2=1167227&view=diff
==============================================================================
--- 
karaf/webconsole/trunk/core/src/main/java/org/apache/karaf/webconsole/core/page/SidebarPage.java
 (original)
+++ 
karaf/webconsole/trunk/core/src/main/java/org/apache/karaf/webconsole/core/page/SidebarPage.java
 Fri Sep  9 14:44:53 2011
@@ -34,10 +34,7 @@ public class SidebarPage extends Secured
     }
 
     protected void setSidebarProvider(SidebarProvider provider) {
-        if (sidebar == null) {
-            sidebar = new SidebarPanel("sidebar", provider);
-            add(sidebar);
-        }
+        addOrReplace(sidebar = new SidebarPanel("sidebar", provider));
     }
 
     /**

Modified: 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/WebConsoleTest.java
URL: 
http://svn.apache.org/viewvc/karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/WebConsoleTest.java?rev=1167227&r1=1167226&r2=1167227&view=diff
==============================================================================
--- 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/WebConsoleTest.java
 (original)
+++ 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/WebConsoleTest.java
 Fri Sep  9 14:44:53 2011
@@ -1,12 +1,18 @@
 package org.apache.karaf.webconsole.core;
 
+import static org.easymock.EasyMock.anyObject;
+
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.karaf.webconsole.core.brand.DefaultBrandProvider;
 import org.apache.karaf.webconsole.core.internal.WebConsoleApplication;
 import org.apache.karaf.webconsole.core.security.KarafJaasWebSession;
+import org.apache.wicket.Page;
 import org.apache.wicket.authentication.AuthenticatedWebSession;
+import org.apache.wicket.markup.html.link.Link;
 import org.apache.wicket.protocol.http.WebApplication;
 import org.junit.Before;
 
@@ -45,4 +51,20 @@ public class WebConsoleTest {
     protected Class<? extends AuthenticatedWebSession> getWebSessionClass() {
         return KarafJaasWebSession.class;
     }
+
+    // utility methods for easy mock
+
+    /**
+     * Easy mock argument matcher.
+     */
+    protected final static String anyString() {
+        return anyObject();
+    }
+
+    /**
+     * Empty list stub.
+     */
+    protected final static List<Link<Page>> emptyLinkList() {
+        return Collections.<Link<Page>>emptyList();
+    }
 }
\ No newline at end of file

Modified: 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SecuredPageTest.java
URL: 
http://svn.apache.org/viewvc/karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SecuredPageTest.java?rev=1167227&r1=1167226&r2=1167227&view=diff
==============================================================================
--- 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SecuredPageTest.java
 (original)
+++ 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SecuredPageTest.java
 Fri Sep  9 14:44:53 2011
@@ -200,20 +200,6 @@ public class SecuredPageTest extends Web
         return AlwaysAuthenticatedWebSession.class;
     }
 
-    /**
-     * Easy mock argument matcher.
-     */
-    private static String anyString() {
-        return anyObject();
-    }
-
-    /**
-     * Empty list stub.
-     */
-    private static List<Link<Page>> emptyLinkList() {
-        return Collections.<Link<Page>>emptyList();
-    }
-
     // Marker interface for tests, normally serialization is controlled by 
paxwicket
     // as ConsoleTabProviders are OSGi services.
     interface SerializableConsoleTabProvider extends Serializable, 
ConsoleTabProvider {}

Added: 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SidebarPageTest.java
URL: 
http://svn.apache.org/viewvc/karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SidebarPageTest.java?rev=1167227&view=auto
==============================================================================
--- 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SidebarPageTest.java
 (added)
+++ 
karaf/webconsole/trunk/core/src/test/java/org/apache/karaf/webconsole/core/page/SidebarPageTest.java
 Fri Sep  9 14:44:53 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.karaf.webconsole.core.page;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.util.Collections;
+
+import org.apache.karaf.webconsole.core.WebConsoleTest;
+import org.apache.karaf.webconsole.core.dashboard.DashboardPage;
+import org.apache.karaf.webconsole.core.navigation.SidebarProvider;
+import org.apache.karaf.webconsole.core.test.AlwaysAuthenticatedWebSession;
+import org.apache.karaf.webconsole.core.test.LinkAnswer;
+import org.apache.karaf.webconsole.core.widget.WidgetProvider;
+import org.apache.wicket.authentication.AuthenticatedWebSession;
+import org.apache.wicket.markup.MarkupException;
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+
+/**
+ * Test sidebar page and sidebar rendering.
+ */
+@RunWith(BlockJUnit4ClassRunner.class)
+public class SidebarPageTest extends WebConsoleTest {
+
+    @Test
+    public void testSidebarWithoutSubItems() {
+        WicketTester tester = new WicketTester(application);
+
+        SidebarProvider provider = createMock(SidebarProvider.class);
+        expect(provider.getMasterPageLink(anyString(), 
anyString())).andAnswer(new LinkAnswer("Test link", DashboardPage.class));
+        expect(provider.getItems(anyString(), 
anyString())).andReturn(emptyLinkList());
+        
expect(provider.getWidgetProviders()).andReturn(Collections.<WidgetProvider>emptyList());
+
+        replay(provider);
+
+        tester.startPage(new TestSidebarPage(provider));
+        tester.assertBookmarkablePageLink("sidebar:masterPageLink", 
DashboardPage.class, "");
+        tester.assertLabel("sidebar:masterPageLink:masterPageLabel", "Test 
link");
+        tester.assertListView("sidebar:subPageLinks", emptyLinkList());
+
+        verify(provider);
+    }
+
+    @Test(expected = MarkupException.class)
+    public void testNoSidebarProvider() {
+        WicketTester tester = new WicketTester(application);
+
+        tester.startPage(SidebarPage.class);
+    }
+
+    @Override
+    protected Class<? extends AuthenticatedWebSession> getWebSessionClass() {
+        return AlwaysAuthenticatedWebSession.class;
+    }
+
+    static class TestSidebarPage extends SidebarPage {
+        public TestSidebarPage(SidebarProvider provider) {
+            setSidebarProvider(provider);
+        }
+    }
+}


Reply via email to