You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by do...@apache.org on 2013/08/21 18:35:18 UTC

svn commit: r1516205 [4/9] - in /james/hupa/trunk: ./ client/src/main/java/org/apache/hupa/ client/src/main/java/org/apache/hupa/client/ client/src/main/java/org/apache/hupa/client/gin/ client/src/main/java/org/apache/hupa/client/mvp/ client/src/main/j...

Copied: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/LoginPresenterPlace.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/LoginPresenterPlace.java?p2=james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/LoginPresenterPlace.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/LoginPresenterPlace.java Wed Aug 21 16:35:16 2013
@@ -17,13 +17,34 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.hupa.shared.exception;
+package org.apache.hupa.client.mvp.place;
 
-public class InvalidSessionException extends HupaException{
+import org.apache.hupa.client.mvp.LoginPresenter;
 
-	private static final long serialVersionUID = 995112620968798947L;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
 
-	public InvalidSessionException(String message) {
-        super(message);
+import net.customware.gwt.presenter.client.gin.ProvidedPresenterPlace;
+import net.customware.gwt.presenter.client.place.PlaceRequest;
+
+public class LoginPresenterPlace extends ProvidedPresenterPlace<LoginPresenter>{
+
+    @Inject
+    public LoginPresenterPlace(Provider<LoginPresenter> presenter) {
+        super(presenter);
+    }
+
+    @Override
+    public String getName() {
+        return "Login";
     }
+
+    @Override
+    protected void preparePresenter(PlaceRequest request, LoginPresenter presenter) {
+        String user = request.getParameter("user", null);
+        if (user != null) {
+            presenter.getDisplay().getUserNameValue().setValue(user);
+        }
+    }
+
 }

Copied: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MessageSendPresenterPlace.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MessageSendPresenterPlace.java?p2=james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MessageSendPresenterPlace.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MessageSendPresenterPlace.java Wed Aug 21 16:35:16 2013
@@ -16,14 +16,25 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.hupa.client.mvp.place;
 
-package org.apache.hupa.shared.exception;
+import org.apache.hupa.client.mvp.MessageSendPresenter;
 
-public class InvalidSessionException extends HupaException{
+import com.google.inject.Inject;
+import com.google.inject.Provider;
 
-	private static final long serialVersionUID = 995112620968798947L;
+import net.customware.gwt.presenter.client.gin.ProvidedPresenterPlace;
 
-	public InvalidSessionException(String message) {
-        super(message);
+public class MessageSendPresenterPlace extends ProvidedPresenterPlace<MessageSendPresenter>{
+
+    @Inject
+    public MessageSendPresenterPlace(Provider<MessageSendPresenter> presenter) {
+        super(presenter);
+    }
+
+    @Override
+    public String getName() {
+        return "MessageSend";
     }
+
 }

Copied: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectProxy.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectProxy.java?p2=james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectProxy.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectProxy.java Wed Aug 21 16:35:16 2013
@@ -16,14 +16,24 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.hupa.client.rf;
 
-package org.apache.hupa.shared.exception;
+import org.apache.hupa.server.rf.Subject;
 
-public class InvalidSessionException extends HupaException{
+import com.google.web.bindery.requestfactory.shared.EntityProxy;
+import com.google.web.bindery.requestfactory.shared.ProxyFor;
 
-	private static final long serialVersionUID = 995112620968798947L;
+@ProxyFor(Subject.class)
+public interface SubjectProxy extends EntityProxy {
+  String getTitle();
 
-	public InvalidSessionException(String message) {
-        super(message);
-    }
+  Long getId();
+
+  Integer getVersion();
+
+  void setTitle(String title);
+
+  void setId(Long id);
+
+  void setVersion(Integer version);
 }

Copied: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectRequest.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectRequest.java?p2=james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectRequest.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectRequest.java Wed Aug 21 16:35:16 2013
@@ -16,14 +16,25 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.hupa.client.rf;
 
-package org.apache.hupa.shared.exception;
+import org.apache.hupa.server.rf.Subject;
 
-public class InvalidSessionException extends HupaException{
+import com.google.web.bindery.requestfactory.shared.InstanceRequest;
+import com.google.web.bindery.requestfactory.shared.Request;
+import com.google.web.bindery.requestfactory.shared.RequestContext;
+import com.google.web.bindery.requestfactory.shared.Service;
 
-	private static final long serialVersionUID = 995112620968798947L;
+@Service(Subject.class)
+public interface SubjectRequest extends RequestContext {
 
-	public InvalidSessionException(String message) {
-        super(message);
-    }
+  Request<java.lang.Long> countSubjects();
+
+  Request<SubjectProxy> findSubject(Long id);
+
+  InstanceRequest<SubjectProxy, java.lang.Void> remove();
+
+  InstanceRequest<SubjectProxy, java.lang.Void> persist();
+
+  Request<String> echo(SubjectProxy subject, String from, String to);
 }

Added: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/DragRefetchPagingScrollTable.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/DragRefetchPagingScrollTable.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/DragRefetchPagingScrollTable.java (added)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/widgets/DragRefetchPagingScrollTable.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,116 @@
+/****************************************************************
+ * 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.hupa.client.widgets;
+
+import java.util.Iterator;
+
+import org.apache.hupa.client.dnd.PagingScrollTableRowDragController;
+import org.apache.hupa.widgets.ui.RefetchPagingScrollTable;
+
+import com.allen_sauer.gwt.dnd.client.DragHandlerAdapter;
+import com.allen_sauer.gwt.dnd.client.DragStartEvent;
+import com.google.gwt.gen2.table.client.AbstractColumnDefinition;
+import com.google.gwt.gen2.table.client.DefaultTableDefinition;
+import com.google.gwt.gen2.table.client.FixedWidthFlexTable;
+import com.google.gwt.gen2.table.client.FixedWidthGrid;
+import com.google.gwt.gen2.table.client.MutableTableModel;
+import com.google.gwt.user.client.ui.Widget;
+
+public class DragRefetchPagingScrollTable<RowType> extends RefetchPagingScrollTable<RowType>{
+    private DragHandlerFactory factory;
+    private int cellIndex =-1;
+    private PagingScrollTableRowDragController tableRowDragController;
+    public DragRefetchPagingScrollTable(MutableTableModel<RowType> tableModel,
+            FixedWidthGrid dataTable, FixedWidthFlexTable headerTable,
+            DefaultTableDefinition<RowType> tableDefinition, PagingScrollTableRowDragController tableRowDragController,int dragColumn) {
+        super(tableModel, dataTable, headerTable, tableDefinition);
+        this.tableRowDragController = tableRowDragController;
+        tableRowDragController.addDragHandler(new DragHandlerAdapter() {
+
+            @Override
+            public void onDragStart(DragStartEvent event) {
+                getDataTable().deselectAllRows();
+            }
+            
+        });
+    }
+
+    /**
+     * Factory which will create new Handler Widgets 
+     *      */
+    public interface DragHandlerFactory {
+        public Widget createHandler();
+    }
+
+    public void setDragHandler(int newCellIndex,int cellWidth,DragHandlerFactory factory) {
+        this.factory = factory;
+        
+        if (newCellIndex < 0) {
+            throw new IllegalArgumentException("cellIndex needs to be higher then 0");
+        }
+        
+        DefaultTableDefinition<RowType> tableDef = (DefaultTableDefinition<RowType>) getTableDefinition();
+        
+        // remove old definition 
+        if (cellIndex != -1) {
+            tableDef.removeColumnDefinition(tableDef.getColumnDefinition(cellIndex));
+        }
+        
+        this.cellIndex = newCellIndex;
+        
+        // Create new ghost definition which will get used later to add the drag widget
+        DragColumnDefinition def = new DragColumnDefinition();
+        def.setColumnSortable(false);
+        def.setColumnTruncatable(false);
+        def.setMaximumColumnWidth(cellWidth);
+        def.setPreferredColumnWidth(cellWidth);
+        def.setMinimumColumnWidth(cellWidth);
+        tableDef.addColumnDefinition(cellIndex,def);
+    }
+    
+    
+    @Override
+    protected void setData(int firstRow, Iterator<RowType> rows) {
+        super.setData(firstRow, rows);
+        
+        if (getRowValues().size() >0 && factory != null && cellIndex > -1) {
+            for (int i = 0; i < getRowValues().size();i++) {
+                Widget handler = factory.createHandler();
+                getDataTable().setWidget(i, cellIndex, handler);
+                tableRowDragController.makeDraggable(handler);
+            }
+        }
+    }
+    
+    private final class DragColumnDefinition extends AbstractColumnDefinition<RowType, Boolean> {
+        
+        @Override
+        public Boolean getCellValue(RowType rowValue) {
+            return true;
+        }
+
+        @Override
+        public void setCellValue(RowType rowValue, Boolean cellValue) {
+        
+        }
+        
+    }
+    
+}

Added: james/hupa/trunk/client/src/test/java/org/apache/hupa/client/HupaMvpTestCase.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/test/java/org/apache/hupa/client/HupaMvpTestCase.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/client/src/test/java/org/apache/hupa/client/HupaMvpTestCase.java (added)
+++ james/hupa/trunk/client/src/test/java/org/apache/hupa/client/HupaMvpTestCase.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.hupa.client;
+
+import com.google.gwt.junit.GWTMockUtilities;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+
+import com.sun.mail.imap.IMAPStore;
+
+import junit.framework.TestCase;
+
+import net.customware.gwt.presenter.client.EventBus;
+
+import org.apache.hupa.client.guice.GuiceMvpTestModule;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.client.guice.GuiceClientTestModule;
+import org.apache.hupa.server.preferences.UserPreferencesStorage;
+import org.apache.hupa.server.utils.SessionUtils;
+import org.apache.hupa.shared.SConsts;
+import org.apache.hupa.shared.data.User;
+
+import javax.mail.Session;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Base class for testing presenters in hupa.
+ * Tests extending this class only work in jvm.
+ * 
+ * @author manolo
+ *
+ */
+public abstract class HupaMvpTestCase extends TestCase {
+    
+    protected Injector injector = Guice.createInjector(getModules());
+
+    protected HttpSession httpSession;
+    protected Session session;
+    protected UserPreferencesStorage userPreferences;
+    protected IMAPStoreCache storeCache;
+    protected User testUser;
+    protected IMAPStore store;
+    protected EventBus eventBus;
+    
+    protected Module[] getModules() {
+        return new Module[]{new GuiceClientTestModule(), new GuiceMvpTestModule()};
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        try {
+            GWTMockUtilities.disarm();
+            httpSession = injector.getInstance(HttpSession.class);
+            session = injector.getInstance(Session.class);
+            userPreferences = injector.getInstance(UserPreferencesStorage.class);
+            storeCache = injector.getInstance(IMAPStoreCache.class);
+            eventBus = injector.getInstance(EventBus.class);
+            
+            SessionUtils.cleanSessionAttributes(httpSession);
+            testUser = injector.getInstance(User.class);
+            store = storeCache.get(testUser);
+            httpSession.setAttribute(SConsts.USER_SESS_ATTR, testUser);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

Added: james/hupa/trunk/client/src/test/java/org/apache/hupa/client/guice/GuiceClientTestModule.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/test/java/org/apache/hupa/client/guice/GuiceClientTestModule.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/client/src/test/java/org/apache/hupa/client/guice/GuiceClientTestModule.java (added)
+++ james/hupa/trunk/client/src/test/java/org/apache/hupa/client/guice/GuiceClientTestModule.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,107 @@
+/****************************************************************
+ * 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.hupa.client.guice;
+
+import java.util.Properties;
+
+import javax.mail.Session;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.guice.AbstractGuiceTestModule;
+import org.apache.hupa.server.guice.demo.DemoGuiceServerModule.DemoIMAPStoreCache;
+import org.apache.hupa.server.guice.providers.DefaultUserSettingsProvider;
+import org.apache.hupa.server.guice.providers.JavaMailSessionProvider;
+import org.apache.hupa.server.handler.AbstractSendMessageHandler;
+import org.apache.hupa.server.handler.ContactsHandler;
+import org.apache.hupa.server.handler.CreateFolderHandler;
+import org.apache.hupa.server.handler.DeleteFolderHandler;
+import org.apache.hupa.server.handler.DeleteMessageByUidHandler;
+import org.apache.hupa.server.handler.FetchFoldersHandler;
+import org.apache.hupa.server.handler.FetchMessagesHandler;
+import org.apache.hupa.server.handler.ForwardMessageHandler;
+import org.apache.hupa.server.handler.GetMessageDetailsHandler;
+import org.apache.hupa.server.handler.IdleHandler;
+import org.apache.hupa.server.handler.LoginUserHandler;
+import org.apache.hupa.server.handler.LogoutUserHandler;
+import org.apache.hupa.server.handler.ReplyMessageHandler;
+import org.apache.hupa.server.handler.SendMessageHandler;
+import org.apache.hupa.server.mock.MockConstants;
+import org.apache.hupa.server.mock.MockHttpSessionProvider;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.server.mock.MockLogProvider;
+import org.apache.hupa.server.preferences.InSessionUserPreferencesStorage;
+import org.apache.hupa.server.preferences.UserPreferencesStorage;
+import org.apache.hupa.server.utils.ConfigurationProperties;
+import org.apache.hupa.shared.data.Settings;
+import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.rpc.Contacts;
+import org.apache.hupa.shared.rpc.SendMessage;
+
+import com.google.inject.Singleton;
+import com.google.inject.name.Names;
+import com.sun.mail.imap.IMAPStore;
+
+/**
+ * Guice module used in client tests.
+ */
+public class GuiceClientTestModule extends AbstractGuiceTestModule {
+
+  @Override
+  protected void configureHandlers() {
+      
+      Properties p = MockConstants.mockProperties;
+      ConfigurationProperties.validateProperties(p);
+      
+      Names.bindProperties(binder(), p);
+      
+      bind(Session.class).toProvider(JavaMailSessionProvider.class);
+      bind(HttpSession.class).toProvider(MockHttpSessionProvider.class);
+      bind(Settings.class).toProvider(DefaultUserSettingsProvider.class).in(Singleton.class);
+      bind(Log.class).toProvider(MockLogProvider.class).in(Singleton.class);
+
+      bind(IMAPStore.class).to(MockIMAPStore.class);
+      bind(IMAPStoreCache.class).to(DemoIMAPStoreCache.class).in(Singleton.class);
+
+      bind(LoginUserHandler.class);
+      bind(LogoutUserHandler.class);
+      bind(IdleHandler.class);
+      
+      bind(FetchFoldersHandler.class);
+      bind(CreateFolderHandler.class);
+      bind(DeleteFolderHandler.class);
+      bind(FetchMessagesHandler.class);
+      bind(DeleteMessageByUidHandler.class);
+      bind(GetMessageDetailsHandler.class);
+      bind(AbstractSendMessageHandler.class).to(SendMessageHandler.class);
+      bind(SendMessageHandler.class);
+      bind(ReplyMessageHandler.class);
+      bind(ForwardMessageHandler.class);
+      
+      bindHandler(Contacts.class, ContactsHandler.class);
+      bindHandler(SendMessage.class, SendMessageHandler.class);
+      
+      bind(UserPreferencesStorage.class).to(InSessionUserPreferencesStorage.class);
+      
+      bind(User.class).to(TestUser.class).in(Singleton.class);
+  }
+
+}
\ No newline at end of file

Added: james/hupa/trunk/client/src/test/java/org/apache/hupa/client/guice/GuiceMvpTestModule.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/test/java/org/apache/hupa/client/guice/GuiceMvpTestModule.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/client/src/test/java/org/apache/hupa/client/guice/GuiceMvpTestModule.java (added)
+++ james/hupa/trunk/client/src/test/java/org/apache/hupa/client/guice/GuiceMvpTestModule.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,135 @@
+/****************************************************************
+ * 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.hupa.client.guice;
+
+import net.customware.gwt.dispatch.client.DispatchAsync;
+import net.customware.gwt.dispatch.client.standard.StandardDispatchService;
+import net.customware.gwt.dispatch.server.Dispatch;
+import net.customware.gwt.dispatch.server.guice.GuiceDispatch;
+import net.customware.gwt.dispatch.shared.Action;
+import net.customware.gwt.dispatch.shared.DispatchException;
+import net.customware.gwt.dispatch.shared.Result;
+import net.customware.gwt.presenter.client.DefaultEventBus;
+import net.customware.gwt.presenter.client.Display;
+import net.customware.gwt.presenter.client.EventBus;
+
+import org.apache.hupa.client.HupaMessages;
+import org.apache.hupa.client.mock.MockMessageSendDisplay;
+import org.apache.hupa.client.mvp.ContactsPresenter;
+import org.apache.hupa.client.mvp.MessageSendPresenter;
+import org.apache.hupa.client.rf.HupaRequestFactory;
+import org.easymock.EasyMock;
+
+import com.google.gwt.event.shared.SimpleEventBus;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.google.web.bindery.requestfactory.server.ServiceLayer;
+import com.google.web.bindery.requestfactory.server.SimpleRequestProcessor;
+import com.google.web.bindery.requestfactory.server.testing.InProcessRequestTransport;
+import com.google.web.bindery.requestfactory.vm.RequestFactorySource;
+
+/**
+ * Guice module used to test presenters
+ * 
+ * @author manolo
+ *
+ */
+public class GuiceMvpTestModule extends AbstractModule {
+    
+    // Override either, to change module behavior
+    protected DispatchAsync dispatchAsyncInstance = null;
+    protected Class<? extends DispatchAsync> dispatchAsyncClass = DispatchTestAsync.class;
+    
+    @Override
+    protected void configure() {
+        if (dispatchAsyncInstance == null) {
+            bind(DispatchAsync.class).to(dispatchAsyncClass).in(Singleton.class);
+        } else {
+            bind(DispatchAsync.class).toInstance(dispatchAsyncInstance);
+        }
+
+        bind(EventBus.class).to(DefaultEventBus.class);
+        
+        bind(DispatchTestAsync.class);
+        
+        HupaMessages messages = EasyMock.createNiceMock(HupaMessages.class);
+        bind(HupaMessages.class).toInstance(messages);
+
+        bindDisplay(ContactsPresenter.Display.class);
+        bind(MessageSendPresenter.Display.class).to(MockMessageSendDisplay.class);
+        
+        bind(com.google.gwt.event.shared.EventBus.class)
+            .to(SimpleEventBus.class)
+            .in(Singleton.class);
+        bind(HupaRequestFactory.class)
+            .toProvider(RequestFactoryProvider.class)
+            .in(Singleton.class);
+    }
+    
+    public static class RequestFactoryProvider implements Provider<HupaRequestFactory> {
+        private static final com.google.gwt.event.shared.EventBus eventBus = new SimpleEventBus();
+        public HupaRequestFactory get() {
+            HupaRequestFactory rf = RequestFactorySource.create(HupaRequestFactory.class);
+            ServiceLayer serviceLayer = ServiceLayer.create();
+            SimpleRequestProcessor processor = new SimpleRequestProcessor(serviceLayer);
+            rf.initialize(eventBus, new InProcessRequestTransport(processor));
+            return rf;
+        }
+    }
+
+    protected <D extends Display> void bindDisplay(final Class<D> display) {
+        final D mockDisplay = EasyMock.createNiceMock(display);
+        bind(display).toInstance(mockDisplay);
+    }
+
+    static class DispatchTestService implements StandardDispatchService {
+        private Dispatch dispatch;
+
+        @Inject
+        public DispatchTestService(Dispatch dispatch) {
+            this.dispatch = dispatch;
+        }
+
+        public Result execute(Action<?> action) throws DispatchException {
+            Result result = dispatch.execute(action);
+            return result;
+        }
+    }
+
+    static public class DispatchTestAsync implements DispatchAsync {
+        private GuiceDispatch dispatch;
+
+        @Inject
+        public DispatchTestAsync(Dispatch dispatch) {
+            this.dispatch = (GuiceDispatch)dispatch;
+        }
+
+        public <A extends Action<R>, R extends Result> void execute(A action, AsyncCallback<R> callback) {
+            try {
+                R result = dispatch.execute(action);
+                callback.onSuccess(result);
+            } catch (DispatchException e) {
+                callback.onFailure(e);
+            }
+        }
+    }
+}
\ No newline at end of file

Added: james/hupa/trunk/client/src/test/java/org/apache/hupa/client/mvp/ContactsPresenterTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/test/java/org/apache/hupa/client/mvp/ContactsPresenterTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/client/src/test/java/org/apache/hupa/client/mvp/ContactsPresenterTest.java (added)
+++ james/hupa/trunk/client/src/test/java/org/apache/hupa/client/mvp/ContactsPresenterTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.hupa.client.mvp;
+
+import org.apache.hupa.client.HupaMvpTestCase;
+import org.apache.hupa.shared.events.ContactsUpdatedEvent;
+import org.apache.hupa.shared.rpc.ContactsResult.Contact;
+import org.easymock.EasyMock;
+
+public class ContactsPresenterTest extends HupaMvpTestCase {
+
+    ContactsPresenter presenter = injector.getInstance(ContactsPresenter.class);
+    ContactsPresenter.Display display = presenter.getDisplay();
+    
+    public void testRevealDisplayWhenListIsEmpty() throws Exception {
+        // Register an event listener
+        presenter.onBind();
+        Contact[] contacts = new Contact[]{};
+        
+        EasyMock.reset(display);
+        display.setContacts(EasyMock.aryEq(contacts));
+        EasyMock.replay(display);
+        // send an event
+        eventBus.fireEvent(new ContactsUpdatedEvent(contacts));
+        assertNotNull(presenter.contacts);
+        assertEquals(0, presenter.contacts.length);
+        EasyMock.verify(display);
+        EasyMock.reset(display);
+    }
+
+    public void testRevealDisplayWhenListHasData() throws Exception {
+        Contact c = new Contact("Somebody <so...@foo.com>");
+        assertEquals("Somebody", c.realname);
+        assertEquals("somebody@foo.com", c.mail);
+        Contact[] contacts = new Contact[]{c};
+        
+        // Register an event listener
+        presenter.onBind();
+        
+        EasyMock.reset(display);
+        display.setContacts(EasyMock.aryEq(contacts));
+        EasyMock.replay(display);
+        // send an event
+        eventBus.fireEvent(new ContactsUpdatedEvent(contacts));
+        assertNotNull(presenter.contacts);
+        assertEquals(1, presenter.contacts.length);
+        EasyMock.verify(display);
+        EasyMock.reset(display);
+    }
+
+    public void testUpdateContactsFromServer() throws Exception {
+        Contact c = new Contact("Somebody <so...@foo.com>");
+        assertEquals("Somebody", c.realname);
+        assertEquals("somebody@foo.com", c.mail);
+        Contact[] contacts = new Contact[]{c};
+        
+        assertNull(presenter.contacts);
+        // Register the event listener
+        presenter.onBind();
+        // Put contacts in server side
+        userPreferences.addContact(contacts);
+        // Call to the server
+        presenter.updateContactsFromServer();
+        assertNotNull(presenter.contacts);
+        assertEquals(1, presenter.contacts.length);
+    }
+}
+

Added: james/hupa/trunk/client/src/test/java/org/apache/hupa/client/mvp/MessageSendPresenterTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/test/java/org/apache/hupa/client/mvp/MessageSendPresenterTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/client/src/test/java/org/apache/hupa/client/mvp/MessageSendPresenterTest.java (added)
+++ james/hupa/trunk/client/src/test/java/org/apache/hupa/client/mvp/MessageSendPresenterTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,241 @@
+/****************************************************************
+ * 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.hupa.client.mvp;
+
+import com.google.inject.Module;
+
+import net.customware.gwt.dispatch.client.DispatchAsync;
+import net.customware.gwt.dispatch.shared.Action;
+import net.customware.gwt.presenter.client.EventBus;
+
+import org.apache.hupa.client.HupaCallback;
+import org.apache.hupa.client.HupaMvpTestCase;
+import org.apache.hupa.client.guice.GuiceMvpTestModule;
+import org.apache.hupa.client.guice.GuiceMvpTestModule.DispatchTestAsync;
+import org.apache.hupa.client.mvp.MessageSendPresenter.Type;
+import org.apache.hupa.client.guice.GuiceClientTestModule;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.Message;
+import org.apache.hupa.shared.data.MessageDetails;
+import org.apache.hupa.shared.data.SMTPMessage;
+import org.apache.hupa.shared.events.FlashEvent;
+import org.apache.hupa.shared.events.SentMessageEvent;
+import org.apache.hupa.shared.events.ServerStatusEvent;
+import org.apache.hupa.shared.rpc.ForwardMessage;
+import org.apache.hupa.shared.rpc.GenericResult;
+import org.apache.hupa.shared.rpc.ReplyMessage;
+import org.apache.hupa.shared.rpc.SendMessage;
+import org.easymock.EasyMock;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class MessageSendPresenterTest extends HupaMvpTestCase {
+
+    
+    protected Module[] getModules() {
+        return new Module[]{new GuiceClientTestModule(), new GuiceMvpTestModule() {
+            @Override
+            protected void configure() {
+                dispatchAsyncInstance = EasyMock.createStrictMock(DispatchAsync.class);
+                super.configure();
+            }
+        }};
+    }
+
+    MessageSendPresenter presenter = injector.getInstance(MessageSendPresenter.class);
+    MessageSendPresenter.Display display = presenter.getDisplay();
+    
+    public void testRemoveEmailFromList() {
+        String[] list = new String[]{"a@a.a", "e@dom.com", "<e...@dom.com>", "Name <e...@dom.com>", "Name < e@dom.com >"};
+        ArrayList<String> newList = presenter.removeEmailFromList(Arrays.asList(list), " e@dom.com ");
+        assertEquals(1, newList.size());
+    }
+
+    public void testValidations() throws Exception {
+        assertFalse(presenter.validate());
+
+        display.getToText().setText("invalid@address");
+        assertFalse(presenter.validate());
+
+        display.getToText().setText("nobody@domain.com");
+        assertTrue(presenter.validate());
+    }
+
+    public void testDispatchMessage() {
+        SMTPMessage message = new SMTPMessage();
+        message.setFrom("from@dom.com");
+        message.setTo(presenter.emailTextToArray("to@dom.com"));
+        message.setText("message");
+
+        DispatchAsync dispatcher = injector.getInstance(DispatchTestAsync.class);
+        EventBus eventBus = EasyMock.createMock(EventBus.class);
+        
+        // When a success message is sent, the eventbus receives a SentMessageEvent
+        // and the display is reset
+        EasyMock.reset(eventBus);
+        eventBus.fireEvent(EasyMock.isA(ServerStatusEvent.class));
+        eventBus.fireEvent(EasyMock.isA(SentMessageEvent.class));
+        EasyMock.replay(eventBus);
+        display.getToText().setText("whatever");
+        presenter.dispatchMessage(dispatcher, eventBus, new SendMessage(message));
+        assertEquals("", display.getToText().getText());
+        EasyMock.verify(eventBus);
+
+        // When a error happens sending a message, the eventbus receives a FlashEvent
+        // and the display is not reset
+        EasyMock.reset(eventBus);
+        eventBus.fireEvent(EasyMock.isA(ServerStatusEvent.class));
+        eventBus.fireEvent(EasyMock.isA(FlashEvent.class));
+        EasyMock.replay(eventBus);
+        display.getToText().setText("whatever");
+        presenter.dispatchMessage(dispatcher, eventBus, new SendMessage(null));
+        assertEquals("whatever", display.getToText().getText());
+        EasyMock.verify(eventBus);
+    }
+
+    public void testSendInvalidMessage() throws Exception {
+        presenter.onBind();
+        presenter.revealDisplay(testUser);
+        assertEquals(testUser.getName(), display.getFromText().getText());
+        
+        display.getSubjectText().setText("Test");
+        display.getMessageHTML().setHTML("Message");
+        
+        fireSendEvent(null);
+        
+        assertNull(presenter.message);
+        assertEquals("Test", display.getSubjectText().getText());
+        assertEquals("Message", display.getMessageHTML().getHTML());
+    }
+
+    public void testSendMessage() throws Exception {
+        presenter.onBind();
+        presenter.revealDisplay(testUser);
+        assertEquals(testUser.getName(), display.getFromText().getText());
+        
+        display.getToText().setText("to1@dom.com; to2@dom.com");
+        display.getCcText().setText("cc1@dom.com, , cc2@dom.com ");
+        display.getBccText().setText("bcc1@dom.com, bcc2@dom.com");
+        display.getSubjectText().setText("Test");
+        display.getMessageHTML().setHTML("Message");
+        
+        fireSendEvent(SendMessage.class);
+        
+        assertEquals("Test", presenter.message.getSubject());
+        assertEquals("Message", presenter.message.getText());
+        assertEquals(testUser.getName(), presenter.message.getFrom());
+        assertEquals(2, presenter.message.getTo().size());
+        assertEquals("to1@dom.com", presenter.message.getTo().get(0));
+        assertEquals(2, presenter.message.getCc().size());
+        assertEquals(2, presenter.message.getBcc().size());
+    }
+    
+
+    public void testMailTo() throws Exception {
+        presenter.onBind();
+        presenter.revealDisplay(testUser, "mailto@dom.com");
+        assertEquals(testUser.getName(), display.getFromText().getText());
+        assertEquals("mailto@dom.com", display.getToText().getText());
+    }
+    
+    public void testReply() {
+        createMockMessageAndRevealDisplay(Type.REPLY);
+        fireSendEvent(ReplyMessage.class);
+        
+        assertEquals("Re: Subject", presenter.message.getSubject());
+        assertTrue(presenter.message.getText().contains("Message"));
+        assertTrue(presenter.message.getText().contains("from@dom.com"));
+        
+        assertEquals(testUser.getName(), presenter.message.getFrom());
+        assertEquals(1, presenter.message.getTo().size());
+        assertEquals("replyto@dom.com", presenter.message.getTo().get(0));
+        assertEquals(0, presenter.message.getCc().size());
+        assertEquals(0, presenter.message.getBcc().size());
+    }
+
+    public void testReplyAll() {
+        createMockMessageAndRevealDisplay(Type.REPLY_ALL);
+        fireSendEvent(ReplyMessage.class);
+        
+        assertEquals("Re: Subject", presenter.message.getSubject());
+        assertTrue(presenter.message.getText().contains("Message"));
+        assertTrue(presenter.message.getText().contains("from@dom.com"));
+        
+        assertEquals(testUser.getName(), presenter.message.getFrom());
+        assertEquals(1, presenter.message.getTo().size());
+        assertEquals("from@dom.com", presenter.message.getTo().get(0));
+        assertEquals(5, presenter.message.getCc().size());
+        assertEquals("replyto@dom.com", presenter.message.getCc().get(0));
+        assertEquals("to1@dom.com", presenter.message.getCc().get(1));
+        assertEquals("to2@dom.com", presenter.message.getCc().get(2));
+        assertEquals("cc1@dom.com", presenter.message.getCc().get(3));
+        assertEquals("cc2@dom.com", presenter.message.getCc().get(4));
+        assertEquals(0, presenter.message.getBcc().size());
+    }
+
+    public void testForward() {
+        createMockMessageAndRevealDisplay(Type.FORWARD);
+        presenter.getDisplay().getToText().setText("valid@dom.com");
+        fireSendEvent(ForwardMessage.class);
+        
+        assertEquals("Fwd: Subject", presenter.message.getSubject());
+        assertTrue(presenter.message.getText().contains("Message"));
+        assertTrue(presenter.message.getText().contains("from@dom.com"));
+        assertTrue(presenter.message.getText().contains("Forwarded message"));
+        assertTrue(presenter.message.getText().contains("Subject"));
+        assertEquals(testUser.getName(), presenter.message.getFrom());
+        assertEquals(1, presenter.message.getTo().size());
+        assertEquals("valid@dom.com", presenter.message.getTo().get(0));
+        assertEquals(0, presenter.message.getCc().size());
+        assertEquals(0, presenter.message.getBcc().size());
+    }
+    
+    private void createMockMessageAndRevealDisplay(Type type) {
+        Message oldmessage = new Message();
+        oldmessage.setFrom("from@dom.com");
+        ArrayList<String> to = new ArrayList<String>(Arrays.asList(new String[]{"to1@dom.com", "to2@dom.com"}));
+        oldmessage.setTo(to);
+        ArrayList<String> cc = new ArrayList<String>(Arrays.asList(new String[]{"cc1@dom.com", "cc2@dom.com"}));
+        oldmessage.setCc(cc);
+        oldmessage.setReplyto("replyto@dom.com");
+        oldmessage.setSubject("Subject");
+        
+        MessageDetails oldDetails = new MessageDetails();
+        oldDetails.setText("Message");
+        oldDetails.setUid(0l);
+        
+        IMAPFolder folder = new IMAPFolder();
+        folder.setFullName("FOLDER");
+        
+        presenter.bind();
+        presenter.revealDisplay(testUser, folder, oldmessage, oldDetails, type);
+    }
+
+    @SuppressWarnings("unchecked")
+    private void fireSendEvent(Class<? extends Action<GenericResult>> commandClass) {
+        DispatchAsync dispatcher = injector.getInstance(DispatchAsync.class);
+        EasyMock.reset(dispatcher);
+        if (commandClass != null)
+            dispatcher.execute(EasyMock.isA(commandClass), EasyMock.isA(HupaCallback.class));
+        EasyMock.replay(dispatcher);
+        display.getSendClick().fireEvent(null);
+        EasyMock.verify(dispatcher);
+    }
+}

Copied: james/hupa/trunk/client/src/test/java/org/apache/hupa/client/rf/SubjectTest.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/test/java/org/apache/hupa/client/rf/SubjectTest.java?p2=james/hupa/trunk/client/src/test/java/org/apache/hupa/client/rf/SubjectTest.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/client/src/test/java/org/apache/hupa/client/rf/SubjectTest.java Wed Aug 21 16:35:16 2013
@@ -16,14 +16,36 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.hupa.client.rf;
 
-package org.apache.hupa.shared.exception;
+import org.apache.hupa.client.HupaMvpTestCase;
 
-public class InvalidSessionException extends HupaException{
+import com.google.web.bindery.requestfactory.shared.Receiver;
 
-	private static final long serialVersionUID = 995112620968798947L;
+public class SubjectTest extends HupaMvpTestCase {
 
-	public InvalidSessionException(String message) {
-        super(message);
+    public void testEcho() throws Exception {
+        HupaRequestFactory rf = injector.getInstance(HupaRequestFactory.class);
+        
+        SubjectRequest req = rf.subjectRequest(); 
+        SubjectProxy t = req.create(SubjectProxy.class);
+        t.setTitle("New-Subject");
+        req.echo(t, "from_manolo", "to_james").fire(new Receiver<String>() {
+            public void onSuccess(String response) {
+                assertTrue(response.contains("from_manolo"));
+                assertTrue(response.contains("to_james"));
+            }
+        });
+        
+        req = rf.subjectRequest(); 
+        t = req.create(SubjectProxy.class);
+        t.setTitle("New-Subject");
+        req.persist().using(t);
+        req.countSubjects().to(new Receiver<Long>() {
+            public void onSuccess(Long response) {
+                assertEquals(1l, response.longValue());
+            }
+        }).fire();
     }
 }
+

Modified: james/hupa/trunk/server/pom.xml
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/pom.xml?rev=1516205&r1=1516204&r2=1516205&view=diff
==============================================================================
--- james/hupa/trunk/server/pom.xml (original)
+++ james/hupa/trunk/server/pom.xml Wed Aug 21 16:35:16 2013
@@ -1,135 +1,135 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-    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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>org.apache.james.hupa</groupId>
-        <artifactId>hupa-parent</artifactId>
-        <version>0.0.5-SNAPSHOT</version>
-        <relativePath>../pom.xml</relativePath>
-    </parent>
-    <artifactId>hupa-server</artifactId>
-    <packaging>jar</packaging>
-    <name>Apache James Hupa Server</name>
-    <description>Servercode implementation to access IMAP Mailbox</description>
-    <dependencies>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>hupa-mock</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>${project.groupId}</groupId>
-            <artifactId>hupa-shared</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>javax.inject</groupId>
-            <artifactId>javax.inject</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>aopalliance</groupId>
-            <artifactId>aopalliance</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>commons-logging</groupId>
-            <artifactId>commons-logging</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>logkit</groupId>
-                    <artifactId>logkit</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>javax.servlet</groupId>
-                    <artifactId>servlet-api</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>log4j</groupId>
-            <artifactId>log4j</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>javax.mail</groupId>
-            <artifactId>mail</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.googlecode.gwtupload</groupId>
-            <artifactId>gwtupload</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>commons-fileupload</groupId>
-            <artifactId>commons-fileupload</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.code.guice</groupId>
-            <artifactId>guice</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.code.guice</groupId>
-            <artifactId>guice-assistedinject</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.code.guice</groupId>
-            <artifactId>guice-servlet</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.gwt</groupId>
-            <artifactId>gwt-user</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.gwt</groupId>
-            <artifactId>gwt-servlet</artifactId>
-            <scope>runtime</scope>
-        </dependency>
-        <dependency>
-            <groupId>com.google.gwt</groupId>
-            <artifactId>gwt-dev</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-    <build>
-        <outputDirectory>war/WEB-INF/classes</outputDirectory>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-war-plugin</artifactId>
-                <configuration>
-                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
-                    <webResources>
-                        <resource>
-                            <directory>war</directory>
-                            <excludes>
-                                <exclude>**/hupa/*</exclude>
-                            </excludes>
-                        </resource>
-                    </webResources>
-                    <warName>${project.name}</warName>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-</project>
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.james.hupa</groupId>
+        <artifactId>hupa-parent</artifactId>
+        <version>0.0.5-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>hupa-server</artifactId>
+    <packaging>jar</packaging>
+    <name>Apache James Hupa Server</name>
+    <description>Servercode implementation to access IMAP Mailbox</description>
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>hupa-mock</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>hupa-shared</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>aopalliance</groupId>
+            <artifactId>aopalliance</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>logkit</groupId>
+                    <artifactId>logkit</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>javax.servlet</groupId>
+                    <artifactId>servlet-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.mail</groupId>
+            <artifactId>mail</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.googlecode.gwtupload</groupId>
+            <artifactId>gwtupload</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.guice</groupId>
+            <artifactId>guice</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.guice</groupId>
+            <artifactId>guice-assistedinject</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.guice</groupId>
+            <artifactId>guice-servlet</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.gwt</groupId>
+            <artifactId>gwt-user</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.gwt</groupId>
+            <artifactId>gwt-servlet</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.gwt</groupId>
+            <artifactId>gwt-dev</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <outputDirectory>war/WEB-INF/classes</outputDirectory>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-war-plugin</artifactId>
+                <configuration>
+                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
+                    <webResources>
+                        <resource>
+                            <directory>war</directory>
+                            <excludes>
+                                <exclude>**/hupa/*</exclude>
+                            </excludes>
+                        </resource>
+                    </webResources>
+                    <warName>${project.name}</warName>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Added: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DefaultUserSettingsProvider.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DefaultUserSettingsProvider.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DefaultUserSettingsProvider.java (added)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DefaultUserSettingsProvider.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.hupa.server.guice;
+
+import org.apache.hupa.shared.data.Settings;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.name.Named;
+
+public class DefaultUserSettingsProvider implements Provider<Settings> {
+    private String inboxFolder;
+    private String sentFolder;
+    private String trashFolder;
+    private String draftFolder;
+    private int postCount;
+
+    @Inject
+    public DefaultUserSettingsProvider(@Named("DefaultInboxFolder") String inboxFolder, @Named("DefaultSentFolder") String sentFolder, @Named("DefaultTrashFolder") String trashFolder, @Named("DefaultDraftsFolder") String draftFolder, @Named("PostFetchMessageCount") int postCount) {
+        this.inboxFolder = inboxFolder;
+        this.sentFolder = sentFolder;
+        this.trashFolder = trashFolder;
+        this.draftFolder = draftFolder;
+        this.postCount = postCount;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see com.google.inject.Provider#get()
+     */
+    public Settings get() {
+        Settings settings = new Settings();
+        settings.setInboxFolderName(inboxFolder);
+        settings.setSentFolderName(sentFolder);
+        settings.setTrashFolderName(trashFolder);
+        settings.setDraftsFolderName(draftFolder);
+        settings.setPostFetchMessageCount(postCount);
+        return settings;
+    }
+
+}

Added: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/GuiceServerModule.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/GuiceServerModule.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/GuiceServerModule.java (added)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/GuiceServerModule.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,145 @@
+/****************************************************************
+ * 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.hupa.server.guice;
+
+import java.util.Properties;
+
+import javax.mail.Session;
+
+import net.customware.gwt.dispatch.server.guice.ActionHandlerModule;
+
+import org.apache.commons.logging.Log;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.InMemoryIMAPStoreCache;
+import org.apache.hupa.server.guice.providers.DefaultUserSettingsProvider;
+import org.apache.hupa.server.guice.providers.JavaMailSessionProvider;
+import org.apache.hupa.server.guice.providers.LogProvider;
+import org.apache.hupa.server.handler.CheckSessionHandler;
+import org.apache.hupa.server.handler.ContactsHandler;
+import org.apache.hupa.server.handler.CreateFolderHandler;
+import org.apache.hupa.server.handler.DeleteAllMessagesHandler;
+import org.apache.hupa.server.handler.DeleteFolderHandler;
+import org.apache.hupa.server.handler.DeleteMessageByUidHandler;
+import org.apache.hupa.server.handler.FetchFoldersHandler;
+import org.apache.hupa.server.handler.FetchMessagesHandler;
+import org.apache.hupa.server.handler.FetchRecentMessagesHandler;
+import org.apache.hupa.server.handler.ForwardMessageHandler;
+import org.apache.hupa.server.handler.GetMessageDetailsHandler;
+import org.apache.hupa.server.handler.IdleHandler;
+import org.apache.hupa.server.handler.LoginUserHandler;
+import org.apache.hupa.server.handler.LogoutUserHandler;
+import org.apache.hupa.server.handler.MoveMessageHandler;
+import org.apache.hupa.server.handler.RenameFolderHandler;
+import org.apache.hupa.server.handler.ReplyMessageHandler;
+import org.apache.hupa.server.handler.SendMessageHandler;
+import org.apache.hupa.server.handler.SetFlagsHandler;
+import org.apache.hupa.server.handler.TagMessagesHandler;
+import org.apache.hupa.server.preferences.InImapUserPreferencesStorage;
+import org.apache.hupa.server.preferences.UserPreferencesStorage;
+import org.apache.hupa.server.servlet.DownloadAttachmentServlet;
+import org.apache.hupa.server.servlet.MessageSourceServlet;
+import org.apache.hupa.server.servlet.UploadAttachmentServlet;
+import org.apache.hupa.shared.data.Settings;
+import org.apache.hupa.shared.rpc.CheckSession;
+import org.apache.hupa.shared.rpc.Contacts;
+import org.apache.hupa.shared.rpc.CreateFolder;
+import org.apache.hupa.shared.rpc.DeleteAllMessages;
+import org.apache.hupa.shared.rpc.DeleteFolder;
+import org.apache.hupa.shared.rpc.DeleteMessageByUid;
+import org.apache.hupa.shared.rpc.FetchFolders;
+import org.apache.hupa.shared.rpc.FetchMessages;
+import org.apache.hupa.shared.rpc.FetchRecentMessages;
+import org.apache.hupa.shared.rpc.ForwardMessage;
+import org.apache.hupa.shared.rpc.GetMessageDetails;
+import org.apache.hupa.shared.rpc.Idle;
+import org.apache.hupa.shared.rpc.LoginUser;
+import org.apache.hupa.shared.rpc.LogoutUser;
+import org.apache.hupa.shared.rpc.MoveMessage;
+import org.apache.hupa.shared.rpc.RenameFolder;
+import org.apache.hupa.shared.rpc.ReplyMessage;
+import org.apache.hupa.shared.rpc.SendMessage;
+import org.apache.hupa.shared.rpc.SetFlag;
+import org.apache.hupa.shared.rpc.TagMessage;
+
+import com.google.inject.Singleton;
+import com.google.inject.name.Names;
+
+/**
+ * Module which binds the handlers and configurations
+ * 
+ * 
+ */
+public class GuiceServerModule extends ActionHandlerModule {
+
+    Properties properties;
+    public GuiceServerModule(Properties properties) {
+        this.properties = properties;
+    }
+    
+    protected Class<? extends IMAPStoreCache> getIMAPStoreCacheClass() {
+        return InMemoryIMAPStoreCache.class;
+    }
+
+    @Override
+    protected void configureHandlers() {
+        try {
+            // Bind addresses and ports for imap and smtp
+            Names.bindProperties(binder(), properties);
+        } catch (Exception e) {
+            throw new RuntimeException("Unable to to configure hupa server," +
+                    "\nmake sure that you have a valid /etc/default/hupa file" +
+                    "\nor the web container has been started with the appropriate parameter:" +
+                    " -Dhupa.config.file=your_hupa_properties_file", e);
+        }
+        
+        bindHandler(CheckSession.class, CheckSessionHandler.class);
+        bindHandler(LoginUser.class, LoginUserHandler.class);
+        bindHandler(FetchFolders.class, FetchFoldersHandler.class);
+        bindHandler(FetchMessages.class, FetchMessagesHandler.class);
+        bindHandler(FetchRecentMessages.class, FetchRecentMessagesHandler.class);
+        bindHandler(LogoutUser.class, LogoutUserHandler.class);
+        bindHandler(GetMessageDetails.class, GetMessageDetailsHandler.class);
+        bindHandler(DeleteMessageByUid.class, DeleteMessageByUidHandler.class);
+        bindHandler(DeleteAllMessages.class, DeleteAllMessagesHandler.class);
+        bindHandler(SendMessage.class, SendMessageHandler.class);
+        bindHandler(ReplyMessage.class, ReplyMessageHandler.class);
+        bindHandler(ForwardMessage.class, ForwardMessageHandler.class);
+        bindHandler(Idle.class, IdleHandler.class);
+        bindHandler(MoveMessage.class, MoveMessageHandler.class);
+        bindHandler(RenameFolder.class, RenameFolderHandler.class);
+        bindHandler(DeleteFolder.class, DeleteFolderHandler.class);
+        bindHandler(CreateFolder.class, CreateFolderHandler.class);
+        bindHandler(TagMessage.class, TagMessagesHandler.class);
+        bindHandler(SetFlag.class, SetFlagsHandler.class);
+        bindHandler(Contacts.class, ContactsHandler.class);
+        
+        bind(IMAPStoreCache.class).to(getIMAPStoreCacheClass()).in(Singleton.class);
+        
+        bind(Log.class).toProvider(LogProvider.class).in(Singleton.class);
+        bind(Settings.class).toProvider(DefaultUserSettingsProvider.class).in(
+                Singleton.class);
+        bind(DownloadAttachmentServlet.class).in(Singleton.class);
+        bind(UploadAttachmentServlet.class).in(Singleton.class);
+        bind(MessageSourceServlet.class).in(Singleton.class);
+        bind(Session.class).toProvider(JavaMailSessionProvider.class);
+        bind(UserPreferencesStorage.class).to(InImapUserPreferencesStorage.class);
+        bind(Properties.class).toInstance(properties);
+    }
+}

Added: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/GuiceServletConfig.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/GuiceServletConfig.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/GuiceServletConfig.java (added)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/GuiceServletConfig.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,122 @@
+/****************************************************************
+ * 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.hupa.server.guice;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.servlet.ServletContextEvent;
+
+import net.customware.gwt.dispatch.server.guice.ActionHandlerModule;
+
+import org.apache.commons.logging.Log;
+import org.apache.hupa.server.guice.demo.DemoGuiceServerModule;
+import org.apache.hupa.server.utils.ConfigurationProperties;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.servlet.GuiceServletContextListener;
+
+/**
+ * Simple GuiceServletContextListener which just create the injector
+ * 
+ */
+public class GuiceServletConfig extends GuiceServletContextListener{
+
+    public static final String SYS_PROP_CONFIG_FILE = "hupa.config.file";
+    public static final String CONFIG_FILE_NAME = "config.properties";
+    public static final String CONFIG_DIR_IN_WAR = "WEB-INF/conf/";
+    
+    private String servletContextRealPath = "";
+    
+    private Properties demoProperties = null;
+    private String demoHostName = null;
+    
+    @Override
+    public void contextInitialized(ServletContextEvent servletContextEvent) {
+        servletContextRealPath = servletContextEvent.getServletContext().getRealPath("/");
+        
+        // We get the mock classes using reflection, so as we can package Hupa without mock stuff.
+        try {
+            Class<?> mockConstants = Class.forName("org.apache.hupa.server.mock.MockConstants");
+            demoProperties = (Properties)mockConstants.getField("mockProperties").get(null);
+            demoHostName = demoProperties.getProperty("IMAPServerAddress");
+        } catch (Exception noDemoAvailable) {
+        }
+        
+        super.contextInitialized(servletContextEvent);
+    }
+    
+    @Override
+    protected Injector getInjector() {
+    	Properties prop = loadProperties();
+        ConfigurationProperties.validateProperties(prop);
+
+        boolean demo = prop.getProperty("IMAPServerAddress").equals(demoHostName);
+
+        ActionHandlerModule module = demo ? new DemoGuiceServerModule(prop) : new GuiceServerModule(prop);
+        Injector injector =  Guice.createInjector(module, new DispatchServletModule());
+        
+        String msg = ">> Started HUPA ";
+        if (demo) {
+        	msg += "in DEMO-MODE";
+        } else {
+        	msg += "with configuration -> " + prop;
+        }
+        injector.getInstance(Log.class).info(msg);
+        
+        return injector;
+    }
+ 
+    /**
+     * Loads the first available configuration file.
+     * 
+     * The preference order for the file is:
+     *   1.- file specified in a system property (-Dhupa.config.file=full_path_to_file)
+     *   2.- file in the user's home: $HOME/.hupa/config.properties
+     *   3.- global configuration in the os: /etc/default/hupa
+     *   4.- file provided in the .war distribution: "WEB-INF/conf/config.properties
+     *   5.- mock properties file which makes the Hupa work in demo mode.
+     *  
+     * If the system property "mock-host" has been defined, and Hupa has been packaged
+     * with the mock stuff, we always return the demo-mode configuration.
+     *    
+     */
+    public Properties loadProperties() {
+        Properties properties = null;
+        if (demoHostName == null || System.getProperty(demoHostName) == null) {
+        	List<String> configurationList = new ArrayList<String>();
+            configurationList.add(System.getProperty(SYS_PROP_CONFIG_FILE));
+            configurationList.add(System.getProperty(System.getenv("HOME") + "/.hupa/" + CONFIG_FILE_NAME));
+            configurationList.add("/etc/default/hupa");
+            configurationList.add(servletContextRealPath + "/" + CONFIG_DIR_IN_WAR + CONFIG_FILE_NAME);
+
+            for (String name : configurationList) {
+                properties = ConfigurationProperties.loadProperties(name);
+                if (properties != null) {
+                    break;
+                }
+            }
+        }
+        return properties == null ? demoProperties : properties;
+    }
+}

Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/JavaMailSessionProvider.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/JavaMailSessionProvider.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/JavaMailSessionProvider.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/JavaMailSessionProvider.java Wed Aug 21 16:35:16 2013
@@ -1,29 +1,34 @@
-/****************************************************************
- * 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.hupa.shared.exception;
-
-public class InvalidSessionException extends HupaException{
-
-	private static final long serialVersionUID = 995112620968798947L;
-
-	public InvalidSessionException(String message) {
-        super(message);
-    }
-}
+/****************************************************************
+ * 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.hupa.server.guice;
+
+import java.util.Properties;
+
+import javax.mail.Session;
+
+import com.google.inject.Provider;
+
+public class JavaMailSessionProvider implements Provider<Session>{
+
+    public Session get() {
+        Session session = Session.getDefaultInstance(new Properties(), null);
+        return session;
+    }
+}

Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/LogProvider.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/LogProvider.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/LogProvider.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/LogProvider.java Wed Aug 21 16:35:16 2013
@@ -1,29 +1,36 @@
-/****************************************************************
- * 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.hupa.shared.exception;
-
-public class InvalidSessionException extends HupaException{
-
-	private static final long serialVersionUID = 995112620968798947L;
-
-	public InvalidSessionException(String message) {
-        super(message);
-    }
-}
+/****************************************************************
+ * 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.hupa.server.guice;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.Log4JLogger;
+
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+
+@Singleton
+public class LogProvider implements Provider<Log>{
+
+    public Log get() {
+        return new Log4JLogger("HupaLogger");
+    }
+
+}

Added: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/demo/DemoGuiceServerModule.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/demo/DemoGuiceServerModule.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/demo/DemoGuiceServerModule.java (added)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/demo/DemoGuiceServerModule.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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.hupa.server.guice.demo;
+
+import java.lang.reflect.Constructor;
+import java.util.Properties;
+
+import javax.mail.NoSuchProviderException;
+import javax.mail.Session;
+import javax.mail.Transport;
+
+import org.apache.commons.logging.Log;
+import org.apache.hupa.server.CachedIMAPStore;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.InMemoryIMAPStoreCache;
+import org.apache.hupa.server.guice.GuiceServerModule;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import com.sun.mail.imap.IMAPStore;
+
+/**
+ * Module which binds the handlers and configurations for demo mode
+ */
+public class DemoGuiceServerModule extends GuiceServerModule {
+
+    public DemoGuiceServerModule(Properties properties) {
+        super(properties);
+    }
+    
+    protected Class<? extends IMAPStoreCache> getIMAPStoreCacheClass() {
+        return DemoIMAPStoreCache.class;
+    }
+    
+    /**
+     * IMAPStoreCache implementation for Demo mode.
+     * 
+     * It uses mock module which emulates fake imap and smtp servers based on
+     * a set of example messages in filesystem and used for unit tests.
+     * 
+     * We use here reflection so as we can deliver Hupa without mock stuff.  
+     *
+     */
+    public static class DemoIMAPStoreCache extends InMemoryIMAPStoreCache {
+        @Inject
+        public DemoIMAPStoreCache(Log logger,
+                @Named("IMAPServerAddress") String address,
+                @Named("IMAPServerPort") int port, 
+                @Named("IMAPS") boolean useSSL,
+                @Named("IMAPConnectionPoolSize") int connectionPoolSize,
+                @Named("IMAPConnectionPoolTimeout") int timeout,
+                @Named("SessionDebug") boolean debug,
+                @Named("TrustStore") String truststore,
+                @Named("TrustStorePassword") String truststorePassword,
+                Session session) {
+            super(logger, address, port, useSSL, connectionPoolSize, timeout,
+                    debug, truststore, truststorePassword, session);
+        }
+
+        @Override
+        public CachedIMAPStore createCachedIMAPStore()
+                throws NoSuchProviderException {
+            try {
+                Class<?> clz = 
+                    Class.forName("org.apache.hupa.server.mock.MockIMAPStore");
+                Constructor<?> cons = clz.getConstructors()[0];
+                IMAPStore store = (IMAPStore) cons
+                        .newInstance(new Object[] { session });
+                return new CachedIMAPStore(store, 300);
+            } catch (Exception e) {
+            }
+            return super.createCachedIMAPStore();
+        }
+
+        @Override
+        public Transport getMailTransport(boolean useSSL)
+                throws NoSuchProviderException {
+            try {
+                Class<?> clz = 
+                    Class.forName("org.apache.hupa.server.mock.MockSMTPTransport");
+                Constructor<?> cons = clz.getConstructors()[0];
+                return (Transport) cons.newInstance(new Object[] { session });
+            } catch (Exception e) {
+            }
+            return super.getMailTransport(useSSL);
+        }
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org