Revision: 1097
Author: lstreepy
Date: 2006-04-27 06:45:49 -0700 (Thu, 27 Apr 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1097&view=rev
Log Message:
-----------
Add tests for DialogPageUtils
Added Paths:
-----------
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/dialog/support/DialogPageUtilsTests.java
trunk/spring-richclient/support/src/test/resources/org/springframework/richclient/dialog/support/generic-application-ctx.xml
Added:
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/dialog/support/DialogPageUtilsTests.java
===================================================================
---
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/dialog/support/DialogPageUtilsTests.java
(rev 0)
+++
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/dialog/support/DialogPageUtilsTests.java
2006-04-27 13:45:49 UTC (rev 1097)
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed 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.springframework.richclient.dialog.support;
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+
+import junit.framework.TestCase;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.richclient.application.Application;
+import
org.springframework.richclient.application.config.DefaultApplicationLifecycleAdvisor;
+import org.springframework.richclient.command.ActionCommand;
+import org.springframework.richclient.core.Guarded;
+import org.springframework.richclient.core.Message;
+import org.springframework.richclient.dialog.AbstractDialogPage;
+import org.springframework.richclient.dialog.DefaultMessageAreaModel;
+import org.springframework.richclient.dialog.DialogPage;
+import org.springframework.richclient.dialog.TitlePane;
+
+/**
+ * Tests for [EMAIL PROTECTED] DialogPageUtils}.
+ *
+ * @author Larry Streepy
+ */
+public class DialogPageUtilsTests extends TestCase {
+
+ public void setUp() {
+ ClassPathXmlApplicationContext applicationContext = new
ClassPathXmlApplicationContext(
+
"org/springframework/richclient/dialog/support/generic-application-ctx.xml");
+ Application.load(null);
+ Application app = new Application(new
DefaultApplicationLifecycleAdvisor());
+ app.setApplicationContext(applicationContext);
+ }
+
+ public void testMessageMonitor() {
+ DialogPage page = new TestDialogPage();
+ TestMessagable monitor = new TestMessagable();
+ DialogPageUtils.addMessageMonitor(page, monitor);
+
+ monitor.resetMessageCount();
+ page.setMessage(new Message("a message"));
+ assertEquals("Message text not equal", monitor.getMessage().getText(),
"a message");
+
+ page.setMessage(new Message("another message"));
+ assertEquals("Message text not equal", monitor.getMessage().getText(),
"another message");
+
+ assertEquals("Message count incorrect", 2, monitor.getMessageCount());
+ }
+
+ public void testPageCompleteAdapter() {
+ TestDialogPage page = new TestDialogPage();
+ Guarded guarded = new TestGuarded();
+
+ DialogPageUtils.adaptPageCompletetoGuarded(page, guarded);
+
+ page.setPageComplete(false);
+ assertFalse("guarded should be disabled", guarded.isEnabled());
+
+ page.setPageComplete(true); // Change it
+ assertTrue("guarded should be enabled", guarded.isEnabled());
+ }
+
+ public void testStandardViewAdaptsOkCommand() {
+ TestDialogPage page = new TestDialogPage();
+
+ ActionCommand okCommand = new ActionCommand("okCommand") {
+ protected void doExecuteCommand() {
+ }
+ };
+ ActionCommand cancelCommand = new ActionCommand("cancelCommand") {
+ protected void doExecuteCommand() {
+ }
+ };
+
+ DialogPageUtils.createStandardView(page, okCommand, cancelCommand);
+
+ page.setPageComplete(false);
+ assertFalse("okCommand should be disabled", okCommand.isEnabled());
+
+ page.setPageComplete(true);
+ assertTrue("okCommand should be enabled", okCommand.isEnabled());
+ }
+
+ public void testCreateTitlePane() {
+ TestDialogPage page = new TestDialogPage();
+
+ TitlePane titlePane = DialogPageUtils.createTitlePane(page);
+
+ page.setMessage(new Message("test message"));
+ assertEquals("Message text not equal",
titlePane.getMessage().getText(), "test message");
+ }
+
+ /**
+ * Class to provide a concrete DialogPage for testing.
+ */
+ private class TestDialogPage extends AbstractDialogPage {
+
+ public TestDialogPage() {
+ super("MyPageId");
+ }
+
+ protected JComponent createControl() {
+ return new JLabel();
+ }
+ }
+
+ /**
+ * Class to inspect Messagable operations.
+ */
+ private class TestMessagable extends DefaultMessageAreaModel {
+
+ private int msgCount = 0;
+
+ public void setMessage( Message message ) {
+ msgCount += 1;
+ super.setMessage(message);
+ }
+
+ public int getMessageCount() {
+ return msgCount;
+ }
+
+ public void resetMessageCount() {
+ msgCount = 0;
+ }
+ }
+
+ /**
+ * Class to inspect Guarded operations.
+ */
+ private class TestGuarded implements Guarded {
+ private boolean enabled = false;
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled( boolean enabled ) {
+ this.enabled = enabled;
+ }
+ }
+}
Added:
trunk/spring-richclient/support/src/test/resources/org/springframework/richclient/dialog/support/generic-application-ctx.xml
===================================================================
---
trunk/spring-richclient/support/src/test/resources/org/springframework/richclient/dialog/support/generic-application-ctx.xml
(rev 0)
+++
trunk/spring-richclient/support/src/test/resources/org/springframework/richclient/dialog/support/generic-application-ctx.xml
2006-04-27 13:45:49 UTC (rev 1097)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
+ "http://www.springframework.org/dtd/spring-beans.dtd">
+<beans>
+
+ <bean id="applicationObjectConfigurer"
+
class="org.springframework.richclient.application.config.DefaultApplicationObjectConfigurer">
+ <constructor-arg index="0" ref="messageSource" />
+ <constructor-arg index="1" ref="imageSource" />
+ <constructor-arg index="2" ref="iconSource" />
+ </bean>
+
+ <bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
+ <property name="basenames">
+ <list>
+
<value>org.springframework.richclient.application.messages</value>
+ </list>
+ </property>
+ </bean>
+
+ <bean id="imageResourcesFactory"
class="org.springframework.context.support.ResourceMapFactoryBean">
+ <property name="locations">
+ <list>
+
<value>classpath:org/springframework/richclient/image/images.properties</value>
+ </list>
+ </property>
+ <property name="resourceBasePath" value="images/" />
+ </bean>
+
+ <bean id="imageSource"
class="org.springframework.richclient.image.DefaultImageSource">
+ <constructor-arg index="0" ref="imageResourcesFactory" />
+ <property name="brokenImageIndicator">
+ <value>images/alert/error_obj.gif</value>
+ </property>
+ </bean>
+
+ <bean id="iconSource"
class="org.springframework.richclient.image.DefaultIconSource">
+ <constructor-arg index="0" ref="imageSource" />
+ </bean>
+
+</beans>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs