geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r473002 [3/3] - in /geronimo/sandbox/gcache: ./ common/ common/src/ common/src/main/ common/src/main/java/ common/src/main/java/org/ common/src/main/java/org/apache/ common/src/main/java/org/apache/geronimo/ common/src/main/java/org/apache/...
Date Thu, 09 Nov 2006 18:23:31 GMT
Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IntrospectionSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IntrospectionSupport.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IntrospectionSupport.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IntrospectionSupport.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,287 @@
+/**
+ *
+ * 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.geronimo.gcache.util;
+
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+public class IntrospectionSupport {
+    
+    static public boolean getProperties(Object target, Map<String, String> props,
+            String optionPrefix) {
+
+        boolean rc = false;
+        if (target == null)
+            throw new IllegalArgumentException("target was null.");
+        if (props == null)
+            throw new IllegalArgumentException("props was null.");
+
+        if (optionPrefix == null)
+            optionPrefix = "";
+
+        Class clazz = target.getClass();
+        Method[] methods = clazz.getMethods();
+        for (int i = 0; i < methods.length; i++) {
+            Method method = methods[i];
+            String name = method.getName();
+            Class type = method.getReturnType();
+            Class params[] = method.getParameterTypes();
+            if (name.startsWith("get") && params.length == 0 && type != null
+                    && isSettableType(type)) {
+
+                try {
+
+                    Object value = method.invoke(target, new Object[] {});
+                    if (value == null)
+                        continue;
+
+                    String strValue = convertToString(value, type);
+                    if (strValue == null)
+                        continue;
+
+                    name = name.substring(3, 4).toLowerCase()
+                            + name.substring(4);
+                    props.put(optionPrefix + name, strValue);
+                    rc = true;
+
+                } catch (Throwable ignore) {
+                }
+
+            }
+        }
+
+        return rc;
+    }
+
+    static public boolean setProperties(Object target, Map props,
+            String optionPrefix) {
+        boolean rc = false;
+        if (target == null)
+            throw new IllegalArgumentException("target was null.");
+        if (props == null)
+            throw new IllegalArgumentException("props was null.");
+
+        for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
+            String name = (String) iter.next();
+            if (name.startsWith(optionPrefix)) {
+                Object value = props.get(name);
+                name = name.substring(optionPrefix.length());
+                if (setProperty(target, name, value)) {
+                    iter.remove();
+                    rc = true;
+                }
+            }
+        }
+        return rc;
+    }
+
+    public static Map extractProperties(Map props, String optionPrefix) {
+        if (props == null)
+            throw new IllegalArgumentException("props was null.");
+
+        HashMap<String, Object> rc = new HashMap<String, Object>(props.size());
+
+        for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
+            String name = (String) iter.next();
+            if (name.startsWith(optionPrefix)) {
+                Object value = props.get(name);
+                name = name.substring(optionPrefix.length());
+                rc.put(name, value);
+                iter.remove();
+            }
+        }
+
+        return rc;
+    }
+
+    public static boolean setProperties(Object target, Map props) {
+        boolean rc = false;
+
+        if (target == null)
+            throw new IllegalArgumentException("target was null.");
+        if (props == null)
+            throw new IllegalArgumentException("props was null.");
+
+        for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
+            Map.Entry entry = (Entry) iter.next();
+            if (setProperty(target, (String) entry.getKey(), entry.getValue())) {
+                iter.remove();
+                rc = true;
+            }
+        }
+
+        return rc;
+    }
+
+    private static boolean setProperty(Object target, String name, Object value) {
+        try {
+            Class clazz = target.getClass();
+            Method setter = findSetterMethod(clazz, name);
+            if (setter == null)
+                return false;
+
+            // If the type is null or it matches the needed type, just use the
+            // value directly
+            if (value == null
+                    || value.getClass() == setter.getParameterTypes()[0]) {
+                setter.invoke(target, new Object[] { value });
+            } else {
+                // We need to convert it
+                setter.invoke(target, new Object[] { convert(value, setter
+                        .getParameterTypes()[0]) });
+            }
+            return true;
+        } catch (Throwable ignore) {
+            return false;
+        }
+    }
+
+    private static Object convert(Object value, Class type)
+            throws URISyntaxException {
+        PropertyEditor editor = PropertyEditorManager.findEditor(type);
+        if (editor != null) {
+            editor.setAsText(value.toString());
+            return editor.getValue();
+        }
+        if (type == URI.class) {
+            return new URI(value.toString());
+        }
+        return null;
+    }
+
+    private static String convertToString(Object value, Class type)
+            throws URISyntaxException {
+        PropertyEditor editor = PropertyEditorManager.findEditor(type);
+        if (editor != null) {
+            editor.setValue(value);
+            return editor.getAsText();
+        }
+        if (type == URI.class) {
+            return ((URI) value).toString();
+        }
+        return null;
+    }
+
+    private static Method findSetterMethod(Class clazz, String name) {
+        // Build the method name.
+        name = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
+        Method[] methods = clazz.getMethods();
+        for (int i = 0; i < methods.length; i++) {
+            Method method = methods[i];
+            Class params[] = method.getParameterTypes();
+            if (method.getName().equals(name) && params.length == 1
+                    && isSettableType(params[0])) {
+                return method;
+            }
+        }
+        return null;
+    }
+
+    private static boolean isSettableType(Class clazz) {
+        if (PropertyEditorManager.findEditor(clazz) != null)
+            return true;
+        if (clazz == URI.class)
+            return true;
+        if (clazz == Boolean.class)
+            return true;
+        return false;
+    }
+
+    static public String toString(Object target) {
+        return toString(target, Object.class);
+    }
+
+    static public String toString(Object target, Class stopClass) {
+        LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
+        addFields(target, target.getClass(), stopClass, map);
+        StringBuffer buffer = new StringBuffer(simpleName(target.getClass()));
+        buffer.append(" {");
+        Set entrySet = map.entrySet();
+        boolean first = true;
+        for (Iterator iter = entrySet.iterator(); iter.hasNext();) {
+            Map.Entry entry = (Map.Entry) iter.next();
+            if (first) {
+                first = false;
+            } else {
+                buffer.append(", ");
+            }
+            buffer.append(entry.getKey());
+            buffer.append(" = ");
+            appendToString(buffer, entry.getValue());
+        }
+        buffer.append("}");
+        return buffer.toString();
+    }
+
+    protected static void appendToString(StringBuffer buffer, Object value) {
+        buffer.append(value);
+    }
+
+    static public String simpleName(Class clazz) {
+        String name = clazz.getName();
+        int p = name.lastIndexOf(".");
+        if (p >= 0) {
+            name = name.substring(p + 1);
+        }
+        return name;
+    }
+
+    static private void addFields(Object target, Class startClass,
+            Class stopClass, LinkedHashMap<String, Object> map) {
+
+        if (startClass != stopClass)
+            addFields(target, startClass.getSuperclass(), stopClass, map);
+
+        Field[] fields = startClass.getDeclaredFields();
+        for (int i = 0; i < fields.length; i++) {
+            Field field = fields[i];
+            if (Modifier.isStatic(field.getModifiers())
+                    || Modifier.isTransient(field.getModifiers())
+                    || Modifier.isPrivate(field.getModifiers())) {
+                continue;
+            }
+
+            try {
+                field.setAccessible(true);
+                Object o = field.get(target);
+                if (o != null && o.getClass().isArray()) {
+                    try {
+                        o = Arrays.asList((Object[]) o);
+                    } catch (Throwable e) {
+                    }
+                }
+                map.put(field.getName(), o);
+            } catch (Throwable e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IntrospectionSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IntrospectionSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IntrospectionSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/StringUtil.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/StringUtil.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/StringUtil.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/StringUtil.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,52 @@
+/**
+ *
+ * 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.geronimo.gcache.util;
+
+public class StringUtil {
+    
+    private static final String DEFAULT_PLACEHOLDER_PREFIX = "${";
+    private static final String DEFAULT_PLACEHOLDER_SUFFIX = "}";
+
+    public static String parseAndReplaceSystemProperty(String str) {
+        StringBuffer buf = new StringBuffer(str);
+        parseAndReplaceSystemProperty(buf);
+        return buf.toString();
+    }
+
+    public static void parseAndReplaceSystemProperty(StringBuffer buf) {
+
+        int start = buf.indexOf(DEFAULT_PLACEHOLDER_PREFIX);
+        while (start != -1) {
+            int end = buf.toString().indexOf(DEFAULT_PLACEHOLDER_SUFFIX, start + DEFAULT_PLACEHOLDER_PREFIX.length());
+            if (end != -1) {
+                String prop = buf.substring(start + DEFAULT_PLACEHOLDER_PREFIX.length(), end);
+                String propVal = System.getProperty(prop);
+                if (propVal != null){
+                    buf.replace(start, end + DEFAULT_PLACEHOLDER_SUFFIX.length(), propVal);
+                    
+                    //Search for another one
+                    start = buf.indexOf(DEFAULT_PLACEHOLDER_PREFIX);
+                }
+            } else {
+                start = -1;
+            }
+        }
+        
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/StringUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/StringUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/StringUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/URISupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/URISupport.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/URISupport.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/URISupport.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,300 @@
+/**
+ *
+ * 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.geronimo.gcache.util;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class URISupport {
+    public static class CompositeData {
+        String scheme;
+        String path;
+        URI components[];
+        Map parameters;
+        String fragment;
+        public String host;
+
+        public URI[] getComponents() {
+            return components;
+        }
+        public String getFragment() {
+            return fragment;
+        }
+        public Map getParameters() {
+            return parameters;
+        }
+        public String getScheme() {
+            return scheme;
+        }
+        public String getPath() {
+            return path;
+        }
+        public String getHost() {
+            return host;
+        }
+
+        public URI toURI() throws URISyntaxException {
+            StringBuffer sb = new StringBuffer();
+            if( scheme!=null ) {
+                sb.append(scheme);
+                sb.append(':');
+            }
+
+            if( host!=null && host.length()!=0 ) {
+                sb.append(host);
+            } else {
+                sb.append('(');
+                for (int i = 0; i < components.length; i++) {
+                    if( i!=0 )
+                        sb.append(',');
+                    sb.append(components[i].toString());
+                }
+                sb.append(')');
+            }
+
+            if( path !=null ) {
+                sb.append('/');
+                sb.append(path);
+            }
+            if(!parameters.isEmpty()) {
+                sb.append("?");
+                sb.append(createQueryString(parameters));
+            }
+            if( fragment!=null ) {
+                sb.append("#");
+                sb.append(fragment);
+            }
+            return new URI(sb.toString());
+        }
+    }
+
+    public static Map parseQuery(String uri) throws URISyntaxException{
+        try{
+            Map<String, String> rc=new HashMap<String,String>();
+            if(uri!=null){
+                String[] parameters=uri.split("&");
+                for(int i=0;i<parameters.length;i++){
+                    int p=parameters[i].indexOf("=");
+                    if(p>=0){
+                        String name= URLDecoder.decode(parameters[i].substring(0,p),"UTF-8");
+                        String value=URLDecoder.decode(parameters[i].substring(p+1),"UTF-8");
+                        rc.put(name,value);
+                    }else{
+                        rc.put(parameters[i],null);
+                    }
+                }
+            }
+            return rc;
+        }catch(UnsupportedEncodingException e){
+            throw (URISyntaxException) new URISyntaxException(e.toString(),"Invalid encoding").initCause(e);
+        }
+    }
+
+    public static Map parseParamters(URI uri) throws URISyntaxException {
+        return uri.getQuery()==null ? Collections.EMPTY_MAP : parseQuery(stripPrefix(uri.getQuery(), "?"));
+    }
+
+    /**
+     * Removes any URI query from the given uri
+     */
+    public static URI removeQuery(URI uri) throws URISyntaxException {
+        return createURIWithQuery(uri, null);
+    }
+
+    /**
+     * Creates a URI with the given query
+     */
+    public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException {
+        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment());
+    }
+
+    public static CompositeData parseComposite(URI uri) throws URISyntaxException {
+
+        CompositeData rc = new CompositeData();
+        rc.scheme = uri.getScheme();
+        String ssp = stripPrefix(uri.getSchemeSpecificPart().trim(), "//").trim();
+
+        parseComposite(uri, rc, ssp);
+
+        rc.fragment = uri.getFragment();
+        return rc;
+    }
+
+    private static void parseComposite(URI uri, CompositeData rc, String ssp) throws URISyntaxException {
+        String componentString;
+        String params;
+
+        if(!checkParenthesis(ssp)){
+            throw new URISyntaxException(uri.toString(), "Not a matching number of '(' and ')' parenthesis");
+        }
+
+        int p;
+        int intialParen = ssp.indexOf("(");
+        if( intialParen==0 ) {
+            rc.host = ssp.substring(0, intialParen);
+            p = rc.host.indexOf("/");
+            if( p >= 0 ) {
+                rc.path = rc.host.substring(p);
+                rc.host = rc.host.substring(0,p);
+            }
+            p = ssp.lastIndexOf(")");
+            componentString = ssp.substring(intialParen+1,p);
+            params = ssp.substring(p+1).trim();
+
+        } else {
+            componentString = ssp;
+            params="";
+        }
+
+        String components[] = splitComponents(componentString);
+        rc.components=new URI[components.length];
+        for (int i = 0; i < components.length; i++) {
+            rc.components[i] = new URI(components[i].trim());
+        }
+
+        p = params.indexOf("?");
+        if( p >= 0 ) {
+            if( p > 0) {
+                rc.path = stripPrefix(params.substring(0, p), "/");
+            }
+            rc.parameters = parseQuery(params.substring(p+1));
+        } else {
+            if( params.length() > 0 )
+                rc.path = stripPrefix(params, "/");
+            rc.parameters = Collections.EMPTY_MAP;
+        }
+    }
+
+    private static String[] splitComponents(String str) {
+        ArrayList<String> l = new ArrayList<String>();
+
+        int last=0;
+        int depth = 0;
+        char chars[] = str.toCharArray();
+        for( int i=0; i < chars.length; i ++ ) {
+            switch( chars[i] ) {
+            case '(':
+                depth++;
+                break;
+            case ')':
+                depth--;
+                break;
+            case ',':
+                if( depth == 0 ) {
+                    String s = str.substring(last, i);
+                    l.add(s);
+                    last=i+1;
+                }
+            }
+        }
+
+        String s = str.substring(last);
+        if( s.length() !=0 )
+            l.add(s);
+
+        String rc[] = new String[l.size()];
+        l.toArray(rc);
+        return rc;
+    }
+
+    public static String stripPrefix(String value, String prefix) {
+        if( value.startsWith(prefix) )
+            return value.substring(prefix.length());
+        return value;
+    }
+
+    public static URI stripScheme(URI uri) throws URISyntaxException {
+        return new URI(stripPrefix(uri.getSchemeSpecificPart().trim(), "//"));
+    }
+
+    public static String createQueryString(Map options) throws URISyntaxException {
+        try {
+            if(options.size()>0) {
+                StringBuffer rc = new StringBuffer();
+                boolean first=true;
+                for (Iterator iter = options.keySet().iterator(); iter.hasNext();) {
+                    if( first )
+                        first=false;
+                    else
+                        rc.append("&");
+
+                    String key = (String) iter.next();
+                    String value = (String)options.get(key);
+                    rc.append(URLEncoder.encode(key, "UTF-8"));
+                    rc.append("=");
+                    rc.append(URLEncoder.encode(value, "UTF-8"));
+                }
+                return rc.toString();
+            } else {
+                return "";
+            }
+        } catch (UnsupportedEncodingException e) {
+            throw (URISyntaxException)new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
+        }
+    }
+
+    /**
+     * Creates a URI from the original URI and the remaining paramaters
+     * @throws URISyntaxException
+     */
+    public static URI createRemainingURI(URI originalURI, Map params) throws URISyntaxException {
+        String s = createQueryString(params);
+        if( s.length()==0 )
+            s = null;
+        return createURIWithQuery(originalURI, s);
+    }
+
+    static public URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException {
+        return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment());
+    }
+
+    public static boolean checkParenthesis(String str){
+        boolean result=true;
+        if(str!=null){
+            int open=0;
+            int closed=0;
+
+            int i=0;
+            while((i=str.indexOf('(',i)) >=0 ){
+                i++;
+                open++;
+            }
+            i=0;
+            while((i=str.indexOf(')',i)) >=0 ){
+                i++;
+                closed++;
+            }
+            result = open == closed;
+        }
+        return result;
+    }
+
+    public int indexOfParenthesisMatch(String str){
+        int result = -1;
+
+        return result;
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/URISupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/URISupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/URISupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,27 @@
+/*
+ * 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.geronimo.gcache.util;
+
+public class UniqueId {
+  static long current= System.currentTimeMillis();
+    
+  static public synchronized long get(){
+    return current++;
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/UniqueId.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,46 @@
+/**
+ *
+ * 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.geronimo.gcache.command;
+
+import org.apache.geronimo.gcache.util.CipherUtil;
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class AuthCommandTest {
+    
+    @Test
+    public void testAuthCommand() throws Exception{
+        AuthCommand command = (AuthCommand) CommandTypes.createCommand(CommandTypes.AUTH_COMMAND);
+        long commandId = command.getCommandId();
+        command.setUserId("test");
+        command.setPassword("secret");
+        command.setPublicKey(CipherUtil.publicKey);
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        AuthCommand readCommand = new AuthCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+        assert readCommand.getCommandId() == commandId;
+        assert readCommand.getUserId().equals("test");
+        assert readCommand.getPassword().equals("secret");
+        
+	
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/AuthCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,65 @@
+/*
+ * 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.geronimo.gcache.command;
+
+
+public class BaseCommandTest {
+/**
+    @Test
+    public void testReadBaseCommand() throws Exception {
+        BaseCommand command = new BaseCommand();
+        command.setCommandId("bad id");
+        byte bytes[] = new byte[34];
+        // write the length
+        ByteBuffer buffer = ByteBuffer.allocateDirect(4);
+        buffer.putInt(commandId.length());
+        buffer.flip();
+        for(int i = 0;i < buffer.limit();i++) {
+            bytes[i] = buffer.get();
+        }
+        // now write the string - buffer comes back flipped
+        buffer = Charset.defaultCharset().encode(commandId);
+        for(int i = 0;i < buffer.limit();i++) {
+            bytes[i + 4] = buffer.get();
+        }
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        ReadableByteChannel channel = Channels.newChannel(bais);
+        command.readExternal(channel);
+        // make sure reading changed the id
+        assert command.getCommandId().equals(commandId);
+    }
+    
+    @Test
+    public void testWriteBaseCommand() throws Exception {
+        BaseCommand writtenCommand = new BaseCommand();
+        String commandId = "this is the id";
+        writtenCommand.setCommandId(commandId);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(34);
+        WritableByteChannel channel = Channels.newChannel(baos);
+        writtenCommand.writeExternal(channel);
+        // make sure writing did not change the id
+        assert writtenCommand.getCommandId().equals(commandId);
+        ByteBuffer buffer = ByteBuffer.wrap(baos.toByteArray());
+        int idLength = buffer.getInt();
+        assert idLength == commandId.length();
+        String newCommandId = Charset.defaultCharset().decode(buffer).toString();
+        assert newCommandId.equals(commandId);
+    }
+  **/  
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BaseCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.geronimo.gcache.command;
+
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class BulkSendCommandTest {
+    
+    @Test
+    public void testBulkSendCommand() throws Exception {
+
+        BulkSendCommand command = (BulkSendCommand) CommandTypes.createCommand(CommandTypes.BULK_SEND_COMMAND);
+        command.setNumberOfCommands(8);
+        long commandId = command.getCommandId();
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        BulkSendCommand readCommand = new BulkSendCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+        assert readCommand.getCommandId() == commandId;
+        assert readCommand.getNumberOfCommands() == 8;
+
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/BulkSendCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,71 @@
+/*
+ * 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.geronimo.gcache.command;
+
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class CacheBaseCommandTest {
+
+    @Test
+    public void testCacheBaseCommand() throws Exception {
+
+        String key = "My Key";
+        String sessionId = "My Session Id";
+
+        CacheBaseCommand command = new CacheBaseCommand();
+        command.setKey(key);
+        command.setSessionId(sessionId);
+
+        long commandId = command.getCommandId();
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        CacheBaseCommand readCommand = new CacheBaseCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+        
+        assert readCommand.getCommandId() == commandId;
+        assert readCommand.getKey().equals(key);
+        assert readCommand.getSessionId().equals(sessionId);
+
+    }
+
+    @Test
+    public void testCacheBaseCommandNoSession() throws Exception {
+
+        String key = "My Key";
+
+        CacheBaseCommand command = new CacheBaseCommand();
+        command.setKey(key);
+        long commandId = command.getCommandId();
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        CacheBaseCommand readCommand = new CacheBaseCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+        assert readCommand.getCommandId() == commandId;
+        assert readCommand.getKey().equals(key);
+        assert readCommand.getSessionId() == null;
+        assert readCommand.hasSession() == false;
+
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CacheBaseCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,55 @@
+/*
+ * 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.geronimo.gcache.command;
+
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class CachePayloadBaseCommandTest {
+
+    @Test
+    public void testCacheValueBaseCommandSerializable() throws Exception {
+
+        String key = "My Key";
+        String sessionId = "My Session Id";
+        String data = "This is some serializable data...";
+
+        CachePayloadBaseCommand command = new CachePayloadBaseCommand();
+        command.setKey(key);
+        command.setSessionId(sessionId);
+        command.setPayload(data);
+
+        long commandId = command.getCommandId();
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        CachePayloadBaseCommand readCommand = new CachePayloadBaseCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+
+        byte readData[] = readCommand.getRawPayload();
+        String readString = (String)BaseCommand.convertObjectFromBytes(readData);
+        assert readString.equals(data);
+
+        assert readCommand.getCommandId() == commandId;
+        assert readCommand.getKey().equals(key);
+        assert readCommand.getSessionId().equals(sessionId);
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/CachePayloadBaseCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.geronimo.gcache.command;
+
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class ClearCacheCommandTest {
+
+    @Test
+    public void testClearCache() throws Exception{
+        String cacheName1 = "Test";
+        
+        //Submit a clear cache
+        ClearCacheCommand command = (ClearCacheCommand)CommandTypes.createCommand(CommandTypes.CLEARCACHE_COMMAND);
+        command.setCacheName(cacheName1);
+        byte[] marshalled = command.marshal();
+
+        ClearCacheCommand readCommand = new ClearCacheCommand();  
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+
+        //Cache1 should be empty
+        assert readCommand.getCacheName().equals(cacheName1);
+
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/ClearCacheCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,42 @@
+/**
+ *
+ * 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.geronimo.gcache.command;
+
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class DiscoveryCommandTest {
+    
+    @Test
+    public void testDiscoveryCommand() throws Exception{
+        DiscoveryCommand command = (DiscoveryCommand) CommandTypes.createCommand(CommandTypes.DISCOVERY_COMMAND);
+        command.setNodeName("node1");
+        command.setService("test");
+        long commandId = command.getCommandId();
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        DiscoveryCommand readCommand = new DiscoveryCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+        assert readCommand.getCommandId() == commandId;
+        assert readCommand.getNodeName().equals("node1");
+        assert readCommand.getService().equals("test");
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/DiscoveryCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.geronimo.gcache.command;
+
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class MessageAckCommandTest {
+
+    @Test
+    public void testMessageAckCommand() throws Exception {
+
+        MessageAckCommand command = (MessageAckCommand) CommandTypes.createCommand(CommandTypes.MESSAGE_ACK_COMMAND);
+        command.setMessageId(99);
+        long commandId = command.getCommandId();
+
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        MessageAckCommand readCommand = new MessageAckCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+        assert readCommand.getCommandId() == commandId;
+        assert readCommand.getMessageId() == 99;
+
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/MessageAckCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,53 @@
+/*
+ * 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.geronimo.gcache.command;
+
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class PutEntryCommandTest {
+    
+    @Test
+    public void testAddEntry() throws Exception {
+
+        String cacheName = "Test";
+        String key = "My Key";
+        String sessionId = "My Session";
+        String data = "My Data";
+
+        PutEntryCommand command = (PutEntryCommand)CommandTypes.createCommand(CommandTypes.PUT_ENTRY_COMMAND);
+
+        command.setCacheName(cacheName);
+        command.setKey(key);
+        command.setSessionId(sessionId);
+        command.setPayload(data);
+        
+        //Convert the command to bytes
+        byte[] marshalled = command.marshal();
+
+        PutEntryCommand readCommand = new PutEntryCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+        
+        assert readCommand.getCacheName().equals(cacheName);
+        assert readCommand.getKey().equals(key);
+        assert readCommand.getSessionId().equals(sessionId);
+        assert readCommand.getPayload().equals(data);
+
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutEntryCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java (added)
+++ geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,68 @@
+/*
+ * 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.geronimo.gcache.command;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.mina.common.ByteBuffer;
+import org.testng.annotations.Test;
+
+public class PutSessionCommandTest {
+
+    private String cacheName = "Test";
+    private String sessionId = "My Session";
+
+    private String key1 = "My Key 1";
+    private String data1 = "My Data 1";
+    private String key2 = "My Key 2";
+    private String data2 = "My Data 2";
+    private String key3 = "My Key 3";
+    private String data3 = "My Data 3";
+
+    @Test
+    public void testPutSessionCommand_object() throws Exception {
+
+        //Create and load the session
+        Map<Object, Object> sessionMap = Collections.synchronizedMap(new HashMap<Object, Object>());
+        sessionMap.put(key1, data1);
+        sessionMap.put(key2, data2);
+        sessionMap.put(key3, data3);
+
+        PutSessionCommand command = (PutSessionCommand) CommandTypes.createCommand(CommandTypes.PUT_SESSION_COMMAND);
+        command.setCacheName(cacheName);
+        command.setSessionId(sessionId);
+        command.setPayloadFromSession(sessionMap);
+        
+        byte[] marshalled = command.marshal();
+        
+        PutSessionCommand readCommand = new PutSessionCommand();
+        readCommand.readExternal(ByteBuffer.wrap(marshalled));
+        
+        Map readSession = readCommand.getSessionFromPayload();
+        assert readSession.size() == 3;
+
+        //Ensure all of the data is here
+        assert ((String) readSession.get(key1)).equals(data1);
+        assert ((String) readSession.get(key2)).equals(data2);
+        assert ((String) readSession.get(key3)).equals(data3);
+
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/test/java/org/apache/geronimo/gcache/command/PutSessionCommandTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gcache/common/temp-testng-customsuite.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/temp-testng-customsuite.xml?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/temp-testng-customsuite.xml (added)
+++ geronimo/sandbox/gcache/common/temp-testng-customsuite.xml Thu Nov  9 10:23:28 2006
@@ -0,0 +1,8 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="gcache-common">
+  <test verbose="2" name="org.apache.geronimo.gcache.command.ClearCacheCommandTest" annotations="JDK">
+    <classes>
+      <class name="org.apache.geronimo.gcache.command.ClearCacheCommandTest"/>
+    </classes>
+  </test>
+</suite>

Propchange: geronimo/sandbox/gcache/common/temp-testng-customsuite.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/temp-testng-customsuite.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/temp-testng-customsuite.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: geronimo/sandbox/gcache/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/pom.xml?view=diff&rev=473002&r1=473001&r2=473002
==============================================================================
--- geronimo/sandbox/gcache/pom.xml (original)
+++ geronimo/sandbox/gcache/pom.xml Thu Nov  9 10:23:28 2006
@@ -18,6 +18,7 @@
 
     <modules>
         <!--module>openwire</module-->
+    <module>common</module>
     <module>client</module>
     <module>server</module>
 </modules>
@@ -39,6 +40,12 @@
             <groupId>com.sun.xml.bind</groupId>
             <artifactId>jaxb-impl</artifactId>
             <version>2.0.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.gcache</groupId>
+            <artifactId>gcache-common</artifactId>
+            <version>${gcacheVersion}</version>
         </dependency>
 
         <dependency>

Modified: geronimo/sandbox/gcache/server/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/pom.xml?view=diff&rev=473002&r1=473001&r2=473002
==============================================================================
--- geronimo/sandbox/gcache/server/pom.xml (original)
+++ geronimo/sandbox/gcache/server/pom.xml Thu Nov  9 10:23:28 2006
@@ -65,7 +65,7 @@
 
         <dependency>
             <groupId>org.apache.geronimo.gcache</groupId>
-            <artifactId>openwire</artifactId>
+            <artifactId>gcache-common</artifactId>
         </dependency>
 
         <dependency>

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java?view=diff&rev=473002&r1=473001&r2=473002
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java (original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPCacheNotifier.java Thu Nov  9 10:23:28 2006
@@ -27,7 +27,7 @@
 import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.apache.geronimo.gcache.command.RemoveEntryCommand;
 import org.apache.geronimo.gcache.command.RemoveSessionCommand;
-import org.apache.geronimo.gcache.server.listeners.CacheNotifier;
+import org.apache.geronimo.gcache.listeners.CacheNotifier;
 import org.apache.geronimo.gcache.transports.Endpoint;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;



Mime
View raw message