mirror of https://github.com/apache/jclouds.git
Adding ApiMetadata domain object for Keystone 2.0
This commit is contained in:
parent
890dd0c15b
commit
dda4a46e83
|
@ -0,0 +1,170 @@
|
|||
/**
|
||||
* 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.keystone.v2_0.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.domain.Link;
|
||||
import org.jclouds.openstack.domain.Resource;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Class ApiMetadata
|
||||
*/
|
||||
public class ApiMetadata extends Resource {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromApiMetadata(this);
|
||||
}
|
||||
|
||||
public static class Builder extends Resource.Builder {
|
||||
private String status;
|
||||
private Date updated;
|
||||
private Set<MediaType> mediaTypes = Sets.newLinkedHashSet();
|
||||
|
||||
public Builder status(String status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder updated(Date updated) {
|
||||
this.updated = updated;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder mediaTypes(Set<MediaType> mediaTypes) {
|
||||
this.mediaTypes = mediaTypes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiMetadata build() {
|
||||
return new ApiMetadata(id, name, links, updated, status, mediaTypes);
|
||||
}
|
||||
|
||||
public Builder fromApiMetadata(ApiMetadata in) {
|
||||
return fromResource(in)
|
||||
.status(in.getStatus())
|
||||
.updated(in.getUpdated())
|
||||
.mediaTypes(in.getMediaTypes());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder id(String id) {
|
||||
return Builder.class.cast(super.id(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder name(String name) {
|
||||
return Builder.class.cast(super.name(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder links(Set<Link> links) {
|
||||
return Builder.class.cast(super.links(links));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromResource(Resource in) {
|
||||
return Builder.class.cast(super.fromResource(in));
|
||||
}
|
||||
}
|
||||
|
||||
private final String status;
|
||||
private final Date updated;
|
||||
@SerializedName("media-types")
|
||||
private final Set<MediaType> mediaTypes;
|
||||
|
||||
protected ApiMetadata(String id, String name, Set<Link> links, Date updated, String status, Set<MediaType> mediaTypes) {
|
||||
super(id, name, links);
|
||||
this.status = status;
|
||||
this.updated = updated;
|
||||
this.mediaTypes = ImmutableSet.copyOf(checkNotNull(mediaTypes, "mediaTypes"));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@Nullable
|
||||
public String getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@Nullable
|
||||
public Date getUpdated() {
|
||||
return this.updated;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@Nullable
|
||||
public Set<MediaType> getMediaTypes() {
|
||||
return Collections.unmodifiableSet(this.mediaTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(status, updated, mediaTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
ApiMetadata that = ApiMetadata.class.cast(obj);
|
||||
return Objects.equal(this.status, that.status)
|
||||
&& Objects.equal(this.updated, that.updated)
|
||||
&& Objects.equal(this.mediaTypes, that.mediaTypes)
|
||||
;
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return super.string()
|
||||
.add("status", status)
|
||||
.add("updated", updated)
|
||||
.add("mediaTypes", mediaTypes);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/**
|
||||
* 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.keystone.v2_0.domain;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
|
||||
/**
|
||||
* Class MediaType
|
||||
*/
|
||||
public class MediaType {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return builder().fromMediaType(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String base;
|
||||
private String type;
|
||||
|
||||
public Builder base(String base) {
|
||||
this.base = base;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MediaType build() {
|
||||
return new MediaType(this);
|
||||
}
|
||||
|
||||
public Builder fromMediaType(MediaType in) {
|
||||
return this.base(in.getBase()).type(in.getType());
|
||||
}
|
||||
}
|
||||
|
||||
private final String base;
|
||||
private final String type;
|
||||
|
||||
protected MediaType(Builder builder) {
|
||||
this.base = builder.base;
|
||||
this.type = builder.type;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@Nullable
|
||||
public String getBase() {
|
||||
return this.base;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@Nullable
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(base, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
MediaType that = MediaType.class.cast(obj);
|
||||
return Objects.equal(this.base, that.base)
|
||||
&& Objects.equal(this.type, that.type)
|
||||
;
|
||||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper("")
|
||||
.add("base", base)
|
||||
.add("type", type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return string().toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* 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.keystone.v2_0.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.openstack.domain.Link;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.ApiMetadata;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Endpoint;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Role;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Service;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Tenant;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Token;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.User;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseApiMetadataTest")
|
||||
public class ParseApiMetadataTest extends BaseItemParserTest<ApiMetadata> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/apiMetadataResponse.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("version")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public ApiMetadata expected() {
|
||||
return ApiMetadata.builder().id("v2.0")
|
||||
.links(ImmutableSet.of(Link.builder().relation(Link.Relation.SELF).href(URI.create("http://172.16.89.140:5000/v2.0/")).build(),
|
||||
Link.builder().relation(Link.Relation.DESCRIBEDBY).type("text/html").href(URI.create("http://docs.openstack.org/api/openstack-identity-service/2.0/content/")).build(),
|
||||
Link.builder().relation(Link.Relation.DESCRIBEDBY).type("application/pdf").href(URI.create("http://docs.openstack.org/api/openstack-identity-service/2.0/identity-dev-guide-2.0.pdf")).build()
|
||||
))
|
||||
.status("beta")
|
||||
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-11-19T00:00:00Z"))
|
||||
.mediaTypes(ImmutableSet.of(
|
||||
org.jclouds.openstack.keystone.v2_0.domain.MediaType.builder().base("application/json").type("application/vnd.openstack.identity-v2.0+json").build(),
|
||||
org.jclouds.openstack.keystone.v2_0.domain.MediaType.builder().base("application/xml").type("application/vnd.openstack.identity-v2.0+xml").build()
|
||||
))
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{"version": {"status": "beta", "updated": "2011-11-19T00:00:00Z", "media-types": [{"base": "application/json", "type": "application/vnd.openstack.identity-v2.0+json"}, {"base": "application/xml", "type": "application/vnd.openstack.identity-v2.0+xml"}], "id": "v2.0", "links": [{"href": "http://172.16.89.140:5000/v2.0/", "rel": "self"}, {"href": "http://docs.openstack.org/api/openstack-identity-service/2.0/content/", "type": "text/html", "rel": "describedby"}, {"href": "http://docs.openstack.org/api/openstack-identity-service/2.0/identity-dev-guide-2.0.pdf", "type": "application/pdf", "rel": "describedby"}]}}
|
Loading…
Reference in New Issue