Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
update example to test validation of nested VirtualCircuits
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Oct 17, 2023
1 parent d073d38 commit 84d8b36
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions examples/VirtualCircuit.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.equinix.openapi.metal.v1.model.VirtualCircuit;
import com.equinix.openapi.metal.v1.model.VrfVirtualCircuit;
import com.equinix.openapi.metal.v1.model.VlanVirtualCircuit;
import com.equinix.openapi.metal.v1.model.InterconnectionPort;

import java.util.UUID;
import java.util.ArrayList;
Expand All @@ -18,43 +19,40 @@ public class ValidateVirtualCircuit {
public static void main(String[] args) {
String vrfVcString = "{\"id\": \"22A111DD-5EE3-4188-9163-78284363CA73\",\"name\": \"SDDC-2-pop_vpc-VC-primary\",\"status\": \"active\",\"bill\": true,\"nni_vnid\": 264,\"nni_vlan\": 264,\"project\": {\"href\": \"/metal/v1/projects/11CCA184-DB21-4659-A029-B704CDC8D5BA\"},\"vrf\": {\"href\": \"/metal/v1/vrfs/E3DEC139-F2A7-401F-BA12-890F206EF3FD\"},\"type\": \"vrf\",\"vnid\": null}";
String vlanVcString = "{\"id\": \"22A111DD-5EE3-4188-9163-78284363CA73\",\"name\": \"SDDC-2-pop_vpc-VC-primary\",\"status\": \"active\",\"bill\": true,\"nni_vnid\": 264,\"nni_vlan\": 264,\"project\": {\"href\": \"/metal/v1/projects/11CCA184-DB21-4659-A029-B704CDC8D5BA\"},\"vrf\": {\"href\": \"/metal/v1/vrfs/E3DEC139-F2A7-401F-BA12-890F206EF3FD\"},\"type\": \"vlan\",\"vnid\": null}";
String connectionPortString = "{\"virtual_circuits\":[" + vrfVcString + "," + vlanVcString + "]}";

JSON json = new JSON();
Type localVarReturnType = new TypeToken<InterconnectionPort>(){}.getType();
JSON.deserialize(connectionPortString, localVarReturnType);
System.out.println("no error from VirtualCircuit when deserializing ports");

// no error from oneOf
localVarReturnType = new TypeToken<VirtualCircuit>(){}.getType();
JSON.deserialize(vlanVcString, localVarReturnType);
JSON.deserialize(vrfVcString, localVarReturnType);
System.out.println("no error when deserializing VirtualCircuit oneOf directly");

try{
// no error from oneOf
JSON json = new JSON();
Type localVarReturnType = new TypeToken<VirtualCircuit>(){}.getType();
localVarReturnType = new TypeToken<VrfVirtualCircuit>(){}.getType();
JSON.deserialize(vlanVcString, localVarReturnType);
JSON.deserialize(vrfVcString, localVarReturnType);
} catch (Exception e) {
System.out.println("validation error from vrf vc when type is vlan");
System.out.println(String.format("Exception message : %s", e.getMessage()));
e.printStackTrace();
}


try{
System.out.println("validation error from vrf vc when type is vlan");
JSON json = new JSON();
Type localVarReturnType = new TypeToken<VrfVirtualCircuit>(){}.getType();
JSON.deserialize(vlanVcString, localVarReturnType);
} catch (Exception e) {
System.out.println(String.format("Exception message : %s", e.getMessage()));
e.printStackTrace();
}

try{
System.out.println("validation error from vlan vc when type is vrf");
JSON json = new JSON();
Type localVarReturnType = new TypeToken<VlanVirtualCircuit>(){}.getType();
localVarReturnType = new TypeToken<VlanVirtualCircuit>(){}.getType();
JSON.deserialize(vrfVcString, localVarReturnType);
} catch (Exception e) {
System.out.println("validation error from vlan vc when type is vrf");
System.out.println(String.format("Exception message : %s", e.getMessage()));
e.printStackTrace();
}


try{
JSON json = new JSON();
Type localVarReturnType = new TypeToken<VirtualCircuit>(){}.getType();
localVarReturnType = new TypeToken<VirtualCircuit>(){}.getType();
JSON.deserialize(vlanVcString, localVarReturnType);
JSON.deserialize(vrfVcString, localVarReturnType);
} catch (Exception e) {
Expand Down

0 comments on commit 84d8b36

Please sign in to comment.