From 2effe84b92a57420f5d0dc69a89ca6334de349be Mon Sep 17 00:00:00 2001 From: Abhinandan Prateek Date: Mon, 5 Jun 2017 13:16:30 +0530 Subject: [PATCH] FR17: Unit test for checking bad and a good command sent to the agent as json --- .../cloud/agent/transport/RequestTest.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/test/com/cloud/agent/transport/RequestTest.java b/core/test/com/cloud/agent/transport/RequestTest.java index ee3b0822558..21766ba038f 100644 --- a/core/test/com/cloud/agent/transport/RequestTest.java +++ b/core/test/com/cloud/agent/transport/RequestTest.java @@ -20,7 +20,6 @@ package com.cloud.agent.transport; import java.nio.ByteBuffer; - import junit.framework.TestCase; import org.apache.log4j.Level; @@ -32,13 +31,16 @@ import org.apache.cloudstack.storage.command.DownloadCommand; import org.apache.cloudstack.storage.to.TemplateObjectTO; import com.cloud.agent.api.Answer; +import com.cloud.agent.api.BadCommand; import com.cloud.agent.api.Command; import com.cloud.agent.api.GetHostStatsCommand; +import com.cloud.agent.api.GetVolumeStatsCommand; import com.cloud.agent.api.SecStorageFirewallCfgCommand; import com.cloud.agent.api.UpdateHostPasswordCommand; import com.cloud.agent.api.storage.DownloadAnswer; import com.cloud.agent.api.storage.ListTemplateCommand; import com.cloud.agent.api.to.NfsTO; +import com.cloud.agent.transport.Request.Version; import com.cloud.exception.UnsupportedVersionException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.serializer.GsonHelper; @@ -250,4 +252,26 @@ public class RequestTest extends TestCase { } } + public void testGoodCommand() { + s_logger.info("Testing good Command"); + String content = "[{\"com.cloud.agent.api.GetVolumeStatsCommand\":{\"volumeUuids\":[\"dcc860ac-4a20-498f-9cb3-bab4d57aa676\"]," + + "\"poolType\":\"NetworkFilesystem\",\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; + Request sreq = new Request(Version.v2, 1L, 2L, 3L, 1L, (short)1, content); + sreq.setSequence(1); + Command cmds[] = sreq.getCommands(); + s_logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); + assert cmds[0].getClass().equals(GetVolumeStatsCommand.class); + } + + public void testBadCommand() { + s_logger.info("Testing Bad Command"); + String content = "[{\"com.cloud.agent.api.SomeJunkCommand\":{\"volumeUuids\":[\"dcc860ac-4a20-498f-9cb3-bab4d57aa676\"]," + + "\"poolType\":\"NetworkFilesystem\",\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; + Request sreq = new Request(Version.v2, 1L, 2L, 3L, 1L, (short)1, content); + sreq.setSequence(1); + Command cmds[] = sreq.getCommands(); + s_logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); + assert cmds[0].getClass().equals(BadCommand.class); + } + }