mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 18:43:26 +01:00
Fix and add some Rest unit and IT tests. Fix by adding a missing type of RoutingConfig.
Signed-off-by: Hugo Trippaers <htrippaers@schubergphilis.com>
This commit is contained in:
parent
b70af44ecf
commit
808c6df6d7
@ -634,6 +634,9 @@ public class NiciraNvpApi {
|
|||||||
|
|
||||||
public static class RoutingConfigAdapter implements JsonDeserializer<RoutingConfig> {
|
public static class RoutingConfigAdapter implements JsonDeserializer<RoutingConfig> {
|
||||||
|
|
||||||
|
private static final String ROUTING_TABLE_ROUTING_CONFIG = "RoutingTableRoutingConfig";
|
||||||
|
private static final String SINGLE_DEFAULT_ROUTE_IMPLICIT_ROUTING_CONFIG = "SingleDefaultRouteImplicitRoutingConfig";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RoutingConfig deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {
|
public RoutingConfig deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {
|
||||||
final JsonObject jsonObject = jsonElement.getAsJsonObject();
|
final JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||||
@ -643,8 +646,10 @@ public class NiciraNvpApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String routingConfigType = jsonObject.get("type").getAsString();
|
final String routingConfigType = jsonObject.get("type").getAsString();
|
||||||
if ("SingleDefaultRouteImplicitRoutingConfig".equals(routingConfigType)) {
|
if (SINGLE_DEFAULT_ROUTE_IMPLICIT_ROUTING_CONFIG.equals(routingConfigType)) {
|
||||||
return context.deserialize(jsonElement, SingleDefaultRouteImplicitRoutingConfig.class);
|
return context.deserialize(jsonElement, SingleDefaultRouteImplicitRoutingConfig.class);
|
||||||
|
} else if (ROUTING_TABLE_ROUTING_CONFIG.equals(routingConfigType)) {
|
||||||
|
return context.deserialize(jsonElement, RoutingTableRoutingConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new JsonParseException("Failed to deserialize type \"" + routingConfigType + "\"");
|
throw new JsonParseException("Failed to deserialize type \"" + routingConfigType + "\"");
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
// or more contributor license agreements. See the NOTICE file
|
||||||
|
// distributed with this work for additional information
|
||||||
|
// regarding copyright ownership. The ASF licenses this file
|
||||||
|
// to you under the Apache License, Version 2.0 (the
|
||||||
|
// "License"); you may not use this file except in compliance
|
||||||
|
// with the License. You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing,
|
||||||
|
// software distributed under the License is distributed on an
|
||||||
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
// KIND, either express or implied. See the License for the
|
||||||
|
// specific language governing permissions and limitations
|
||||||
|
// under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
package com.cloud.network.nicira;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RoutingTableRoutingConfig extends RoutingConfig {
|
||||||
|
public final String type = "RoutingTableRoutingConfig";
|
||||||
|
|
||||||
|
public RoutingTableRoutingConfig() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,199 +20,214 @@
|
|||||||
package com.cloud.network.nicira;
|
package com.cloud.network.nicira;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
|
import org.apache.commons.httpclient.HttpMethod;
|
||||||
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
|
import org.apache.commons.httpclient.methods.DeleteMethod;
|
||||||
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
|
import org.apache.commons.httpclient.methods.PutMethod;
|
||||||
|
import org.apache.commons.httpclient.params.HttpClientParams;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
|
|
||||||
|
import com.cloud.utils.rest.RESTServiceConnector;
|
||||||
|
import com.cloud.utils.rest.RESTValidationStrategy;
|
||||||
|
|
||||||
public class NiciraNvpApiTest {
|
public class NiciraNvpApiTest {
|
||||||
// protected static final String UUID = "aaaa";
|
protected static final String UUID = "aaaa";
|
||||||
// protected static final String UUID2 = "bbbb";
|
protected static final String UUID2 = "bbbb";
|
||||||
// protected static final String UUID_SEC_PROFILE_URI = NiciraNvpApi.SEC_PROFILE_URI_PREFIX + "/aaaa";
|
protected static final String UUID_SEC_PROFILE_URI = NiciraNvpApi.SEC_PROFILE_URI_PREFIX + "/aaaa";
|
||||||
// protected static final String SCHEMA = "myTestSchema";
|
protected static final String SCHEMA = "myTestSchema";
|
||||||
// protected static final String SCHEMA2 = "myTestSchema2";
|
protected static final String SCHEMA2 = "myTestSchema2";
|
||||||
// protected static final String HREF = "myTestHref";
|
protected static final String HREF = "myTestHref";
|
||||||
// protected static final String HREF2 = "myTestHref2";
|
protected static final String HREF2 = "myTestHref2";
|
||||||
// protected static final String DISPLAY_NAME = "myTestName";
|
protected static final String SEC_PROFILE_JSON_RESPONSE =
|
||||||
// protected static final String UUID_JSON_RESPONSE = "{\"uuid\" : \"aaaa\"}";
|
"{\"uuid\" : \"aaaa\","
|
||||||
// protected static final String SEC_PROFILE_JSON_RESPONSE =
|
+ "\"display_name\" : \"myTestName\","
|
||||||
// "{\"uuid\" : \"aaaa\","
|
+ "\"href\" : \"myTestHref\","
|
||||||
// + "\"display_name\" : \"myTestName\","
|
+ "\"schema\" : \"myTestSchema\"}";
|
||||||
// + "\"href\" : \"myTestHref\","
|
|
||||||
// + "\"schema\" : \"myTestSchema\"}";
|
protected static final String SEC_PROFILE_LIST_JSON_RESPONSE = "{\"results\" : [{\"uuid\" : \"aaaa\","
|
||||||
//
|
+ "\"display_name\" : \"myTestName\","
|
||||||
// protected static final String SEC_PROFILE_LIST_JSON_RESPONSE = "{\"results\" : [{\"uuid\" : \"aaaa\","
|
+ "\"href\" : \"myTestHref\","
|
||||||
// + "\"display_name\" : \"myTestName\","
|
+ "\"schema\" : \"myTestSchema\"},"
|
||||||
// + "\"href\" : \"myTestHref\","
|
+ "{ \"uuid\" : \"bbbb\","
|
||||||
// + "\"schema\" : \"myTestSchema\"},"
|
+ "\"display_name\" : \"myTestName2\","
|
||||||
// + "{ \"uuid\" : \"bbbb\","
|
+ "\"href\" : \"myTestHref2\","
|
||||||
// + "\"display_name\" : \"myTestName2\","
|
+ "\"schema\" : \"myTestSchema2\"}],"
|
||||||
// + "\"href\" : \"myTestHref2\","
|
+ "\"result_count\": 2}";
|
||||||
// + "\"schema\" : \"myTestSchema2\"}],"
|
|
||||||
// + "\"result_count\": 2}";
|
NiciraNvpApi api;
|
||||||
//
|
HttpClient client = mock(HttpClient.class);
|
||||||
// NiciraNvpApi api;
|
HttpMethod method;
|
||||||
// HttpClient client = mock(HttpClient.class);
|
String type;
|
||||||
// HttpMethod method;
|
String uri;
|
||||||
// String type;
|
|
||||||
// String uri;
|
@Before
|
||||||
//
|
public void setUp() {
|
||||||
// @Before
|
final HttpClientParams hmp = mock(HttpClientParams.class);
|
||||||
// public void setUp() {
|
when(client.getParams()).thenReturn(hmp);
|
||||||
// final HttpClientParams hmp = mock(HttpClientParams.class);
|
api = new NiciraNvpApi();
|
||||||
// when(client.getParams()).thenReturn(hmp);
|
|
||||||
// api = new NiciraNvpApi();
|
api.restConnector = new RESTServiceConnector(new RESTValidationStrategy()) {
|
||||||
//
|
@Override
|
||||||
// api.restConnector = new RESTServiceConnector() {
|
public HttpClient createHttpClient() {
|
||||||
// @Override
|
return client;
|
||||||
// public HttpClient createHttpClient() {
|
}
|
||||||
// return client;
|
|
||||||
// }
|
@Override
|
||||||
//
|
public HttpMethod createMethod(final String newType, final String newUri) {
|
||||||
// @Override
|
type = newType;
|
||||||
// public HttpMethod createMethod(final String newType, final String newUri) {
|
uri = newUri;
|
||||||
// type = newType;
|
return method;
|
||||||
// uri = newUri;
|
}
|
||||||
// return method;
|
};
|
||||||
// }
|
|
||||||
// };
|
api.setAdminCredentials("admin", "adminpass");
|
||||||
//
|
api.setControllerAddress("localhost");
|
||||||
// api.setAdminCredentials("admin", "adminpass");
|
}
|
||||||
// api.setControllerAddress("localhost");
|
|
||||||
// }
|
@Test
|
||||||
//
|
public void testFindSecurityProfile() throws NiciraNvpApiException, IOException {
|
||||||
// @Test
|
// Prepare
|
||||||
// public void testFindSecurityProfile() throws NiciraNvpApiException, IOException {
|
method = mock(GetMethod.class);
|
||||||
// // Prepare
|
when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
|
||||||
// method = mock(GetMethod.class);
|
when(method.getResponseBodyAsString()).thenReturn(SEC_PROFILE_LIST_JSON_RESPONSE);
|
||||||
// when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
|
final NameValuePair[] queryString = new NameValuePair[]{
|
||||||
// when(method.getResponseBodyAsString()).thenReturn(SEC_PROFILE_LIST_JSON_RESPONSE);
|
new NameValuePair("fields","*")};
|
||||||
// final NameValuePair[] queryString = new NameValuePair[]{
|
|
||||||
// new NameValuePair("fields","*")};
|
// Execute
|
||||||
//
|
final NiciraNvpList<SecurityProfile> actualProfiles = api.findSecurityProfile();
|
||||||
// // Execute
|
|
||||||
// final NiciraNvpList<SecurityProfile> actualProfiles = api.findSecurityProfile();
|
// Assert
|
||||||
//
|
verify(method, times(1)).releaseConnection();
|
||||||
// // Assert
|
verify(method, times(1)).setQueryString(queryString);
|
||||||
// verify(method, times(1)).releaseConnection();
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// verify(method, times(1)).setQueryString(queryString);
|
UUID, actualProfiles.getResults().get(0).getUuid());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// UUID, actualProfiles.getResults().get(0).getUuid());
|
HREF, actualProfiles.getResults().get(0).getHref());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Schema in the newly created SecurityProfile",
|
||||||
// HREF, actualProfiles.getResults().get(0).getHref());
|
SCHEMA, actualProfiles.getResults().get(0).getSchema());
|
||||||
// assertEquals("Wrong Schema in the newly created SecurityProfile",
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// SCHEMA, actualProfiles.getResults().get(0).getSchema());
|
UUID2, actualProfiles.getResults().get(1).getUuid());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// UUID2, actualProfiles.getResults().get(1).getUuid());
|
HREF2, actualProfiles.getResults().get(1).getHref());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Schema in the newly created SecurityProfile",
|
||||||
// HREF2, actualProfiles.getResults().get(1).getHref());
|
SCHEMA2, actualProfiles.getResults().get(1).getSchema());
|
||||||
// assertEquals("Wrong Schema in the newly created SecurityProfile",
|
assertEquals("Wrong Schema in the newly created SecurityProfile",
|
||||||
// SCHEMA2, actualProfiles.getResults().get(1).getSchema());
|
2, actualProfiles.getResultCount());
|
||||||
// assertEquals("Wrong Schema in the newly created SecurityProfile",
|
assertEquals("Wrong URI for SecurityProfile creation REST service",
|
||||||
// 2, actualProfiles.getResultCount());
|
NiciraNvpApi.SEC_PROFILE_URI_PREFIX, uri);
|
||||||
// assertEquals("Wrong URI for SecurityProfile creation REST service",
|
assertEquals("Wrong URI for SecurityProfile creation REST service",
|
||||||
// NiciraNvpApi.SEC_PROFILE_URI_PREFIX, uri);
|
NiciraNvpApi.GET_METHOD_TYPE, type);
|
||||||
// assertEquals("Wrong URI for SecurityProfile creation REST service",
|
}
|
||||||
// NiciraNvpApi.GET_METHOD_TYPE, type);
|
|
||||||
// }
|
@Test
|
||||||
//
|
public void testFindSecurityProfileByUuid() throws NiciraNvpApiException, IOException {
|
||||||
// @Test
|
// Prepare
|
||||||
// public void testFindSecurityProfileByUuid() throws NiciraNvpApiException, IOException {
|
method = mock(GetMethod.class);
|
||||||
// // Prepare
|
when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
|
||||||
// method = mock(GetMethod.class);
|
when(method.getResponseBodyAsString()).thenReturn(SEC_PROFILE_LIST_JSON_RESPONSE);
|
||||||
// when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
|
final NameValuePair[] queryString = new NameValuePair[]{
|
||||||
// when(method.getResponseBodyAsString()).thenReturn(SEC_PROFILE_LIST_JSON_RESPONSE);
|
new NameValuePair("uuid", UUID),
|
||||||
// final NameValuePair[] queryString = new NameValuePair[]{
|
new NameValuePair("fields","*")
|
||||||
// new NameValuePair("uuid", UUID),
|
};
|
||||||
// new NameValuePair("fields","*")
|
|
||||||
// };
|
// Execute
|
||||||
//
|
final NiciraNvpList<SecurityProfile> actualProfiles = api.findSecurityProfile(UUID);
|
||||||
// // Execute
|
|
||||||
// final NiciraNvpList<SecurityProfile> actualProfiles = api.findSecurityProfile(UUID);
|
// Assert
|
||||||
//
|
verify(method, times(1)).releaseConnection();
|
||||||
// // Assert
|
verify(method, times(1)).setQueryString(queryString);
|
||||||
// verify(method, times(1)).releaseConnection();
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// verify(method, times(1)).setQueryString(queryString);
|
UUID, actualProfiles.getResults().get(0).getUuid());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// UUID, actualProfiles.getResults().get(0).getUuid());
|
HREF, actualProfiles.getResults().get(0).getHref());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Schema in the newly created SecurityProfile",
|
||||||
// HREF, actualProfiles.getResults().get(0).getHref());
|
SCHEMA, actualProfiles.getResults().get(0).getSchema());
|
||||||
// assertEquals("Wrong Schema in the newly created SecurityProfile",
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// SCHEMA, actualProfiles.getResults().get(0).getSchema());
|
UUID2, actualProfiles.getResults().get(1).getUuid());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// UUID2, actualProfiles.getResults().get(1).getUuid());
|
HREF2, actualProfiles.getResults().get(1).getHref());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Schema in the newly created SecurityProfile",
|
||||||
// HREF2, actualProfiles.getResults().get(1).getHref());
|
SCHEMA2, actualProfiles.getResults().get(1).getSchema());
|
||||||
// assertEquals("Wrong Schema in the newly created SecurityProfile",
|
assertEquals("Wrong Schema in the newly created SecurityProfile",
|
||||||
// SCHEMA2, actualProfiles.getResults().get(1).getSchema());
|
2, actualProfiles.getResultCount());
|
||||||
// assertEquals("Wrong Schema in the newly created SecurityProfile",
|
assertEquals("Wrong URI for SecurityProfile creation REST service",
|
||||||
// 2, actualProfiles.getResultCount());
|
NiciraNvpApi.SEC_PROFILE_URI_PREFIX, uri);
|
||||||
// assertEquals("Wrong URI for SecurityProfile creation REST service",
|
assertEquals("Wrong HTTP method for SecurityProfile creation REST service",
|
||||||
// NiciraNvpApi.SEC_PROFILE_URI_PREFIX, uri);
|
NiciraNvpApi.GET_METHOD_TYPE, type);
|
||||||
// assertEquals("Wrong HTTP method for SecurityProfile creation REST service",
|
}
|
||||||
// NiciraNvpApi.GET_METHOD_TYPE, type);
|
|
||||||
// }
|
@Test
|
||||||
//
|
public void testCreateSecurityProfile() throws NiciraNvpApiException, IOException {
|
||||||
// @Test
|
// Prepare
|
||||||
// public void testCreateSecurityProfile() throws NiciraNvpApiException, IOException {
|
final SecurityProfile inputSecProfile = new SecurityProfile();
|
||||||
// // Prepare
|
method = mock(PostMethod.class);
|
||||||
// final SecurityProfile inputSecProfile = new SecurityProfile();
|
when(method.getStatusCode()).thenReturn(HttpStatus.SC_CREATED);
|
||||||
// method = mock(PostMethod.class);
|
when(method.getResponseBodyAsString()).thenReturn(SEC_PROFILE_JSON_RESPONSE);
|
||||||
// when(method.getStatusCode()).thenReturn(HttpStatus.SC_CREATED);
|
|
||||||
// when(method.getResponseBodyAsString()).thenReturn(SEC_PROFILE_JSON_RESPONSE);
|
// Execute
|
||||||
//
|
final SecurityProfile actualSecProfile = api.createSecurityProfile(inputSecProfile);
|
||||||
// // Execute
|
|
||||||
// final SecurityProfile actualSecProfile = api.createSecurityProfile(inputSecProfile);
|
// Assert
|
||||||
//
|
verify(method, times(1)).releaseConnection();
|
||||||
// // Assert
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// verify(method, times(1)).releaseConnection();
|
UUID, actualSecProfile.getUuid());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
||||||
// UUID, actualSecProfile.getUuid());
|
HREF, actualSecProfile.getHref());
|
||||||
// assertEquals("Wrong Uuid in the newly created SecurityProfile",
|
assertEquals("Wrong Schema in the newly created SecurityProfile",
|
||||||
// HREF, actualSecProfile.getHref());
|
SCHEMA, actualSecProfile.getSchema());
|
||||||
// assertEquals("Wrong Schema in the newly created SecurityProfile",
|
assertEquals("Wrong URI for SecurityProfile creation REST service",
|
||||||
// SCHEMA, actualSecProfile.getSchema());
|
NiciraNvpApi.SEC_PROFILE_URI_PREFIX, uri);
|
||||||
// assertEquals("Wrong URI for SecurityProfile creation REST service",
|
assertEquals("Wrong HTTP method for SecurityProfile creation REST service",
|
||||||
// NiciraNvpApi.SEC_PROFILE_URI_PREFIX, uri);
|
NiciraNvpApi.POST_METHOD_TYPE, type);
|
||||||
// assertEquals("Wrong HTTP method for SecurityProfile creation REST service",
|
}
|
||||||
// NiciraNvpApi.POST_METHOD_TYPE, type);
|
|
||||||
// }
|
@Test
|
||||||
//
|
public void testUpdateSecurityProfile() throws NiciraNvpApiException, IOException {
|
||||||
// @Test
|
// Prepare
|
||||||
// public void testUpdateSecurityProfile() throws NiciraNvpApiException, IOException {
|
final SecurityProfile inputSecProfile = new SecurityProfile();
|
||||||
// // Prepare
|
method = mock(PutMethod.class);
|
||||||
// final SecurityProfile inputSecProfile = new SecurityProfile();
|
when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
|
||||||
// method = mock(PutMethod.class);
|
|
||||||
// when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
|
// Execute
|
||||||
//
|
api.updateSecurityProfile(inputSecProfile, UUID);
|
||||||
// // Execute
|
|
||||||
// api.updateSecurityProfile(inputSecProfile, UUID);
|
// Assert
|
||||||
//
|
verify(method, times(1)).releaseConnection();
|
||||||
// // Assert
|
assertEquals("Wrong URI for SecurityProfile creation REST service",
|
||||||
// verify(method, times(1)).releaseConnection();
|
UUID_SEC_PROFILE_URI, uri);
|
||||||
// assertEquals("Wrong URI for SecurityProfile creation REST service",
|
assertEquals("Wrong HTTP method for SecurityProfile creation REST service",
|
||||||
// UUID_SEC_PROFILE_URI, uri);
|
NiciraNvpApi.PUT_METHOD_TYPE, type);
|
||||||
// assertEquals("Wrong HTTP method for SecurityProfile creation REST service",
|
}
|
||||||
// NiciraNvpApi.PUT_METHOD_TYPE, type);
|
|
||||||
// }
|
@Test
|
||||||
//
|
public void testDeleteSecurityProfile() throws NiciraNvpApiException, IOException {
|
||||||
// @Test
|
// Prepare
|
||||||
// public void testDeleteSecurityProfile() throws NiciraNvpApiException, IOException {
|
method = mock(DeleteMethod.class);
|
||||||
// // Prepare
|
when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
|
||||||
// method = mock(DeleteMethod.class);
|
|
||||||
// when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
|
// Execute
|
||||||
//
|
api.deleteSecurityProfile(UUID);
|
||||||
// // Execute
|
|
||||||
// api.deleteSecurityProfile(UUID);
|
// Assert
|
||||||
//
|
verify(method, times(1)).releaseConnection();
|
||||||
// // Assert
|
assertEquals("Wrong URI for SecurityProfile deletion REST service", UUID_SEC_PROFILE_URI, uri);
|
||||||
// verify(method, times(1)).releaseConnection();
|
assertEquals("Wrong HTTP method for SecurityProfile deletion REST service", NiciraNvpApi.DELETE_METHOD_TYPE, type);
|
||||||
// assertEquals("Wrong URI for SecurityProfile deletion REST service", UUID_SEC_PROFILE_URI, uri);
|
}
|
||||||
// assertEquals("Wrong HTTP method for SecurityProfile deletion REST service", NiciraNvpApi.DELETE_METHOD_TYPE, type);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Test(expected = JsonParseException.class)
|
@Test(expected = JsonParseException.class)
|
||||||
public void testRoutingConfigAdapterNoType() throws NiciraNvpApiException, IOException {
|
public void testRoutingConfigAdapterNoType() throws NiciraNvpApiException, IOException {
|
||||||
|
|||||||
@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
//import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.Header;
|
import org.apache.commons.httpclient.Header;
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
@ -45,28 +44,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class RESTServiceConnectorTest {
|
public class RESTServiceConnectorTest {
|
||||||
protected static final String UUID = "aaaa";
|
protected static final String UUID = "aaaa";
|
||||||
protected static final String UUID2 = "bbbb";
|
|
||||||
protected static final String SCHEMA = "myTestSchema";
|
|
||||||
protected static final String SCHEMA2 = "myTestSchema2";
|
|
||||||
protected static final String HREF = "myTestHref";
|
|
||||||
protected static final String HREF2 = "myTestHref2";
|
|
||||||
protected static final String DISPLAY_NAME = "myTestName";
|
|
||||||
protected static final String UUID_JSON_RESPONSE = "{\"uuid\" : \"aaaa\"}";
|
protected static final String UUID_JSON_RESPONSE = "{\"uuid\" : \"aaaa\"}";
|
||||||
protected static final String SEC_PROFILE_JSON_RESPONSE =
|
|
||||||
"{\"uuid\" : \"aaaa\","
|
|
||||||
+ "\"display_name\" : \"myTestName\","
|
|
||||||
+ "\"href\" : \"myTestHref\","
|
|
||||||
+ "\"schema\" : \"myTestSchema\"}";
|
|
||||||
|
|
||||||
protected static final String SEC_PROFILE_LIST_JSON_RESPONSE = "{\"results\" : [{\"uuid\" : \"aaaa\","
|
|
||||||
+ "\"display_name\" : \"myTestName\","
|
|
||||||
+ "\"href\" : \"myTestHref\","
|
|
||||||
+ "\"schema\" : \"myTestSchema\"},"
|
|
||||||
+ "{ \"uuid\" : \"bbbb\","
|
|
||||||
+ "\"display_name\" : \"myTestName2\","
|
|
||||||
+ "\"href\" : \"myTestHref2\","
|
|
||||||
+ "\"schema\" : \"myTestSchema2\"}],"
|
|
||||||
+ "\"result_count\": 2}";
|
|
||||||
|
|
||||||
RESTServiceConnector connector;
|
RESTServiceConnector connector;
|
||||||
HttpClient client = mock(HttpClient.class);
|
HttpClient client = mock(HttpClient.class);
|
||||||
@ -175,9 +153,6 @@ public class RESTServiceConnectorTest {
|
|||||||
verify(gm, times(1)).getStatusCode();
|
verify(gm, times(1)).getStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bit of a roundabout way to ensure that login is called after an un authorized result
|
|
||||||
* It not possible to properly mock login()
|
|
||||||
*/
|
|
||||||
@Test(expected = CloudstackRESTException.class)
|
@Test(expected = CloudstackRESTException.class)
|
||||||
public void testExecuteMethodWithLogin() throws CloudstackRESTException, HttpException, IOException {
|
public void testExecuteMethodWithLogin() throws CloudstackRESTException, HttpException, IOException {
|
||||||
final GetMethod gm = mock(GetMethod.class);
|
final GetMethod gm = mock(GetMethod.class);
|
||||||
@ -187,6 +162,34 @@ public class RESTServiceConnectorTest {
|
|||||||
verify(gm, times(1)).getStatusCode();
|
verify(gm, times(1)).getStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Bit of a roundabout way to ensure that login is called after an un authorized result
|
||||||
|
* It not possible to properly mock login()
|
||||||
|
*/
|
||||||
|
public void testExecuteMethodWithLoginSucced2ndAttempt() throws CloudstackRESTException, HttpException, IOException {
|
||||||
|
// Prepare
|
||||||
|
final GetMethod gm = mock(GetMethod.class);
|
||||||
|
when(gm.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED).thenReturn(HttpStatus.SC_UNAUTHORIZED);
|
||||||
|
|
||||||
|
final RESTValidationStrategy previousValidationStrategy = connector.validation;
|
||||||
|
connector.validation = new RESTValidationStrategy(){
|
||||||
|
@Override
|
||||||
|
protected void login(final String protocol, final HttpClient client)
|
||||||
|
throws CloudstackRESTException {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
};
|
||||||
|
connector.setAdminCredentials("admin", "adminpass");
|
||||||
|
connector.setControllerAddress("localhost");
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
connector.executeMethod(gm);
|
||||||
|
// Leave mock object as is was
|
||||||
|
connector.validation = previousValidationStrategy;
|
||||||
|
|
||||||
|
// Assert/verify
|
||||||
|
verify(gm, times(2)).getStatusCode();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteCreateObject() throws CloudstackRESTException, IOException {
|
public void testExecuteCreateObject() throws CloudstackRESTException, IOException {
|
||||||
JsonEntity ls = new JsonEntity();
|
JsonEntity ls = new JsonEntity();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user