⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testgdatarequest.java

📁 lucene2.2.0版本
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/**  * 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;  import java.util.Enumeration;import java.util.HashMap;import java.util.Map;import java.util.StringTokenizer;import javax.servlet.http.HttpServletRequest;import junit.framework.TestCase;import org.apache.lucene.gdata.search.config.IndexSchema;import org.apache.lucene.gdata.search.config.IndexSchemaField;import org.apache.lucene.gdata.search.config.IndexSchemaField.ContentType;import org.apache.lucene.gdata.server.GDataRequest.GDataRequestType;import org.apache.lucene.gdata.server.GDataRequest.OutputFormat;import org.apache.lucene.gdata.server.registry.GDataServerRegistry;import org.apache.lucene.gdata.server.registry.ProvidedService;import org.apache.lucene.gdata.utils.ProvidedServiceStub;import org.apache.lucene.gdata.utils.StorageStub;import org.easymock.MockControl; /**  *   * @author Simon Willnauer  *   */ public class TestGDataRequest extends TestCase {     private HttpServletRequest request;      private MockControl control;      private GDataRequest feedRequest;         private Map parametermap = new HashMap();        @Override     protected void setUp() throws Exception {        try{            GDataServerRegistry.getRegistry().registerComponent(StorageStub.class,null);        }catch (Exception e) {        }        ProvidedService configurator = new ProvidedServiceStub();        GDataServerRegistry.getRegistry().registerService(configurator);        IndexSchema schema = new IndexSchema();        //must be set        schema.setDefaultSearchField("field");        schema.setIndexLocation("/tmp/");        schema.setName(ProvidedServiceStub.SERVICE_NAME);                ((ProvidedServiceStub)configurator).setIndexSchema(schema);                    this.control = MockControl.createControl(HttpServletRequest.class);         this.request = (HttpServletRequest) this.control.getMock();         this.feedRequest = new GDataRequest(this.request,GDataRequestType.GET);              }      protected void tearDown() throws Exception {         super.tearDown();         this.control.reset();         GDataServerRegistry.getRegistry().destroy();    }      public void testConstructor() {         try {             new GDataRequest(null,GDataRequestType.GET);             fail("IllegalArgumentException expected");         } catch (IllegalArgumentException e) {             //          }         try {             new GDataRequest(null,null);             fail("IllegalArgumentException expected");         } catch (IllegalArgumentException e) {             //          }         try {             new GDataRequest(this.request,null);             fail("IllegalArgumentException expected");         } catch (IllegalArgumentException e) {             //          }     }      public void testGetFeedId() throws GDataRequestException {         this.control.expectAndDefaultReturn(this.request.getParameterMap(),this.parametermap);        this.control.expectAndDefaultReturn(this.request.getPathInfo(),                 "/"+ProvidedServiceStub.SERVICE_NAME+"/feed/1/1");         this.control.expectAndDefaultReturn(this.request.getParameter("alt"),                 null);         this.control.replay();         this.feedRequest.initializeRequest();         assertEquals("feedID", this.feedRequest.getFeedId(), "feed");         this.control.reset();      }      public void testEmptyPathInfo() {         this.control.expectAndDefaultReturn(this.request.getPathInfo(), "/");         this.control.expectAndDefaultReturn(this.request.getParameter("alt"),                 null);         this.control.replay();         try {             this.feedRequest.initializeRequest();              fail("FeedRequestException expected");         } catch (GDataRequestException e) {             // expected         } catch (Exception e) {             fail("FeedRequestException expected");         }      }      public void testGetFeedIdWithoutEntry() throws GDataRequestException {         this.control.expectAndDefaultReturn(this.request.getParameterMap(),this.parametermap);        this.control                 .expectAndDefaultReturn(this.request.getPathInfo(), "/"+ProvidedServiceStub.SERVICE_NAME+"/feed");         this.control.expectAndDefaultReturn(this.request.getParameter("alt"),                 null);         this.control.replay();         this.feedRequest.initializeRequest();         assertEquals("feedID", this.feedRequest.getFeedId(), "feed");     }      public void testGetEntyId() throws GDataRequestException {         this.control.expectAndDefaultReturn(this.request.getParameterMap(),this.parametermap);        this.control.expectAndDefaultReturn(this.request.getPathInfo(),                 "/"+ProvidedServiceStub.SERVICE_NAME+"/feed/1/15");         this.control.expectAndDefaultReturn(this.request.getParameter("alt"),                 null);         this.control.replay();         this.feedRequest.initializeRequest();         assertEquals("entryid", this.feedRequest.getEntryId(), "1");         assertEquals("feedId", this.feedRequest.getFeedId(), "feed");         assertEquals("entryid", this.feedRequest.getEntryVersion(), "15");         this.control.reset();      }      public void testSetResponseFormatAtom() throws GDataRequestException {         this.control.expectAndDefaultReturn(this.request.getParameterMap(),this.parametermap);        this.control.expectAndDefaultReturn(this.request.getParameter("alt"),                 "atom");         this.control                 .expectAndDefaultReturn(this.request.getPathInfo(),"/"+ProvidedServiceStub.SERVICE_NAME+ "/feed");         this.control.replay();         this.feedRequest.initializeRequest();         assertEquals("ResponseFromat Atom", this.feedRequest                 .getRequestedResponseFormat(), OutputFormat.ATOM);         this.control.reset();     }      public void testSetResponseFormatRSS() throws GDataRequestException {         this.control.expectAndDefaultReturn(this.request.getParameterMap(),this.parametermap);        this.control.expectAndDefaultReturn(this.request.getParameter("alt"),                 "rss");         this.control                 .expectAndDefaultReturn(this.request.getPathInfo(), "/"+ProvidedServiceStub.SERVICE_NAME+"/feed");         this.control.replay();         this.feedRequest.initializeRequest();         assertEquals("ResponseFromat RSS", this.feedRequest                 .getRequestedResponseFormat(), OutputFormat.RSS);         this.control.reset();     }      public void testSetResponseFormatKeepAtom() throws GDataRequestException {         this.control.expectAndDefaultReturn(this.request.getParameterMap(),this.parametermap);        this.control.expectAndDefaultReturn(this.request.getParameter("alt"),                 "fooBar");         this.control                 .expectAndDefaultReturn(this.request.getPathInfo(), "/"+ProvidedServiceStub.SERVICE_NAME+"/feed");         this.control.replay();         this.feedRequest.initializeRequest();         assertEquals("ResponseFromat Atom", this.feedRequest                 .getRequestedResponseFormat(), OutputFormat.ATOM);         this.control.reset();     }      public void testSetResponseFormatNull() throws GDataRequestException {         this.control.expectAndDefaultReturn(this.request.getParameterMap(),this.parametermap);        this.control.expectAndDefaultReturn(this.request.getParameter("alt"),                 null);          this.control                 .expectAndDefaultReturn(this.request.getPathInfo(), "/"+ProvidedServiceStub.SERVICE_NAME+"/feed");         this.control.replay();         this.feedRequest.initializeRequest();         assertEquals("ResponseFromat Atom", this.feedRequest                 .getRequestedResponseFormat(), OutputFormat.ATOM);         this.control.reset();     }      public void testGetItemsPerPage() throws GDataRequestException {         this.control.expectAndReturn(this.request.getParameter("max-results"),                 null);         this.control.replay();         assertEquals("default value 25", 25, this.feedRequest.getItemsPerPage());         this.control.verify();         this.control.reset();          this.control.expectAndReturn(this.request.getParameter("max-results"),                 "24", 2);         this.control.replay();         assertEquals("24 results", 24, this.feedRequest.getItemsPerPage());         this.control.verify();         this.control.reset();                  this.control.expectAndReturn(this.request.getParameter("max-results"),                 "-1", 2);         this.control.replay(); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -