Improved parsing tests

This commit is contained in:
Jeremy Daggett 2012-02-28 21:16:54 -08:00
parent 0f4fce2e19
commit 2287d2bbcf
4 changed files with 249 additions and 36 deletions

View File

@ -0,0 +1,87 @@
/**
* 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.openstack.nova.v1_1.parse;
import java.net.URI;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.domain.Link;
import org.jclouds.openstack.domain.Resource;
import org.jclouds.openstack.domain.Link.Relation;
import org.jclouds.openstack.nova.v1_1.config.NovaParserModule;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
* @author Jeremy Daggett
*/
@Test(groups = "unit", testName = "ParseImageListTest")
public class ParseImageListTest extends BaseSetParserTest<Resource> {
@Override
public String resource() {
return "/image_list.json";
}
@Override
@SelectJson("images")
@Consumes(MediaType.APPLICATION_JSON)
public Set<Resource> expected() {
return ImmutableSet
.of(Resource
.builder()
.id("52415800-8b69-11e0-9b19-734f6f006e54")
.name("CentOS 5.2")
.links(
Link.create(
Relation.SELF,
URI.create("http://servers.api.openstack.org/v1.1/1234/images/52415800-8b69-11e0-9b19-734f6f006e54")),
Link.create(
Relation.BOOKMARK,
URI.create("http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f6f006e54")))
.build(),
Resource
.builder()
.id("52415800-8b69-11e0-9b19-734f5736d2a2")
.name("My Server Backup")
.links(
Link.create(
Relation.SELF,
URI.create("http://servers.api.openstack.org/v1.1/1234/images/52415800-8b69-11e0-9b19-734f5736d2a2")),
Link.create(
Relation.BOOKMARK,
URI.create("http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f5736d2a2")))
.build());
}
protected Injector injector() {
return Guice.createInjector(new NovaParserModule(), new GsonModule());
}
}

View File

@ -0,0 +1,104 @@
/**
* 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.openstack.nova.v1_1.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.domain.Link;
import org.jclouds.openstack.domain.Link.Relation;
import org.jclouds.openstack.domain.Resource;
import org.jclouds.openstack.nova.v1_1.config.NovaParserModule;
import org.jclouds.openstack.nova.v1_1.domain.Image;
import org.jclouds.openstack.nova.v1_1.domain.ImageStatus;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Jeremy Daggett
*/
@Test(groups = "unit", testName = "ParseImageTest")
public class ParseImageTest extends BaseItemParserTest<Image> {
@Override
public String resource() {
return "/image_details.json";
}
@Override
@SelectJson("image")
@Consumes(MediaType.APPLICATION_JSON)
public Image expected() {
return Image
.builder()
.id("52415800-8b69-11e0-9b19-734f5736d2a2")
.name("My Server Backup")
.updated(
new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2010-10-10T12:00:00Z"))
.created(
new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2010-08-10T12:00:00Z"))
.tenantId("12345")
.userId("joe")
.status(ImageStatus.SAVING)
.progress(80)
.minDisk(5)
.minRam(256)
.metadata(new ImmutableMap.Builder<String, String>()
.put("ImageType", "Gold")
.put("ImageVersion", "1.5").build())
.server(
Resource
.builder()
.id("52415800-8b69-11e0-9b19-734f335aa7b3")
.name("null")
.links(
Link.create(
Relation.SELF,
URI.create("http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f335aa7b3")),
Link.create(
Relation.BOOKMARK,
URI.create("http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f335aa7b3")))
.build())
.links(
ImmutableSet.of(
Link.create(
Relation.SELF,
URI.create("http://servers.api.openstack.org/v1.1/1234/images/52415800-8b69-11e0-9b19-734f5736d2a2")),
Link.create(
Relation.BOOKMARK,
URI.create("http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f5736d2a2"))))
.build();
}
protected Injector injector() {
return Guice.createInjector(new NovaParserModule(), new GsonModule());
}
}

View File

@ -18,17 +18,25 @@
*/
package org.jclouds.openstack.nova.v1_1.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.domain.Link;
import org.jclouds.openstack.domain.Link.Relation;
import org.jclouds.openstack.domain.Resource;
import org.jclouds.openstack.nova.v1_1.config.NovaParserModule;
import org.jclouds.openstack.nova.v1_1.domain.Address;
import org.jclouds.openstack.nova.v1_1.domain.Server;
import org.jclouds.openstack.nova.v1_1.domain.ServerStatus;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -50,10 +58,54 @@ public class ParseServerTest extends BaseItemParserTest<Server> {
return Server
.builder()
.id("52415800-8b69-11e0-9b19-734f000004d2")
.tenantId("1234")
.userId("5678")
.name("sample-server")
.publicAddresses(Address.createV4("67.23.10.132"), Address.createV6("::babe:67.23.10.132"),
Address.createV4("67.23.10.131"), Address.createV6("::babe:4317:0A83")).privateAddresses(
Address.createV4("10.176.42.16"), Address.createV6("::babe:10.176.42.16")).build();
.updated(
new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2010-10-10T12:00:00Z"))
.created(
new SimpleDateFormatDateService()
.iso8601SecondsDateParse("2010-08-10T12:00:00Z"))
.hostId("e4d909c290d0fb1ca068ffaddf22cbd0")
.accessIPv4("67.23.10.132")
.accessIPv6("::babe:67.23.10.132")
.status(ServerStatus.BUILD)
.progress(60)
.image(
Resource
.builder()
.id("52415800-8b69-11e0-9b19-734f6f006e54")
.name("null")
.links(
Link.create(
Relation.SELF,
URI.create("http://servers.api.openstack.org/v1.1/1234/images/52415800-8b69-11e0-9b19-734f6f006e54")),
Link.create(
Relation.BOOKMARK,
URI.create("http://servers.api.openstack.org/1234/images/52415800-8b69-11e0-9b19-734f6f006e54")))
.build())
.flavor(Resource
.builder()
.id("52415800-8b69-11e0-9b19-734f216543fd")
.name("null")
.links(
Link.create(
Relation.SELF,
URI.create("http://servers.api.openstack.org/v1.1/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd")),
Link.create(
Relation.BOOKMARK,
URI.create("http://servers.api.openstack.org/1234/flavors/52415800-8b69-11e0-9b19-734f216543fd")))
.build())
.metadata(new ImmutableMap.Builder<String, String>()
.put("Server Label", "Web Head 1")
.put("Image Version", "2.1").build())
.publicAddresses(Address.createV4("67.23.10.132"),
Address.createV6("::babe:67.23.10.132"),
Address.createV4("67.23.10.131"),
Address.createV6("::babe:4317:0A83"))
.privateAddresses(Address.createV4("10.176.42.16"),
Address.createV6("::babe:10.176.42.16")).build();
}

View File

@ -3,15 +3,6 @@
{
"id": "52415800-8b69-11e0-9b19-734f6f006e54",
"name": "CentOS 5.2",
"updated": "2010-10-10T12:00:00Z",
"created": "2010-08-10T12:00:00Z",
"tenant_id" : "12345",
"user_id" : "joe",
"status": "ACTIVE",
"metadata": {
"ImageType": "Gold",
"ImageVersion": "1.5"
},
"links": [
{
"rel": "self",
@ -26,27 +17,6 @@
{
"id" : "52415800-8b69-11e0-9b19-734f5736d2a2",
"name" : "My Server Backup",
"updated" : "2010-10-10T12:00:00Z",
"created" : "2010-08-10T12:00:00Z",
"tenant_id" : "12345",
"user_id" : "joe",
"status" : "SAVING",
"progress" : 80,
"minDisk" : 5,
"minRam" : 256,
"server" : {
"id": "52415800-8b69-11e0-9b19-734f335aa7b3",
"links": [
{
"rel": "self",
"href": "http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f335aa7b3"
},
{
"rel": "bookmark",
"href": "http://servers.api.openstack.org/1234/servers/52415800-8b69-11e0-9b19-734f335aa7b3"
}
]
},
"links": [
{
"rel" : "self",