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

Commit

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

import com.google.protobuf.InvalidProtocolBufferException;
import org.junit.Assert;
import org.junit.Test;

public class VpcTest {
@Test
public void basicSerializationVerification() {
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 byte[] binaryState = state.toByteArray();

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

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 f4bc00b

Please sign in to comment.