abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calav...@apache.org
Subject svn commit: r680749 [2/2] - in /incubator/abdera/java/trunk/extensions/opensearch: ./ src/main/java/org/apache/abdera/ext/opensearch/ src/main/java/org/apache/abdera/ext/opensearch/model/ src/main/java/org/apache/abdera/ext/opensearch/server/ src/main/...
Date Tue, 29 Jul 2008 16:07:36 GMT
Modified: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/OpenSearchTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/OpenSearchTest.java?rev=680749&r1=680748&r2=680749&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/OpenSearchTest.java (original)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/OpenSearchTest.java Tue Jul 29 09:07:28 2008
@@ -1,53 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  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.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-package org.apache.abdera.test.ext.opensearch;
-
-import java.io.InputStream;
-
-import junit.framework.Assert;
-
-import org.apache.abdera.Abdera;
-import org.apache.abdera.ext.opensearch.IntegerElement;
-import org.apache.abdera.ext.opensearch.OpenSearchConstants;
-import org.apache.abdera.model.Document;
-import org.apache.abdera.model.Element;
-import org.apache.abdera.parser.Parser;
-import org.junit.Test;
-
-public class OpenSearchTest extends Assert {
-  @Test
-  public void testBasics() throws Exception
-  {
-    Parser parser = Abdera.getNewParser();
-    
-    InputStream stream = OpenSearchTest.class.getResourceAsStream("/opensearch.xml");
-    Document<Element> doc = parser.parse(stream);
-
-    IntegerElement tr = doc.getRoot().getFirstChild(OpenSearchConstants.TOTAL_RESULTS_V10);
-    assertNotNull(tr);
-    assertEquals(tr.getValue(), 47);
-
-    IntegerElement ipp = doc.getRoot().getFirstChild(OpenSearchConstants.ITEMS_PER_PAGE_V10);
-    assertNotNull(ipp);
-    assertEquals(ipp.getValue(), 1);
-
-    IntegerElement si = doc.getRoot().getFirstChild(OpenSearchConstants.START_INDEX_V10);
-    assertNotNull(si);
-    assertEquals(si.getValue(), 1);
-  }
-}

Modified: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/TestSuite.java?rev=680749&r1=680748&r2=680749&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/TestSuite.java (original)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/TestSuite.java Tue Jul 29 09:07:28 2008
@@ -1,30 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  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.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-package org.apache.abdera.test.ext.opensearch;
-
-import org.junit.internal.runners.TextListener;
-import org.junit.runner.JUnitCore;
-
-public class TestSuite  {
-  public static void main(String[] args) {
-    JUnitCore runner = new JUnitCore();
-    runner.addListener(new TextListener(System.out));
-    runner.run(
-      OpenSearchTest.class);
-  }
-}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/OpenSearchAtomTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/OpenSearchAtomTest.java?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/OpenSearchAtomTest.java (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/OpenSearchAtomTest.java Tue Jul 29 09:07:28 2008
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.ext.opensearch.model;
+
+import java.io.InputStream;
+
+import java.io.StringWriter;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.opensearch.OpenSearchConstants;
+import org.apache.abdera.ext.opensearch.model.IntegerElement;
+import org.apache.abdera.ext.opensearch.model.Query;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.parser.Parser;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLAssert;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+
+public class OpenSearchAtomTest extends XMLAssert {
+
+    private static final int TOTAL_RESULTS = 47;
+    private static final int START_INDEX = 1;
+    private static final int ITEMS_PER_PAGE = 1;
+    private static final String QUERY_TERMS = "some content";
+    
+    static {
+        Map<String, String> nsContext = new HashMap<String, String>();
+        nsContext.put(OpenSearchConstants.OS_PREFIX, OpenSearchConstants.OPENSEARCH_NS);
+        XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(nsContext));
+    }
+    
+    @Test
+    public void testAtomResponseCreation() throws Exception {
+        Feed feed = Abdera.getInstance().getFactory().newFeed();
+        
+        feed.setId("http://example.com/opensearch+example");
+        feed.setTitle("An OpenSearch Example");
+        feed.setUpdated(new Date());
+        
+        Query query = feed.addExtension(OpenSearchConstants.QUERY);
+        query.setRole(Query.Role.REQUEST);
+        query.setSearchTerms(QUERY_TERMS);
+        
+        IntegerElement totalResults = feed.addExtension(OpenSearchConstants.TOTAL_RESULTS);
+        totalResults.setValue(TOTAL_RESULTS);
+        IntegerElement itemsPerPage = feed.addExtension(OpenSearchConstants.ITEMS_PER_PAGE);
+        itemsPerPage.setValue(ITEMS_PER_PAGE);
+        IntegerElement startIndex = feed.addExtension(OpenSearchConstants.START_INDEX);
+        startIndex.setValue(START_INDEX);
+        
+        StringWriter writer = new StringWriter();
+        feed.writeTo(writer);
+        
+        String result = writer.toString();
+        
+        System.out.print(result);
+        
+        assertXpathEvaluatesTo(String.valueOf(TOTAL_RESULTS), "//os:totalResults", result);
+        assertXpathEvaluatesTo(String.valueOf(ITEMS_PER_PAGE), "//os:itemsPerPage", result);
+        assertXpathEvaluatesTo(String.valueOf(START_INDEX), "//os:startIndex", result);
+        assertXpathEvaluatesTo(Query.Role.REQUEST.toString().toLowerCase(), "//os:Query/@role", result);
+        assertXpathEvaluatesTo(QUERY_TERMS, "//os:Query/@searchTerms", result);
+    }
+    
+    @Test
+    public void testAtomResponseParsing() throws Exception {
+        Parser parser = Abdera.getNewParser();
+
+        InputStream stream = OpenSearchAtomTest.class.getResourceAsStream("/atomResponse.xml");
+        Document<Element> doc = parser.parse(stream);
+
+        IntegerElement tr = doc.getRoot().getFirstChild(OpenSearchConstants.TOTAL_RESULTS);
+        assertNotNull(tr);
+        assertEquals(47, tr.getValue());
+
+        IntegerElement ipp = doc.getRoot().getFirstChild(OpenSearchConstants.ITEMS_PER_PAGE);
+        assertNotNull(ipp);
+        assertEquals(1, ipp.getValue());
+
+        IntegerElement si = doc.getRoot().getFirstChild(OpenSearchConstants.START_INDEX);
+        assertNotNull(si);
+        assertEquals(1, si.getValue());
+        
+        Query q = doc.getRoot().getFirstChild(OpenSearchConstants.QUERY);
+        assertNotNull(q);
+        assertEquals(Query.Role.REQUEST, q.getRole());
+        assertEquals(QUERY_TERMS, q.getSearchTerms());
+    }
+}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/OpenSearchDescriptionTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/OpenSearchDescriptionTest.java?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/OpenSearchDescriptionTest.java (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/model/OpenSearchDescriptionTest.java Tue Jul 29 09:07:28 2008
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.ext.opensearch.model;
+
+
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.opensearch.OpenSearchConstants;
+import org.apache.abdera.ext.opensearch.model.OpenSearchDescription;
+import org.apache.abdera.ext.opensearch.model.Query;
+import org.apache.abdera.ext.opensearch.model.StringElement;
+import org.apache.abdera.ext.opensearch.model.Url;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.parser.Parser;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLAssert;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+
+public class OpenSearchDescriptionTest extends XMLAssert {
+    
+    private static final String DESCRIPTION = "This is a description";
+    private static final String SHORT_NAME = "This is a short name";
+    private static final String TAG1 = "FirstTag";
+    private static final String TAG2 = "SecondTag";
+    private static final String TAGS = TAG1 + " " + TAG2;
+    private static final String URL_TEMPLATE = "http://example.com/?q={searchTerms}";
+    private static final String URL_TYPE = "application/atom+xml";
+    private static final String QUERY_TERMS = "term1 term2";
+    
+    static {
+        Map<String, String> nsContext = new HashMap<String, String>();
+        nsContext.put(OpenSearchConstants.OS_PREFIX, OpenSearchConstants.OPENSEARCH_NS);
+        XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(nsContext));
+    }
+    
+    @Test
+    public void testOpenSearchDescriptionDocumentCreation() throws Exception {
+        OpenSearchDescription document = new OpenSearchDescription(Abdera.getInstance());
+        
+        document.setShortName(SHORT_NAME);
+        document.setDescription(DESCRIPTION);
+        document.setTags(TAG1, TAG2);
+        
+        Url url = new Url(Abdera.getInstance());
+        url.setType(URL_TYPE);
+        url.setTemplate(URL_TEMPLATE);
+        
+        Query query = new Query(Abdera.getInstance());
+        query.setRole(Query.Role.EXAMPLE);
+        query.setSearchTerms(QUERY_TERMS);
+        
+        document.addUrls(url);
+        document.addQueries(query);
+        
+        StringWriter writer = new StringWriter();
+        document.writeTo(writer);
+        
+        String result = writer.toString();
+        
+        System.out.print(result);
+        
+        assertXpathEvaluatesTo(SHORT_NAME, "/os:OpenSearchDescription/os:ShortName", result);
+        assertXpathEvaluatesTo(DESCRIPTION, "/os:OpenSearchDescription/os:Description", result);
+        assertXpathEvaluatesTo(TAGS, "/os:OpenSearchDescription/os:Tags", result);
+        assertXpathEvaluatesTo(URL_TYPE, "/os:OpenSearchDescription/os:Url/@type", result);
+        assertXpathEvaluatesTo(URL_TEMPLATE, "/os:OpenSearchDescription/os:Url/@template", result);
+        assertXpathEvaluatesTo(Query.Role.EXAMPLE.toString().toLowerCase(), "/os:OpenSearchDescription/os:Query/@role", result);
+        assertXpathEvaluatesTo(QUERY_TERMS, "/os:OpenSearchDescription/os:Query/@searchTerms", result);
+        assertXpathEvaluatesTo(new Integer(1).toString(), "/os:OpenSearchDescription/os:Url/@indexOffset", result);
+        assertXpathEvaluatesTo(new Integer(1).toString(), "/os:OpenSearchDescription/os:Url/@pageOffset", result);
+    }
+    
+    @Test
+    public void testOpenSearchDescriptionDocumentParsing() throws Exception {
+        Parser parser = Abdera.getNewParser();
+
+        InputStream stream = OpenSearchAtomTest.class.getResourceAsStream("/opensearchDescription.xml");
+        Document<Element> doc = parser.parse(stream);
+
+        StringElement shortName = doc.getRoot().getFirstChild(OpenSearchConstants.SHORT_NAME);
+        assertNotNull(shortName);
+        assertEquals(SHORT_NAME, shortName.getValue());
+
+        StringElement description = doc.getRoot().getFirstChild(OpenSearchConstants.DESCRIPTION);
+        assertNotNull(description);
+        assertEquals(DESCRIPTION, description.getValue());
+
+        StringElement tags = doc.getRoot().getFirstChild(OpenSearchConstants.TAGS);
+        assertNotNull(tags);
+        assertEquals(TAGS, tags.getValue());
+        
+        Query q = doc.getRoot().getFirstChild(OpenSearchConstants.QUERY);
+        assertNotNull(q);
+        assertEquals(Query.Role.EXAMPLE, q.getRole());
+        assertEquals(QUERY_TERMS, q.getSearchTerms());
+        
+        Url u = doc.getRoot().getFirstChild(OpenSearchConstants.URL);
+        assertNotNull(u);
+        assertEquals(URL_TYPE, u.getType());
+        assertEquals(URL_TEMPLATE, u.getTemplate());
+    }
+}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/AbstractOpenSearchServerTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/AbstractOpenSearchServerTest.java?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/AbstractOpenSearchServerTest.java (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/AbstractOpenSearchServerTest.java Tue Jul 29 09:07:28 2008
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.ext.opensearch.server;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.abdera.ext.opensearch.OpenSearchConstants;
+import org.apache.abdera.ext.opensearch.model.Query;
+import org.apache.abdera.ext.opensearch.server.OpenSearchInfo;
+import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchInfo;
+import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchQueryInfo;
+import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchUrlInfo;
+import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchUrlParameterInfo;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLAssert;
+import org.custommonkey.xmlunit.XMLUnit;
+
+public abstract class AbstractOpenSearchServerTest extends XMLAssert {
+
+    protected static final String DESCRIPTION = "This is a description";
+    protected static final String SHORT_NAME = "This is a short name";
+    protected static final String TAG1 = "FirstTag";
+    protected static final String TAG2 = "SecondTag";
+    protected static final String TAGS = TAG1 + " " + TAG2;
+    protected static final String SEARCH_PATH_1 = "/search1";
+    protected static final String SEARCH_PATH_2 = "/search2";
+    protected static final String TEMPLATE_PARAM_1_NAME = "q";
+    protected static final String TEMPLATE_PARAM_1_VALUE = "searchTerms";
+    protected static final String TEMPLATE_PARAM_2_NAME = "c";
+    protected static final String TEMPLATE_PARAM_2_VALUE = "count";
+    protected static final String QUERY_TERMS = "term1 term2";
+
+    static {
+        Map<String, String> nsContext = new HashMap<String, String>();
+        nsContext.put(OpenSearchConstants.OS_PREFIX, OpenSearchConstants.OPENSEARCH_NS);
+        XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(nsContext));
+    }
+
+    protected OpenSearchInfo createOpenSearchInfo() throws Exception {
+        SimpleOpenSearchInfo osInfo = new SimpleOpenSearchInfo();
+        SimpleOpenSearchQueryInfo osQueryInfo = new SimpleOpenSearchQueryInfo();
+        SimpleOpenSearchUrlInfo osUrlInfo1 = new SimpleOpenSearchUrlInfo();
+        SimpleOpenSearchUrlInfo osUrlInfo2 = new SimpleOpenSearchUrlInfo();
+        SimpleOpenSearchUrlParameterInfo osParamInfo1 = new SimpleOpenSearchUrlParameterInfo();
+        SimpleOpenSearchUrlParameterInfo osParamInfo2 = new SimpleOpenSearchUrlParameterInfo();
+        
+        osInfo.setShortName(SHORT_NAME);
+        osInfo.setDescription(DESCRIPTION);
+        osInfo.setTags(TAG1, TAG2);
+        
+        osQueryInfo.setRole(Query.Role.EXAMPLE);
+        osQueryInfo.setSearchTerms(QUERY_TERMS);
+        
+        osInfo.setQueries(osQueryInfo);
+        
+        osUrlInfo1.setSearchPath(SEARCH_PATH_1);
+        osUrlInfo2.setSearchPath(SEARCH_PATH_2);
+        
+        osParamInfo1.setName(TEMPLATE_PARAM_1_NAME);
+        osParamInfo1.setValue(TEMPLATE_PARAM_1_VALUE);
+        
+        osParamInfo2.setName(TEMPLATE_PARAM_2_NAME);
+        osParamInfo2.setValue(TEMPLATE_PARAM_2_VALUE);
+        osParamInfo2.setOptional(true);
+        
+        osUrlInfo1.setSearchParameters(osParamInfo1, osParamInfo2);
+        osUrlInfo2.setSearchParameters(osParamInfo1, osParamInfo2);
+        
+        osInfo.setUrls(osUrlInfo1, osUrlInfo2);
+        
+        return osInfo;
+    }
+}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/JettyServer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/JettyServer.java?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/JettyServer.java (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/JettyServer.java Tue Jul 29 09:07:28 2008
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.ext.opensearch.server;
+
+import org.apache.abdera.protocol.server.Provider;
+import org.apache.abdera.protocol.server.servlet.AbderaServlet;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+
+public class JettyServer {
+
+    public static final int DEFAULT_PORT = 9002;
+    private final int port;
+    private Server server;
+
+    public JettyServer() {
+        this(DEFAULT_PORT);
+    }
+
+    public JettyServer(int port) {
+        this.port = port;
+    }
+
+    public void start(final Provider myProvider) throws Exception {
+        server = new Server(port);
+        Context context = new Context(server, "/", Context.SESSIONS);
+        ServletHolder servletHolder = new ServletHolder(new AbderaServlet() {
+
+            protected Provider createProvider() {
+                myProvider.init(this.getAbdera(), this.getProperties(this.getServletConfig()));
+                return myProvider;
+            }
+        });
+        context.addServlet(servletHolder, "/*");
+        server.start();
+    }
+
+    public void stop() throws Exception {
+        server.stop();
+    }
+}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/AbstractOpenSearchUrlAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/AbstractOpenSearchUrlAdapterTest.java?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/AbstractOpenSearchUrlAdapterTest.java (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/AbstractOpenSearchUrlAdapterTest.java Tue Jul 29 09:07:28 2008
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.ext.opensearch.server.impl;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.apache.abdera.ext.opensearch.OpenSearchConstants;
+import org.apache.abdera.ext.opensearch.model.IntegerElement;
+import org.apache.abdera.ext.opensearch.server.OpenSearchInfo;
+import org.apache.abdera.ext.opensearch.server.impl.AbstractOpenSearchUrlAdapter;
+import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchUrlInfo;
+import org.apache.abdera.ext.opensearch.server.processors.OpenSearchTargetTypes;
+import org.apache.abdera.ext.opensearch.server.processors.OpenSearchUrlRequestProcessor;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Person;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.RequestProcessor;
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
+import org.apache.abdera.protocol.server.impl.DefaultProvider;
+import org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager;
+import org.apache.abdera.protocol.server.impl.RouteManager;
+import org.apache.abdera.test.ext.opensearch.server.AbstractOpenSearchServerTest;
+import org.apache.abdera.test.ext.opensearch.server.JettyServer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AbstractOpenSearchUrlAdapterTest extends AbstractOpenSearchServerTest {
+    
+    private JettyServer server = new JettyServer();
+    private OpenSearchInfo osInfo;
+    private OpenSearchUrlRequestProcessor osUrlProcessor;
+    
+    @Before
+    public void setUp() throws Exception {
+        this.osInfo = this.createOpenSearchInfo();
+        ((SimpleOpenSearchUrlInfo) osInfo.getUrls()[0]).setOpenSearchUrlAdapter(new TestingOpenSearchUrlAdapter());
+        
+        this.osUrlProcessor = new OpenSearchUrlRequestProcessor();
+        this.osUrlProcessor.setOpenSearchInfo(this.osInfo);
+
+        Map<TargetType, RequestProcessor> processors = new HashMap<TargetType, RequestProcessor>();
+        processors.put(OpenSearchTargetTypes.OPENSEARCH_URL, osUrlProcessor);
+
+        DefaultWorkspaceManager wsManager = new DefaultWorkspaceManager();
+        wsManager.setWorkspaces(new LinkedList<WorkspaceInfo>());
+
+        RouteManager routeManager = new RouteManager();
+        routeManager.addRoute("service", "/", TargetType.TYPE_SERVICE)
+                .addRoute("feed", "/atom/:collection", TargetType.TYPE_COLLECTION)
+                .addRoute("entry", "/atom/:collection/:entry", TargetType.TYPE_ENTRY)
+                .addRoute("categories", "/atom/:collection/:entry;categories", TargetType.TYPE_CATEGORIES)
+                .addRoute("osSearch1", "/search1", OpenSearchTargetTypes.OPENSEARCH_URL);
+
+        DefaultProvider provider = new DefaultProvider("/");
+        provider.setWorkspaceManager(wsManager);
+        provider.setTargetResolver(routeManager);
+        provider.setTargetBuilder(routeManager);
+        provider.addRequestProcessors(processors);
+
+        this.server.start(provider);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        this.server.stop();
+    }
+    
+    @Test
+    public void testOpenSearchFeedResponse() throws Exception {
+        AbderaClient client = new AbderaClient();
+        ClientResponse response = client.get("http://localhost:9002/search1?q=test1&c=1");
+        assertEquals(200, response.getStatus());
+        
+        Document<Feed> feedDoc = response.getDocument();
+        Feed feed = feedDoc.getRoot();
+        assertEquals(TestingOpenSearchUrlAdapter.OS_FEED_ID, feed.getId().toString());
+        assertEquals(TestingOpenSearchUrlAdapter.OS_FEED_TITLE, feed.getTitle());
+        assertEquals(TestingOpenSearchUrlAdapter.OS_FEED_AUTHOR, feed.getAuthor().getName());
+        assertEquals(2, ((IntegerElement) feed.getExtension(OpenSearchConstants.TOTAL_RESULTS)).getValue());
+        assertEquals(2, feed.getEntries().size());
+        assertNotNull(feed.getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_ID));
+        assertNotNull(feed.getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_ID));
+        assertEquals(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_TITLE, feed.getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_ID).getTitle());
+        assertEquals(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_DESC, feed.getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_1_ID).getContent());
+        assertEquals(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_TITLE, feed.getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_ID).getTitle());
+        assertEquals(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_DESC, feed.getEntry(TestingOpenSearchUrlAdapter.SEARCH_RESULT_2_ID).getContent());
+    }
+    
+    private class TestingOpenSearchUrlAdapter extends AbstractOpenSearchUrlAdapter<SearchResult> {
+        
+        public static final String OS_FEED_AUTHOR = "Sergio Bossa";
+        public static final String OS_FEED_ID = "http://www.acme.org/feed/id";
+        public static final String OS_FEED_TITLE = "Feed Title";
+        public static final String SEARCH_RESULT_1_DESC = "Search Result 1 description";
+        public static final String SEARCH_RESULT_1_ID = "urn:1";
+        public static final String SEARCH_RESULT_1_TITLE = "Search Result 1 title";
+        public static final String SEARCH_RESULT_2_DESC = "Search Result 2 description";
+        public static final String SEARCH_RESULT_2_ID = "urn:2";
+        public static final String SEARCH_RESULT_2_TITLE = "Search Result 2 title";
+
+        protected String getOpenSearchFeedId(RequestContext request) {
+            return OS_FEED_ID;
+        }
+
+        protected String getOpenSearchFeedTitle(RequestContext request) {
+            return OS_FEED_TITLE;
+        }
+
+        protected Person getOpenSearchFeedAuthor(RequestContext request) {
+            Person p = request.getAbdera().getFactory().newAuthor();
+            p.setName(OS_FEED_AUTHOR);
+            return p;
+        }
+
+        protected Date getOpenSearchFeedUpdatedDate(RequestContext request) {
+            return new Date();
+        }
+
+        protected List<SearchResult> doSearch(RequestContext request, Map<String, String> parameters) {
+            List<SearchResult> result = new LinkedList<SearchResult>();
+            SearchResult sr1 = new SearchResult(SEARCH_RESULT_1_ID, SEARCH_RESULT_1_TITLE, SEARCH_RESULT_1_DESC);
+            SearchResult sr2 = new SearchResult(SEARCH_RESULT_2_ID, SEARCH_RESULT_2_TITLE, SEARCH_RESULT_2_DESC);
+            result.add(sr1);
+            result.add(sr2);
+            return result;
+        }
+
+        protected void fillEntry(Entry entry, SearchResult entity) {
+            entry.setId(entity.getId());
+            entry.setTitle(entity.getTitle());
+            entry.setContent(entity.getDescription());
+        }
+    }
+    
+    private class SearchResult {
+        
+        private String id;
+        private String title;
+        private String description;
+
+        public SearchResult(String id, String title, String description) {
+            this.id = id;
+            this.title = title;
+            this.description = description;
+        }
+        
+        public String getTitle() {
+            return this.title;
+        }
+
+        public void setTitle(String title) {
+            this.title = title;
+        }
+
+        public String getDescription() {
+            return this.description;
+        }
+
+        public void setDescription(String description) {
+            this.description = description;
+        }
+
+        public String getId() {
+            return this.id;
+        }
+
+        public void setId(String id) {
+            this.id = id;
+        }
+    }
+}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/SimpleOpenSearchInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/SimpleOpenSearchInfoTest.java?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/SimpleOpenSearchInfoTest.java (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/impl/SimpleOpenSearchInfoTest.java Tue Jul 29 09:07:28 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.ext.opensearch.server.impl;
+
+import java.io.StringWriter;
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.opensearch.model.OpenSearchDescription;
+import org.apache.abdera.ext.opensearch.model.Query;
+import org.apache.abdera.ext.opensearch.server.OpenSearchInfo;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.test.ext.opensearch.server.AbstractOpenSearchServerTest;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.*;
+
+public class SimpleOpenSearchInfoTest extends AbstractOpenSearchServerTest {
+
+    private OpenSearchInfo osInfo;
+    
+    @Before
+    public void setUp() throws Exception {
+        this.osInfo = this.createOpenSearchInfo();
+    }
+    
+    @Test
+    public void testOpenSearchDescriptionCreationFromOpenSearchInfo() throws Exception {
+        RequestContext requestMock = createMock(RequestContext.class);
+        expect(requestMock.getAbdera()).andReturn(Abdera.getInstance()).anyTimes();
+        expect(requestMock.getBaseUri()).andReturn(new IRI("http://www.acme.org/")).anyTimes();
+        
+        replay(requestMock);
+        
+        OpenSearchDescription description = this.osInfo.asOpenSearchDescriptionElement(requestMock);
+        StringWriter writer = new StringWriter();
+        description.writeTo(writer);
+        
+        String result = writer.toString();
+        System.out.print(result);
+        
+        assertXpathEvaluatesTo(SHORT_NAME, "/os:OpenSearchDescription/os:ShortName", result);
+        assertXpathEvaluatesTo(DESCRIPTION, "/os:OpenSearchDescription/os:Description", result);
+        assertXpathEvaluatesTo(TAGS, "/os:OpenSearchDescription/os:Tags", result);
+        assertXpathEvaluatesTo(Query.Role.EXAMPLE.toString().toLowerCase(), "/os:OpenSearchDescription/os:Query/@role", result);
+        assertXpathEvaluatesTo(QUERY_TERMS, "/os:OpenSearchDescription/os:Query/@searchTerms", result);
+        assertXpathEvaluatesTo("application/atom+xml", "/os:OpenSearchDescription/os:Url[1]/@type", result);
+        assertXpathEvaluatesTo("http://www.acme.org/search1?q={searchTerms}&c={count?}", "/os:OpenSearchDescription/os:Url[1]/@template", result);
+        assertXpathEvaluatesTo("application/atom+xml", "/os:OpenSearchDescription/os:Url[2]/@type", result);
+        assertXpathEvaluatesTo("http://www.acme.org/search2?q={searchTerms}&c={count?}", "/os:OpenSearchDescription/os:Url[2]/@template", result);
+    }
+}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchDescriptionRequestProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchDescriptionRequestProcessorTest.java?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchDescriptionRequestProcessorTest.java (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchDescriptionRequestProcessorTest.java Tue Jul 29 09:07:28 2008
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.ext.opensearch.server.processors;
+
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import org.apache.abdera.ext.opensearch.OpenSearchConstants;
+import org.apache.abdera.ext.opensearch.model.Query;
+import org.apache.abdera.ext.opensearch.server.OpenSearchInfo;
+import org.apache.abdera.ext.opensearch.server.processors.OpenSearchDescriptionRequestProcessor;
+import org.apache.abdera.ext.opensearch.server.processors.OpenSearchTargetTypes;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.protocol.Response.ResponseType;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.server.RequestProcessor;
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
+import org.apache.abdera.protocol.server.impl.DefaultProvider;
+import org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager;
+import org.apache.abdera.protocol.server.impl.RouteManager;
+import org.apache.abdera.test.ext.opensearch.server.AbstractOpenSearchServerTest;
+import org.apache.abdera.test.ext.opensearch.server.JettyServer;
+import org.apache.abdera.util.MimeTypeHelper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OpenSearchDescriptionRequestProcessorTest extends AbstractOpenSearchServerTest {
+
+    private JettyServer server = new JettyServer();
+    private OpenSearchInfo osInfo;
+    private OpenSearchDescriptionRequestProcessor osRequestProcessor;
+
+    @Before
+    public void setUp() throws Exception {
+        this.osInfo = this.createOpenSearchInfo();
+        this.osRequestProcessor = new OpenSearchDescriptionRequestProcessor();
+        this.osRequestProcessor.setOpenSearchInfo(osInfo);
+
+        Map<TargetType, RequestProcessor> processors = new HashMap<TargetType, RequestProcessor>();
+        processors.put(OpenSearchTargetTypes.OPENSEARCH_DESCRIPTION, osRequestProcessor);
+
+        DefaultWorkspaceManager wsManager = new DefaultWorkspaceManager();
+        wsManager.setWorkspaces(new LinkedList<WorkspaceInfo>());
+
+        RouteManager routeManager = new RouteManager();
+        routeManager.addRoute("service", "/", TargetType.TYPE_SERVICE)
+                .addRoute("feed", "/atom/:collection", TargetType.TYPE_COLLECTION)
+                .addRoute("entry", "/atom/:collection/:entry", TargetType.TYPE_ENTRY)
+                .addRoute("categories", "/atom/:collection/:entry;categories", TargetType.TYPE_CATEGORIES)
+                .addRoute("osDescription", "/search", OpenSearchTargetTypes.OPENSEARCH_DESCRIPTION);
+
+        DefaultProvider provider = new DefaultProvider("/");
+        provider.setWorkspaceManager(wsManager);
+        provider.setTargetResolver(routeManager);
+        provider.setTargetBuilder(routeManager);
+        provider.addRequestProcessors(processors);
+
+        this.server.start(provider);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        this.server.stop();
+    }
+
+    @Test
+    public void testOpenSearchDescriptionRequestProcessorOutput() throws Exception {
+        AbderaClient client = new AbderaClient();
+        ClientResponse resp = client.get("http://localhost:9002/search");
+
+        assertNotNull(resp);
+        assertEquals(ResponseType.SUCCESS, resp.getType());
+        assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), OpenSearchConstants.OPENSEARCH_DESCRIPTION_CONTENT_TYPE));
+
+        Document doc = resp.getDocument();
+        StringWriter writer = new StringWriter();
+        doc.writeTo(writer);
+
+        String result = writer.toString();
+        System.out.println(result);
+
+        assertXpathEvaluatesTo(SHORT_NAME, "/os:OpenSearchDescription/os:ShortName", result);
+        assertXpathEvaluatesTo(DESCRIPTION, "/os:OpenSearchDescription/os:Description", result);
+        assertXpathEvaluatesTo(TAGS, "/os:OpenSearchDescription/os:Tags", result);
+        assertXpathEvaluatesTo(Query.Role.EXAMPLE.toString().toLowerCase(), "/os:OpenSearchDescription/os:Query/@role", result);
+        assertXpathEvaluatesTo(QUERY_TERMS, "/os:OpenSearchDescription/os:Query/@searchTerms", result);
+        assertXpathEvaluatesTo("application/atom+xml", "/os:OpenSearchDescription/os:Url[1]/@type", result);
+        assertXpathEvaluatesTo("http://localhost:9002/search1?q={searchTerms}&c={count?}", "/os:OpenSearchDescription/os:Url[1]/@template", result);
+        assertXpathEvaluatesTo("application/atom+xml", "/os:OpenSearchDescription/os:Url[2]/@type", result);
+        assertXpathEvaluatesTo("http://localhost:9002/search2?q={searchTerms}&c={count?}", "/os:OpenSearchDescription/os:Url[2]/@template", result);
+    }
+}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchUrlRequestProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchUrlRequestProcessorTest.java?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchUrlRequestProcessorTest.java (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/java/org/apache/abdera/test/ext/opensearch/server/processors/OpenSearchUrlRequestProcessorTest.java Tue Jul 29 09:07:28 2008
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera.test.ext.opensearch.server.processors;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import org.apache.abdera.ext.opensearch.server.OpenSearchInfo;
+import org.apache.abdera.ext.opensearch.server.OpenSearchUrlAdapter;
+import org.apache.abdera.ext.opensearch.server.impl.SimpleOpenSearchUrlInfo;
+import org.apache.abdera.ext.opensearch.server.processors.OpenSearchTargetTypes;
+import org.apache.abdera.ext.opensearch.server.processors.OpenSearchUrlRequestProcessor;
+import org.apache.abdera.protocol.client.AbderaClient;
+import org.apache.abdera.protocol.client.ClientResponse;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.RequestProcessor;
+import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
+import org.apache.abdera.protocol.server.context.SimpleResponseContext;
+import org.apache.abdera.protocol.server.impl.DefaultProvider;
+import org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager;
+import org.apache.abdera.protocol.server.impl.RouteManager;
+import org.apache.abdera.test.ext.opensearch.server.AbstractOpenSearchServerTest;
+import org.apache.abdera.test.ext.opensearch.server.JettyServer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OpenSearchUrlRequestProcessorTest extends AbstractOpenSearchServerTest {
+
+    private JettyServer server = new JettyServer();
+    private OpenSearchInfo osInfo;
+    private OpenSearchUrlRequestProcessor osUrlProcessor;
+
+    @Before
+    public void setUp() throws Exception {
+        this.osInfo = this.createOpenSearchInfo();
+        ((SimpleOpenSearchUrlInfo) osInfo.getUrls()[0]).setOpenSearchUrlAdapter(new TestingOpenSearchUrlAdapter1());
+        ((SimpleOpenSearchUrlInfo) osInfo.getUrls()[1]).setOpenSearchUrlAdapter(new TestingOpenSearchUrlAdapter2());
+        
+        this.osUrlProcessor = new OpenSearchUrlRequestProcessor();
+        this.osUrlProcessor.setOpenSearchInfo(this.osInfo);
+
+        Map<TargetType, RequestProcessor> processors = new HashMap<TargetType, RequestProcessor>();
+        processors.put(OpenSearchTargetTypes.OPENSEARCH_URL, osUrlProcessor);
+
+        DefaultWorkspaceManager wsManager = new DefaultWorkspaceManager();
+        wsManager.setWorkspaces(new LinkedList<WorkspaceInfo>());
+
+        RouteManager routeManager = new RouteManager();
+        routeManager.addRoute("service", "/", TargetType.TYPE_SERVICE)
+                .addRoute("feed", "/atom/:collection", TargetType.TYPE_COLLECTION)
+                .addRoute("entry", "/atom/:collection/:entry", TargetType.TYPE_ENTRY)
+                .addRoute("categories", "/atom/:collection/:entry;categories", TargetType.TYPE_CATEGORIES)
+                .addRoute("osSearch1", "/search1", OpenSearchTargetTypes.OPENSEARCH_URL)
+                .addRoute("osSearch2", "/search2", OpenSearchTargetTypes.OPENSEARCH_URL)
+                .addRoute("osSearch3", "/search3", OpenSearchTargetTypes.OPENSEARCH_URL);
+
+        DefaultProvider provider = new DefaultProvider("/");
+        provider.setWorkspaceManager(wsManager);
+        provider.setTargetResolver(routeManager);
+        provider.setTargetBuilder(routeManager);
+        provider.addRequestProcessors(processors);
+
+        this.server.start(provider);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        this.server.stop();
+    }
+
+    @Test
+    public void testProcessSuccessfully() throws Exception {
+        AbderaClient client = new AbderaClient();
+        ClientResponse response = null;
+        // Test with first adapter:
+        response = client.get("http://localhost:9002/search1?q=test1&c=1");
+        assertEquals(200, response.getStatus());
+        // Test with second adapter:
+        client.get("http://localhost:9002/search2?q=test2&c=1");
+        assertEquals(200, response.getStatus());
+    }
+    
+    @Test
+    public void testProcessFailsBecauseOfNoAdapterFound() throws Exception {
+        AbderaClient client = new AbderaClient();
+        ClientResponse response = null;
+        // No adapter found for this Open Search url:
+        response = client.get("http://localhost:9002/search3?q=test1&c=1");
+        assertEquals(404, response.getStatus());
+    }
+
+    private class TestingOpenSearchUrlAdapter1 implements OpenSearchUrlAdapter {
+
+        public ResponseContext search(RequestContext request, Map<String, String> parameters) {
+            assertEquals(SEARCH_PATH_1, request.getTargetPath().substring(0, request.getTargetPath().indexOf("?")));
+            assertNotNull(parameters.get(TEMPLATE_PARAM_1_NAME));
+            assertEquals("test1", parameters.get(TEMPLATE_PARAM_1_NAME));
+            assertNotNull(parameters.get(TEMPLATE_PARAM_2_NAME));
+            assertEquals("1", parameters.get(TEMPLATE_PARAM_2_NAME));
+            return new SimpleResponseContext() {
+
+                protected void writeEntity(Writer writer) throws IOException {
+                }
+
+                public boolean hasEntity() {
+                    return false;
+                }
+            }.setStatus(200);
+        }
+    }
+
+    private class TestingOpenSearchUrlAdapter2 implements OpenSearchUrlAdapter {
+
+        public ResponseContext search(RequestContext request, Map<String, String> parameters) {
+            assertEquals(SEARCH_PATH_2, request.getTargetPath().substring(0, request.getTargetPath().indexOf("?")));
+            assertNotNull(parameters.get(TEMPLATE_PARAM_1_NAME));
+            assertEquals("test2", parameters.get(TEMPLATE_PARAM_1_NAME));
+            assertNotNull(parameters.get(TEMPLATE_PARAM_2_NAME));
+            assertEquals("1", parameters.get(TEMPLATE_PARAM_2_NAME));
+            return new SimpleResponseContext() {
+
+                protected void writeEntity(Writer writer) throws IOException {
+                }
+
+                public boolean hasEntity() {
+                    return false;
+                }
+            }.setStatus(200);
+        }
+    }
+}

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/atomResponse.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/atomResponse.xml?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/atomResponse.xml (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/atomResponse.xml Tue Jul 29 09:07:28 2008
@@ -0,0 +1,22 @@
+<feed xmlns="http://www.w3.org/2005/Atom"
+      xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
+    <title>An OpenSearch Example</title>
+    <link href="http://example.com/opensearch+example"/>
+    <updated>1978-12-13T18:30:02Z</updated>
+    <author>
+        <name>Garrett Rooney</name>
+    </author>
+    <id>http://example.com/opensearch+example</id>
+    <opensearch:totalResults>47</opensearch:totalResults>
+    <opensearch:startIndex>1</opensearch:startIndex>
+    <opensearch:itemsPerPage>1</opensearch:itemsPerPage>
+    <opensearch:Query role="request" searchTerms="some content"/>
+    <entry>
+        <title>The entry's title</title>
+        <id>http://example.com/opensearch+example/entry</id>
+        <updated>2003-11-13T18:30:02Z</updated>
+        <content type="text">
+            Some content goes here...
+        </content>
+    </entry>
+</feed>

Modified: incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/opensearch.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/opensearch.xml?rev=680749&r1=680748&r2=680749&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/opensearch.xml (original)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/opensearch.xml Tue Jul 29 09:07:28 2008
@@ -1,21 +0,0 @@
-<feed xmlns="http://www.w3.org/2005/Atom"
-      xmlns:opensearch="http://a9.com/-/spec/opensearchrss/1.0/">
-  <title>An OpenSearch Example</title>
-  <link href="http://example.com/opensearch+example"/>
-  <updated>1978-12-13T18:30:02Z</updated>
-  <author>
-    <name>Garrett Rooney</name>
-  </author>
-  <id>http;//example.com/opensearch+example</id>
-  <opensearch:totalResults>47</opensearch:totalResults>
-  <opensearch:startIndex>1</opensearch:startIndex>
-  <opensearch:itemsPerPage>1</opensearch:itemsPerPage>
-  <entry>
-    <title>The entry's title</title>
-    <id>http://example.com/opensearch+example/entry</id>
-    <updated>2003-11-13T18:30:02Z</updated>
-    <content type="text">
-      Some content goes here...
-    </content>
-  </entry>
-</feed>

Added: incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/opensearchDescription.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/opensearchDescription.xml?rev=680749&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/opensearchDescription.xml (added)
+++ incubator/abdera/java/trunk/extensions/opensearch/src/test/resources/opensearchDescription.xml Tue Jul 29 09:07:28 2008
@@ -0,0 +1,7 @@
+<os:OpenSearchDescription xmlns:os="http://a9.com/-/spec/opensearch/1.1/">
+    <os:ShortName>This is a short name</os:ShortName>
+    <os:Description>This is a description</os:Description>
+    <os:Tags>FirstTag SecondTag</os:Tags>
+    <os:Url indexOffset="1" pageOffset="1" type="application/atom+xml" template="http://example.com/?q={searchTerms}"/>
+    <os:Query role="example" searchTerms="term1 term2" />
+</os:OpenSearchDescription>
\ No newline at end of file



Mime
View raw message