TestAbstractFeedHandlerpublic class TestAbstractFeedHandler extends TestCase
Fields Summary |
---|
private org.easymock.MockControl | requestMockControl | private HttpServletRequest | mockRequest | private String | accountName | private org.easymock.MockControl | adminServiceMockControl | private org.apache.lucene.gdata.server.administration.AdminService | adminService | private org.apache.lucene.gdata.utils.ServiceFactoryStub | stub | private String | serviceName | private static File | incomingFeed | BufferedReader | reader |
Methods Summary |
---|
protected void | setUp()
try {
GDataServerRegistry.getRegistry().registerComponent(StorageStub.class,null);
GDataServerRegistry.getRegistry().registerComponent(ServiceFactoryStub.class,null);
} catch (RegistryException e) {
e.printStackTrace();
}
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()
super.tearDown();
| public void | testCreateFeedFromRequest()
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();
| public void | testCreateRequestedAccount()
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(GDataResponse.BAD_REQUEST) );
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();
|
|