Explorar o código

AMBARI-774. Renable and fix AgentResourceTest. (mahadev)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1391311 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar %!s(int64=13) %!d(string=hai) anos
pai
achega
a5fc1a4095

+ 2 - 0
AMBARI-666-CHANGES.txt

@@ -171,6 +171,8 @@ AMBARI-666 branch (unreleased changes)
 
 
   BUG FIXES
   BUG FIXES
 
 
+  AMBARI-774. Renable and fix AgentResourceTest. (mahadev) 
+
   AMBARI-773. Change Host FSM as per new requirements of heartbeat handler. (hitesh)
   AMBARI-773. Change Host FSM as per new requirements of heartbeat handler. (hitesh)
 
 
   AMBARI-761. Fix broken build for adding guice servlet dependency. (mahadev)
   AMBARI-761. Fix broken build for adding guice servlet dependency. (mahadev)

+ 4 - 0
ambari-server/src/main/java/org/apache/ambari/server/agent/AgentCommand.java

@@ -32,6 +32,10 @@ public abstract class AgentCommand {
   @XmlElement
   @XmlElement
   private AgentCommandType commandType;
   private AgentCommandType commandType;
   
   
+  public AgentCommand() {
+    this.commandType = AgentCommandType.STATUS_COMMAND;
+  }
+  
   public AgentCommand(AgentCommandType type) {
   public AgentCommand(AgentCommandType type) {
     this.commandType = type;
     this.commandType = type;
   }
   }

+ 16 - 4
ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java

@@ -19,7 +19,8 @@
 package org.apache.ambari.server.agent;
 package org.apache.ambari.server.agent;
 
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.mock;
-
+import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.any;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MediaType;
 
 
 import junit.framework.Assert;
 import junit.framework.Assert;
@@ -56,13 +57,24 @@ public class AgentResourceTest extends JerseyTest {
   }
   }
   
   
   public class MockModule extends AbstractModule {
   public class MockModule extends AbstractModule {
-
+    
+    RegistrationResponse response = new RegistrationResponse();
+    HeartBeatResponse hresponse = new HeartBeatResponse();
+    
     @Override
     @Override
     protected void configure() {
     protected void configure() {
+      handler = mock(HeartBeatHandler.class);
+      response.setResponseStatus(RegistrationStatus.OK);
+      hresponse.setResponseId(0L);
+      when(handler.handleRegistration(any(Register.class))).thenReturn(
+          response);
+      when(handler.handleHeartBeat(any(HeartBeat.class))).thenReturn(hresponse);
       requestStaticInjection(AgentResource.class);
       requestStaticInjection(AgentResource.class);
       bind(Clusters.class).to(ClustersImpl.class);
       bind(Clusters.class).to(ClustersImpl.class);
       actionManager = mock(ActionManager.class);
       actionManager = mock(ActionManager.class);
       bind(ActionManager.class).toInstance(actionManager);
       bind(ActionManager.class).toInstance(actionManager);
+      bind(AgentCommand.class).to(ExecutionCommand.class);
+      bind(HeartBeatHandler.class).toInstance(handler);
     }    
     }    
   }
   }
   
   
@@ -90,7 +102,7 @@ public class AgentResourceTest extends JerseyTest {
     return json;
     return json;
   }
   }
   
   
-  //@Test
+  @Test
   public void agentRegistration() throws UniformInterfaceException, JSONException {
   public void agentRegistration() throws UniformInterfaceException, JSONException {
     RegistrationResponse response;
     RegistrationResponse response;
     WebResource webResource = resource();
     WebResource webResource = resource();
@@ -100,7 +112,7 @@ public class AgentResourceTest extends JerseyTest {
     Assert.assertEquals(response.getResponseStatus(), RegistrationStatus.OK);
     Assert.assertEquals(response.getResponseStatus(), RegistrationStatus.OK);
   }
   }
   
   
-  //@Test
+  @Test
   public void agentHeartBeat() throws UniformInterfaceException, JSONException {
   public void agentHeartBeat() throws UniformInterfaceException, JSONException {
     HeartBeatResponse response;
     HeartBeatResponse response;
     WebResource resource = resource();
     WebResource resource = resource();