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

Commit

Permalink
TEMP example exercising validation code
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Oct 16, 2023
1 parent 056351c commit 09bd1e4
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions examples/VirtualCircuit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import com.equinix.openapi.ApiClient;
import com.equinix.openapi.ApiException;
import com.equinix.openapi.Configuration;
import com.equinix.openapi.JSON;
import com.equinix.openapi.auth.ApiKeyAuth;
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 java.util.UUID;
import java.util.ArrayList;
import java.util.List;

import java.lang.reflect.Type;
import com.google.gson.reflect.TypeToken;

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}";

try{
// no error from oneOf
JSON json = new JSON();
Type localVarReturnType = new TypeToken<VirtualCircuit>(){}.getType();
JSON.deserialize(vlanVcString, localVarReturnType);
JSON.deserialize(vrfVcString, localVarReturnType);
} catch (Exception e) {
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();
JSON.deserialize(vrfVcString, localVarReturnType);
} catch (Exception e) {
System.out.println(String.format("Exception message : %s", e.getMessage()));
e.printStackTrace();
}


try{
JSON json = new JSON();
Type localVarReturnType = new TypeToken<VirtualCircuit>(){}.getType();
JSON.deserialize(vlanVcString, localVarReturnType);
JSON.deserialize(vrfVcString, localVarReturnType);
} catch (Exception e) {
System.out.println(String.format("Exception message : %s", e.getMessage()));
e.printStackTrace();
}
}
}

0 comments on commit 09bd1e4

Please sign in to comment.