lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r417565 [3/4] - in /lucene/java/trunk/contrib/gdata-server: src/java/org/apache/lucene/gdata/data/ src/java/org/apache/lucene/gdata/server/administration/ src/java/org/apache/lucene/gdata/server/authentication/ src/java/org/apache/lucene/gd...
Date Tue, 27 Jun 2006 19:31:23 GMT
Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/ResourceNotFoundException.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/ResourceNotFoundException.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/ResourceNotFoundException.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/ResourceNotFoundException.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.storage;
+
+/**
+ * This exception will be thrown if an requested resource of a resource to modify can not be found
+ * @author Simon Willnauer
+ *
+ */
+public class ResourceNotFoundException extends StorageException {
+
+   
+    private static final long serialVersionUID = -8549987918130998249L;
+
+    /**
+     * Constructs an empty ResourceNotFoundException
+     */
+    public ResourceNotFoundException() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * Constructs a new ResourceNotFoundException with an exception message
+     * @param message - the exception message
+     */
+    public ResourceNotFoundException(String message) {
+        super(message);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * Constructs a new ResourceNotFoundException with an exception message and a root cause 
+     * @param message - the exception message
+     * @param cause - the root cause of this exception
+     */
+    public ResourceNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * Constructs a new ResourceNotFoundException with  a root cause
+     * @param cause - the root cause of this exception
+     * 
+     */
+    public ResourceNotFoundException(Throwable cause) {
+        super(cause);
+        // TODO Auto-generated constructor stub
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageAccountWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageAccountWrapper.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageAccountWrapper.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageAccountWrapper.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,111 @@
+package org.apache.lucene.gdata.storage.lucenestorage;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.gdata.data.GDataAccount;
+
+/**
+ * Wrapps a User Object.
+ * The wrapper provides also a Lucene repesentation of the user;
+ * User Objects will not be Buffered in the lucene storage component. Each User will be written imidialtely.
+ * @author Simon Willnauer
+ *
+ */
+public class StorageAccountWrapper implements StorageWrapper{
+    private static final Log LOG = LogFactory.getLog(StorageAccountWrapper.class);
+    
+    /**
+     * Lucene field for the username
+     */
+    public static final String FIELD_ACCOUNTNAME = "accountName";
+    /**
+     * Lucene field for the password
+     */
+    public static final String FIELD_PASSWORD = "passwd";
+    /**
+     * Lucene field for the author name
+     */
+    public static final String FIELD_AUTHORNAME = "author";
+    /**
+     * Lucene field for the author mail address
+     */
+    public static final String FIELD_AUTHORMAIL = "authorMail";
+    /**
+     * Lucene field for the author link
+     */
+    public static final String FIELD_AUTHORHREF = "authorHref";
+    /**
+     * Lucene field fot the userroles
+     */
+    public static final String FIELD_ROLES = "userroles";
+    private final GDataAccount user;
+    /**
+     * @param user - the user to be wrapped
+     */
+    public StorageAccountWrapper(final GDataAccount user) {
+        if(user == null)
+            throw new IllegalArgumentException("user must not be null");
+        this.user = user;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageWrapper#getLuceneDocument()
+     */
+    public Document getLuceneDocument() {
+        Document doc = new Document();
+        
+        doc.add(new Field(FIELD_ACCOUNTNAME,this.user.getName(),Field.Store.YES,Field.Index.UN_TOKENIZED));
+        doc.add(new Field(FIELD_PASSWORD,this.user.getPassword()==null?"":this.user.getPassword(),Field.Store.YES,Field.Index.NO));
+        doc.add(new Field(FIELD_AUTHORNAME,this.user.getAuthorname()==null?"":this.user.getAuthorname(),Field.Store.YES,Field.Index.NO));
+        doc.add(new Field(FIELD_AUTHORMAIL,this.user.getAuthorMail()==null?"":this.user.getAuthorMail(),Field.Store.YES,Field.Index.NO));
+        doc.add(new Field(FIELD_AUTHORHREF,this.user.getAuthorLink()==null?"":this.user.getAuthorLink().toString(),Field.Store.YES,Field.Index.NO));
+        doc.add(new Field(FIELD_ROLES, Integer.toString(this.user.getRolesAsInt()),Field.Store.YES,Field.Index.NO)); 
+       
+        return doc;
+    }
+   
+   
+    
+    
+    /**
+     * @param doc - a lucene document representation of an user
+     * @return - the user to build from the document. or <code>null</code> if the document is <code>null</code>
+     */
+    public static GDataAccount buildEntity(final Document doc){
+        if(doc == null)
+            return null;
+        
+        GDataAccount user = new GDataAccount();
+        user.setName(doc.get(FIELD_ACCOUNTNAME));
+        user.setPassword(doc.get(FIELD_PASSWORD));
+        user.setAuthorname(doc.get(FIELD_AUTHORNAME));
+        user.setAuthorMail(doc.get(FIELD_AUTHORMAIL));
+        try{
+        user.setRolesAsInt(Integer.parseInt(doc.get(FIELD_ROLES)));
+        }catch (NumberFormatException e) {
+            LOG.info("Can't parse userroles: "+user.getName()+" throws NumberFormatException. -- skipping --",e);
+        }
+        try {
+            if(doc.get(FIELD_AUTHORHREF)!= null)
+                user.setAuthorLink(new URL(doc.get(FIELD_AUTHORHREF)));
+        } catch (MalformedURLException e) {
+            LOG.info("SPECIFIED URL for user: "+user.getName()+" throws MalformedURLException. -- skipping --",e);
+        }
+        return user;
+    }
+    
+   
+
+    /**
+     * @return - the wrapped user
+     */
+    public GDataAccount getUser() {
+        return this.user;
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageFeedWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageFeedWrapper.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageFeedWrapper.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageFeedWrapper.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,106 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.storage.lucenestorage;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+
+import com.google.gdata.data.BaseFeed;
+import com.google.gdata.util.common.xml.XmlWriter;
+
+/**
+ * This immutable class wrapps <tt>GDataAccount</tt> instances for an internal Storage representation of 
+ * an account. This class also acts as a Documentfactory for lucene documents to 
+ * be stored inside the index. 
+ * @author Simon Willnauer
+ *
+ */
+public class StorageFeedWrapper implements StorageWrapper {
+    
+    private static final String INTERNAL_ENCODING = "UTF-8";
+    /**
+     * the account who owns the feed 
+     */
+    public static final String FIELD_ACCOUNTREFERENCE = "accountReference";
+    /**
+     * the id of the feed
+     */
+    public static final String FIELD_FEED_ID = "feedId";
+    /**
+     * The xml feed representation
+     */
+    public static final String FIELD_CONTENT = "content";
+    
+    /**
+     * The creation timestamp
+     */
+    public static final String FIELD_TIMESTAMP = "timestamp";
+
+    /**
+     * The Service this feed belongs to. 
+     */
+    public static final String FIELD_SERVICE_ID = "serviceId";
+    private final ServerBaseFeed feed;
+    private final String accountName;
+    private final ProvidedService config;
+    private final String content;
+    
+    
+    /**
+     * @param feed 
+     * @param accountname 
+     * @throws IOException 
+     * 
+     */
+    public StorageFeedWrapper(final ServerBaseFeed feed, final String accountname) throws IOException {
+        this.feed = feed;
+        this.accountName = accountname;
+        this.config = feed.getServiceConfig();
+        this.content = buildContent();
+       
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageWrapper#getLuceneDocument()
+     */
+    public Document getLuceneDocument() {
+        Document doc = new Document();
+        doc.add(new Field(FIELD_ACCOUNTREFERENCE,this.accountName,Field.Store.YES,Field.Index.UN_TOKENIZED));
+        doc.add(new Field(FIELD_FEED_ID,this.feed.getId(),Field.Store.YES,Field.Index.UN_TOKENIZED));
+        doc.add(new Field(FIELD_CONTENT,this.content,Field.Store.COMPRESS,Field.Index.NO));
+        doc.add(new Field(FIELD_SERVICE_ID,this.feed.getServiceType(),Field.Store.YES,Field.Index.NO));
+        return doc;
+    }
+
+    private String buildContent() throws IOException { 
+        StringWriter writer = new StringWriter(); 
+        XmlWriter xmlWriter = new XmlWriter(writer, INTERNAL_ENCODING); 
+        this.feed.generateAtom(xmlWriter,this.config.getExtensionProfile()); 
+        return writer.toString(); 
+    }
+    /**
+     * @return - the wrapped feed
+     */
+    public BaseFeed getFeed(){
+        return this.feed.getFeed();
+    }
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageWrapper.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageWrapper.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageWrapper.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/StorageWrapper.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,38 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.storage.lucenestorage;
+
+import org.apache.lucene.document.Document;
+
+/**
+ * A interface to be implemented by <tt>StorageWrapper</tt> sub classes to
+ * provide a lucene document for each entity wrapped.
+ * 
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageAccountWrapper
+ * @see org.apache.lucene.gdata.storage.lucenestorage.StorageFeedWrapper
+ * @author Simon Willnauer
+ * 
+ */
+public interface StorageWrapper {
+    /**
+     * Returns a Lucene document representing the Wrapped Entry
+     * 
+     * @return a Lucene Document
+     */
+    public abstract Document getLuceneDocument();
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverController.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverController.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverController.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverController.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,169 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.storage.lucenestorage.recover;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.storage.StorageException;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageModifier;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;
+
+
+/**
+ * @author Simon Willnauer
+ * 
+ */
+public class RecoverController {
+    private static final Log LOG = LogFactory.getLog(RecoverController.class);
+    private final File recoverDirectory;
+
+    private static final String FILE_SUFFIX = ".rec";
+
+    private File currentRecoverFile;
+
+    private RecoverWriter writer;
+
+    private Writer fileWriter;
+
+    private BufferedReader fileReader;
+
+    private RecoverReader reader;
+
+    private Lock lock = new ReentrantLock();
+    
+    private final boolean recover;
+    private final boolean keepRecoverFiles;
+
+    public RecoverController(final File recoverDirectory, boolean recover, boolean keepRecoverFiles) {
+        if (recoverDirectory == null)
+            throw new IllegalArgumentException("directory must not be null");
+        if (!recoverDirectory.isDirectory())
+            throw new IllegalStateException("the given File is not a directory");
+        this.recover = recover;
+        this.keepRecoverFiles = keepRecoverFiles;
+        this.recoverDirectory = recoverDirectory;
+       
+    }
+
+   public void storageModified(StorageEntryWrapper wrapper)
+            throws RecoverException {
+        // prevent deadlock either recovering or writing
+        if(this.recover){
+            LOG.warn("Can't write entry, Recovercontroller is initialized in recover mode");
+            return;
+        }
+        this.lock.lock();
+        try {
+
+            this.writer.writeEntry(wrapper, this.fileWriter);
+        } catch (Exception e) {
+            LOG.error("Writing entry failed -- create new recover file",e);
+            throw new RecoverException(
+                    "Writing entry failed -- create new recover file",e);
+
+        } finally {
+            this.lock.unlock();
+        }
+    }
+    
+    public void recoverEntries(final StorageModifier modifier){
+        // prevent deadlock either recovering or writing
+        if(!this.recover){
+            LOG.warn("Can't recover entries, Recovercontroller is initialized in write mode");
+            return;
+        }
+        this.lock.lock();
+        try{
+            this.reader = new RecoverReader();
+        File[] files = this.recoverDirectory.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            if(!files[i].isDirectory()){
+                try{
+                this.fileReader = new BufferedReader(new FileReader(files[i]));
+                List<StorageEntryWrapper> entryList = this.reader.recoverEntries(this.fileReader);
+                if(entryList.size() == 0)
+                    continue;
+                storeEntries(entryList,modifier);
+                this.fileReader.close();
+                if(!this.keepRecoverFiles)
+                    files[i].delete();
+                }catch (StorageException e) {
+                    LOG.error("Can't store recover entries for file: "+files[i].getName()+" -- keep file "+e.getMessage(),e);
+                }catch (IOException e) {
+                    LOG.error("Can't recover entries for file: "+files[i].getName()+" -- keep file",e);
+                }
+            }
+        }
+        
+        }finally{
+            this.lock.unlock();
+        }
+    }
+    
+    protected void storeEntries(final List<StorageEntryWrapper> entries, final StorageModifier modifier) throws StorageException{
+        for (StorageEntryWrapper wrapper : entries) {
+            if(wrapper.getOperation() == StorageOperation.DELETE)
+                modifier.deleteEntry(wrapper);
+            else if(wrapper.getOperation() == StorageOperation.INSERT)
+                modifier.insertEntry(wrapper);
+            else if(wrapper.getOperation() == StorageOperation.UPDATE)
+                modifier.updateEntry(wrapper);
+                
+            
+        }
+    }
+
+    protected synchronized void initialize() throws IOException {
+        if(this.recover)
+            return;
+        String filename = System.currentTimeMillis() + FILE_SUFFIX;
+        this.currentRecoverFile = new File(this.recoverDirectory, filename);
+        this.writer = new RecoverWriter();
+        this.fileWriter = new BufferedWriter(new FileWriter(
+                this.currentRecoverFile));
+
+    }
+
+    protected void destroy() throws RecoverException {
+        if (this.fileWriter != null) {
+            this.lock.lock();
+            try {
+                this.fileWriter.flush();
+                this.fileWriter.close();
+            } catch (IOException e) {
+                throw new RecoverException("Can't close recover writer ", e);
+            } finally {
+                this.lock.unlock();
+            }
+        }
+    }
+    
+    
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverException.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverException.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverException.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverException.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.storage.lucenestorage.recover;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class RecoverException extends Exception {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -1862309520257024464L;
+
+    /**
+     * 
+     */
+    public RecoverException() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param arg0
+     */
+    public RecoverException(String arg0) {
+        super(arg0);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param arg0
+     * @param arg1
+     */
+    public RecoverException(String arg0, Throwable arg1) {
+        super(arg0, arg1);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @param arg0
+     */
+    public RecoverException(Throwable arg0) {
+        super(arg0);
+        // TODO Auto-generated constructor stub
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverReader.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverReader.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverReader.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,174 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gdata.storage.lucenestorage.recover;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.ServerBaseEntry;
+import org.apache.lucene.gdata.server.GDataEntityBuilder;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;
+
+import com.google.gdata.data.BaseEntry;
+import com.google.gdata.util.ParseException;
+
+/**
+ * Recovers the written object from the harddisc
+ * @author Simon Willnauer
+ *
+ */
+public class RecoverReader {
+    
+    private static final Log LOG = LogFactory.getLog(RecoverReader.class);
+    private RecoverStrategy strategy; 
+    protected RecoverReader(){
+        this.strategy = new RecoverStrategy();
+    }
+    /**
+     * @param reader
+     * @return
+     * @throws IOException
+     */
+    public List<StorageEntryWrapper> recoverEntries(final BufferedReader reader) throws IOException{
+        List<StorageEntryWrapper> actionList = new ArrayList<StorageEntryWrapper>();
+        this.strategy = new RecoverStrategy();
+        String input = null;
+        String metaData = null;
+        String entryData = null;
+        while((input=reader.readLine())!= null){
+            if(metaData == null){
+                metaData = input;
+                continue;
+            }
+            if(input.equals(RecoverWriter.STORAGE_OPERATION_SEPARATOR)){
+                try{
+                actionList.add(this.strategy.recover(metaData,entryData));
+                }catch (RecoverException e) {
+                  LOG.error("Skipping recover entry for metadata: "+metaData,e);
+                }
+                this.strategy = new RecoverStrategy();
+                metaData = null;
+                entryData = null;
+             continue;   
+            }
+            if(entryData == null){
+                entryData = input;
+            }
+            
+        }
+        
+        
+        
+        return actionList;
+        
+    }
+    
+    
+    
+    
+    
+  
+    
+    
+    private static  class RecoverStrategy{
+        private StorageOperation operation;
+        private ProvidedService config;
+        private String feedId;
+        private String entryId;
+        private long timestamp;
+        /**
+         * @param metaData
+         * @param entry
+         * @return
+         * @throws RecoverException
+         */
+        public StorageEntryWrapper recover(String metaData, String entry) throws RecoverException{
+                fillMetaData(metaData);
+                ServerBaseEntry retVal = null;
+                if(entry != null && this.operation == StorageOperation.DELETE)
+                    throw new RecoverException("Can not recover -- Delete operation has entry part");
+                if(entry != null)
+                    try {
+                        retVal = new ServerBaseEntry(buildEntry(entry,this.config));
+                    } catch (Exception e) {
+                        throw new RecoverException("Exception occured while building entry -- "+e.getMessage(),e);
+                    }
+                else
+                    retVal = new ServerBaseEntry();
+                retVal.setId(this.entryId);
+                retVal.setFeedId(this.feedId);
+                retVal.setServiceConfig(this.config);
+                
+           try{
+            return new StorageEntryWrapper(retVal,this.operation);
+           }catch (IOException e) {
+               throw new RecoverException("Can't create StorageWrapper -- "+e.getMessage(),e);
+        }
+        }
+        private void fillMetaData(String recoverString) throws RecoverException{
+            StringTokenizer tokenizer = new StringTokenizer(recoverString,RecoverWriter.META_DATA_SEPARATOR);
+            String temp = tokenizer.nextToken();
+            if(temp.equals("D"))
+                this.operation = StorageOperation.DELETE;
+            else if(temp.equals("U"))
+                this.operation = StorageOperation.UPDATE;
+            else if(temp.equals("I"))
+                this.operation = StorageOperation.INSERT;
+            else
+                throw new RecoverException("Illegal metadata --- "+recoverString);
+            temp = tokenizer.nextToken();
+            if(temp == null)
+                throw new RecoverException("Can't recover feed Id -- "+temp);
+            this.feedId = temp;
+            temp = tokenizer.nextToken();
+            if(temp == null)
+                throw new RecoverException("Can't recover entry Id -- "+temp);
+             this.entryId = temp;
+            
+            temp = tokenizer.nextToken();
+            try{
+                this.timestamp = Long.parseLong(temp);
+            }catch (Exception e) {
+                throw new RecoverException("Can't recover timestamp -- "+temp,e);
+            }
+            
+            if(this.operation != StorageOperation.DELETE){
+                temp = tokenizer.nextToken();
+                if(temp == null)
+                    throw new RecoverException("Can't recover service -- "+temp);  
+                if(!GDataServerRegistry.getRegistry().isServiceRegistered(temp))
+                    throw new RecoverException("Service in recover metadata is not registered  - "+temp);
+                this.config = GDataServerRegistry.getRegistry().getProvidedService(temp);
+                
+            }
+            
+        }
+        
+        private BaseEntry buildEntry(String entry, ProvidedService serviceConfig) throws ParseException, IOException{
+           StringReader reader = new StringReader(entry);
+           return GDataEntityBuilder.buildEntry(reader,serviceConfig);
+        }
+    }
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverWriter.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverWriter.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/RecoverWriter.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,104 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.storage.lucenestorage.recover;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;
+
+import com.google.gdata.data.BaseEntry;
+import com.google.gdata.util.common.xml.XmlWriter;
+
+/**
+ * Writes the recover objects to the hard disc.
+ * @author Simon Willnauer
+ *
+ */
+public class RecoverWriter {
+    protected static final String META_DATA_SEPARATOR = ";";
+    protected static final String META_DATA_ENTRY_SEPARATOR = System.getProperty("line.separator");
+    protected static final String STORAGE_OPERATION_SEPARATOR = "###########";
+    protected static final String OPERATION_DELETE = "D";
+    protected static final String OPERATION_UPDATE = "U";
+    protected static final String OPERATION_INSERT = "I";
+    protected static final String FILE_PREFIX = ".strg";
+   
+    
+    
+    /**
+     * @param wrapper 
+     * @throws IOException 
+     * 
+     * 
+     * 
+     */
+    public void writeEntry(StorageEntryWrapper wrapper,Writer writer)throws IOException{
+        
+        writeOperation(wrapper.getOperation(),writer);
+        writeFeedID(wrapper.getFeedId(),writer);
+        writeEntryID(wrapper.getEntryId(),writer);
+        writeTimeStamp(wrapper.getTimestamp().toString(),writer);
+        if(!wrapper.getOperation().equals(StorageOperation.DELETE)){
+        writeService(wrapper,writer);
+            writer.write(META_DATA_ENTRY_SEPARATOR);
+            BaseEntry entry = wrapper.getEntry();
+            XmlWriter xmlWriter = new XmlWriter(writer);
+            entry.generateAtom(xmlWriter,wrapper.getConfigurator().getExtensionProfile());
+        }
+        writer.write(META_DATA_ENTRY_SEPARATOR);
+        writer.write(STORAGE_OPERATION_SEPARATOR);
+        writer.write(META_DATA_ENTRY_SEPARATOR);
+    }
+
+   
+
+    private void writeTimeStamp(String timestamp, Writer writer) throws IOException{
+        writer.write(timestamp);
+        writer.write(META_DATA_SEPARATOR);
+    }
+    private void writeFeedID(String feedId,Writer writer) throws IOException{
+        writer.write(feedId);
+        writer.write(META_DATA_SEPARATOR);
+    }
+    private void writeEntryID(String entryId,Writer writer) throws IOException{
+        writer.write(entryId);
+        writer.write(META_DATA_SEPARATOR);
+    }
+    
+    private void writeService(StorageEntryWrapper wrapper, Writer writer) throws IOException{
+        ProvidedService config = wrapper.getConfigurator();
+        writer.write(config.getName());
+        writer.write(META_DATA_SEPARATOR);
+    }
+ 
+    private void writeOperation(StorageOperation operation, Writer writer) throws IOException{
+        if(operation.equals(StorageOperation.INSERT))
+            writer.write(OPERATION_INSERT);
+        else if (operation.equals(StorageOperation.UPDATE)) 
+            writer.write(OPERATION_UPDATE);
+        else if (operation.equals(StorageOperation.DELETE)) 
+            writer.write(OPERATION_DELETE);
+        writer.write(META_DATA_SEPARATOR);
+    }
+    
+    
+    
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/package.html
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/package.html?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/package.html (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/storage/lucenestorage/recover/package.html Tue Jun 27 12:31:20 2006
@@ -0,0 +1,10 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> 
+<html> 
+<head> 
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
+   <meta name="Author" content="Simon Willnauer"> 
+</head> 
+<body> 
+Recovering component for the lucene storage
+</body> 
+</html> 

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/DateFormater.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/DateFormater.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/DateFormater.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/DateFormater.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,125 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Stack;
+
+/**
+ * This class uses the {@link java.text.SimpleDateFormat} class to format dates
+ * into strings according to given date pattern.
+ * <p>
+ * As the creation of <tt>SimpleDateFormat</tt> objects is quiet expensive and
+ * formating dates is used quiet fequently the objects will be cached and reused
+ * in subsequent calls.
+ * </p>
+ * <p>
+ * This implementation is thread safe as it uses {@link java.util.Stack} as a
+ * cache
+ * </p>
+ * 
+ * @author Simon Willnauer
+ * 
+ */
+public class DateFormater {
+    private final Stack<SimpleDateFormat> objectStack = new Stack<SimpleDateFormat>();
+
+    private static final DateFormater formater = new DateFormater();
+
+    /**
+     * Date format as it is used in Http Last modified header (Tue, 15 Nov 1994
+     * 12:45:26 GMT)
+     */
+    public static String HTTP_HEADER_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss z";
+    /**
+     *  Date format as it is used in Http Last modified header (Tue, 15 Nov 1994
+     * 12:45:26 +0000)
+     */
+    public static String HTTP_HEADER_DATE_FORMAT_TIME_OFFSET = "EEE, d MMM yyyy HH:mm:ss Z";
+
+    private DateFormater() {
+        super();
+    }
+
+    /**
+     * Formats the given Date into the given date pattern.
+     * 
+     * @param date -
+     *            the date to format
+     * @param format -
+     *            date pattern
+     * @return - the string representation of the given <tt>Date</tt>
+     *         according to the given pattern
+     */
+    public static String formatDate(final Date date, String format) {
+        if (date == null || format == null)
+            throw new IllegalArgumentException(
+                    "given parameters must not be null");
+        SimpleDateFormat inst = formater.getFormater();
+        inst.applyPattern(format);
+        formater.returnFomater(inst);
+        return inst.format(date);
+    }
+    /**
+     * Parses the given string into one of the specified formates
+     * @param date - the string to parse
+     * @param formates - formates
+     * @return a {@link Date} instance representing the given string
+     * @throws ParseException - if the string can not be parsed
+     */
+    public static Date parseDate(final String date, final String...formates) throws ParseException{
+        for (int i = 0; i < formates.length; i++) {
+            try {
+             return parseDate(date,formates[i]);
+            } catch (ParseException e) {
+                //
+            }
+        }
+        throw new ParseException("Unparseable date: "+date,0);
+        
+    }
+    
+    /**
+     * Parses the given string into the specified formate
+     * @param dateString - the string to parse
+     * @param pattern - the expected formate
+     * @return a {@link Date} instance representing the given string
+     * @throws ParseException - if the string can not be parsed
+     */
+    public static Date parseDate(final String dateString,String pattern) throws ParseException{
+        if(dateString == null|| pattern == null)
+            throw new IllegalArgumentException(
+            "given parameters must not be null");
+        SimpleDateFormat inst = formater.getFormater();
+        inst.applyPattern(pattern);
+        return inst.parse(dateString);
+    }
+
+    private SimpleDateFormat getFormater() {
+        if (this.objectStack.empty())
+            return new SimpleDateFormat();
+        return this.objectStack.pop();
+    }
+
+    private void returnFomater(final SimpleDateFormat format) {
+        if (this.objectStack.size() <= 25)
+            this.objectStack.push(format);
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/package.html
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/package.html?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/package.html (added)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/utils/package.html Tue Jun 27 12:31:20 2006
@@ -0,0 +1,10 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> 
+<html> 
+<head> 
+   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
+   <meta name="Author" content="Simon Willnauer"> 
+</head> 
+<body> 
+Utils package
+</body> 
+</html> 

Added: lucene/java/trunk/contrib/gdata-server/src/test/gdata-config.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/gdata-config.xml?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/gdata-config.xml (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/gdata-config.xml Tue Jun 27 12:31:20 2006
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gdata>
+	<service name="feed" public="true">
+		<feed-class>com.google.gdata.data.Feed</feed-class>
+		<entry-class>com.google.gdata.data.Entry</entry-class>
+		<extension-profile>
+			com.google.gdata.data.ExtensionProfile
+		</extension-profile>
+	</service>
+	<service name="calendar" public="true">
+		<feed-class>
+			com.google.gdata.data.extensions.EventFeed
+		</feed-class>
+		<entry-class>
+			com.google.gdata.data.extensions.EventEntry
+		</entry-class>
+		<extension-profile>
+			com.google.gdata.data.ExtensionProfile
+		</extension-profile>
+	</service>
+	<server-components>
+		<component>
+			org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController
+		</component>
+		<component>
+			org.apache.lucene.gdata.servlet.handler.DefaultRequestHandlerFactory
+		</component>
+		<component>
+			org.apache.lucene.gdata.server.ServiceFactory
+		</component>
+		<component>
+			org.apache.lucene.gdata.server.authentication.BlowfishAuthenticationController
+		</component>
+	</server-components>
+</gdata>
\ No newline at end of file

Added: lucene/java/trunk/contrib/gdata-server/src/test/lucenestorage.properties.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/lucenestorage.properties.xml?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/lucenestorage.properties.xml (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/lucenestorage.properties.xml Tue Jun 27 12:31:20 2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+<comment>Lucene Storage Properties</comment>
+<entry key="gdata.server.storage.lucene.buffersize">20</entry>
+<entry key="gdata.server.storage.lucene.optimizeInterval">20</entry>
+<entry key="gdata.server.storage.lucene.persistFactor">20</entry>
+<entry key="gdata.server.storage.lucene.directory.ramDirectory">true</entry>
+<entry key="gdata.server.storage.lucene.directory">/tmp/storage/</entry>
+<entry key="gdata.server.storage.lucene.recover">true</entry>
+<entry key="gdata.server.storage.lucene.recover.keepFiles">false</entry>
+</properties>

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/data/TestGDataUser.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,65 @@
+package org.apache.lucene.gdata.data;
+
+import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
+
+import junit.framework.TestCase;
+
+public class TestGDataUser extends TestCase {
+    private GDataAccount user;
+    @Override
+    protected void setUp() throws Exception {
+        this.user = new GDataAccount();
+        this.user.setName("simon");
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.data.GDataUser.isUserInRole(UserRole)'
+     */
+    public void testIsUserInRole() {
+        assertTrue(this.user.isUserInRole(AccountRole.USER));
+        assertFalse(this.user.isUserInRole(AccountRole.ENTRYAMINISTRATOR));
+        this.user.setRole(AccountRole.ENTRYAMINISTRATOR);
+        assertTrue(this.user.isUserInRole(AccountRole.ENTRYAMINISTRATOR));
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.data.GDataUser.getRolesAsInt()'
+     */
+    public void testGetRolesAsInt() {
+        assertEquals(1,this.user.getRolesAsInt());
+        this.user.setRole(AccountRole.ENTRYAMINISTRATOR);
+        assertEquals(3,this.user.getRolesAsInt());
+        this.user.setRole(AccountRole.FEEDAMINISTRATOR);
+        assertEquals(7,this.user.getRolesAsInt());
+        this.user.setRole(AccountRole.USERADMINISTRATOR);
+        assertEquals(15,this.user.getRolesAsInt());
+        
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.data.GDataUser.setRolesAsInt(int)'
+     */
+    public void testSetRolesAsInt() {
+        this.user.setRolesAsInt(2);
+        this.user.setRolesAsInt(4);
+        this.user.setRolesAsInt(8);
+        assertEquals(4,this.user.getRoles().size()); 
+        this.user.setRolesAsInt(15);
+        assertEquals(4,this.user.getRoles().size());
+        this.user = new GDataAccount();
+        this.user.setName("simon");
+        this.user.setRolesAsInt(15);
+        assertEquals(4,this.user.getRoles().size());
+        
+    }
+    
+    
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/administration/TestAccountBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/administration/TestAccountBuilder.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/administration/TestAccountBuilder.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/administration/TestAccountBuilder.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,54 @@
+package org.apache.lucene.gdata.server.administration;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
+import org.xml.sax.SAXException;
+
+public class TestAccountBuilder extends TestCase {
+    private StringReader reader;
+    private String inputXML;
+    protected void setUp() throws Exception {
+        this.inputXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+                "<account>" +
+                "<account-name>simon</account-name>" +
+                "<password>simon</password>" +
+                "<account-role>6</account-role>" +
+                "<account-owner>" +
+                "<name>simon willnauer</name>" +
+                "<email-address>simon@gmail.com</email-address>" +
+                "<url>http://www.javawithchopsticks.de</url>" +
+                "</account-owner>" +
+                "</account>";
+
+        this.reader = new StringReader(this.inputXML);
+        
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.server.administration.AdminEntityBuilder.buildUser(Reader)'
+     */
+    public void testBuildUser() throws IOException, SAXException {
+        
+        GDataAccount user = AccountBuilder.buildAccount(this.reader);
+        assertEquals("simon",user.getName());
+        assertEquals("simon willnauer",user.getAuthorname());
+        assertEquals("simon@gmail.com",user.getAuthorMail());
+        assertEquals("simon",user.getPassword());
+        assertEquals(new URL("http://www.javawithchopsticks.de"),user.getAuthorLink());
+        assertTrue(user.isUserInRole(AccountRole.ENTRYAMINISTRATOR));
+        assertTrue(user.isUserInRole(AccountRole.FEEDAMINISTRATOR));
+        assertFalse(user.isUserInRole(AccountRole.USERADMINISTRATOR));
+        
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/authentication/TestBlowfishAuthenticationController.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/authentication/TestBlowfishAuthenticationController.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/authentication/TestBlowfishAuthenticationController.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/server/authentication/TestBlowfishAuthenticationController.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,94 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.server.authentication;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.GDataAccount.AccountRole;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class TestBlowfishAuthenticationController extends TestCase {
+    private BlowfishAuthenticationController controller;
+    private String key = "myKey";
+    private String accountName = "simon";
+    
+    private String clientIp = "192.168.0.127";
+    protected void setUp() throws Exception {
+        this.controller = new BlowfishAuthenticationController();
+        this.controller.setKey(this.key);
+        
+        this.controller.initialize();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.server.authentication.AuthenticationController.authenticatAccount(HttpServletRequest)'
+     */
+    public void testAuthenticatAccount() throws IllegalBlockSizeException, BadPaddingException, AuthenticationException, IOException {
+        GDataAccount account = new GDataAccount();
+        account.setName(accountName);
+        account.setPassword("testme");
+        account.setRole(AccountRole.ENTRYAMINISTRATOR);
+        
+        String token = this.controller.authenticatAccount(account,this.clientIp);
+        String notSame = this.controller.calculateAuthToken("192.168.0",Integer.toString(account.getRolesAsInt()),this.accountName);
+        assertNotSame(notSame,token);
+        String authString = "192.168.0#"+this.accountName +"#"+account.getRolesAsInt()+"#";
+        assertTrue(this.controller.deCryptAuthToken(token).startsWith(authString));
+        assertTrue(this.controller.deCryptAuthToken(notSame).startsWith(authString));
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.server.authentication.AuthenticationController.authenticateToken(String)'
+     */
+    public void testAuthenticateToken() throws IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException, AuthenticationException {
+        GDataAccount account = new GDataAccount();
+        account.setName("simon");
+        account.setPassword("testme");
+        account.setRole(AccountRole.ENTRYAMINISTRATOR);
+        String token = this.controller.calculateAuthToken("192.168.0",Integer.toString(account.getRolesAsInt()),this.accountName);
+        
+        assertTrue(this.controller.authenticateToken(token,this.clientIp,AccountRole.ENTRYAMINISTRATOR,this.accountName));
+        assertTrue(this.controller.authenticateToken(token,this.clientIp,AccountRole.USER,this.accountName));
+        assertFalse(this.controller.authenticateToken(token,this.clientIp,AccountRole.USERADMINISTRATOR,"someOtherAccount"));
+        try{
+        this.controller.authenticateToken(token+"test",this.clientIp,AccountRole.ENTRYAMINISTRATOR,this.accountName);
+        fail("exception expected");
+        }catch (Exception e) {
+            // TODO: handle exception
+        }
+        this.controller.setMinuteOffset(0);
+        assertFalse(this.controller.authenticateToken(token,this.clientIp,AccountRole.ENTRYAMINISTRATOR,this.accountName));
+        
+    }
+
+    
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestAbstractFeedHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestAbstractFeedHandler.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestAbstractFeedHandler.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestAbstractFeedHandler.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,213 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gdata.servlet.handler;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.gdata.data.GDataAccount;
+import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.ServiceException;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.administration.AdminService;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.apache.lucene.gdata.server.registry.RegistryException;
+import org.apache.lucene.gdata.servlet.handler.AbstractFeedHandler.FeedHandlerException;
+import org.apache.lucene.gdata.utils.ProvidedServiceStub;
+import org.apache.lucene.gdata.utils.ServiceFactoryStub;
+import org.apache.lucene.gdata.utils.StorageStub;
+import org.easymock.MockControl;
+
+import com.google.gdata.util.ParseException;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class TestAbstractFeedHandler extends TestCase {
+    private MockControl requestMockControl; 
+    
+    private HttpServletRequest mockRequest = null; 
+    
+    private String accountName = "acc"; 
+    private MockControl adminServiceMockControl;
+    private AdminService adminService = null;
+    private ServiceFactoryStub stub;
+    private String serviceName = StorageStub.SERVICE_TYPE_RETURN;
+    private static File incomingFeed = new File("src/test/org/apache/lucene/gdata/server/registry/TestEntityBuilderIncomingFeed.xml");
+    BufferedReader reader;
+    static{
+        
+        try {
+            
+            GDataServerRegistry.getRegistry().registerComponent(StorageStub.class);
+            GDataServerRegistry.getRegistry().registerComponent(ServiceFactoryStub.class);
+        } catch (RegistryException e) {
+            
+            e.printStackTrace();
+        }
+    }
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        GDataServerRegistry.getRegistry().registerService(new ProvidedServiceStub());
+       this.requestMockControl = MockControl.createControl(HttpServletRequest.class);
+       this.adminServiceMockControl = MockControl.createControl(AdminService.class);
+       this.adminService = (AdminService)this.adminServiceMockControl.getMock();
+       this.mockRequest = (HttpServletRequest)this.requestMockControl.getMock();
+       this.stub = (ServiceFactoryStub)GDataServerRegistry.getRegistry().lookup(ServiceFactory.class,ComponentType.SERVICEFACTORY);
+       this.stub.setAdminService(this.adminService);
+       this.reader =  new BufferedReader(new FileReader(incomingFeed));
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.servlet.handler.AbstractFeedHandler.createFeedFromRequest(HttpServletRequest)'
+     */
+    public void testCreateFeedFromRequest() throws ParseException, IOException, FeedHandlerException {
+        
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getParameter("service"), this.serviceName);
+        this.requestMockControl.expectAndReturn(this.mockRequest.getReader(),this.reader);
+        this.requestMockControl.replay();
+        AbstractFeedHandler handler = new InsertFeedHandler();
+        try{
+        ServerBaseFeed feed = handler.createFeedFromRequest(this.mockRequest);
+        assertNotNull(feed.getId());
+        
+        }catch (Exception e) {
+            e.printStackTrace();
+            fail("unexpected exception -- "+e.getMessage());
+            
+        }
+        this.requestMockControl.verify();
+        this.requestMockControl.reset();
+        /*
+         * Test for not registered service
+         */
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getParameter("service"), "some other service");
+        this.requestMockControl.replay();
+         handler = new InsertFeedHandler();
+        try{
+        ServerBaseFeed feed = handler.createFeedFromRequest(this.mockRequest);
+        
+        fail(" exception expected");
+        }catch (FeedHandlerException e) {
+            e.printStackTrace();
+            assertEquals(HttpServletResponse.SC_NOT_FOUND,handler.getErrorCode());
+        }
+        this.requestMockControl.verify();
+        
+        this.requestMockControl.reset();
+        /*
+         * Test for IOException
+         */
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getParameter("service"), this.serviceName);
+        this.reader.close();
+        this.requestMockControl.expectAndReturn(this.mockRequest.getReader(),this.reader);
+        this.requestMockControl.replay();
+         handler = new InsertFeedHandler();
+        try{
+        ServerBaseFeed feed = handler.createFeedFromRequest(this.mockRequest);
+        
+        fail(" exception expected");
+        }catch (IOException e) {
+            e.printStackTrace();
+            assertEquals(HttpServletResponse.SC_BAD_REQUEST,handler.getErrorCode());
+        }
+        this.requestMockControl.verify();
+        
+        
+        
+        
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.servlet.handler.AbstractFeedHandler.createRequestedAccount(HttpServletRequest)'
+     */
+    public void testCreateRequestedAccount() throws IOException, ParseException, ServiceException {
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getParameter(AbstractFeedHandler.PARAMETER_ACCOUNT), this.accountName);
+        GDataAccount a = new GDataAccount();
+        a.setName("helloworld");
+        this.adminServiceMockControl.expectAndReturn(this.adminService.getAccount(this.accountName),a );
+        this.requestMockControl.replay();
+        this.adminServiceMockControl.replay();
+        AbstractFeedHandler handler = new InsertFeedHandler();
+        try{
+            
+            GDataAccount account = handler.createRequestedAccount(this.mockRequest);
+       
+        assertEquals(a,account);
+        
+        }catch (Exception e) {
+            e.printStackTrace();
+            fail("unexpected exception -- "+e.getMessage());
+            
+        }
+        this.requestMockControl.verify();
+        this.requestMockControl.reset();
+        this.adminServiceMockControl.verify();
+        this.adminServiceMockControl.reset();
+        
+        /*
+         *Test for service exception 
+         */
+        
+        this.requestMockControl.expectAndDefaultReturn(this.mockRequest 
+                .getParameter(AbstractFeedHandler.PARAMETER_ACCOUNT), this.accountName);
+        
+        a.setName("helloworld");
+        this.adminServiceMockControl.expectAndDefaultThrow(this.adminService.getAccount(this.accountName),new ServiceException() );
+        this.requestMockControl.replay();
+        this.adminServiceMockControl.replay();
+         handler = new InsertFeedHandler();
+        try{
+            
+            GDataAccount account = handler.createRequestedAccount(this.mockRequest);
+       
+            fail(" exception expected ");
+        
+        }catch (Exception e) {
+            e.printStackTrace();
+            assertEquals(HttpServletResponse.SC_BAD_REQUEST,handler.getErrorCode());
+            
+        }
+        this.requestMockControl.verify();
+        this.requestMockControl.reset();
+        this.adminServiceMockControl.verify();
+        this.adminServiceMockControl.reset();
+        
+        
+        
+        
+        
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestRequestAuthenticator.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestRequestAuthenticator.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestRequestAuthenticator.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/servlet/handler/TestRequestAuthenticator.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,79 @@
+package org.apache.lucene.gdata.servlet.handler;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.gdata.server.authentication.AuthenticationController;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.easymock.MockControl;
+
+public class TestRequestAuthenticator extends TestCase {
+    private MockControl requestMock;
+    private HttpServletRequest request;
+    private RequestAuthenticator authenticator;
+    private String tokenHeader;
+    private String token;
+    private Cookie authCookie;
+    
+    protected void setUp() throws Exception {
+    createMocks();
+    this.authenticator = new RequestAuthenticator();
+    this.token = "myToken";
+    this.tokenHeader = "GoogleLogin auth="+this.token;
+    this.authCookie = new Cookie("Auth",this.token);
+    }
+    protected void createMocks() {
+        this.requestMock = MockControl.createControl(HttpServletRequest.class);
+        this.request = (HttpServletRequest)this.requestMock.getMock();
+        
+    }
+    protected void tearDown() throws Exception {
+        GDataServerRegistry.getRegistry().destroy();
+    }
+    /*
+     * Test method for 'org.apache.lucene.gdata.servlet.handler.RequestAuthenticator.authenticateAccount(GDataRequest, AccountRole)'
+     */
+    public void testGetTokenFromRequest() {
+        // test token present
+        this.requestMock.expectAndDefaultReturn(this.request.getHeader(AuthenticationController.AUTHORIZATION_HEADER), this.tokenHeader);
+        this.requestMock.replay();
+        assertEquals(this.token,this.authenticator.getTokenFromRequest(this.request));
+        this.requestMock.verify();
+        this.requestMock.reset();
+        
+        // test token null / cookie present
+        this.requestMock.expectAndDefaultReturn(this.request.getHeader(AuthenticationController.AUTHORIZATION_HEADER), null);
+        this.requestMock.expectAndDefaultReturn(this.request.getCookies(), new Cookie[]{this.authCookie});
+        this.requestMock.replay();
+        assertEquals(this.token,this.authenticator.getTokenFromRequest(this.request));
+        this.requestMock.verify();
+        this.requestMock.reset();
+        
+        // test token null / cookie not present
+        this.requestMock.expectAndDefaultReturn(this.request.getHeader(AuthenticationController.AUTHORIZATION_HEADER), null);
+        this.requestMock.expectAndDefaultReturn(this.request.getCookies(), new Cookie[]{new Cookie("somekey","someValue")});
+        this.requestMock.replay();
+        assertNull(this.authenticator.getTokenFromRequest(this.request));
+        this.requestMock.verify();
+        this.requestMock.reset();
+        
+//      test token null / cookie array emtpy 
+        this.requestMock.expectAndDefaultReturn(this.request.getHeader(AuthenticationController.AUTHORIZATION_HEADER), null);
+        this.requestMock.expectAndDefaultReturn(this.request.getCookies(), new Cookie[]{});
+        this.requestMock.replay();
+        assertNull(this.authenticator.getTokenFromRequest(this.request));
+        this.requestMock.verify();
+        this.requestMock.reset();
+        
+//      test token null / cookie array null
+        this.requestMock.expectAndDefaultReturn(this.request.getHeader(AuthenticationController.AUTHORIZATION_HEADER), null);
+        this.requestMock.expectAndDefaultReturn(this.request.getCookies(), null);
+        this.requestMock.replay();
+        assertNull(this.authenticator.getTokenFromRequest(this.request));
+        this.requestMock.verify();
+        this.requestMock.reset();
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageModifierStub.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageModifierStub.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageModifierStub.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/StorageModifierStub.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,153 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.gdata.storage.lucenestorage;
+
+import java.io.IOException;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.gdata.storage.StorageException;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageBuffer;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageCoreController;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageModifier;
+import org.apache.lucene.gdata.utils.StorageControllerStub;
+import org.apache.lucene.index.IndexModifier;
+import org.apache.lucene.store.RAMDirectory;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class StorageModifierStub extends StorageModifier {
+
+    /**
+     * @param controller
+     * @param modifier
+     * @param buffer
+     * @param persitsFactor
+     * @param optimizeInterval
+     * @throws IOException 
+     * @throws StorageException 
+     */
+    public StorageModifierStub(StorageCoreController controller,
+            IndexModifier modifier, StorageBuffer buffer, int persitsFactor,
+            int optimizeInterval) throws IOException, StorageException {
+        
+        super(new StorageCoreController(), new IndexModifier(new RAMDirectory(),new StandardAnalyzer(),true), new StorageBuffer(1),1, 1);
+        
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#close()
+     */
+    @Override
+    protected void close() throws IOException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#createAccount(org.apache.lucene.gdata.storage.lucenestorage.StorageAccountWrapper)
+     */
+    @Override
+    public void createAccount(StorageAccountWrapper account) throws StorageException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#createFeed(org.apache.lucene.gdata.storage.lucenestorage.StorageFeedWrapper)
+     */
+    @Override
+    public void createFeed(StorageFeedWrapper wrapper) throws StorageException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#deleteAccount(java.lang.String)
+     */
+    @Override
+    public void deleteAccount(String accountName) throws StorageException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#deleteEntry(org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper)
+     */
+    @Override
+    public void deleteEntry(StorageEntryWrapper wrapper) throws StorageException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#deleteFeed(java.lang.String)
+     */
+    @Override
+    public void deleteFeed(String feedId) throws StorageException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#forceWrite()
+     */
+    @Override
+    protected void forceWrite() throws IOException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#insertEntry(org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper)
+     */
+    @Override
+    public void insertEntry(StorageEntryWrapper wrapper) throws StorageException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#updateAccount(org.apache.lucene.gdata.storage.lucenestorage.StorageAccountWrapper)
+     */
+    @Override
+    public void updateAccount(StorageAccountWrapper user) throws StorageException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#updateEntry(org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper)
+     */
+    @Override
+    public void updateEntry(StorageEntryWrapper wrapper) throws StorageException {
+        
+        
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.storage.lucenestorage.StorageModifier#updateFeed(org.apache.lucene.gdata.storage.lucenestorage.StorageFeedWrapper)
+     */
+    @Override
+    public void updateFeed(StorageFeedWrapper wrapper) throws StorageException {
+        
+        
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRecoverController.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRecoverController.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRecoverController.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRecoverController.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,105 @@
+package org.apache.lucene.gdata.storage.lucenestorage.recover;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.rmi.registry.Registry;
+
+import org.apache.lucene.gdata.data.ServerBaseEntry;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.apache.lucene.gdata.storage.StorageException;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageModifier;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageModifierStub;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;
+import org.apache.lucene.gdata.utils.ProvidedServiceStub;
+import org.easymock.MockControl;
+
+import com.google.gdata.data.DateTime;
+
+import junit.framework.TestCase;
+
+public class TestRecoverController extends TestCase {
+    private RecoverController writeController;
+    private RecoverController readController;
+    private File recDir = new File("./temp/");
+    private String feedId = "feedid";
+    private String entryId = "entryId";
+    
+    protected void setUp() throws Exception {
+        if(!this.recDir.exists())
+            this.recDir.mkdir();
+        GDataServerRegistry.getRegistry().registerService(new ProvidedServiceStub());
+        this.writeController = new RecoverController(this.recDir,false,false);
+        this.readController = new RecoverController(this.recDir,true,false);
+        
+        
+
+        
+    }
+
+    protected void tearDown() throws Exception {
+        
+        
+        
+        File[] files = this.recDir.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            files[i].delete();
+        }
+        this.recDir.delete();
+      GDataServerRegistry.getRegistry().destroy();
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.storage.lucenestorage.recover.RecoverController.storageModified(StorageEntryWrapper)'
+     */
+    public void testStorageModified() throws IOException, RecoverException {
+        this.writeController.initialize();
+        ServerBaseEntry entry = new ServerBaseEntry();
+        entry.setFeedId(this.feedId);
+        entry.setId(entryId);
+        entry.setUpdated(DateTime.now());
+        entry.setServiceConfig(new ProvidedServiceStub());
+        StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,StorageOperation.INSERT);
+        this.writeController.storageModified(wrapper);
+        assertEquals(1,this.recDir.listFiles().length);
+        this.writeController.destroy();
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.storage.lucenestorage.recover.RecoverController.recoverEntries(StorageModifier)'
+     */
+    public void testRecoverEntries() throws IOException, StorageException, RecoverException {
+        testStorageModified();
+        
+        int length = this.recDir.listFiles().length;
+        assertEquals(1,length);
+        
+        this.readController.initialize();
+        try{
+        this.readController.recoverEntries(new StorageModifierStub(null,null,null,0,0));
+        }catch (Exception e) {
+            fail("unexpected exception"+e.getMessage());
+        }
+        this.readController.destroy();
+        assertEquals(0,this.recDir.listFiles().length);
+        assertNotSame(length,this.recDir.listFiles().length);
+        createCorruptedFile();
+        this.readController.initialize();
+        try{
+        this.readController.recoverEntries(new StorageModifierStub(null,null,null,0,0));
+        }catch (Exception e) {
+            fail("unexpected exception"+e.getMessage());
+        }
+        this.readController.destroy();
+        assertEquals(1,this.recDir.listFiles().length);
+    }
+    
+    
+    private void createCorruptedFile() throws IOException{
+        FileWriter writer = new FileWriter(new File(this.recDir,"somefile.rec"));
+        writer.write("someString\nSomeOtherString");
+        writer.close();
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRecoverWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRecoverWriter.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRecoverWriter.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRecoverWriter.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,75 @@
+package org.apache.lucene.gdata.storage.lucenestorage.recover;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.gdata.data.ServerBaseEntry;
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;
+import org.apache.lucene.gdata.utils.ProvidedServiceStub;
+
+import com.google.gdata.data.DateTime;
+import com.google.gdata.data.Entry;
+import com.google.gdata.data.PlainTextConstruct;
+
+public class TestRecoverWriter extends TestCase {
+    private static final String ENTRYID = "myID";
+    private static final String TITLE = "title";
+    private static final String FEEDID = "myFeed";
+    
+    private static final Long TIMESTAMP = 132326657L;
+    private DateTime dateTime = new DateTime(TIMESTAMP,0);
+    String compareEntry = "I;"+FEEDID+";"+ENTRYID+";"+TIMESTAMP+";" +ProvidedServiceStub.SERVICE_NAME+";"+RecoverWriter.META_DATA_ENTRY_SEPARATOR+
+            "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom'><atom:id>"+ENTRYID+"</atom:id><atom:updated>"+this.dateTime.toString()+"</atom:updated><atom:title type='text'>" + TITLE+
+            "</atom:title></atom:entry>"+RecoverWriter.META_DATA_ENTRY_SEPARATOR+RecoverWriter.STORAGE_OPERATION_SEPARATOR+RecoverWriter.META_DATA_ENTRY_SEPARATOR;
+    String compareDelete = "D;"+FEEDID+";"+ENTRYID+";"+TIMESTAMP+";"+RecoverWriter.META_DATA_ENTRY_SEPARATOR+RecoverWriter.STORAGE_OPERATION_SEPARATOR+RecoverWriter.META_DATA_ENTRY_SEPARATOR;
+    StorageEntryWrapper wrapper;
+    StorageEntryWrapper deleteWrapper;
+
+    protected void setUp() throws Exception {
+        ServerBaseEntry entry = new ServerBaseEntry(new Entry());
+        entry.setId(ENTRYID);
+        
+        entry.setUpdated(new DateTime(TIMESTAMP,0));
+        entry.setTitle(new PlainTextConstruct(TITLE));
+        ProvidedService config = new ProvidedServiceStub();
+        entry.setFeedId(FEEDID);
+        entry.setServiceConfig(config);
+        this.wrapper = new StorageEntryWrapper(entry,StorageOperation.INSERT);
+        this.deleteWrapper = new StorageEntryWrapper(entry,StorageOperation.DELETE);
+        
+        
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.storage.lucenestorage.recover.RecoverWriter.writeEntry(StorageEntryWrapper, Writer)'
+     */
+    public void testWriteEntry() throws IOException {
+        RecoverWriter wr = new RecoverWriter();
+        StringWriter writer = new StringWriter();
+        wr.writeEntry(this.wrapper,writer);
+        assertEquals(compareEntry,writer.toString());
+        writer.close();
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.storage.lucenestorage.recover.RecoverWriter.writeDelete(String, String, Writer)'
+     */
+    public void testWriteDelete() throws IOException {
+        RecoverWriter wr = new RecoverWriter();
+        StringWriter writer = new StringWriter();
+        wr.writeEntry(this.deleteWrapper,writer);
+        System.out.println(writer.toString());
+        assertEquals(compareDelete,writer.toString());
+        writer.close();
+    }
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRevocerReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRevocerReader.java?rev=417565&view=auto
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRevocerReader.java (added)
+++ lucene/java/trunk/contrib/gdata-server/src/test/org/apache/lucene/gdata/storage/lucenestorage/recover/TestRevocerReader.java Tue Jun 27 12:31:20 2006
@@ -0,0 +1,82 @@
+package org.apache.lucene.gdata.storage.lucenestorage.recover;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.apache.lucene.gdata.server.registry.ProvidedService;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper;
+import org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper.StorageOperation;
+import org.apache.lucene.gdata.utils.ProvidedServiceStub;
+
+import com.google.gdata.data.DateTime;
+
+public class TestRevocerReader extends TestCase {
+    private RecoverReader recReader;
+    private static final String feedId = "myFeed";
+    private static final String entryId = "myID";
+    private static final Long timestamp = System.currentTimeMillis();
+    private String title = "myTitle";
+    private static final DateTime dateTime = DateTime.now();
+    private String delete = "D;"+feedId+";"+entryId+";"+timestamp+";\n###########\n";
+    private String insert = "I;"+feedId+";"+entryId+";"+timestamp+";" +ProvidedServiceStub.SERVICE_NAME+";"+RecoverWriter.META_DATA_ENTRY_SEPARATOR+
+    "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom'><atom:id>"+entryId+"</atom:id><atom:updated>"+dateTime.toString()+"</atom:updated><atom:title type='text'>" + this.title+
+    "</atom:title></atom:entry>"+RecoverWriter.META_DATA_ENTRY_SEPARATOR+RecoverWriter.STORAGE_OPERATION_SEPARATOR+RecoverWriter.META_DATA_ENTRY_SEPARATOR;
+    protected void setUp() throws Exception {
+        this.recReader = new RecoverReader();
+        GDataServerRegistry.getRegistry().registerService(new ProvidedServiceStub());
+        
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'org.apache.lucene.gdata.storage.lucenestorage.recover.RecoverReader.getNonDeleteEntries(Reader)'
+     */
+    public void testRecoverDeletedEntries() throws IOException {
+        StringReader reader = new StringReader(this.delete);
+        assertNotNull(this.recReader.recoverEntries(new BufferedReader(reader)));
+        reader = new StringReader(this.delete);
+        List<StorageEntryWrapper> recList = this.recReader.recoverEntries(new BufferedReader(reader));
+        assertEquals(1,recList.size());
+        StorageEntryWrapper delWrapper = recList.get(0);
+        assertEquals(StorageOperation.DELETE,delWrapper.getOperation());
+        assertEquals(feedId,delWrapper.getFeedId());
+        assertEquals(entryId,delWrapper.getEntryId());
+        
+    }
+    public void testRecoverInsertedEntries() throws IOException {
+        
+        StringReader reader = new StringReader(this.insert);
+        List<StorageEntryWrapper> recList = this.recReader.recoverEntries(new BufferedReader(reader));
+        assertEquals(1,recList.size());
+        StorageEntryWrapper insWrapper = recList.get(0);
+        assertEquals(StorageOperation.INSERT,insWrapper.getOperation());
+        assertEquals(feedId,insWrapper.getFeedId());
+        assertEquals(entryId,insWrapper.getEntryId());
+        assertEquals(dateTime,insWrapper.getEntry().getUpdated());
+        assertEquals(this.title,insWrapper.getEntry().getTitle().getPlainText());
+        
+        
+    }
+    
+    public void testRecoverReader()throws IOException{
+        StringReader reader = new StringReader(this.insert+this.delete);
+        List<StorageEntryWrapper> recList = this.recReader.recoverEntries(new BufferedReader(reader));
+        assertEquals(2,recList.size());
+        assertEquals(StorageOperation.INSERT,recList.get(0).getOperation());
+        assertEquals(StorageOperation.DELETE,recList.get(1).getOperation());
+        
+        reader = new StringReader("some corrupted\n###########\n"+this.insert);
+        recList = this.recReader.recoverEntries(new BufferedReader(reader));
+        assertEquals(1,recList.size());
+        assertEquals(StorageOperation.INSERT,recList.get(0).getOperation());
+        
+    }
+}



Mime
View raw message