mirror of https://github.com/apache/jclouds.git
Fix json parsing for ip forwarding rules
This commit is contained in:
parent
8569771712
commit
cd0086c92e
|
@ -31,8 +31,10 @@ import org.jclouds.cloudstack.filters.QuerySigner;
|
|||
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
|
||||
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
@ -56,7 +58,7 @@ public interface NATAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listIpForwardingRules")
|
||||
@Unwrap(depth = 2)
|
||||
@SelectJson("ipforwardingrule")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<IPForwardingRule>> listIPForwardingRules(ListIPForwardingRulesOptions... options);
|
||||
|
@ -66,7 +68,8 @@ public interface NATAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listIpForwardingRules")
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@SelectJson("ipforwardingrule")
|
||||
@OnlyElement
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<IPForwardingRule> getIPForwardingRule(@QueryParam("id") long id);
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.lang.reflect.Method;
|
|||
import org.jclouds.cloudstack.options.CreateIPForwardingRuleOptions;
|
||||
import org.jclouds.cloudstack.options.ListIPForwardingRulesOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
|
||||
|
@ -53,7 +54,7 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
|
|||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
|
@ -71,7 +72,7 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
|
|||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
|
@ -88,7 +89,6 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
|
|||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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 org.jclouds.cloudstack.parse;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.cloudstack.domain.IPForwardingRule;
|
||||
import org.jclouds.json.BaseSetParserTest;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListIPForwardingRulesResponseTest extends BaseSetParserTest<IPForwardingRule> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/listipforwardingrulesresponse.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("ipforwardingrule")
|
||||
public Set<IPForwardingRule> expected() {
|
||||
return ImmutableSet.<IPForwardingRule> of(
|
||||
IPForwardingRule.builder().id(66).protocol("tcp").startPort(22).endPort(22).virtualMachineId(58)
|
||||
.virtualMachineDisplayName("i-4-58-VM").virtualMachineName("i-4-58-VM")
|
||||
.IPAddressId(15).IPAddress("10.27.27.64").state("Active").build());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"listipforwardingrulesresponse": {
|
||||
"count": 1,
|
||||
"ipforwardingrule": [{
|
||||
"id": 66,
|
||||
"protocol": "tcp",
|
||||
"virtualmachineid": 58,
|
||||
"virtualmachinename": "i-4-58-VM",
|
||||
"virtualmachinedisplayname": "i-4-58-VM",
|
||||
"ipaddressid": 15,
|
||||
"ipaddress": "10.27.27.64",
|
||||
"startport": 22,
|
||||
"endport": 22,
|
||||
"state": "Active"
|
||||
}]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue