You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nuvem-commits@incubator.apache.org by lr...@apache.org on 2010/11/21 05:17:17 UTC

svn commit: r1037382 - in /incubator/nuvem/trunk: nuvem-api/ nuvem-api/src/main/java/org/apache/nuvem/cloud/user/ nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/ nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ nuvem-api/src/main/java/org/...

Author: lresende
Date: Sun Nov 21 05:17:16 2010
New Revision: 1037382

URL: http://svn.apache.org/viewvc?rev=1037382&view=rev
Log:
NUVEM-6 - Applying patch from John Pradeep with new XMPP component support

Added:
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/XMPPEndPointFactory.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ContentType.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java
      - copied, changed from r1037381, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ErrorCode.java
      - copied, changed from r1037381, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageBuilder.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageListener.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/PayLoad.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Status.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPEndPoint.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPException.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/AbstractXMPPEndPoint.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/LoggingMessageListener.java   (with props)
    incubator/nuvem/trunk/nuvem-api/src/test/
    incubator/nuvem/trunk/nuvem-api/src/test/java/
    incubator/nuvem/trunk/nuvem-api/src/test/java/org/
    incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/
    incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/
    incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/
    incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/
    incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/api/
    incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/api/JIDTestCase.java   (with props)
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java   (with props)
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleStatusAdapter.java   (with props)
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPoint.java   (with props)
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPMessageAdapter.java   (with props)
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/impl/
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/impl/GoogleUserServiceTestCase.java   (with props)
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/impl/
    incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPointTestCase.java   (with props)
Modified:
    incubator/nuvem/trunk/nuvem-api/pom.xml
    incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java
    incubator/nuvem/trunk/nuvem-google/pom.xml
    incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/user/impl/GoogleUserService.java

Modified: incubator/nuvem/trunk/nuvem-api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/pom.xml?rev=1037382&r1=1037381&r2=1037382&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/pom.xml (original)
+++ incubator/nuvem/trunk/nuvem-api/pom.xml Sun Nov 21 05:17:16 2010
@@ -48,6 +48,12 @@
             <version>4.8.1</version>
             <scope>test</scope>
         </dependency>
+        
+        <dependency>
+    		<groupId>commons-lang</groupId>
+    		<artifactId>commons-lang</artifactId>
+    		<version>2.2</version>
+		</dependency>
 	</dependencies>
 
 </project>

Modified: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java?rev=1037382&r1=1037381&r2=1037382&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java Sun Nov 21 05:17:16 2010
@@ -24,33 +24,62 @@ import java.io.Serializable;
 public class User implements Serializable {
 	private static final long serialVersionUID = -503746790472903416L;
 
-	public static enum ROLES { UNDEFINED, USER, ADMIN};
-
-    protected String userId;
-    protected String nickName;
-    protected String email;
-
-    public User () {
-
-    }
-
-    public User(String userId, String nickName, String email) {
-        this.userId = userId;
-        this.nickName = nickName;
-        this.email = email;
-    }
-
-    public String getUserId() {
-        return this.userId;
-    }
-
-    public String getNickname() {
-        return this.nickName;
-    }
-
-    public String getEmail() {
-        return this.email;
-    }
-
-
+	protected String userId;
+	protected String nickName;
+	protected String email;
+
+	public static enum ROLES {
+		UNDEFINED, USER, ADMIN
+	};
+
+	/** Represents a dummy user for usage instead of nulls **/
+	public static final User DUMMY_USER = new User("dummyid", "dummy name","dummy@email.com");
+
+
+	public User() {
+
+	}
+
+	public User(String userId, String nickName, String email) {
+		this.userId = userId;
+		this.nickName = nickName;
+		this.email = email;
+	}
+
+	public String getUserId() {
+		return this.userId;
+	}
+
+	public String getNickname() {
+		return this.nickName;
+	}
+
+	public String getEmail() {
+		return this.email;
+	}
+
+	/**
+	 * Checks only for the user ID as it is supposed to be a unique identifier
+	 * for the user.
+	 */
+	@Override
+	public boolean equals(Object o) {
+		if (this == o)
+			return true;
+		if (!(o instanceof User))
+			return false;
+
+		final User user = (User) o;
+
+		return userId.equals(user.userId);
+	}
+
+	/**
+	 * Considers only the hashcode of the userid as userid is the unique
+	 * id of the user.
+	 */
+	@Override
+	public int hashCode() {
+		return userId.hashCode();
+	}
 }

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/XMPPEndPointFactory.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/XMPPEndPointFactory.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/XMPPEndPointFactory.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/XMPPEndPointFactory.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,20 @@
+package org.apache.nuvem.cloud.xmpp;
+
+import org.apache.nuvem.cloud.xmpp.api.XMPPEndPoint;
+
+public final class XMPPEndPointFactory {
+
+    private static final XMPPEndPointFactory instance = new XMPPEndPointFactory();
+
+    public static XMPPEndPointFactory getInstance() {
+        if (instance == null)
+            throw new IllegalStateException("Factory not initialized properly...");
+        return instance;
+    }
+
+    public XMPPEndPoint getEndPoint() {
+        // TODO:find the implementation here.
+        // return new GoogleXMPPEndpoint();
+        return null;
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/XMPPEndPointFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/XMPPEndPointFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ContentType.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ContentType.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ContentType.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ContentType.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,29 @@
+/*
+ * 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.nuvem.cloud.xmpp.api;
+
+/**
+ * Used to label the type of content present in the payload of a message.
+ *
+ */
+public enum ContentType {
+    PLAN_STRING, GROUP_CHAT;
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ContentType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ContentType.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java (from r1037381, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java?p2=incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java&p1=incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java&r1=1037381&r2=1037382&rev=1037382&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java Sun Nov 21 05:17:16 2010
@@ -1,5 +1,6 @@
 /*
  * 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
@@ -17,40 +18,39 @@
  * under the License.
  */
 
-package org.apache.nuvem.cloud.user;
-
-import java.io.Serializable;
-
-public class User implements Serializable {
-	private static final long serialVersionUID = -503746790472903416L;
-
-	public static enum ROLES { UNDEFINED, USER, ADMIN};
-
-    protected String userId;
-    protected String nickName;
-    protected String email;
+package org.apache.nuvem.cloud.xmpp.api;
 
-    public User () {
+/**
+ * Contains the error details used.
+ *
+ */
+public final class Error {
 
-    }
+    /**
+     * Description of the error.
+     */
+    private String description;
+
+    /**
+     * The actual error code.
+     */
+    private ErrorCode code;
 
-    public User(String userId, String nickName, String email) {
-        this.userId = userId;
-        this.nickName = nickName;
-        this.email = email;
+    public Error(ErrorCode code) {
+        this.code = code;
     }
 
-    public String getUserId() {
-        return this.userId;
+    public Error(ErrorCode code, String description) {
+        this.code = code;
+        this.description = description;
     }
 
-    public String getNickname() {
-        return this.nickName;
+    public String description() {
+        return description;
     }
 
-    public String getEmail() {
-        return this.email;
+    public ErrorCode code() {
+        return code;
     }
 
-
 }

Copied: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ErrorCode.java (from r1037381, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ErrorCode.java?p2=incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ErrorCode.java&p1=incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java&r1=1037381&r2=1037382&rev=1037382&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/user/User.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/ErrorCode.java Sun Nov 21 05:17:16 2010
@@ -1,5 +1,6 @@
 /*
  * 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
@@ -17,40 +18,16 @@
  * under the License.
  */
 
-package org.apache.nuvem.cloud.user;
-
-import java.io.Serializable;
-
-public class User implements Serializable {
-	private static final long serialVersionUID = -503746790472903416L;
-
-	public static enum ROLES { UNDEFINED, USER, ADMIN};
-
-    protected String userId;
-    protected String nickName;
-    protected String email;
-
-    public User () {
+package org.apache.nuvem.cloud.xmpp.api;
 
-    }
-
-    public User(String userId, String nickName, String email) {
-        this.userId = userId;
-        this.nickName = nickName;
-        this.email = email;
-    }
-
-    public String getUserId() {
-        return this.userId;
-    }
-
-    public String getNickname() {
-        return this.nickName;
-    }
-
-    public String getEmail() {
-        return this.email;
-    }
+/**
+ * XMPP error codes.
+ *
+ */
+public enum ErrorCode {
 
+    // TODO:the value of the code should be used in the constructor.
 
+    // TODO: complete by adding all error codes along with the descriptions.
+    BAD_FORMAT, CONFLICT, HOST_UNKNOWN, HOST_GONE, IMPROPER_ADDRESSING, USER_OFFLINE, CONNECTION_TIMEOUT, INVALID_FROM, NOT_AUTHORIZED, UNSUPPORTED_ENCODING, INVALID_TO, INVALID_ID, UNKNOWN_ERROR;
 }

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java Sun Nov 21 05:17:16 2010
@@ -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.nuvem.cloud.xmpp.api;
+
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Represents the XMPP ID.
+ *
+ */
+public final class JID {
+
+    /**
+     * The validation pattern for an JID id.
+     */
+    private static final Pattern VALID_PATTERN = Pattern.compile("^(?:([^@/<>'\"]+)@)?([^@/<>'\"]+)(?:/([^<>'\"]*))?$");
+
+    /**
+     * To be used instead of null.
+     */
+    public static final JID UNKNOWN = new JID("unknown@unknown.com");
+
+    /**
+     * The string form of the JID.
+     */
+    private String id;
+
+    /**
+     * Constructor. Validates the id passed as paramter befor initialising.
+     *
+     * @param id
+     */
+    public JID(String id) {
+        if (id == null || !VALID_PATTERN.matcher(id).matches())
+            throw new IllegalArgumentException("invalid JID! please check the format.. ");
+        this.id = id;
+    }
+
+    /**
+     * Returns the string representation of the JID.
+     *
+     * @return
+     */
+    public String asString() {
+        return id;
+    }
+
+    /**
+     * Returns only the domain identifier of the JID.
+     *
+     * @return
+     */
+    public String domainIdentifier() {
+        return StringUtils.substringBefore(this.id, "@");
+    }
+
+    /**
+     * Returns only the node identifier of this JID.
+     *
+     * @return the node identifier.
+     */
+    public String nodeIdentifier() {
+        return StringUtils.substringBetween(id, "@", "/");
+    }
+
+    /**
+     * Returns only the resource identifier of the JID.
+     *
+     * @return the resource identifier.
+     */
+    public String resourceIdentifier() {
+        return StringUtils.substringAfter(id, "/");
+    }
+
+    /**
+     * Just to make the equality check more descriptive and meaningful.
+     *
+     * @param jid the jid to which this jid is compared with.
+     * @return true if both the jid are same, false otherwise.
+     */
+    public boolean isSameAs(JID jid) {
+        return this.equals(jid);
+    }
+
+    /**
+     * .
+     */
+    public boolean equals(Object o) {
+        if (this == o)
+            return true;
+        if (!(o instanceof JID))
+            return false;
+
+        final JID jid = (JID)o;
+
+        return id.equals(jid.id);
+    }
+
+    /**
+	 */
+    public int hashCode() {
+        return id.hashCode();
+    }
+
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,156 @@
+/*
+ * 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.nuvem.cloud.xmpp.api;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+/**
+ * Encapsulates the complete message that needs to be delivered through the XMPP
+ * channel.
+ *
+ */
+public final class Message {
+
+    /**
+     * to be used instead of null.
+     */
+    public static final Message EMPTY_MESSAGE = new Message(PayLoad.EMPTY, JID.UNKNOWN, JID.UNKNOWN);
+
+    // TODO: Need to see the potential use of this headers feield and remove it
+    // if not required.
+    /**
+     * Message headers if any.
+     */
+    private Map<String, String> headers = new HashMap<String, String>();
+
+    /**
+     * Represents and ecloses the actual content to be delivered over xmpp.
+     */
+    private PayLoad payLoad;
+
+    /**
+     * Identifies the reciepient to whom the message should be delivered.
+     */
+    private JID recipient;
+
+    /**
+     * Identifies the sender of this message.
+     */
+    private JID sender;
+
+    /**
+     * Constructor.
+     *
+     * @param payLoad - the payload of this message.
+     * @param recipient - the reciepient for this message.
+     * @param sender - the sender of this message.
+     */
+    public Message(PayLoad payLoad, JID recipient, JID sender) {
+        this(payLoad, recipient);
+        this.sender = sender;
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param payLoad - the payload.
+     * @param recipient - the recipient.
+     */
+    public Message(PayLoad payLoad, JID recipient) {
+        this.payLoad = payLoad;
+        this.recipient = recipient;
+    }
+
+    /**
+     * Adds headers to the message.
+     *
+     * @param headers the headers.
+     */
+    public void addHeaders(Map<String, String> headers) {
+        if (headers != null && headers.size() > 0)
+            this.headers.putAll(headers);
+    }
+
+    /**
+     * Returns the payload of this message.
+     *
+     * @return the payload
+     */
+    public PayLoad payLoad() {
+        return this.payLoad;
+    }
+
+    /**
+     * Returns the recipient of this message.
+     *
+     * @return the recipient.
+     */
+    public JID recipient() {
+        return recipient;
+    }
+
+    /**
+     * Returns the sender of this message.
+     *
+     * @return the sender.
+     */
+    public JID sender() {
+        return sender;
+    }
+
+    /**
+     * Returns all the headers associated with this message.
+     *
+     * @return headers
+     */
+    public Map<String, String> headers() {
+        return Collections.unmodifiableMap(this.headers);
+    }
+
+    /**
+     * equals.
+     */
+    public boolean equals(Object o) {
+        if (this == o)
+            return true;
+        if (!(o instanceof Message))
+            return false;
+
+        final Message message = (Message)o;
+
+        return new EqualsBuilder().append(this.payLoad, message.payLoad).append(this.recipient, message.recipient)
+            .append(this.sender, message.sender).isEquals();
+    }
+
+    /**
+     * Considers only the hashcode of the userid as userid is the unique id of
+     * the user.
+     */
+    public int hashCode() {
+        return new HashCodeBuilder().append(this.payLoad).append(this.recipient).append(this.sender).toHashCode();
+    }
+
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageBuilder.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageBuilder.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageBuilder.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageBuilder.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,138 @@
+/*
+ * 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.nuvem.cloud.xmpp.api;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Used to build the message.
+ *
+ */
+public class MessageBuilder {
+
+    /**
+     * The sender of a message.
+     */
+    private JID from;
+
+    /**
+     * The recipient to whom a message is being built.
+     */
+    private JID recipient;
+
+    /**
+     * The content to deliver to the recipient.
+     */
+    private String content;
+
+    /**
+     * The locale.
+     */
+    private Locale locale;
+
+    /**
+     * Headers if any. <b>Note:This is not used internally at the moment. </b>
+     */
+    private Map<String, String> headers = new HashMap<String, String>();
+
+    /**
+     * Initializes the JID for recipient.
+     *
+     * @param jid the JID for the recipient.
+     * @return the message builder.
+     */
+    public MessageBuilder toRecipient(String jid) {
+        this.recipient = new JID(jid);
+        return this;
+    }
+
+    /**
+     * The sender for a message.
+     *
+     * @param jid the jid of the sender.
+     * @return the message builder.
+     */
+    public MessageBuilder from(String jid) {
+        this.from = new JID(jid);
+        return this;
+    }
+
+    public MessageBuilder inLanguage(Locale locale) {
+        this.locale = locale;
+        return this;
+    }
+
+    /**
+     * Initialises the content for sending to the recipient.
+     *
+     * @param content the actual content.
+     * @return the message builder.
+     */
+    public MessageBuilder containing(String content) {
+        this.content = content;
+        return this;
+    }
+
+    /**
+     * Initializes a header.
+     *
+     * @param key the key of the header.
+     * @param value the value for the header.
+     * @return the message builder.
+     */
+    public MessageBuilder withHeader(String key, String value) {
+        headers.put(key, value);
+        return this;
+    }
+
+    /**
+     * Initialises the headeres.
+     *
+     * @param headers a map of headers.
+     * @return the message builder.
+     */
+    public MessageBuilder withHeaders(Map<String, String> headers) {
+        if (headers != null && headers.size() > 0)
+            this.headers.putAll(headers);
+        return this;
+    }
+
+    /**
+     * Builds the message by using all the previously passed attributes through
+     * various methods like.
+     * <ul>
+     * <li/>{@link #containing(Object)}
+     * <li/>{@link #toRecipient(String)}
+     * <li/>{@link #withHeader(String, String)}
+     * <li/>{@link #withHeaders(Map)}
+     *
+     * @return
+     */
+    public Message build() {
+        PayLoad payLoad = new PayLoad(content, locale);
+        Message message = new Message(payLoad, recipient, from);
+        message.addHeaders(headers);
+        return message;
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageListener.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageListener.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageListener.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageListener.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,23 @@
+package org.apache.nuvem.cloud.xmpp.api;
+
+import org.apache.nuvem.cloud.xmpp.common.LoggingMessageListener;
+
+/**
+ * Listens to XMPP messages of a specific type.
+ *
+ */
+public interface MessageListener {
+
+    /**
+     * To be used as default one.
+     */
+    public static final MessageListener LOGGING_LISTENER = new LoggingMessageListener();
+
+    /**
+     * Listens for messages.
+     *
+     * @param message
+     */
+    void listen(Message message);
+
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/MessageListener.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/PayLoad.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/PayLoad.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/PayLoad.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/PayLoad.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,112 @@
+/*
+ * 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.nuvem.cloud.xmpp.api;
+
+import java.util.Locale;
+
+/**
+ * The actual payload (can be considered to represent XMPP Stream) that will be
+ * carried through the XMPP channel.
+ *
+ */
+public final class PayLoad {
+
+    /**
+     * usage instead of null.
+     */
+    public static final PayLoad EMPTY = new PayLoad("Empty Content");
+
+    /**
+     * TODO:should be configurable.
+     */
+    private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
+
+    /**
+     * The actual content.
+     */
+    private String content;
+
+    /**
+     * Identifies the type of the content.
+     */
+    private ContentType type;
+
+    private Locale locale;
+
+    public PayLoad(String content) {
+        this(content, DEFAULT_LOCALE);
+    }
+
+    public PayLoad(String content, Locale locale) {
+        this.content = content;
+        if (locale != null)
+            this.locale = locale;
+    }
+
+    public Locale locale() {
+        return locale;
+    }
+
+    /**
+     * Sets the content type for the payload.
+     *
+     * @param type the content type.
+     */
+    public void setContentType(ContentType type) {
+        this.type = type;
+    }
+
+    public String content() {
+        return content;
+    }
+
+    /**
+     * Returns the content type present in the payload.
+     *
+     * @return the content type.
+     */
+    public ContentType contentType() {
+        return type;
+    }
+
+    /**
+     * Checks only for the user ID as it is supposed to be a unique identifier
+     * for the user.
+     */
+    public boolean equals(Object o) {
+        if (this == o)
+            return true;
+        if (!(o instanceof PayLoad))
+            return false;
+
+        final PayLoad payLoad = (PayLoad)o;
+
+        return content.equals(payLoad.content);
+    }
+
+    /**
+     * Considers only the hashcode of the userid as userid is the unique id of
+     * the user.
+     */
+    public int hashCode() {
+        return content.hashCode();
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/PayLoad.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/PayLoad.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Status.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Status.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Status.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Status.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.nuvem.cloud.xmpp.api;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The status of sending a message to indicate whether was message was sent to
+ * the recipient successfully or was there any error.
+ *
+ */
+public final class Status {
+
+    private List<Error> errors = new ArrayList<Error>();
+
+    public Status(List<Error> errors) {
+        this.errors = new ArrayList<Error>();
+        this.errors.addAll(errors);
+    }
+
+    public Status() {
+
+    }
+
+    public Status(Error error) {
+        this.errors = new ArrayList<Error>();
+        this.errors.add(error);
+    }
+
+    public void addError(Error error) {
+        this.errors.add(error);
+    }
+
+    public boolean hasErrors() {
+        return errors != null && errors.size() > 0;
+    }
+
+    public boolean wasSentSuccessfuly() {
+        return errors == null || errors.size() == 0;
+    }
+
+    public List<Error> errors() {
+        return errors;
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Status.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Status.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPEndPoint.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPEndPoint.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPEndPoint.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPEndPoint.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,123 @@
+/*
+ * 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.nuvem.cloud.xmpp.api;
+
+/**
+ * Represents An EndPoint for client to send and receive XMPP messages.
+ * <p>
+ * The implementations of <code>XMPPEndPoint</code> are specific to each cloud
+ * platform.
+ * </p>
+ *
+ */
+public interface XMPPEndPoint {
+
+    boolean isConnected();
+
+    /**
+     * Returns a unique id of this endpoint.
+     *
+     * @return the unique id.
+     */
+    String uniqueID();
+
+    /**
+     * Sends the message to a target JID enclosed inside the
+     * <code>Message</code>.
+     *
+     * @param message - the message that needs to be delivered to a target
+     *            JID/Node.
+     * @return A response object which holds the status of the delivery of
+     *         message.
+     * @see org.apache.nuvem.cloud.xmpp.api.Message
+     */
+    Status sendMessage(Message message);
+
+    /**
+     * Sends a text message to a recipient, this is a simplified version for
+     * sending message compared to {@link #sendMessage(Message)} where you need
+     * to build the message using the {@link MessageBuilder}
+     *
+     * @param content - the text content to be sent to recipient.
+     * @param recipient - the recipient
+     * @return status of the message delivery
+     */
+    Status sendMessage(String content, String recipient);
+
+    /**
+     * Registers a <code>MessageListener</code> to listen to messages sent by a
+     * particular JID which is also passed as argument to this API.
+     * <p>
+     * </p>
+     *
+     * @param jid - the JID for which a message listener is bound.
+     * @param listener - will recieve messages sent by a client/node identified
+     *            by the JID passed as the first argument.
+     */
+    void registerListner(JID jid, MessageListener listener);
+
+    /**
+     * Clears the listener for the specified JID.
+     *
+     * @param jid the JID for which the listener will be removed which means the
+     *            messages from the particular JID will be lost!
+     * @return true if listener removed, false otherwise.
+     */
+    boolean clearListenersFor(JID jid);
+
+    /**
+     * Clears all the listeners.
+     */
+    void clearAllListeners();
+
+    /**
+     * Finds the presence of a particular recipient.
+     *
+     * @param jid
+     * @return
+     */
+    boolean isPresent(JID jid);
+
+    /**
+     * Simplified version of {@link #isPresent(JID)}
+     *
+     * @param id the JID in string format
+     * @return true if the JID is present, false otherwise.
+     */
+    boolean isPresent(String id);
+
+    /**
+     * Sends an XMPP invitation to the JID passed as argument.
+     *
+     * @param jid the jid.
+     * @throws IllegalArgumentException if JID is invalid.
+     */
+    Status invite(JID jid);
+
+    /**
+     * Simplified version of invitation API.
+     *
+     * @param jid the jid to invite for chat.
+     * @throws IllegalArgumentException if JID is invalid.
+     */
+    Status invite(String jid);
+
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPEndPoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPEndPoint.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPException.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPException.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPException.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPException.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,25 @@
+package org.apache.nuvem.cloud.xmpp.api;
+
+/**
+ * Thrown when unknown exception occurs at the layer beneath nuvem.
+ *
+ */
+public class XMPPException extends RuntimeException {
+
+    /**
+     * serial id.
+     */
+    private static final long serialVersionUID = 5047965549033367275L;
+
+    public XMPPException(Exception e) {
+        super(e);
+    }
+
+    public XMPPException(String msg, Exception e) {
+        super(msg, e);
+    }
+
+    public XMPPException(String msg) {
+        super(msg);
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/XMPPException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/AbstractXMPPEndPoint.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/AbstractXMPPEndPoint.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/AbstractXMPPEndPoint.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/AbstractXMPPEndPoint.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,96 @@
+/*
+ * 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.nuvem.cloud.xmpp.common;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+
+import org.apache.nuvem.cloud.xmpp.api.JID;
+import org.apache.nuvem.cloud.xmpp.api.Message;
+import org.apache.nuvem.cloud.xmpp.api.MessageBuilder;
+import org.apache.nuvem.cloud.xmpp.api.MessageListener;
+import org.apache.nuvem.cloud.xmpp.api.Status;
+import org.apache.nuvem.cloud.xmpp.api.XMPPEndPoint;
+
+/**
+ * Encloses the common code for various types of end points irrespective of the
+ * platform.
+ *
+ */
+public abstract class AbstractXMPPEndPoint {
+    private static final Logger log = Logger.getLogger(XMPPEndPoint.class.getName());
+
+    /**
+     * Listeners for recivnig the XMPP messages from specific JIDs
+     */
+    protected static Map<JID, MessageListener> listeners = new ConcurrentHashMap<JID, MessageListener>();
+
+    public boolean isConnected() {
+        throw new UnsupportedOperationException("still not implemented");
+    }
+
+    public String uniqueID() {
+        throw new UnsupportedOperationException("still not implemented");
+    }
+
+    public void registerListner(org.apache.nuvem.cloud.xmpp.api.JID jid, MessageListener listener) {
+        if (listener == null || jid == null)
+            return;
+        listeners.put(jid, listener);
+
+    }
+
+    public Status sendMessage(String content, String recipient) {
+        Message message = new MessageBuilder().containing(content).toRecipient(recipient).build();
+        return sendMessage(message);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean clearListenersFor(JID jid) {
+        if (listeners != null) {
+            return listeners.remove(jid) != null;
+        }
+        return false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void clearAllListeners() {
+        if (listeners != null)
+            listeners.clear();
+    }
+
+    public abstract Status sendMessage(org.apache.nuvem.cloud.xmpp.api.Message message);
+
+    public static MessageListener getListenerFor(JID jid) {
+
+        MessageListener target = null;
+        if (listeners != null && (target = listeners.get(jid)) != null)
+            return target;
+        // default listener.
+        return MessageListener.LOGGING_LISTENER;
+
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/AbstractXMPPEndPoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/AbstractXMPPEndPoint.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/LoggingMessageListener.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/LoggingMessageListener.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/LoggingMessageListener.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/LoggingMessageListener.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,22 @@
+package org.apache.nuvem.cloud.xmpp.common;
+
+import java.util.logging.Logger;
+
+import org.apache.nuvem.cloud.xmpp.api.Message;
+import org.apache.nuvem.cloud.xmpp.api.MessageListener;
+import org.apache.nuvem.cloud.xmpp.api.XMPPEndPoint;
+
+/**
+ * Default message listener which will log the message information.
+ *
+ */
+public class LoggingMessageListener implements MessageListener {
+
+    private static final Logger log = Logger.getLogger(XMPPEndPoint.class.getName());
+
+    @Override
+    public void listen(Message message) {
+        log.warning("no listeners found to listen to a specific message:" + message);
+    }
+
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/LoggingMessageListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/common/LoggingMessageListener.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/api/JIDTestCase.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/api/JIDTestCase.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/api/JIDTestCase.java (added)
+++ incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/api/JIDTestCase.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,14 @@
+package org.apache.nuvem.cloud.xmpp.api;
+
+import org.junit.Ignore;
+
+/**
+ * Validates JID related scenarios/validations.
+ */
+@Ignore
+public class JIDTestCase {
+
+    public void testInvalidJID() {
+
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/api/JIDTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-api/src/test/java/org/apache/nuvem/cloud/xmpp/api/JIDTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/nuvem/trunk/nuvem-google/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/pom.xml?rev=1037382&r1=1037381&r2=1037382&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/pom.xml (original)
+++ incubator/nuvem/trunk/nuvem-google/pom.xml Sun Nov 21 05:17:16 2010
@@ -93,6 +93,20 @@
             <version>4.8.1</version>
             <scope>test</scope>
         </dependency>
+        
+        <dependency>
+   			<groupId>org.easymock</groupId>
+   			<artifactId>easymock</artifactId>
+   			<version>3.0</version>
+   			<scope>test</scope>
+		</dependency>
+
+        <dependency>
+    		<groupId>javax.servlet</groupId>
+    		<artifactId>servlet-api</artifactId>
+    		<version>2.5</version>
+    		<scope>provided</scope>
+		</dependency>
 	</dependencies>
 
 	<build>

Modified: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/user/impl/GoogleUserService.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/user/impl/GoogleUserService.java?rev=1037382&r1=1037381&r2=1037382&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/user/impl/GoogleUserService.java (original)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/user/impl/GoogleUserService.java Sun Nov 21 05:17:16 2010
@@ -80,7 +80,7 @@ public class GoogleUserService implement
             return new User(googleUser.getUserId(), googleUser.getNickname(), googleUser.getEmail());
         } 
         
-        return new User(null, null, null);
+        return User.DUMMY_USER;
     }
 
     

Added: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java (added)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,37 @@
+package org.apache.nuvem.cloud.xmpp.impl;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+
+import com.google.appengine.api.xmpp.JID;
+import com.google.appengine.api.xmpp.Message;
+import com.google.appengine.api.xmpp.XMPPService;
+import com.google.appengine.api.xmpp.XMPPServiceFactory;
+
+/**
+ * A servlet to recieve XMPP messages from google cloud platform.
+ *
+ */
+public class GoogleRecieverServlet extends HttpServlet {
+    /**
+     * serial id.
+     */
+    private static final long serialVersionUID = -6839442887435183490L;
+
+    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
+        XMPPService xmpp = XMPPServiceFactory.getXMPPService();
+        Message message = xmpp.parseMessage(req);
+        org.apache.nuvem.cloud.xmpp.api.Message nuvemMessage = GoogleXMPPMessageAdapter.toNuvemMessage(message);
+        JID from = message.getFromJid();
+
+        // for identifying the listeners, we exclude the resource.
+        String jidExcludingResource = StringUtils.substringBefore(from.getId(), "/");
+        GoogleXMPPEndPoint.getListenerFor(new org.apache.nuvem.cloud.xmpp.api.JID(jidExcludingResource))
+            .listen(nuvemMessage);
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleRecieverServlet.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleStatusAdapter.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleStatusAdapter.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleStatusAdapter.java (added)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleStatusAdapter.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,44 @@
+package org.apache.nuvem.cloud.xmpp.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.nuvem.cloud.xmpp.api.Error;
+import org.apache.nuvem.cloud.xmpp.api.ErrorCode;
+import org.apache.nuvem.cloud.xmpp.api.Status;
+
+import com.google.appengine.api.xmpp.JID;
+import com.google.appengine.api.xmpp.SendResponse;
+
+/**
+ * Acts as an adapter to transform the status recieved by the the send API to
+ * the form compatible with nuvem.
+ *
+ */
+public class GoogleStatusAdapter {
+
+    /**
+     * converstion map.
+     */
+    private static Map<SendResponse.Status, ErrorCode> converstionMap;
+
+    static {
+        converstionMap = new HashMap<SendResponse.Status, ErrorCode>();
+        converstionMap.put(SendResponse.Status.INVALID_ID, ErrorCode.INVALID_ID);
+        converstionMap.put(SendResponse.Status.OTHER_ERROR, ErrorCode.UNKNOWN_ERROR);
+    }
+
+    public static Status toStatus(SendResponse responseStatus) {
+        Status status = new Status();
+        ErrorCode code = null;
+        if (responseStatus != null && responseStatus.getStatusMap() != null && !responseStatus.getStatusMap().isEmpty()) {
+            Map<JID, SendResponse.Status> statuses = responseStatus.getStatusMap();
+            for (JID jid : statuses.keySet()) {
+                if (converstionMap.containsKey(statuses.get(jid)))
+                    status.addError(new Error(code, "For :" + jid.getId()));
+            }
+        }
+        return status;
+
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleStatusAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleStatusAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPoint.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPoint.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPoint.java (added)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPoint.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,126 @@
+/*
+ * 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.nuvem.cloud.xmpp.impl;
+
+import java.util.logging.Logger;
+
+import org.apache.nuvem.cloud.xmpp.api.Error;
+import org.apache.nuvem.cloud.xmpp.api.ErrorCode;
+import org.apache.nuvem.cloud.xmpp.api.Status;
+import org.apache.nuvem.cloud.xmpp.api.XMPPEndPoint;
+import org.apache.nuvem.cloud.xmpp.common.AbstractXMPPEndPoint;
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+
+import com.google.appengine.api.xmpp.JID;
+import com.google.appengine.api.xmpp.Message;
+import com.google.appengine.api.xmpp.SendResponse;
+import com.google.appengine.api.xmpp.XMPPService;
+import com.google.appengine.api.xmpp.XMPPServiceFactory;
+
+@Service(XMPPEndPoint.class)
+@Scope("COMPOSITE")
+public class GoogleXMPPEndPoint extends AbstractXMPPEndPoint implements XMPPEndPoint {
+
+    private static final Logger log = Logger.getLogger(XMPPEndPoint.class.getName());
+
+    /**
+     * Google's XMPP service.
+     */
+    private XMPPService xmpp;
+
+    @Init
+    public void init() {
+        xmpp = XMPPServiceFactory.getXMPPService();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Status sendMessage(org.apache.nuvem.cloud.xmpp.api.Message message) {
+        if (message == null || message.recipient() == null) {
+            throw new IllegalArgumentException("invalid input");
+        }
+
+        Status deliveryStatus = new Status();
+        JID jid = new JID(message.recipient().asString());
+        Message msg = GoogleXMPPMessageAdapter.toGoogleMessage(message);
+
+        SendResponse status = null;
+        if (xmpp.getPresence(jid).isAvailable()) {
+            log.info("user online...");
+            try {
+                status = xmpp.sendMessage(msg);
+            } catch (RuntimeException e) {
+                deliveryStatus.addError(new Error(ErrorCode.UNKNOWN_ERROR,
+                                                  "unknown runtime error while sending message over XMPP"));
+                return deliveryStatus;
+            }
+            log.info(status.toString());
+        } else {
+            log.info("user offline...");
+            deliveryStatus.addError(new org.apache.nuvem.cloud.xmpp.api.Error(ErrorCode.USER_OFFLINE));
+            return deliveryStatus;
+        }
+        return GoogleStatusAdapter.toStatus(status);
+    }
+
+    @Override
+    public Status invite(org.apache.nuvem.cloud.xmpp.api.JID jid) {
+        if (jid == null)
+            throw new IllegalArgumentException("jid cannot be null");
+        Status deliveryStatus = new Status();
+        JID googleJID = new JID(jid.asString());
+        try {
+            xmpp.sendInvitation(googleJID);
+        } catch (RuntimeException e) {
+            deliveryStatus.addError(new Error(ErrorCode.UNKNOWN_ERROR,
+                                              "unknown runtime error while sending invitiation over XMPP"));
+            return deliveryStatus;
+        }
+        return deliveryStatus;
+    }
+
+    /**
+     * {@inheritDoc} validation of the input will be done within
+     * {@link org.apache.nuvem.cloud.xmpp.api.JID}
+     */
+    @Override
+    public Status invite(String jid) {
+        return invite(new org.apache.nuvem.cloud.xmpp.api.JID(jid));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isPresent(org.apache.nuvem.cloud.xmpp.api.JID jid) {
+        return xmpp.getPresence(new JID(jid.asString())).isAvailable();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isPresent(String id) {
+        return isPresent(new org.apache.nuvem.cloud.xmpp.api.JID(id));
+    }
+
+}

Propchange: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPoint.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPMessageAdapter.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPMessageAdapter.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPMessageAdapter.java (added)
+++ incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPMessageAdapter.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,31 @@
+package org.apache.nuvem.cloud.xmpp.impl;
+
+import com.google.appengine.api.xmpp.JID;
+import com.google.appengine.api.xmpp.Message;
+import com.google.appengine.api.xmpp.MessageBuilder;
+
+/**
+ * Transforms messages of nuvem format to google's format.
+ *
+ */
+public class GoogleXMPPMessageAdapter {
+
+    public static Message toGoogleMessage(org.apache.nuvem.cloud.xmpp.api.Message nuvemMessage) {
+        JID jid = new JID(nuvemMessage.recipient().asString());
+        Message msg = new MessageBuilder().
+            withRecipientJids(jid).
+            withBody(nuvemMessage.payLoad().content())
+            .build();
+        return msg;
+    }
+
+    public static org.apache.nuvem.cloud.xmpp.api.Message toNuvemMessage(Message googleMessage) {
+        String sender = googleMessage.getFromJid().getId();
+        org.apache.nuvem.cloud.xmpp.api.Message nuvemMessage =
+            new org.apache.nuvem.cloud.xmpp.api.MessageBuilder().
+                                                from(sender).
+                                                containing(googleMessage.getBody())
+                                                .build();
+        return nuvemMessage;
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPMessageAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-google/src/main/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPMessageAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/impl/GoogleUserServiceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/impl/GoogleUserServiceTestCase.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/impl/GoogleUserServiceTestCase.java (added)
+++ incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/impl/GoogleUserServiceTestCase.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.nuvem.cloud.user.impl;
+
+import java.lang.reflect.Field;
+
+
+import junit.framework.Assert;
+
+import org.apache.nuvem.cloud.user.UserService;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.appengine.api.users.User;
+
+/**
+ * Tests the Google user service Wrapper class by mocking the the actual google
+ * API.
+
+ *
+ */
+public class GoogleUserServiceTestCase {
+
+	private com.google.appengine.api.users.UserService mockGoogleUserService;
+
+	private UserService userService = new GoogleUserService();
+
+	@Before
+	public void setUp() throws IllegalArgumentException, IllegalAccessException {
+		mockGoogleUserService = EasyMock
+				.createMock(com.google.appengine.api.users.UserService.class);
+
+		for (Field field : userService.getClass().getDeclaredFields()) {
+			if (field.getName().equals("googleUerService")) {
+				field.setAccessible(true);
+				field.set(userService, mockGoogleUserService);
+			}
+		}
+	}
+
+	@Test
+	public void testForValidUser() {
+		// set expectations
+		EasyMock.expect(mockGoogleUserService.getCurrentUser()).andReturn(
+				new User("test@test.com", "domain", "tester"));
+		EasyMock.replay(mockGoogleUserService);
+		// test the api
+		org.apache.nuvem.cloud.user.User user = userService.getCurrentUser();
+		Assert.assertNotNull(user);
+	}
+
+	@Test
+	public void testForNullUser() {
+		// set expecatations
+		EasyMock.expect(mockGoogleUserService.getCurrentUser()).andReturn(null);
+		EasyMock.replay(mockGoogleUserService);
+
+		// test api
+		org.apache.nuvem.cloud.user.User user = userService.getCurrentUser();
+		Assert.assertEquals(org.apache.nuvem.cloud.user.User.DUMMY_USER, user);
+	}
+}

Propchange: incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/impl/GoogleUserServiceTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/user/impl/GoogleUserServiceTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPointTestCase.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPointTestCase.java?rev=1037382&view=auto
==============================================================================
--- incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPointTestCase.java (added)
+++ incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPointTestCase.java Sun Nov 21 05:17:16 2010
@@ -0,0 +1,157 @@
+package org.apache.nuvem.cloud.xmpp.impl;
+
+import java.lang.reflect.Field;
+
+import junit.framework.Assert;
+
+import org.apache.nuvem.cloud.xmpp.api.ErrorCode;
+import org.apache.nuvem.cloud.xmpp.api.Message;
+import org.apache.nuvem.cloud.xmpp.api.MessageBuilder;
+import org.apache.nuvem.cloud.xmpp.api.MessageListener;
+import org.apache.nuvem.cloud.xmpp.api.Status;
+import org.easymock.EasyMock;
+import org.easymock.IArgumentMatcher;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.appengine.api.xmpp.JID;
+import com.google.appengine.api.xmpp.Presence;
+import com.google.appengine.api.xmpp.SendResponse;
+import com.google.appengine.api.xmpp.XMPPService;
+
+public class GoogleXMPPEndPointTestCase {
+
+    /**
+     * Mocked service.
+     */
+    private XMPPService mockXMPPService;
+
+    private GoogleXMPPEndPoint endPoint = new GoogleXMPPEndPoint();
+
+    @Before
+    public void setUp() throws IllegalArgumentException, IllegalAccessException {
+        mockXMPPService = EasyMock.createMock(XMPPService.class);
+
+        for (Field field : endPoint.getClass().getDeclaredFields()) {
+            if (field.getName().equals("xmpp")) {
+                field.setAccessible(true);
+                field.set(endPoint, mockXMPPService);
+            }
+        }
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testWithNullMessage() {
+        endPoint.sendMessage(null);
+    }
+
+    @Test
+    public void testWithValidMessageButToOfflineRecipient() {
+        Presence presence = new Presence(false);
+        JID jid = new JID("test@test.com");
+        Message message =
+            new MessageBuilder().containing("content").toRecipient("test@test.com").from("from@test.com").build();
+        EasyMock.expect(mockXMPPService.getPresence(jidMatcher(jid))).andReturn(presence);
+        EasyMock.replay(mockXMPPService);
+
+        Status status = endPoint.sendMessage(message);
+        Assert.assertTrue(status.hasErrors());
+        Assert.assertTrue(ErrorCode.USER_OFFLINE == status.errors().get(0).code());
+
+    }
+
+    @Test
+    public void testWithValidMessageAndForOnlineRecipient() {
+        Presence presence = new Presence(true);
+        JID jid = new JID("test@test.com");
+        Message message =
+            new MessageBuilder().containing("content").toRecipient("test@test.com").from("from@test.com").build();
+        EasyMock.expect(mockXMPPService.getPresence(jidMatcher(jid))).andReturn(presence);
+        EasyMock.expect(mockXMPPService.sendMessage(EasyMock.<com.google.appengine.api.xmpp.Message> anyObject()))
+            .andReturn(new SendResponse());
+        EasyMock.replay(mockXMPPService);
+        Status status = endPoint.sendMessage(message);
+        Assert.assertTrue(!status.hasErrors());
+    }
+
+    private JID jidMatcher(JID jid) {
+        EasyMock.reportMatcher(new GoogleJIDMatcher(jid));
+        return null;
+    }
+
+    /**
+     * Using custom JID matcher as google's JID equals method is not working as
+     * expected.
+     */
+    private static class GoogleJIDMatcher implements IArgumentMatcher {
+        private JID expected;
+
+        public GoogleJIDMatcher(JID expected) {
+            this.expected = expected;
+        }
+
+        public boolean matches(Object obj) {
+            if (!(obj instanceof JID)) {
+                return false;
+            }
+            JID actual = (JID)obj;
+            return actual.getId().equals(expected.getId());
+        }
+
+        @Override
+        public void appendTo(StringBuffer buffer) {
+            buffer.append("eqException(");
+            buffer.append(expected.getClass().getName());
+            buffer.append(" with id:");
+            buffer.append(expected.getId());
+
+        }
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testInviteWithInvalidJID() {
+        endPoint.invite("");
+    }
+
+    @Test
+    public void testInviteWithValidJID() {
+        JID jid = new JID("test@test.com");
+        mockXMPPService.sendInvitation(jidMatcher(jid));
+        EasyMock.expectLastCall();
+        EasyMock.replay(mockXMPPService);
+        endPoint.invite("test@test.com");
+    }
+
+    @Test
+    public void testRegisterAndRetrieveValidListener() {
+        MessageListener listener = new MessageListener() {
+
+            @Override
+            public void listen(Message message) {
+
+            }
+        };
+        endPoint.registerListner(new org.apache.nuvem.cloud.xmpp.api.JID("test@domain.com"), listener);
+        MessageListener registeredListener =
+            GoogleXMPPEndPoint.getListenerFor(new org.apache.nuvem.cloud.xmpp.api.JID("test@domain.com"));
+        Assert.assertNotNull(registeredListener);
+    }
+
+    @Test
+    public void testListnerClearing() {
+        MessageListener listener = new MessageListener() {
+
+            @Override
+            public void listen(Message message) {
+
+            }
+        };
+        org.apache.nuvem.cloud.xmpp.api.JID jid = new org.apache.nuvem.cloud.xmpp.api.JID("test@domain.com");
+        endPoint.registerListner(jid, listener);
+        MessageListener registeredListener =
+            GoogleXMPPEndPoint.getListenerFor(new org.apache.nuvem.cloud.xmpp.api.JID("test@domain.com"));
+        Assert.assertNotNull(registeredListener);
+        Assert.assertTrue(endPoint.clearListenersFor(jid));
+        Assert.assertEquals(MessageListener.LOGGING_LISTENER, GoogleXMPPEndPoint.getListenerFor(jid));
+    }
+}

Propchange: incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPointTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/nuvem/trunk/nuvem-google/src/test/java/org/apache/nuvem/cloud/xmpp/impl/GoogleXMPPEndPointTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date