JCLOUDS-1067: Fix cookbook grouping mapping in Chef metadata

This commit is contained in:
Ignasi Barrera 2016-01-25 15:39:06 +01:00
parent 02b2e80b27
commit 773aa30c64
4 changed files with 124 additions and 8 deletions

View File

@ -0,0 +1,103 @@
/*
* 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 org.jclouds.chef.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
/**
* Information of a group of attributes in a namespace.
*/
public class Grouping {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String title;
private String description;
public Builder title(String title) {
this.title = checkNotNull(title, "title");
return this;
}
public Builder description(String description) {
this.description = description;
return this;
}
public Grouping build() {
return new Grouping(title, description);
}
}
private final String title;
private final String description;
@ConstructorProperties({ "title", "description" })
protected Grouping(String title, String description) {
this.title = title;
this.description = description;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((title == null) ? 0 : title.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Grouping other = (Grouping) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}
@Override
public String toString() {
return "Grouping [title=" + title + ", description=" + description + "]";
}
}

View File

@ -49,7 +49,7 @@ public class Metadata {
private ImmutableMap.Builder<String, String> recipes = ImmutableMap.builder();
private ImmutableMap.Builder<String, String> replacing = ImmutableMap.builder();
private String name;
private ImmutableMap.Builder<String, String> groupings = ImmutableMap.builder();
private ImmutableMap.Builder<String, Grouping> groupings = ImmutableMap.builder();
private String longDescription;
private ImmutableMap.Builder<String, Attribute> attributes = ImmutableMap.builder();
private ImmutableMap.Builder<String, String> recommendations = ImmutableMap.builder();
@ -154,12 +154,12 @@ public class Metadata {
return this;
}
public Builder grouping(String key, String value) {
public Builder grouping(String key, Grouping value) {
this.groupings.put(checkNotNull(key, "key"), checkNotNull(value, "value"));
return this;
}
public Builder grouping(Map<String, String> groupings) {
public Builder grouping(Map<String, Grouping> groupings) {
this.groupings.putAll(checkNotNull(groupings, "groupings"));
return this;
}
@ -211,7 +211,7 @@ public class Metadata {
private final Map<String, String> recipes;
private final Map<String, String> replacing;
private final String name;
private final Map<String, String> groupings;
private final Map<String, Grouping> groupings;
@SerializedName("long_description")
private final String longDescription;
private final Map<String, Attribute> attributes;
@ -224,7 +224,7 @@ public class Metadata {
@Nullable Map<String, String> dependencies, String maintainerEmail, @Nullable Map<String, String> conflicting,
String description, @Nullable Map<String, String> providing, @Nullable Map<String, String> platforms,
String version, @Nullable Map<String, String> recipes, @Nullable Map<String, String> replacing, String name,
@Nullable Map<String, String> groupings, String longDescription, @Nullable Map<String, Attribute> attributes,
@Nullable Map<String, Grouping> groupings, String longDescription, @Nullable Map<String, Attribute> attributes,
@Nullable Map<String, String> recommendations) {
this.license = license;
this.maintainer = maintainer;
@ -297,7 +297,7 @@ public class Metadata {
return name;
}
public Map<String, String> getGroupings() {
public Map<String, Grouping> getGroupings() {
return groupings;
}

View File

@ -25,6 +25,7 @@ import java.net.URI;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.chef.domain.CookbookVersion;
import org.jclouds.chef.domain.Grouping;
import org.jclouds.chef.domain.Metadata;
import org.jclouds.chef.domain.Resource;
import org.jclouds.http.HttpResponse;
@ -101,8 +102,11 @@ public class ParseCookbookVersionFromJsonTest {
.maintainer("Your Name") //
.maintainerEmail("youremail@example.com") //
.description("A fabulous new cookbook") //
.version("0.0.0").name("apache-chef-demo") //
.version("0.0.0") //
.name("apache-chef-demo") //
.longDescription("") //
.grouping("one", Grouping.builder().title("One title").description("One description").build()) //
.grouping("two", Grouping.builder().title("Two title").description("Two description").build()) //
.build())
.rootFile(
Resource

View File

@ -17,7 +17,16 @@
"long_description": "",
"recommendations": {},
"version": "0.0.0",
"groupings": {},
"groupings": {
"one": {
"title": "One title",
"description": "One description"
},
"two": {
"title": "Two title",
"description": "Two description"
}
},
"recipes": {},
"conflicting": {},
"description": "A fabulous new cookbook",