Skip to content

Commit

Permalink
initial check in for network test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Cheng committed Apr 14, 2014
1 parent 384a653 commit 890cf0f
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import java.util.ArrayList;

import com.microsoft.windowsazure.core.OperationResponse;
import com.microsoft.windowsazure.management.network.models.*;
import com.microsoft.windowsazure.tracing.CloudTracing;
import com.microsoft.windowsazure.exception.ServiceException;

import org.junit.AfterClass;
Expand All @@ -27,54 +29,75 @@
import org.junit.Test;

public class ClientRootCertificateOperationsTests extends NetworkManagementIntegrationTestBase {
private static String virtualNetworkName = "network123";


@BeforeClass
public static void setup() throws Exception {
createService();
createNetwork(virtualNetworkName);
//cleanup();
}

@AfterClass
public static void cleanup() throws Exception {
try {
ClientRootCertificateListResponse ClientRootCertificateListResponse = networkManagementClient.getClientRootCertificatesOperations().list(virtualNetworkName);
ArrayList<ClientRootCertificateListResponse.ClientRootCertificate> clientRootCertificatelist = ClientRootCertificateListResponse.getClientRootCertificates();
for (ClientRootCertificateListResponse.ClientRootCertificate clientRootCertificate : clientRootCertificatelist) {
Assert.assertNotNull(clientRootCertificate.getThumbprint());
}
String virtualNetworkName ="";
try
{
ClientRootCertificateListResponse ClientRootCertificateListResponse = networkManagementClient.getClientRootCertificatesOperations().list(virtualNetworkName);
ArrayList<ClientRootCertificateListResponse.ClientRootCertificate> clientRootCertificatelist = ClientRootCertificateListResponse.getClientRootCertificates();
for (ClientRootCertificateListResponse.ClientRootCertificate clientRootCertificate : clientRootCertificatelist)
{

}
}
catch (ServiceException e) {
e.printStackTrace();
}
}


@Test
public void createClientRootCertificatesSuccess() throws Exception {
String virtualNetworkName = "testsdkVirtualNetwork01";
String certificateValue ="";
// Arrange
ClientRootCertificateCreateParameters createParameters = new ClientRootCertificateCreateParameters();
createParameters.setCertificate(certificateValue);

// Act
OperationResponse operationResponse = networkManagementClient.getClientRootCertificatesOperations().create(virtualNetworkName, createParameters);

// Assert
Assert.assertEquals(201, operationResponse.getStatusCode());
Assert.assertNotNull(operationResponse.getRequestId());
}

@Test
public void getClientRootCertificates() throws Exception {
ClientRootCertificateListResponse ClientRootCertificateListResponse = networkManagementClient.getClientRootCertificatesOperations().list(virtualNetworkName);
ArrayList<ClientRootCertificateListResponse.ClientRootCertificate> clientRootCertificatelist = ClientRootCertificateListResponse.getClientRootCertificates();
for (ClientRootCertificateListResponse.ClientRootCertificate clientRootCertificate : clientRootCertificatelist) {
// Act
ClientRootCertificateGetResponse clientRootCertificateGetResponse = networkManagementClient.getClientRootCertificatesOperations().get(virtualNetworkName, clientRootCertificate.getThumbprint());
String certificateThumbprint = "testsdkClientRootCertificate";
String virtualNetworkName = "testsdkVirtualNetwork01";
// Act
ClientRootCertificateGetResponse clientRootCertificateGetResponse = networkManagementClient.getClientRootCertificatesOperations().get(virtualNetworkName, certificateThumbprint);

// Assert
Assert.assertEquals(200, clientRootCertificateGetResponse.getStatusCode());
Assert.assertNotNull(clientRootCertificateGetResponse.getRequestId());
Assert.assertNotNull(clientRootCertificateGetResponse.getCertificate());
}
// Assert
Assert.assertEquals(200, clientRootCertificateGetResponse.getStatusCode());
Assert.assertNotNull(clientRootCertificateGetResponse.getRequestId());
Assert.assertNotNull(clientRootCertificateGetResponse.getCertificate());
}

@Test
public void listClientRootCertificatesSuccess() throws Exception {
try {
ClientRootCertificateListResponse ClientRootCertificateListResponse = networkManagementClient.getClientRootCertificatesOperations().list(virtualNetworkName);
ArrayList<ClientRootCertificateListResponse.ClientRootCertificate> clientRootCertificatelist = ClientRootCertificateListResponse.getClientRootCertificates();
for (ClientRootCertificateListResponse.ClientRootCertificate clientRootCertificate : clientRootCertificatelist) {
Assert.assertNotNull(clientRootCertificate.getThumbprint());
}
String virtualNetworkName ="testsdkVirtualNetwork01";
try
{
ClientRootCertificateListResponse ClientRootCertificateListResponse = networkManagementClient.getClientRootCertificatesOperations().list(virtualNetworkName);
ArrayList<ClientRootCertificateListResponse.ClientRootCertificate> clientRootCertificatelist = ClientRootCertificateListResponse.getClientRootCertificates();
for (ClientRootCertificateListResponse.ClientRootCertificate clientRootCertificate : clientRootCertificatelist)
{
System.out.println("clientRootCertificate.getThumbprint() = " + clientRootCertificate.getThumbprint());
System.out.println("clientRootCertificate.getExpirationTime() = " + clientRootCertificate.getExpirationTime());
System.out.println("clientRootCertificate.getSubject() = " + clientRootCertificate.getSubject());
}
}
catch (ServiceException e) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,91 @@

package com.microsoft.windowsazure.management.network;

import java.util.ArrayList;

import com.microsoft.windowsazure.core.OperationResponse;
import com.microsoft.windowsazure.management.network.models.*;
import com.microsoft.windowsazure.tracing.CloudTracing;
import com.microsoft.windowsazure.exception.ServiceException;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class GatewayOperationsTests extends NetworkManagementIntegrationTestBase {
private static String virtualNetworkName = "network123";


@BeforeClass
public static void setup() throws Exception {
createService();
createNetwork(virtualNetworkName);
//cleanup();
}

@AfterClass
public static void cleanup() throws Exception {
String virtualNetworkName = "";
try
{
// Arrange
GatewayListConnectionsResponse gatewayListConnectionsResponse = networkManagementClient.getGatewaysOperations().listConnections(virtualNetworkName);
ArrayList<GatewayListConnectionsResponse.GatewayConnection> gatewayConnectionlist = gatewayListConnectionsResponse.getConnections();
for (GatewayListConnectionsResponse.GatewayConnection gatewayConnection : gatewayConnectionlist )
{
// if (gatewayConnection.getAllocatedIPAddresses()().contains("testsdkGateway"))
// {
// virtualnetworkManagementClient.getGatewaysOperations().delete(virtualNetworkName);
// }
}
}
catch (ServiceException e) {
e.printStackTrace();
}
}

@Test
public void gatewayListSupportedDevicesResponse() throws Exception {
// Arrange
GatewayListSupportedDevicesResponse gatewayListConnectionsResponse = networkManagementClient.getGatewaysOperations().listSupportedDevices();

public void createReservedIPSuccess() throws Exception {
String gatewayName = "testsdkGateway";
String gatewayDescription = "testsdkGatewayDescription";
// Arrange
GatewayCreateParameters createParameters = new GatewayCreateParameters();
//createParameters.setConfiguration(configurationValue);

// Act
OperationResponse operationResponse = networkManagementClient.getGatewaysOperations().create(gatewayName, createParameters);

// Assert
Assert.assertEquals(200, gatewayListConnectionsResponse.getStatusCode());
Assert.assertNotNull(gatewayListConnectionsResponse.getRequestId());
Assert.assertEquals(201, operationResponse.getStatusCode());
Assert.assertNotNull(operationResponse.getRequestId());
}

@Test
public void getReservedIPSuccess() throws Exception {
String ipName = "testsdkNetwork";
// Act
GatewayGetResponse networkReservedIPGetResponse = networkManagementClient.getGatewaysOperations().get(ipName);
// Assert
Assert.assertEquals(200, networkReservedIPGetResponse.getStatusCode());
Assert.assertNotNull(networkReservedIPGetResponse.getRequestId());
//Assert.assertNotNull(NetworkResponse.getCapabilities());
//Assert.assertEquals(NetworkName1, NetworkResponse.getName());
//Assert.assertEquals(NetworkLocation1, NetworkResponse.getLocation());
//Assert.assertEquals(Networklabel1, NetworkResponse.getLabel());
}

@Test
public void listReservedIPSuccess() throws Exception {
String virtualNetworkName = "";

// Arrange
GatewayListConnectionsResponse gatewayListConnectionsResponse =networkManagementClient.getGatewaysOperations().listConnections(virtualNetworkName);
ArrayList<GatewayListConnectionsResponse.GatewayConnection> gatewayConnectionlist = gatewayListConnectionsResponse.getConnections();
for (GatewayListConnectionsResponse.GatewayConnection gatewayConnection : gatewayConnectionlist )
{
// if (gatewayConnection.getAllocatedIPAddresses()().contains("testsdkGateway"))
// {
// virtualnetworkManagementClient.getGatewaysOperations().delete(virtualNetworkName);
// }
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,101 +14,25 @@
*/
package com.microsoft.windowsazure.management.network;

import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.net.URI;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.junit.Assert;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.microsoft.windowsazure.core.pipeline.apache.ApacheConfigurationProperties;
import com.microsoft.windowsazure.core.utils.BOMInputStream;
import com.microsoft.windowsazure.core.utils.KeyStoreType;
import com.microsoft.windowsazure.management.configuration.*;
import com.microsoft.windowsazure.management.network.models.NetworkGetConfigurationResponse;
import com.microsoft.windowsazure.management.network.models.NetworkSetConfigurationParameters;
import com.microsoft.windowsazure.*;

public abstract class NetworkManagementIntegrationTestBase {

protected static NetworkManagementClient networkManagementClient;
protected static NetworkManagementClient networkManagementClient;

protected static void createService() throws Exception {
// reinitialize configuration from known state
Configuration config = createConfiguration();
config.setProperty(ApacheConfigurationProperties.PROPERTY_RETRY_HANDLER, new DefaultHttpRequestRetryHandler());

Configuration config = createConfiguration();
networkManagementClient = NetworkManagementService.create(config);
}

protected static void createNetwork(String networkName) throws Exception {
NetworkGetConfigurationResponse operationResponse = networkManagementClient.getNetworksOperations().getConfiguration();

//Assert
Assert.assertEquals(200, operationResponse.getStatusCode());
Assert.assertNotNull(operationResponse.getRequestId());
Assert.assertNotNull(operationResponse.getConfiguration());

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(new BOMInputStream(new ByteArrayInputStream(operationResponse.getConfiguration().getBytes())));

NodeList list = responseDoc.getElementsByTagNameNS("http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration", "VirtualNetworkSite");
boolean exist = false;
for (int i = 0; i < list.getLength(); i++) {
if (list.item(i).getAttributes().getNamedItem("name").getTextContent().equals(networkName)) {
exist = true;
break;
}
}

if (!exist) {
Element vnets = (Element) responseDoc.getElementsByTagNameNS("http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration", "VirtualNetworkSites").item(0);
Element vnet = responseDoc.createElementNS("http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration", "VirtualNetworkSite");
vnet.setAttribute("name", networkName);
vnet.setAttribute("AffinityGroup", "azuresdkci");

Element addressSpace = responseDoc.createElementNS("http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration", "AddressSpace");
vnet.appendChild(addressSpace);

Element addressPrefix = responseDoc.createElementNS("http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration", "AddressPrefix");
addressPrefix.setTextContent("10.10.0.0/8");
addressSpace.appendChild(addressPrefix);

vnets.appendChild(vnet);

DOMSource domSource = new DOMSource(responseDoc);
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(domSource, streamResult);

NetworkSetConfigurationParameters parameters = new NetworkSetConfigurationParameters();
parameters.setConfiguration(stringWriter.toString());
networkManagementClient.getNetworksOperations().setConfiguration(parameters);
}
}

protected static Configuration createConfiguration() throws Exception {
String baseUri = System.getenv(ManagementConfiguration.URI);
return ManagementConfiguration.configure(
baseUri != null ? new URI(baseUri) : null,
System.getenv(ManagementConfiguration.SUBSCRIPTION_ID),
System.getenv(ManagementConfiguration.KEYSTORE_PATH),
System.getenv(ManagementConfiguration.KEYSTORE_PASSWORD),
KeyStoreType.fromString(System.getenv(ManagementConfiguration.KEYSTORE_TYPE))
);
// return ManagementConfiguration.configure(
// System.getenv(ManagementConfiguration.SUBSCRIPTION_ID),
// System.getenv(ManagementConfiguration.KEYSTORE_PATH),
// System.getenv(ManagementConfiguration.KEYSTORE_PASSWORD)
// );
return PublishSettingsLoader.createManagementConfiguration("C:\\Users\\xuezhain\\Downloads\\node-Azpad057T7N4266-6-28-2013-credentials.publishsettings","00977cdb-163f-435f-9c32-39ec8ae61f4d");
}
}
Loading

0 comments on commit 890cf0f

Please sign in to comment.