incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1431843 [7/10] - in /incubator/ambari/trunk: ./ ambari-agent/ ambari-agent/conf/unix/ ambari-agent/src/main/package/rpm/ ambari-agent/src/main/puppet/modules/configgenerator/manifests/ ambari-agent/src/main/puppet/modules/hdp-ganglia/manif...
Date Fri, 11 Jan 2013 03:02:41 GMT
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java?rev=1431843&r1=1431842&r2=1431843&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ClusterServiceTest.java Fri Jan 11 03:02:37 2013
@@ -20,219 +20,167 @@ package org.apache.ambari.server.api.ser
 
 import org.apache.ambari.server.api.handlers.RequestHandler;
 import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.api.services.serializers.ResultSerializer;
 import org.junit.Test;
 
-import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
 
-import static org.easymock.EasyMock.*;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
 
 
 /**
  * Unit tests for ClusterService.
  */
-public class ClusterServiceTest {
+public class ClusterServiceTest extends BaseServiceTest {
 
   @Test
-  public void testGetCluster() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
+   public void testGetCluster() {
+    String clusterName = "clusterName";
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
+
+    //test
+    ClusterService clusterService = new TestClusterService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.getCluster(getHttpHeaders(), getUriInfo(), clusterName);
+    verifyResults(response, 200);
+  }
 
+  @Test
+  public void testGetCluster__ErrorState() {
     String clusterName = "clusterName";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
-        eq(resourceDef))).andReturn(request);
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
+
+    //test
+    ClusterService clusterService = new TestClusterService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.getCluster(getHttpHeaders(), getUriInfo(), clusterName);
+    verifyResults(response, 500);
+  }
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(true).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.GET, serializedResult, true)).andReturn(response);
+  @Test
+  public void testGetClusters() {
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
 
     //test
-    ClusterService clusterService = new TestClusterService(resourceDef, clusterName, requestFactory, responseFactory, requestHandler);
-    assertSame(response, clusterService.getCluster(httpHeaders, uriInfo, clusterName));
+    ClusterService clusterService = new TestClusterService(getResource(), null, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.getClusters(getHttpHeaders(), getUriInfo());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    verifyResults(response, 200);
   }
 
   @Test
-  public void testGetClusters() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
-        eq(resourceDef))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(true).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.GET, serializedResult, true)).andReturn(response);
-
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+  public void testGetClusters__ErrorState() {
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
 
     //test
-    ClusterService clusterService = new TestClusterService(resourceDef, null, requestFactory, responseFactory, requestHandler);
-    assertSame(response, clusterService.getClusters(httpHeaders, uriInfo));
+    ClusterService clusterService = new TestClusterService(getResource(), null, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.getClusters(getHttpHeaders(), getUriInfo());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    verifyResults(response, 500);
   }
 
   @Test
   public void testCreateCluster() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    String clusterName = "clusterName";
+    String body = "body";
+
+    registerExpectations(Request.Type.POST, body, 201, false);
+    replayMocks();
+
+    //test
+    ClusterService clusterService = new TestClusterService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.createCluster(body, getHttpHeaders(), getUriInfo(), clusterName);
+
+    verifyResults(response, 201);
+  }
 
+  @Test
+  public void testCreateCluster__ErrorState() {
     String clusterName = "clusterName";
+    String body = "body";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.POST),
-        eq(resourceDef))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.POST, serializedResult, false)).andReturn(response);
-
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    registerExpectations(Request.Type.POST, body, 500, true);
+    replayMocks();
 
     //test
-    ClusterService clusterService = new TestClusterService(resourceDef, clusterName, requestFactory, responseFactory, requestHandler);
-    assertSame(response, clusterService.createCluster("body", httpHeaders, uriInfo, clusterName));
+    ClusterService clusterService = new TestClusterService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.createCluster(body, getHttpHeaders(), getUriInfo(), clusterName);
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    verifyResults(response, 500);
   }
 
   @Test
   public void testUpdateCluster() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    String clusterName = "clusterName";
+    String body = "body";
+
+    registerExpectations(Request.Type.PUT, body, 200, false);
+    replayMocks();
+
+    //test
+    ClusterService clusterService = new TestClusterService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.updateCluster(body, getHttpHeaders(), getUriInfo(), clusterName);
 
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testUpdateCluster__ErrorState() {
     String clusterName = "clusterName";
+    String body = "body";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
-        eq(resourceDef))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(true).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.PUT, serializedResult, true)).andReturn(response);
-
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    registerExpectations(Request.Type.PUT, body, 500, true);
+    replayMocks();
 
     //test
-    ClusterService clusterService = new TestClusterService(resourceDef, clusterName, requestFactory, responseFactory, requestHandler);
-    assertSame(response, clusterService.updateCluster("body", httpHeaders, uriInfo, clusterName));
+    ClusterService clusterService = new TestClusterService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.updateCluster(body, getHttpHeaders(), getUriInfo(), clusterName);
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    verifyResults(response, 500);
   }
 
   @Test
   public void testDeleteCluster() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    String clusterName = "clusterName";
 
+    registerExpectations(Request.Type.DELETE, null, 200, false);
+    replayMocks();
+
+    //test
+    ClusterService clusterService = new TestClusterService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.deleteCluster(getHttpHeaders(), getUriInfo(), clusterName);
+
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testDeleteCluster__ErrorState() {
     String clusterName = "clusterName";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.DELETE),
-        eq(resourceDef))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.DELETE, serializedResult, false)).andReturn(response);
-
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    registerExpectations(Request.Type.DELETE, null, 500, true);
+    replayMocks();
 
     //test
-    ClusterService clusterService = new TestClusterService(resourceDef, clusterName, requestFactory, responseFactory, requestHandler);
-    assertSame(response, clusterService.deleteCluster(httpHeaders, uriInfo, clusterName));
+    ClusterService clusterService = new TestClusterService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = clusterService.deleteCluster(getHttpHeaders(), getUriInfo(), clusterName);
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    verifyResults(response, 500);
   }
 
   private class TestClusterService extends ClusterService {
     private RequestFactory m_requestFactory;
-    private ResponseFactory m_responseFactory;
     private RequestHandler m_requestHandler;
     private ResourceInstance m_resourceDef;
     private String m_clusterId;
 
     private TestClusterService(ResourceInstance resourceDef, String clusterId, RequestFactory requestFactory,
-                               ResponseFactory responseFactory, RequestHandler handler) {
+                               RequestHandler handler) {
       m_resourceDef = resourceDef;
       m_requestFactory = requestFactory;
-      m_responseFactory = responseFactory;
       m_requestHandler = handler;
       m_clusterId = clusterId;
     }
@@ -249,12 +197,7 @@ public class ClusterServiceTest {
     }
 
     @Override
-    ResponseFactory getResponseFactory() {
-      return m_responseFactory;
-    }
-
-    @Override
-    RequestHandler getRequestHandler() {
+    RequestHandler getRequestHandler(Request.Type requestType) {
       return m_requestHandler;
     }
   }

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java?rev=1431843&r1=1431842&r2=1431843&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ComponentServiceTest.java Fri Jan 11 03:02:37 2013
@@ -22,284 +22,235 @@ package org.apache.ambari.server.api.ser
 
 import org.apache.ambari.server.api.handlers.RequestHandler;
 import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.api.services.serializers.ResultSerializer;
 import org.junit.Test;
 
-import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
 
-import static org.easymock.EasyMock.*;
-import static org.easymock.EasyMock.eq;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
 
 /**
  * Unit tests for ComponentService.
  */
-public class ComponentServiceTest {
+public class ComponentServiceTest extends BaseServiceTest {
 
   @Test
-  public void testGetComponent() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
+  public void testGetComponent()  {
     String clusterName = "clusterName";
     String serviceName = "serviceName";
     String componentName = "componentName";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
-        eq(resourceDef))).andReturn(request);
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(true).atLeastOnce();
+    //test
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, componentName,
+        getRequestFactory(), getRequestHandler());
 
-    expect(responseFactory.createResponse(Request.Type.GET, serializedResult, true)).andReturn(response);
+    Response response = componentService.getComponent(getHttpHeaders(), getUriInfo(), componentName);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetComponent__ErrorState()  {
+    String clusterName = "clusterName";
+    String serviceName = "serviceName";
+    String componentName = "componentName";
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    registerExpectations(Request.Type.GET, null, 404, true);
+    replayMocks();
 
     //test
-    ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, componentName,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, componentService.getComponent(httpHeaders, uriInfo, componentName));
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, componentName,
+        getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = componentService.getComponent(getHttpHeaders(), getUriInfo(), componentName);
+    verifyResults(response, 404);
   }
 
   @Test
   public void testGetComponents() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
     String clusterName = "clusterName";
     String serviceName = "serviceName";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
-        eq(resourceDef))).andReturn(request);
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(true).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.GET, serializedResult, true)).andReturn(response);
+    //test
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, null,
+        getRequestFactory(), getRequestHandler());
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = componentService.getComponents(getHttpHeaders(), getUriInfo());
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetComponents__ErrorState() {
+    String clusterName = "clusterName";
+    String serviceName = "serviceName";
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
 
     //test
-    ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, null, requestFactory, responseFactory, requestHandler);
-    assertSame(response, componentService.getComponents(httpHeaders, uriInfo));
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, null,
+        getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = componentService.getComponents(getHttpHeaders(), getUriInfo());
+    verifyResults(response, 500);
   }
 
   @Test
   public void testCreateComponent() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
     String clusterName = "clusterName";
     String serviceName = "serviceName";
     String componentName = "componentName";
+    String body = "{body}";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.POST),
-        eq(resourceDef))).andReturn(request);
+    registerExpectations(Request.Type.POST, body, 201, false);
+    replayMocks();
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
+    //test
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, componentName,
+        getRequestFactory(), getRequestHandler());
 
-    expect(responseFactory.createResponse(Request.Type.POST, serializedResult, false)).andReturn(response);
+    Response response = componentService.createComponent(body, getHttpHeaders(), getUriInfo(), componentName);
+    verifyResults(response, 201);
+  }
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+  @Test
+  public void testCreateComponent__ErrorState() {
+    String clusterName = "clusterName";
+    String serviceName = "serviceName";
+    String componentName = "componentName";
+    String body = "{body}";
+
+    registerExpectations(Request.Type.POST, body, 500, true);
+    replayMocks();
 
     //test
-    ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, componentName,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, componentService.createComponent("body", httpHeaders, uriInfo, componentName));
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, componentName,
+        getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = componentService.createComponent(body, getHttpHeaders(), getUriInfo(), componentName);
+    verifyResults(response, 500);
   }
 
   @Test
   public void testUpdateComponent() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
     String clusterName = "clusterName";
     String serviceName = "serviceName";
     String componentName = "componentName";
+    String body = "{body}";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
-        eq(resourceDef))).andReturn(request);
+    registerExpectations(Request.Type.PUT, body, 200, false);
+    replayMocks();
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
+    //test
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, componentName,
+        getRequestFactory(), getRequestHandler());
+
+    Response response = componentService.updateComponent(body, getHttpHeaders(), getUriInfo(), componentName);
+    verifyResults(response, 200);
+  }
 
-    expect(responseFactory.createResponse(Request.Type.PUT, serializedResult, false)).andReturn(response);
+  @Test
+  public void testUpdateComponent__ErrorState() {
+    String clusterName = "clusterName";
+    String serviceName = "serviceName";
+    String componentName = "componentName";
+    String body = "{body}";
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    registerExpectations(Request.Type.PUT, body, 500, true);
+    replayMocks();
 
     //test
-    ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, componentName,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, componentService.updateComponent("body", httpHeaders, uriInfo, componentName));
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, componentName,
+        getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = componentService.updateComponent(body, getHttpHeaders(), getUriInfo(), componentName);
+    verifyResults(response, 500);
   }
 
   @Test
   public void testUpdateComponents() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
     String clusterName = "clusterName";
     String serviceName = "serviceName";
+    String body = "{body}";
+
+    registerExpectations(Request.Type.PUT, body, 200, false);
+    replayMocks();
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
-        eq(resourceDef))).andReturn(request);
+    //test
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, null,
+        getRequestFactory(), getRequestHandler());
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
+    Response response = componentService.updateComponents(body, getHttpHeaders(), getUriInfo());
+    verifyResults(response, 200);
+  }
 
-    expect(responseFactory.createResponse(Request.Type.PUT, serializedResult, false)).andReturn(response);
+  @Test
+  public void testUpdateComponents__ErrorState() {
+    String clusterName = "clusterName";
+    String serviceName = "serviceName";
+    String body = "{body}";
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    registerExpectations(Request.Type.PUT, body, 500, true);
+    replayMocks();
 
     //test
-    ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, null,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, componentService.updateComponents("body", httpHeaders, uriInfo));
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, null,
+        getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = componentService.updateComponents(body, getHttpHeaders(), getUriInfo());
+    verifyResults(response, 500);
   }
 
   @Test
   public void testDeleteComponent() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
     String clusterName = "clusterName";
     String serviceName = "serviceName";
-    String componentName = "componentName";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.DELETE),
-        eq(resourceDef))).andReturn(request);
+    registerExpectations(Request.Type.DELETE, null, 200, false);
+    replayMocks();
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
+    //test
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, null,
+        getRequestFactory(), getRequestHandler());
 
-    expect(responseFactory.createResponse(Request.Type.DELETE, serializedResult, false)).andReturn(response);
+    Response response = componentService.deleteComponent(getHttpHeaders(), getUriInfo(), null);
+    verifyResults(response, 200);
+  }
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+  @Test
+  public void testDeleteComponent__ErrorState() {
+    String clusterName = "clusterName";
+    String serviceName = "serviceName";
+
+    registerExpectations(Request.Type.DELETE, null, 500, true);
+    replayMocks();
 
     //test
-    ComponentService componentService = new TestComponentService(resourceDef, clusterName, serviceName, componentName,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, componentService.deleteComponent(httpHeaders, uriInfo, componentName));
+    ComponentService componentService = new TestComponentService(getResource(), clusterName, serviceName, null,
+        getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = componentService.deleteComponent(getHttpHeaders(), getUriInfo(), null);
+    verifyResults(response, 500);
   }
 
-
-
   private class TestComponentService extends ComponentService {
     private RequestFactory m_requestFactory;
-    private ResponseFactory m_responseFactory;
     private RequestHandler m_requestHandler;
-    private ResourceInstance m_resourceDef;
+    private ResourceInstance m_resource;
     private String m_clusterId;
     private String m_serviceId;
     private String m_componentId;
 
-    private TestComponentService(ResourceInstance resourceDef, String clusterId, String serviceId, String componentId, RequestFactory requestFactory, ResponseFactory responseFactory, RequestHandler handler) {
+    private TestComponentService(ResourceInstance resourceDef, String clusterId, String serviceId, String componentId,
+                                 RequestFactory requestFactory, RequestHandler handler) {
       super(clusterId, serviceId);
       m_requestFactory = requestFactory;
-      m_responseFactory = responseFactory;
       m_requestHandler = handler;
-      m_resourceDef = resourceDef;
+      m_resource = resourceDef;
       m_clusterId = clusterId;
       m_serviceId = serviceId;
       m_componentId = componentId;
@@ -310,7 +261,7 @@ public class ComponentServiceTest {
       assertEquals(m_clusterId, clusterName);
       assertEquals(m_serviceId, serviceName);
       assertEquals(m_componentId, componentName);
-      return m_resourceDef;
+      return m_resource;
     }
 
     @Override
@@ -319,12 +270,7 @@ public class ComponentServiceTest {
     }
 
     @Override
-    ResponseFactory getResponseFactory() {
-      return m_responseFactory;
-    }
-
-    @Override
-    RequestHandler getRequestHandler() {
+    RequestHandler getRequestHandler(Request.Type requestType) {
       return m_requestHandler;
     }
   }

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ConfigurationServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ConfigurationServiceTest.java?rev=1431843&r1=1431842&r2=1431843&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ConfigurationServiceTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/ConfigurationServiceTest.java Fri Jan 11 03:02:37 2013
@@ -17,83 +17,48 @@
  */
 package org.apache.ambari.server.api.services;
 
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
 
 import javax.ws.rs.core.*;
 
 import org.apache.ambari.server.api.handlers.RequestHandler;
 import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.api.services.serializers.ResultSerializer;
 import org.junit.Test;
 
 
-public class ConfigurationServiceTest {
+public class ConfigurationServiceTest extends BaseServiceTest {
   
   @Test
-  public void testCreateConfiguration() {
-    ResourceInstance resourceInstance = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-  
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-  
+  public void testCreateConfiguration() throws Exception{
     String clusterName = "clusterName";
 
     String body = "{ \"type\":\"hdfs-site\", \"tag\":\"my-new-tag\"," +
         "\"properties\":{ \"key1\":\"value1\", \"key2\":\"value2\" } }";
-    
-    expect(requestFactory.createRequest(eq(httpHeaders), eq(body), eq(uriInfo), eq(Request.Type.POST),
-        eq(resourceInstance))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.POST, serializedResult, false)).andReturn(response);
-
-    replay(resourceInstance, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
-    
+
+    registerExpectations(Request.Type.POST, body, 200, false);
+    replayMocks();
+
     //test
-    ConfigurationService hostService = new TestConfigurationService(resourceInstance, clusterName, requestFactory, responseFactory, requestHandler);
-    assertSame(response, hostService.createConfigurations(body, httpHeaders, uriInfo));
+    ConfigurationService configService = new TestConfigurationService(getResource(), clusterName, getRequestFactory(), getRequestHandler());
+    Response response = configService.createConfigurations(body, getHttpHeaders(), getUriInfo());
 
-    verify(resourceInstance, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);  
+    verifyResults(response, 200);
   }
   
   private class TestConfigurationService extends ConfigurationService {
     private RequestFactory m_requestFactory;
-    private ResponseFactory m_responseFactory;
     private RequestHandler m_requestHandler;
     private ResourceInstance m_resourceInstance;
     private String m_clusterId;
 
     private TestConfigurationService(ResourceInstance resourceInstance, String clusterId, RequestFactory requestFactory,
-                               ResponseFactory responseFactory, RequestHandler handler) {
+                                     RequestHandler handler) {
       super(clusterId);
       m_resourceInstance = resourceInstance;
       m_clusterId = clusterId;
       m_requestFactory = requestFactory;
-      m_responseFactory = responseFactory;
       m_requestHandler = handler;
     }
-    
-    
 
     @Override
     ResourceInstance createConfigurationResource(String clusterName) {
@@ -107,12 +72,7 @@ public class ConfigurationServiceTest {
     }
 
     @Override
-    ResponseFactory getResponseFactory() {
-      return m_responseFactory;
-    }
-
-    @Override
-    RequestHandler getRequestHandler() {
+    RequestHandler getRequestHandler(Request.Type requestType) {
       return m_requestHandler;
     }    
   }

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/DeleteRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/DeleteRequestTest.java?rev=1431843&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/DeleteRequestTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/DeleteRequestTest.java Fri Jan 11 03:02:37 2013
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * DeleteRequest unit tests
+ */
+public class DeleteRequestTest extends BaseRequestTest {
+  @Test
+  public void testRequestType() {
+    assertSame(Request.Type.DELETE, new DeleteRequest(null, null, null, null).getRequestType());
+  }
+
+  @Test
+  public void testGetQueryPredicate() throws Exception {
+    String uri = "http://foo.bar.com/api/v1/clusters?foo=bar&orProp1=5|orProp2!=6|orProp3<100&prop!=5&prop2>10&prop3>=20&prop4<500&prop5<=1&fields=field1,category/field2";
+    super.testGetQueryPredicate(uri);
+  }
+
+  @Test
+  public void testGetFields() {
+    String fields = "prop,category/prop1,category2/category3/prop2[1,2,3],prop3[4,5,6],category4[7,8,9],sub-resource/*[10,11,12],finalProp";
+    super.testGetFields(fields);
+  }
+
+  protected Request getTestRequest(HttpHeaders headers, String body, UriInfo uriInfo) {
+    return new DeleteRequest(headers, body, uriInfo, null);
+  }
+}

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/GetRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/GetRequestTest.java?rev=1431843&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/GetRequestTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/GetRequestTest.java Fri Jan 11 03:02:37 2013
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
+/**
+ * GetRequest unit tests.
+ */
+public class GetRequestTest extends BaseRequestTest {
+
+  @Test
+  public void testRequestType() {
+    assertSame(Request.Type.GET, new GetRequest(null, null, null, null).getRequestType());
+  }
+
+  @Test
+  public void testGetQueryPredicate() throws Exception {
+    String uri = "http://foo.bar.com/api/v1/clusters?foo=bar&orProp1=5|orProp2!=6|orProp3<100&prop!=5&prop2>10&prop3>=20&prop4<500&prop5<=1&fields=field1,category/field2";
+    super.testGetQueryPredicate(uri);
+  }
+
+  @Test
+  public void testGetFields() {
+    String fields = "prop,category/prop1,category2/category3/prop2[1,2,3],prop3[4,5,6],category4[7,8,9],sub-resource/*[10,11,12],finalProp";
+    super.testGetFields(fields);
+  }
+
+  protected Request getTestRequest(HttpHeaders headers, String body, UriInfo uriInfo) {
+    return new GetRequest(headers, body, uriInfo, null);
+  }
+}

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/HostComponentServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/HostComponentServiceTest.java?rev=1431843&r1=1431842&r2=1431843&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/HostComponentServiceTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/HostComponentServiceTest.java Fri Jan 11 03:02:37 2013
@@ -21,269 +21,224 @@ package org.apache.ambari.server.api.ser
 
 import org.apache.ambari.server.api.handlers.RequestHandler;
 import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.api.services.serializers.ResultSerializer;
 import org.junit.Test;
 
-import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
 
-import static org.easymock.EasyMock.*;
-import static org.easymock.EasyMock.eq;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
 
 /**
  * Unit tests for HostComponentService.
  */
-public class HostComponentServiceTest {
+public class HostComponentServiceTest extends BaseServiceTest {
   @Test
   public void testGetHostComponent() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
+    String clusterName = "clusterName";
+    String hostName = "hostName";
+    String hostComponentName = "hostComponentName";
+
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
 
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, hostComponentName, getRequestFactory(), getRequestHandler());
+
+    Response response = hostComponentService.getHostComponent(getHttpHeaders(), getUriInfo(), hostComponentName);
+    verifyResults(response, 200);
+  }
 
+  @Test
+  public void testGetHostComponent__ErrorState() {
     String clusterName = "clusterName";
     String hostName = "hostName";
     String hostComponentName = "hostComponentName";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
-        eq(resourceDef))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(true).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.GET, serializedResult, true)).andReturn(response);
-
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
-
-    //test
-    HostComponentService hostComponentService = new TestHostComponentService(resourceDef, clusterName, hostName, hostComponentName,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, hostComponentService.getHostComponent(httpHeaders, uriInfo, hostComponentName));
+    registerExpectations(Request.Type.GET, null, 404, true);
+    replayMocks();
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, hostComponentName, getRequestFactory(), getRequestHandler());
+
+    Response response = hostComponentService.getHostComponent(getHttpHeaders(), getUriInfo(), hostComponentName);
+    verifyResults(response, 404);
   }
 
   @Test
   public void testGetHostComponents() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
     String clusterName = "clusterName";
     String hostName = "hostName";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.GET),
-        eq(resourceDef))).andReturn(request);
+    registerExpectations(Request.Type.GET, null, 200, false);
+    replayMocks();
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(true).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.GET, serializedResult, true)).andReturn(response);
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, null, getRequestFactory(), getRequestHandler());
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = hostComponentService.getHostComponents(getHttpHeaders(), getUriInfo());
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testGetHostComponents__ErrorState() {
+    String clusterName = "clusterName";
+    String hostName = "hostName";
+
+    registerExpectations(Request.Type.GET, null, 500, true);
+    replayMocks();
 
     //test
-    HostComponentService componentService = new TestHostComponentService(resourceDef, clusterName, hostName, null, requestFactory,
-        responseFactory, requestHandler);
-    assertSame(response, componentService.getHostComponents(httpHeaders, uriInfo));
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, null, getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = hostComponentService.getHostComponents(getHttpHeaders(), getUriInfo());
+    verifyResults(response, 500);
   }
 
   @Test
   public void testCreateHostComponent() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
+    String clusterName = "clusterName";
+    String hostName = "hostName";
+    String hostComponentName = "hostComponentName";
+    String body = "body";
 
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    registerExpectations(Request.Type.POST, body, 201, false);
+    replayMocks();
+
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, hostComponentName, getRequestFactory(), getRequestHandler());
 
+    Response response = hostComponentService.createHostComponent(body, getHttpHeaders(), getUriInfo(), hostComponentName);
+    verifyResults(response, 201);
+  }
+
+  @Test
+  public void testCreateHostComponent__ErrorState() {
     String clusterName = "clusterName";
     String hostName = "hostName";
     String hostComponentName = "hostComponentName";
+    String body = "body";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.POST),
-        eq(resourceDef))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.POST, serializedResult, false)).andReturn(response);
-
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
-
-    //test
-    HostComponentService hostComponentService = new TestHostComponentService(resourceDef, clusterName, hostName, hostComponentName,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, hostComponentService.createHostComponent("body", httpHeaders, uriInfo, hostComponentName));
+    registerExpectations(Request.Type.POST, body, 500, true);
+    replayMocks();
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, hostComponentName, getRequestFactory(), getRequestHandler());
+
+    Response response = hostComponentService.createHostComponent(body, getHttpHeaders(), getUriInfo(), hostComponentName);
+    verifyResults(response, 500);
   }
 
   @Test
   public void testUpdateHostComponent() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
+    String clusterName = "clusterName";
+    String hostName = "hostName";
+    String hostComponentName = "hostComponentName";
+    String body = "body";
+
+    registerExpectations(Request.Type.PUT, body, 200, false);
+    replayMocks();
+
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, hostComponentName, getRequestFactory(), getRequestHandler());
 
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    Response response = hostComponentService.updateHostComponent(body, getHttpHeaders(), getUriInfo(), hostComponentName);
+    verifyResults(response, 200);
+  }
 
+  @Test
+  public void testUpdateHostComponent__ErrorState() {
     String clusterName = "clusterName";
     String hostName = "hostName";
     String hostComponentName = "hostComponentName";
+    String body = "body";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
-        eq(resourceDef))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.PUT, serializedResult, false)).andReturn(response);
-
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
-
-    //test
-    HostComponentService hostComponentService = new TestHostComponentService(resourceDef, clusterName, hostName, hostComponentName,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, hostComponentService.updateHostComponent("body", httpHeaders, uriInfo, hostComponentName));
+    registerExpectations(Request.Type.PUT, body, 500, true);
+    replayMocks();
+
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, hostComponentName, getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = hostComponentService.updateHostComponent(body, getHttpHeaders(), getUriInfo(), hostComponentName);
+    verifyResults(response, 500);
   }
 
   @Test
   public void testUpdateHostComponents() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
-
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
-
     String clusterName = "clusterName";
     String hostName = "hostName";
+    String body = "body";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), eq("body"), eq(uriInfo), eq(Request.Type.PUT),
-        eq(resourceDef))).andReturn(request);
+    registerExpectations(Request.Type.PUT, body, 200, false);
+    replayMocks();
+
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, null, getRequestFactory(), getRequestHandler());
 
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.PUT, serializedResult, false)).andReturn(response);
+    Response response = hostComponentService.updateHostComponents(body, getHttpHeaders(), getUriInfo());
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testUpdateHostComponents__ErrorState() {
+    String clusterName = "clusterName";
+    String hostName = "hostName";
+    String body = "body";
 
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    registerExpectations(Request.Type.PUT, body, 500, true);
+    replayMocks();
 
     //test
-    HostComponentService hostComponentService = new TestHostComponentService(resourceDef, clusterName, hostName, null,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, hostComponentService.updateHostComponents("body", httpHeaders, uriInfo));
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, null, getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = hostComponentService.updateHostComponents(body, getHttpHeaders(), getUriInfo());
+    verifyResults(response, 500);
   }
 
   @Test
   public void testDeleteHostComponent() {
-    ResourceInstance resourceDef = createStrictMock(ResourceInstance.class);
-    ResultSerializer resultSerializer = createStrictMock(ResultSerializer.class);
-    Object serializedResult = new Object();
-    RequestFactory requestFactory = createStrictMock(RequestFactory.class);
-    ResponseFactory responseFactory = createStrictMock(ResponseFactory.class);
-    Request request = createNiceMock(Request.class);
-    RequestHandler requestHandler = createStrictMock(RequestHandler.class);
-    Result result = createStrictMock(Result.class);
-    Response response = createStrictMock(Response.class);
+    String clusterName = "clusterName";
+    String hostName = "hostName";
+    String hostComponentName = "hostComponentName";
+
+    registerExpectations(Request.Type.DELETE, null, 200, false);
+    replayMocks();
 
-    HttpHeaders httpHeaders = createNiceMock(HttpHeaders.class);
-    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, hostComponentName, getRequestFactory(), getRequestHandler());
 
+    Response response = hostComponentService.deleteHostComponent(getHttpHeaders(), getUriInfo(), hostComponentName);
+    verifyResults(response, 200);
+  }
+
+  @Test
+  public void testDeleteHostComponent__ErrorState() {
     String clusterName = "clusterName";
     String hostName = "hostName";
     String hostComponentName = "hostComponentName";
 
-    // expectations
-    expect(requestFactory.createRequest(eq(httpHeaders), isNull(String.class), eq(uriInfo), eq(Request.Type.DELETE),
-        eq(resourceDef))).andReturn(request);
-
-    expect(requestHandler.handleRequest(request)).andReturn(result);
-    expect(request.getResultSerializer()).andReturn(resultSerializer);
-    expect(resultSerializer.serialize(result, uriInfo)).andReturn(serializedResult);
-    expect(result.isSynchronous()).andReturn(false).atLeastOnce();
-    expect(responseFactory.createResponse(Request.Type.DELETE, serializedResult, false)).andReturn(response);
-
-    replay(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
-
-    //test
-    HostComponentService hostComponentService = new TestHostComponentService(resourceDef, clusterName, hostName, hostComponentName,
-        requestFactory, responseFactory, requestHandler);
-    assertSame(response, hostComponentService.deleteHostComponent(httpHeaders, uriInfo, hostComponentName));
+    registerExpectations(Request.Type.DELETE, null, 500, true);
+    replayMocks();
+
+    //test
+    HostComponentService hostComponentService = new TestHostComponentService(getResource(), clusterName,
+        hostName, hostComponentName, getRequestFactory(), getRequestHandler());
 
-    verify(resourceDef, resultSerializer, requestFactory, responseFactory, request, requestHandler,
-        result, response, httpHeaders, uriInfo);
+    Response response = hostComponentService.deleteHostComponent(getHttpHeaders(), getUriInfo(), hostComponentName);
+    verifyResults(response, 500);
   }
 
   private class TestHostComponentService extends HostComponentService {
     private RequestFactory m_requestFactory;
-    private ResponseFactory m_responseFactory;
     private RequestHandler m_requestHandler;
     private ResourceInstance m_resourceDef;
     private String m_clusterId;
@@ -291,14 +246,13 @@ public class HostComponentServiceTest {
     private String m_hostComponentId;
 
     private TestHostComponentService(ResourceInstance resourceDef, String clusterId, String hostId, String hostComponentId,
-                                     RequestFactory requestFactory, ResponseFactory responseFactory, RequestHandler handler) {
+                                     RequestFactory requestFactory, RequestHandler handler) {
       super(clusterId, hostId);
       m_resourceDef = resourceDef;
       m_clusterId = clusterId;
       m_hostId = hostId;
       m_hostComponentId = hostComponentId;
       m_requestFactory = requestFactory;
-      m_responseFactory = responseFactory;
       m_requestHandler = handler;
     }
 
@@ -317,12 +271,7 @@ public class HostComponentServiceTest {
     }
 
     @Override
-    ResponseFactory getResponseFactory() {
-      return m_responseFactory;
-    }
-
-    @Override
-    RequestHandler getRequestHandler() {
+    RequestHandler getRequestHandler(Request.Type requestType) {
       return m_requestHandler;
     }
   }



Mime
View raw message