myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r513248 - in /myfaces/fusion/trunk/core: ./ src/main/java/org/apache/myfaces/fusion/frameworkAdapter/ src/test/java/ src/test/java/org/apache/myfaces/fusion/conversation/ src/test/java/org/apache/myfaces/fusion/frameworkAdapter/
Date Thu, 01 Mar 2007 09:52:40 GMT
Author: imario
Date: Thu Mar  1 01:52:40 2007
New Revision: 513248

URL: http://svn.apache.org/viewvc?view=rev&rev=513248
Log:
setup the test framework for core, implemented a basic conversation flow test

Added:
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/DummyConversation.java
  (with props)
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/TestConversation.java
  (with props)
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/
    myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/MockFrameworkAdapter.java
  (contents, props changed)
      - copied, changed from r512217, myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/JsfFrameworkAdapter.java
    myfaces/fusion/trunk/core/src/test/java/testApplicationContext.xml   (with props)
Modified:
    myfaces/fusion/trunk/core/pom.xml
    myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/FrameworkAdapter.java

Modified: myfaces/fusion/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/pom.xml?view=diff&rev=513248&r1=513247&r2=513248
==============================================================================
--- myfaces/fusion/trunk/core/pom.xml (original)
+++ myfaces/fusion/trunk/core/pom.xml Thu Mar  1 01:52:40 2007
@@ -70,6 +70,20 @@
 
 		<!-- test dependencies -->
 
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-mock</artifactId>
+			<version>2.0.2</version>
+			<scope>test</scope>
+		</dependency>
+
+                <dependency>
+                        <groupId>cglib</groupId>
+                        <artifactId>cglib</artifactId>
+                        <version>2.1_3</version>
+			<scope>test</scope>
+                </dependency>
+
 	</dependencies>
 
 	<build>

Modified: myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/FrameworkAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/FrameworkAdapter.java?view=diff&rev=513248&r1=513247&r2=513248
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/FrameworkAdapter.java
(original)
+++ myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/FrameworkAdapter.java
Thu Mar  1 01:52:40 2007
@@ -27,14 +27,24 @@
  */
 public class FrameworkAdapter
 {
-	private final static FrameworkAdapterInterface INSTANCE = new JsfFrameworkAdapter();
+	private static FrameworkAdapterInterface INSTANCE;
 
 	private FrameworkAdapter()
 	{
 	}
 
+	static void setFrameworkAdapter(FrameworkAdapterInterface frameworkAdapterInterface)
+	{
+		INSTANCE = frameworkAdapterInterface;
+	}
+
 	public static FrameworkAdapterInterface getInstance()
 	{
+		if (INSTANCE == null)
+		{
+			INSTANCE = new JsfFrameworkAdapter();
+		}
+
 		return INSTANCE;
 	}
 

Added: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/DummyConversation.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/DummyConversation.java?view=auto&rev=513248
==============================================================================
--- myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/DummyConversation.java
(added)
+++ myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/DummyConversation.java
Thu Mar  1 01:52:40 2007
@@ -0,0 +1,74 @@
+/*
+ * 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.myfaces.fusion.conversation;
+
+public class DummyConversation implements ConversationBindingListener
+{
+	private String data;
+
+	public static ConversationBindingListener callback;
+
+	public DummyConversation()
+	{
+	}
+
+	public void touch()
+	{
+	}
+
+	public String getData()
+	{
+		return data;
+	}
+
+	public void setData(String data)
+	{
+		this.data = data;
+	}
+
+	public Conversation checkCurrentConversation()
+	{
+		return Conversation.getCurrentInstance();
+	}
+
+	public void invalidateSelf()
+	{
+		Conversation.getCurrentInstance().invalidate();
+	}
+
+	public void invalidateAndRestartSelf()
+	{
+		Conversation.getCurrentInstance().invalidateAndRestart();
+	}
+
+	public DummyConversation getRaw()
+	{
+		return this;
+	}
+
+	public void valueBound(ConversationBindingEvent event)
+	{
+		callback.valueBound(event);
+	}
+
+	public void valueUnbound(ConversationBindingEvent event)
+	{
+		callback.valueUnbound(event);
+	}
+}

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/DummyConversation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/DummyConversation.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/DummyConversation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/TestConversation.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/TestConversation.java?view=auto&rev=513248
==============================================================================
--- myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/TestConversation.java
(added)
+++ myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/TestConversation.java
Thu Mar  1 01:52:40 2007
@@ -0,0 +1,125 @@
+/*
+ * 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.myfaces.fusion.conversation;
+
+import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
+import org.springframework.aop.scope.ScopedObject;
+import org.apache.myfaces.fusion.frameworkAdapter.MockFrameworkAdapter;
+
+/**
+ * Test various aspects of the conversation handling
+ */
+public class TestConversation extends AbstractDependencyInjectionSpringContextTests implements
ConversationBindingListener
+{
+	protected String[] getConfigLocations()
+	{
+		return new String[]
+			{
+				"classpath:testApplicationContext.xml"
+			};
+	}
+
+
+	private int valueBoundCount = 0;
+	private int valueUnboundCount = 0;
+
+	protected void onSetUp() throws Exception
+	{
+		super.onSetUp();
+
+		MockFrameworkAdapter frameworkAdapter = MockFrameworkAdapter.register();
+		frameworkAdapter.setApplicationContext(applicationContext);
+	}
+
+	public void testConversation() throws Exception
+	{
+		DummyConversation.callback=this;
+		final String CONVERSATION_NAME = "dummyConversation";
+
+		valueBoundCount = 0;
+		valueUnboundCount = 0;
+
+		/* simple create test */
+		DummyConversation conv = (DummyConversation) applicationContext.getBean(CONVERSATION_NAME);
+
+		assertTrue("should be a scoped object", conv instanceof ScopedObject);
+
+		assertFalse("conversation should not have been started yet", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));
+		assertEquals("value bound", 0, valueBoundCount);
+		assertEquals("value unbound", 0, valueUnboundCount);
+		conv.touch();
+		assertEquals("value bound", 1, valueBoundCount);
+		assertEquals("value unbound", 0, valueUnboundCount);
+		assertTrue("conversation should have been started", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));
+
+		/* check if correct conversation has been started */
+		Conversation conversationHolder = conv.checkCurrentConversation();
+		assertNotNull("current conversation", conversationHolder);
+		assertEquals("conversation name", CONVERSATION_NAME, conversationHolder.getName());
+
+		/* invalidate conversation */
+		conv.invalidateSelf();
+
+		assertFalse("conversation should not be running", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));
+		assertTrue("conversation should be marked invalid", conversationHolder.isInvalid());
+		assertEquals("value bound", 1, valueBoundCount);
+		assertEquals("value unbound", 1, valueUnboundCount);
+
+		conv.touch();
+		assertTrue("conversation should have been started", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));
+		assertEquals("value bound", 2, valueBoundCount);
+
+
+		/* check if a new conversation bean has been created */
+		conv.setData("check");
+
+		conv.invalidateAndRestartSelf();
+
+		assertEquals("value bound", 2, valueBoundCount);
+		assertEquals("value unbound", 2, valueUnboundCount);
+
+		assertTrue("conversation should still be running", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));
+
+		DummyConversation convNew = (DummyConversation) applicationContext.getBean(CONVERSATION_NAME);
+
+		assertNotNull("should have got a new conversation", convNew);
+		assertNull("the conversation is not new", conv.getData());
+
+		convNew.touch();
+
+		assertEquals("value bound", 3, valueBoundCount);
+
+		/* clear the whole conversation context */
+
+		ConversationManager.getInstance().clearCurrentConversationContext();
+
+		assertEquals("value unbound", 3, valueUnboundCount);
+		assertFalse("conversation should not be running", ConversationManager.getInstance().hasConversation(CONVERSATION_NAME));
+	}
+
+	public void valueBound(ConversationBindingEvent event)
+	{
+		valueBoundCount++;
+	}
+
+	public void valueUnbound(ConversationBindingEvent event)
+	{
+		valueUnboundCount++;
+	}
+}

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/TestConversation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/TestConversation.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/conversation/TestConversation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/MockFrameworkAdapter.java
(from r512217, myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/JsfFrameworkAdapter.java)
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/MockFrameworkAdapter.java?view=diff&rev=513248&p1=myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/JsfFrameworkAdapter.java&r1=512217&p2=myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/MockFrameworkAdapter.java&r2=513248
==============================================================================
--- myfaces/fusion/trunk/core/src/main/java/org/apache/myfaces/fusion/frameworkAdapter/JsfFrameworkAdapter.java
(original)
+++ myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/MockFrameworkAdapter.java
Thu Mar  1 01:52:40 2007
@@ -23,110 +23,101 @@
 package org.apache.myfaces.fusion.frameworkAdapter;
 
 import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
 
-import javax.faces.context.FacesContext;
-import javax.servlet.ServletContext;
 import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
 
 /**
- * A JSF Implementation for the FrameworkAdapter
+ * A Mock implementation for test environments
  */
-public class JsfFrameworkAdapter implements FrameworkAdapterInterface
+public class MockFrameworkAdapter implements FrameworkAdapterInterface
 {
-	protected FacesContext getFacesContext()
-	{
-		FacesContext context = FacesContext.getCurrentInstance();
-		if (context == null)
-		{
-			throw new IllegalStateException("no facesContext");
-		}
-		return context;
+	private ConfigurableApplicationContext configurableApplicationContext;
+
+	private final Map sessionMap = new TreeMap();
+	private final Map requestMap = new TreeMap();
+	private final Map requestParameterMap = new TreeMap();
+	private final Map initMap = new TreeMap();
+
+	public static MockFrameworkAdapter register()
+	{
+		MockFrameworkAdapter instance = new MockFrameworkAdapter();
+		FrameworkAdapter.setFrameworkAdapter(instance);
+		return instance;
 	}
 
 	public String getInitParameter(String key)
 	{
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getInitParameter(key);
+		return (String) initMap.get(key);
 	}
 
 	public Object getRequestParameterAttribute(String key)
 	{
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestParameterMap().get(key);
+		return requestParameterMap.get(key);
 	}
 
 	public boolean containsRequestParameterAttribute(String key)
 	{
-		FacesContext context = getFacesContext();
+		return requestParameterMap.containsKey(key);
+	}
 
-		return context.getExternalContext().getRequestParameterMap().containsKey(key);
+	public void setRequestParameterAttribute(String key , Object value)
+	{
+		requestParameterMap.put(key, value);
 	}
 
 	public Object getRequestAttribute(String key)
 	{
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestMap().get(key);
+		return requestMap.get(key);
 	}
 
 	public void setRequestAttribute(String key, Object value)
 	{
-		FacesContext context = getFacesContext();
+		requestMap.put(key, value);
+	}
 
-		context.getExternalContext().getRequestMap().put(key, value);
+	public void clearRequestMap()
+	{
+		requestMap.clear();
 	}
 
 	public boolean containsRequestAttribute(String key)
 	{
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestMap().containsKey(key);
+		return requestMap.containsKey(key);
 	}
 
 	public Object getSessionAttribute(String key)
 	{
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getSessionMap().get(key);
+		return sessionMap.get(key);
 	}
 
 	public void setSessionAttribute(String key, Object value)
 	{
-		FacesContext context = getFacesContext();
-
-		context.getExternalContext().getSessionMap().put(key, value);
+		sessionMap.put(key, value);
 	}
 
 	public boolean containsSessionAttribute(String key, Object value)
 	{
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getSessionMap().containsKey(key);
+		return sessionMap.containsKey(key);
 	}
 
 	public String getRequestContextPath()
 	{
-		FacesContext context = getFacesContext();
-
-		return context.getExternalContext().getRequestContextPath();
+		return "/test";
 	}
 
 	public ConfigurableApplicationContext getApplicationContext()
 	{
-		// TODO: What about portlets ?
-		ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
+		return configurableApplicationContext;
+	}
 
-		return (ConfigurableApplicationContext) WebApplicationContextUtils.getWebApplicationContext(servletContext);
+	public void setApplicationContext(ConfigurableApplicationContext configurableApplicationContext)
+	{
+		this.configurableApplicationContext = configurableApplicationContext;
 	}
 
 	public void redirect(String url) throws IOException
 	{
-		FacesContext context = getFacesContext();
-
-		context.getExternalContext().redirect(url);
-		context.responseComplete();
 	}
 }

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/MockFrameworkAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/MockFrameworkAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/fusion/trunk/core/src/test/java/org/apache/myfaces/fusion/frameworkAdapter/MockFrameworkAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: myfaces/fusion/trunk/core/src/test/java/testApplicationContext.xml
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/core/src/test/java/testApplicationContext.xml?view=auto&rev=513248
==============================================================================
--- myfaces/fusion/trunk/core/src/test/java/testApplicationContext.xml (added)
+++ myfaces/fusion/trunk/core/src/test/java/testApplicationContext.xml Thu Mar  1 01:52:40
2007
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	   xmlns:tx="http://www.springframework.org/schema/tx"
+	   xmlns:aop="http://www.springframework.org/schema/aop"
+	   xsi:schemaLocation="
+			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
+			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
+
+	<!-- register our custom spring scope -->
+	<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
+		<property name="scopes">
+			<map>
+				<entry key="conversation">
+					<bean class="org.apache.myfaces.fusion.conversation.spring.SpringConversationScope"
/>
+				</entry>
+			</map>
+		</property>
+	</bean>
+
+	<bean
+		name="dummyConversation"
+		class="org.apache.myfaces.fusion.conversation.DummyConversation"
+		scope="conversation"
+		autowire="byName">
+
+		<aop:scoped-proxy/>
+	</bean>
+
+</beans>
\ No newline at end of file

Propchange: myfaces/fusion/trunk/core/src/test/java/testApplicationContext.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/fusion/trunk/core/src/test/java/testApplicationContext.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/fusion/trunk/core/src/test/java/testApplicationContext.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message