}
public void testCreateUpdateAndDeletePort() {
for (String zoneId : api.getConfiguredZones()) {
NetworkApi netApi = api.getNetworkApiForZone(zoneId);
Reference net = netApi.create("jclouds-port-test");
assertNotNull(net);
PortApi portApi = api.getPortApiForZoneAndNetwork(zoneId, net.getId());
Reference portRef = portApi.create();
assertNotNull(portRef);
Port port = portApi.get(portRef.getId());
PortDetails portDetails = portApi.getDetails(portRef.getId());
NetworkDetails networkDetails = netApi.getDetails(net.getId());
assertEquals(port.getState(), portDetails.getState());
for(Port checkme : ImmutableList.of(port, portDetails, Iterables.getOnlyElement(networkDetails.getPorts()))) {
assertEquals(checkme.getId(), portRef.getId());
}
assertTrue(portApi.updateState(portRef.getId(), Port.State.DOWN));
port = portApi.get(portRef.getId());
portDetails = portApi.getDetails(portRef.getId());
for(Port checkme : ImmutableList.of(port, portDetails)) {
assertEquals(checkme.getId(), portRef.getId());
assertEquals(checkme.getState(), Port.State.DOWN);
}
assertTrue(portApi.plugAttachment(port.getId(), "jclouds-live-test"));
Attachment attachment = portApi.showAttachment(port.getId());
portDetails = portApi.getDetails(portRef.getId());
for(Attachment checkme : ImmutableList.of(attachment, portDetails.getAttachment())) {
assertNotNull(checkme);
assertEquals(checkme.getId(), "jclouds-live-test");
}
assertTrue(portApi.unplugAttachment(port.getId()));
assertTrue(portApi.delete(portRef.getId()));
assertTrue(netApi.delete(net.getId()));
}
}