Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Add ByteString serialization UT
Browse files Browse the repository at this point in the history
  • Loading branch information
xieus committed Jul 16, 2019
1 parent f4bc00b commit 151e309
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/com/futurewei/alioth/controller/schema/VpcTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.futurewei.alioth.controller.schema;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -21,6 +22,7 @@ public void basicSerializationVerification() {
.setOperationType(Common.OperationType.CREATE)
.setConfiguration(config)
.build();

final byte[] binaryState = state.toByteArray();

try {
Expand All @@ -36,4 +38,37 @@ public void basicSerializationVerification() {
Assert.assertTrue(false);
}
}

@Test
public void stringSerializationVerification() {
String project_id = "dbf72700-5106-4a7a-918f-a016853911f8";
String vpc_id = "99d9d709-8478-4b46-9f3f-2206b1023fd3";
String vpc_name = "SuperVpc";
String cidr = "192.168.0.0/16";
final Vpc.VpcConfiguration config = Vpc.VpcConfiguration.newBuilder()
.setProjectId(project_id)
.setId(vpc_id)
.setName(vpc_name)
.setCidr(cidr)
.build();
final Vpc.VpcState state = Vpc.VpcState.newBuilder()
.setOperationType(Common.OperationType.CREATE)
.setConfiguration(config)
.build();

final ByteString byteStringState = state.toByteString();

try {
final Vpc.VpcState deserializedObject = Vpc.VpcState.parseFrom(byteStringState);

Assert.assertEquals("operation type mismatched", Common.OperationType.CREATE, deserializedObject.getOperationType());

Assert.assertEquals("project id mismatched", project_id, deserializedObject.getConfiguration().getProjectId());
Assert.assertEquals("vpc id mismatched", vpc_id, deserializedObject.getConfiguration().getId());
Assert.assertEquals("vpc name mismatched", vpc_name, deserializedObject.getConfiguration().getName());
Assert.assertEquals("cidr mismatched", cidr, deserializedObject.getConfiguration().getCidr());
} catch (InvalidProtocolBufferException bf_exp) {
Assert.assertTrue(false);
}
}
}

0 comments on commit 151e309

Please sign in to comment.