mirror of https://github.com/apache/cloudstack.git
Add unit test for DataTO/DataStoreTO serializer/deserializer adapter.
This commit is contained in:
parent
e0ab845e92
commit
bb7a72b7d6
|
|
@ -68,6 +68,8 @@ public class GsonHelper {
|
|||
builder.registerTypeAdapter(new TypeToken<Pair<Long, Long>>() {
|
||||
}.getType(), new NwGroupsCommandTypeAdaptor());
|
||||
Gson gson = builder.create();
|
||||
dsAdaptor.initGson(gson);
|
||||
dtAdaptor.initGson(gson);
|
||||
cmdAdaptor.initGson(gson);
|
||||
ansAdaptor.initGson(gson);
|
||||
return gson;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.cloud.agent.api.Answer;
|
|||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.GetHostStatsCommand;
|
||||
import com.cloud.agent.api.SecStorageFirewallCfgCommand;
|
||||
import com.cloud.agent.api.SecStorageSetupCommand;
|
||||
import com.cloud.agent.api.UpdateHostPasswordCommand;
|
||||
import com.cloud.agent.api.storage.DownloadAnswer;
|
||||
import com.cloud.agent.api.to.NfsTO;
|
||||
|
|
@ -129,6 +130,36 @@ public class RequestTest extends TestCase {
|
|||
compareRequest(cresp, sresp);
|
||||
}
|
||||
|
||||
|
||||
public void testSerDeserTO() {
|
||||
s_logger.info("Testing serializing and deserializing interface TO works as expected");
|
||||
|
||||
NfsTO nfs = new NfsTO("nfs://192.168.56.10/opt/storage/secondary", DataStoreRole.Image);
|
||||
SecStorageSetupCommand cmd = new SecStorageSetupCommand(nfs, "nfs://192.168.56.10/opt/storage/secondary", null);
|
||||
Request sreq = new Request(2, 3, cmd, true);
|
||||
sreq.setSequence(892403718);
|
||||
|
||||
|
||||
byte[] bytes = sreq.getBytes();
|
||||
|
||||
assert Request.getSequence(bytes) == 892403718;
|
||||
assert Request.getManagementServerId(bytes) == 3;
|
||||
assert Request.getAgentId(bytes) == 2;
|
||||
assert Request.getViaAgentId(bytes) == 2;
|
||||
Request creq = null;
|
||||
try {
|
||||
creq = Request.parse(bytes);
|
||||
} catch (ClassNotFoundException e) {
|
||||
s_logger.error("Unable to parse bytes: ", e);
|
||||
} catch (UnsupportedVersionException e) {
|
||||
s_logger.error("Unable to parse bytes: ", e);
|
||||
}
|
||||
|
||||
assert creq != null : "Couldn't get the request back";
|
||||
|
||||
compareRequest(creq, sreq);
|
||||
}
|
||||
|
||||
public void testDownload() {
|
||||
s_logger.info("Testing Download answer");
|
||||
VMTemplateVO template = new VMTemplateVO(1, "templatename", ImageFormat.QCOW2, true, true, true, TemplateType.USER, "url", true, 32, 1, "chksum", "displayText", true, 30, true,
|
||||
|
|
|
|||
Loading…
Reference in New Issue