mirror of https://github.com/apache/jclouds.git
Added support for Chef 0.10
In Chef Server 0.10 the way the cookbooks are returned has changed. For this reason, a couple of domain classes have been added to support this new model. Also added a @Provider in the ChefParserModule that will inject the appropriate parser depending on the jclouds.api-version property set on the context. This way the ChefAsyncClient method signatures remain unchanged and the parser used to parse the cookbooks will be choosen at runtime depending on the version used to create the context.
This commit is contained in:
parent
d743d11934
commit
b88516fedc
|
@ -53,6 +53,8 @@ import org.jclouds.chef.domain.Sandbox;
|
|||
import org.jclouds.chef.domain.SearchResult;
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
import org.jclouds.chef.filters.SignedHeaderAuth;
|
||||
import org.jclouds.chef.functions.ParseCookbookDefinitionCheckingChefVersion;
|
||||
import org.jclouds.chef.functions.ParseCookbookVersionsCheckingChefVersion;
|
||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||
import org.jclouds.chef.functions.ParseSearchClientsFromJson;
|
||||
import org.jclouds.chef.functions.ParseSearchDatabagFromJson;
|
||||
|
@ -70,7 +72,6 @@ import org.jclouds.rest.annotations.ParamParser;
|
|||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
|
||||
|
@ -91,7 +92,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@Headers(keys = "X-Chef-Version", values = "{" + Constants.PROPERTY_API_VERSION + "}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface ChefAsyncClient {
|
||||
public static final String VERSION = "0.9.8";
|
||||
public static final String VERSION = "0.10.8";
|
||||
|
||||
/**
|
||||
* @see ChefClient#getUploadSandboxForChecksums(Set)
|
||||
|
@ -121,7 +122,7 @@ public interface ChefAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@Path("/cookbooks")
|
||||
@ResponseParser(ParseKeySetFromJson.class)
|
||||
@ResponseParser(ParseCookbookDefinitionCheckingChefVersion.class)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<String>> listCookbooks();
|
||||
|
||||
|
@ -147,7 +148,7 @@ public interface ChefAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@Path("/cookbooks/{cookbookname}")
|
||||
@Unwrap
|
||||
@ResponseParser(ParseCookbookVersionsCheckingChefVersion.class)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<String>> getVersionsOfCookbook(@PathParam("cookbookname") String cookbookName);
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
|
||||
import org.jclouds.chef.domain.Client;
|
||||
import org.jclouds.chef.domain.CookbookVersion;
|
||||
import org.jclouds.chef.domain.DatabagItem;
|
||||
|
@ -35,19 +33,13 @@ import org.jclouds.chef.domain.Role;
|
|||
import org.jclouds.chef.domain.Sandbox;
|
||||
import org.jclouds.chef.domain.SearchResult;
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
import org.jclouds.chef.functions.UriForResource;
|
||||
import org.jclouds.chef.options.CreateClientOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Chef.
|
||||
|
|
|
@ -30,18 +30,28 @@ import java.security.cert.CertificateException;
|
|||
import java.security.cert.X509Certificate;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.DatabagItem;
|
||||
import org.jclouds.chef.functions.ParseCookbookDefinitionFromJson;
|
||||
import org.jclouds.chef.functions.ParseCookbookVersionsV09FromJson;
|
||||
import org.jclouds.chef.functions.ParseCookbookVersionsV10FromJson;
|
||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.crypto.Pems;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.InputSuppliers;
|
||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
|
||||
import org.jclouds.json.internal.NullHackJsonLiteralAdapter;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.Gson;
|
||||
|
@ -205,6 +215,36 @@ public class ChefParserModule extends AbstractModule {
|
|||
return ImmutableMap.<Type, Object> of(DatabagItem.class, adapter, PrivateKey.class, privateAdapter,
|
||||
PublicKey.class, publicAdapter, X509Certificate.class, certAdapter);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@CookbookParser
|
||||
public Function<HttpResponse, Set<String>> provideCookbookDefinitionAdapter(@ApiVersion String apiVersion,
|
||||
ParseCookbookDefinitionFromJson v10parser, ParseKeySetFromJson v09parser) {
|
||||
Pattern versionPattern = Pattern.compile("\\d\\.(\\d)\\.\\d");
|
||||
Matcher m = versionPattern.matcher(apiVersion);
|
||||
if (m.matches()) {
|
||||
return Integer.valueOf(m.group(1)) > 9? v10parser : v09parser;
|
||||
} else {
|
||||
// Default to the latest version of the parser
|
||||
return v10parser;
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@CookbookVersionsParser
|
||||
public Function<HttpResponse, Set<String>> provideCookbookDefinitionAdapter(@ApiVersion String apiVersion,
|
||||
ParseCookbookVersionsV10FromJson v10parser, ParseCookbookVersionsV09FromJson v09parser) {
|
||||
Pattern versionPattern = Pattern.compile("\\d\\.(\\d)\\.\\d");
|
||||
Matcher m = versionPattern.matcher(apiVersion);
|
||||
if (m.matches()) {
|
||||
return Integer.valueOf(m.group(1)) > 9? v10parser : v09parser;
|
||||
} else {
|
||||
// Default to the latest version of the parser
|
||||
return v10parser;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* 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.chef.config;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Used to configure the cookbook Json parser.
|
||||
* <p>
|
||||
* Chef Server version 0.9 and 0.10 return a different Json when rquesting the cookbook
|
||||
* definitions. This annotation can be used to setup the cookbook parser.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Target({METHOD, PARAMETER, FIELD})
|
||||
@Retention(RUNTIME)
|
||||
@Qualifier
|
||||
public @interface CookbookParser
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* 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.chef.config;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Used to configure the cookbook versions Json parser.
|
||||
* <p>
|
||||
* Chef Server version 0.9 and 0.10 return a different Json when rquesting the cookbook
|
||||
* versions. This annotation can be used to setup the cookbook versions parser.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Target({METHOD, PARAMETER, FIELD})
|
||||
@Retention(RUNTIME)
|
||||
@Qualifier
|
||||
public @interface CookbookVersionsParser
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
/**
|
||||
* 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.chef.domain;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Cookbook definition as returned by the Chef server >= 0.10.8.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
public class CookbookDefinition {
|
||||
|
||||
private URI url;
|
||||
private Set<Version> versions = Sets.newLinkedHashSet();
|
||||
|
||||
// only for deserialization
|
||||
CookbookDefinition() {
|
||||
|
||||
}
|
||||
|
||||
public CookbookDefinition(URI url, Set<Version> versions) {
|
||||
this.url = url;
|
||||
this.versions = versions;
|
||||
}
|
||||
|
||||
public URI getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public Set<Version> getVersions() {
|
||||
return versions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
||||
result = prime * result + ((versions == null) ? 0 : versions.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;
|
||||
CookbookDefinition other = (CookbookDefinition) obj;
|
||||
if (url == null)
|
||||
{
|
||||
if (other.url != null)
|
||||
return false;
|
||||
}
|
||||
else if (!url.equals(other.url))
|
||||
return false;
|
||||
if (versions == null)
|
||||
{
|
||||
if (other.versions != null)
|
||||
return false;
|
||||
}
|
||||
else if (!versions.equals(other.versions))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CookbookDefinition [url=" + url + ", versions=" + versions + "]";
|
||||
}
|
||||
|
||||
|
||||
public static class Version {
|
||||
private URI url;
|
||||
private String version;
|
||||
|
||||
// only for deserialization
|
||||
Version() {
|
||||
|
||||
}
|
||||
|
||||
public Version(URI url, String version) {
|
||||
this.url = url;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public URI getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
||||
result = prime * result + ((version == null) ? 0 : version.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;
|
||||
Version other = (Version) obj;
|
||||
if (url == null)
|
||||
{
|
||||
if (other.url != null)
|
||||
return false;
|
||||
}
|
||||
else if (!url.equals(other.url))
|
||||
return false;
|
||||
if (version == null)
|
||||
{
|
||||
if (other.version != null)
|
||||
return false;
|
||||
}
|
||||
else if (!version.equals(other.version))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Version [url=" + url + ", version=" + version + "]";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.config.CookbookParser;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Parses a cookbook definition from a Json response, taking care of using the
|
||||
* appropriate parser.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseCookbookDefinitionCheckingChefVersion implements Function<HttpResponse, Set<String>> {
|
||||
|
||||
@VisibleForTesting
|
||||
final Function<HttpResponse, Set<String>> parser;
|
||||
|
||||
@Inject
|
||||
ParseCookbookDefinitionCheckingChefVersion(@CookbookParser Function<HttpResponse, Set<String>> parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> apply(HttpResponse response) {
|
||||
return parser.apply(response);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.CookbookDefinition;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Parses a cookbook definition from a Json response, assuming a Chef Server >= 0.10.8.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseCookbookDefinitionFromJson implements Function<HttpResponse, Set<String>> {
|
||||
|
||||
/** Parser for responses from chef server >= 0.10.8 */
|
||||
private final ParseJson<Map<String, CookbookDefinition>> parser;
|
||||
|
||||
@Inject
|
||||
ParseCookbookDefinitionFromJson(ParseJson<Map<String, CookbookDefinition>> parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> apply(HttpResponse response) {
|
||||
return parser.apply(response).keySet();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.config.CookbookVersionsParser;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* Parses a cookbook versions from a Json response, taking care of using the
|
||||
* appropriate parser.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseCookbookVersionsCheckingChefVersion implements Function<HttpResponse, Set<String>> {
|
||||
|
||||
@VisibleForTesting
|
||||
final Function<HttpResponse, Set<String>> parser;
|
||||
|
||||
@Inject
|
||||
ParseCookbookVersionsCheckingChefVersion(@CookbookVersionsParser Function<HttpResponse, Set<String>> parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> apply(HttpResponse response) {
|
||||
return parser.apply(response);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Parses the cookbook versions in a Chef Server <= 0.9.8.
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseCookbookVersionsV09FromJson implements Function<HttpResponse, Set<String>> {
|
||||
|
||||
private final ParseJson<Map<String, Set<String>>> json;
|
||||
|
||||
@Inject
|
||||
ParseCookbookVersionsV09FromJson(ParseJson<Map<String, Set<String>>> json) {
|
||||
this.json = json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> apply(HttpResponse arg0) {
|
||||
return Iterables.getFirst(json.apply(arg0).values(), null);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.CookbookDefinition;
|
||||
import org.jclouds.chef.domain.CookbookDefinition.Version;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Parses the cookbook versions in a Chef Server >= 0.10.8.
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseCookbookVersionsV10FromJson implements Function<HttpResponse, Set<String>> {
|
||||
|
||||
/** Parser for responses from chef server >= 0.10.8 */
|
||||
private final ParseJson<Map<String, CookbookDefinition>> parser;
|
||||
|
||||
@Inject
|
||||
ParseCookbookVersionsV10FromJson(ParseJson<Map<String, CookbookDefinition>> parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> apply(HttpResponse response) {
|
||||
CookbookDefinition def = Iterables.getFirst(parser.apply(response).values(), null);
|
||||
return Sets.newLinkedHashSet(Iterables.transform(def.getVersions(), new Function<Version, String>() {
|
||||
@Override
|
||||
public String apply(Version input)
|
||||
{
|
||||
return input.getVersion();
|
||||
}})
|
||||
);
|
||||
}
|
||||
}
|
|
@ -24,6 +24,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.chef.domain.Resource;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
@ -33,6 +35,7 @@ import com.google.common.base.Function;
|
|||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Singleton
|
||||
public class UriForResource implements Function<Object, URI> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,6 +36,8 @@ import org.jclouds.chef.domain.Resource;
|
|||
import org.jclouds.chef.domain.Role;
|
||||
import org.jclouds.chef.filters.SignedHeaderAuth;
|
||||
import org.jclouds.chef.filters.SignedHeaderAuthTest;
|
||||
import org.jclouds.chef.functions.ParseCookbookDefinitionCheckingChefVersion;
|
||||
import org.jclouds.chef.functions.ParseCookbookVersionsCheckingChefVersion;
|
||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||
import org.jclouds.chef.functions.ParseSearchClientsFromJson;
|
||||
import org.jclouds.chef.functions.ParseSearchDatabagFromJson;
|
||||
|
@ -189,13 +191,29 @@ public class ChefAsyncClientTest extends BaseAsyncClientTest<ChefAsyncClient> {
|
|||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncClient.VERSION + "-test\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseCookbookDefinitionCheckingChefVersion.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetVersionsOfCookbook() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ChefAsyncClient.class.getMethod("getVersionsOfCookbook", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "apache2");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks/apache2 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncClient.VERSION + "-test\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionsCheckingChefVersion.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testClientExists() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ChefAsyncClient.class.getMethod("clientExists", String.class);
|
||||
|
|
|
@ -18,24 +18,25 @@
|
|||
*/
|
||||
package org.jclouds.chef;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.chef.domain.CookbookVersion;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.chef.internal.BaseChefClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ChefClient}
|
||||
* Tests behavior of {@code ChefClient} against a Chef Server <= 0.9.8.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "live" })
|
||||
public class ChefClientLiveTest extends BaseChefClientLiveTest {
|
||||
|
||||
@Test
|
||||
public void testListCookbookVersionsWithChefService() throws Exception {
|
||||
Iterable<? extends CookbookVersion> cookbooks = context.getChefService().listCookbookVersions();
|
||||
assertNotNull(cookbooks);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties props = super.setupProperties();
|
||||
props.setProperty(Constants.PROPERTY_API_VERSION, ChefAsyncClient.VERSION);
|
||||
return props;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,13 +25,16 @@ import java.net.URI;
|
|||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.crypto.CryptoStreams;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -41,7 +44,14 @@ import com.google.inject.Injector;
|
|||
@Test(groups = { "unit" })
|
||||
public class BindHexEncodedMD5sToJsonPayloadTest {
|
||||
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
BindChecksumsToJsonPayload binder = injector.getInstance(BindChecksumsToJsonPayload.class);
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.security.cert.CertificateException;
|
|||
import java.security.cert.X509Certificate;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Client;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
|
@ -37,10 +38,12 @@ import org.jclouds.io.Payloads;
|
|||
import org.jclouds.io.payloads.RSADecryptingPayload;
|
||||
import org.jclouds.io.payloads.RSAEncryptingPayload;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -51,7 +54,7 @@ import com.google.inject.TypeLiteral;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" }, sequential = true)
|
||||
@Test(groups = { "unit" })
|
||||
public class ParseClientFromJsonTest {
|
||||
|
||||
private static final String PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEAyb2ZJJqGm0KKR+8nfQJNsSd+F9tXNMV7CfOcW6jsqs8EZgiV\nR09hD1IYOj4YqM0qJONlgyg4xRWewdSG7QTPj1lJpVAida9sXy2+kzyagZA1Am0O\nZcbqb5hoeIDgcX+eDa79s0u0DomjcfO9EKhvHLBz+zM+3QqPRkPV8nYTbfs+HjVz\nzOU6D1B0XR3+IPZZl2AnWs2d0qhnStHcDUvnRVQ0P482YwN9VgceOZtpPz0DCKEJ\n5Tx5STub8k0/zt/VAMHQafLSuQMLd2s4ZLuOZptN//uAsTmxireqd37z+8ZTdBbJ\n8LEpJ+iCXuSfm5aUh7iw6oxvToY2AL53+jK2UQIDAQABAoIBAQDA88B3i/xWn0vX\nBVxFamCYoecuNjGwXXkSyZew616A+EOCu47bh4aTurdFbYL0YFaAtaWvzlaN2eHg\nDb+HDuTefE29+WkcGk6SshPmiz5T0XOCAICWw6wSVDkHmGwS4jZvbAFm7W8nwGk9\nYhxgxFiRngswJZFopOLoF5WXs2td8guIYNslMpo7tu50iFnBHwKO2ZsPAk8t9nnS\nxlDavKruymEmqHCr3+dtio5eaenJcp3fjoXBQOKUk3ipII29XRB8NqeCVV/7Kxwq\nckqOBEbRwBclckyIbD+RiAgKvOelORjEiE9R42vuqvxRA6k9kd9o7utlX0AUtpEn\n3gZc6LepAoGBAP9ael5Y75+sK2JJUNOOhO8ae45cdsilp2yI0X+UBaSuQs2+dyPp\nkpEHAxd4pmmSvn/8c9TlEZhr+qYbABXVPlDncxpIuw2Ajbk7s/S4XaSKsRqpXL57\nzj/QOqLkRk8+OVV9q6lMeQNqLtEj1u6JPviX70Ro+FQtRttNOYbfdP/fAoGBAMpA\nXjR5woV5sUb+REg9vEuYo8RSyOarxqKFCIXVUNsLOx+22+AK4+CQpbueWN7jotrl\nYD6uT6svWi3AAC7kiY0UI/fjVPRCUi8tVoQUE0TaU5VLITaYOB+W/bBaDE4M9560\n1NuDWO90baA5dfU44iuzva02rGJXK9+nS3o8nk/PAoGBALOL6djnDe4mwAaG6Jco\ncd4xr8jkyPzCRZuyBCSBbwphIUXLc7hDprPky064ncJD1UDmwIdkXd/fpMkg2QmA\n/CUk6LEFjMisqHojOaCL9gQZJPhLN5QUN2x1PJWGjs1vQh8Tkx0iUUCOa8bQPXNR\n+34OTsW6TUna4CSZAycLfhffAoGBAIggVsefBCvuQkF0NeUhmDCRZfhnd8y55RHR\n1HCvqKIlpv+rhcX/zmyBLuteopYyRJRsOiE2FW00i8+rIPRu4Z3Q5nybx7w3PzV9\noHN5R5baE9OyI4KpZWztpYYitZF67NcnAvVULHHOvVJQGnKYfLHJYmrJF7GA1ojM\nAuMdFbjFAoGAPxUhxwFy8gaqBahKUEZn4F81HFP5ihGhkT4QL6AFPO2e+JhIGjuR\n27+85hcFqQ+HHVtFsm81b/a+R7P4UuCRgc8eCjxQMoJ1Xl4n7VbjPbHMnIN0Ryvd\nO4ZpWDWYnCO021JTOUUOJ4J/y0416Bvkw0z59y7sNX7wDBBHHbK/XCc=\n-----END RSA PRIVATE KEY-----\n";
|
||||
|
@ -63,7 +66,14 @@ public class ParseClientFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException, CertificateException, InvalidKeySpecException {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Client>>() {
|
||||
}));
|
||||
crypto = injector.getInstance(Crypto.class);
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseCookbookDefinitionCheckingChefVersion}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseCookbookDefinitionCheckingChefVersionTest {
|
||||
|
||||
public void testParserFor09() {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8");
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
ParseCookbookDefinitionCheckingChefVersion parser = injector.getInstance(ParseCookbookDefinitionCheckingChefVersion.class);
|
||||
assertTrue(parser.parser instanceof ParseKeySetFromJson);
|
||||
}
|
||||
|
||||
public void testParserFor010() {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8");
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
ParseCookbookDefinitionCheckingChefVersion parser = injector.getInstance(ParseCookbookDefinitionCheckingChefVersion.class);
|
||||
assertTrue(parser.parser instanceof ParseCookbookDefinitionFromJson);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseCookbookDefinitionFromJson}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseCookbookDefinitionFromJsonTest {
|
||||
|
||||
private ParseCookbookDefinitionFromJson handler;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(ParseCookbookDefinitionFromJson.class);
|
||||
}
|
||||
|
||||
public void testParse010Response() {
|
||||
assertEquals(
|
||||
handler
|
||||
.apply(new HttpResponse(
|
||||
200,
|
||||
"ok",
|
||||
Payloads
|
||||
.newStringPayload("{" +
|
||||
"\"apache2\" => {" +
|
||||
"\"url\" => \"http://localhost:4000/cookbooks/apache2\"," +
|
||||
"\"versions\" => [" +
|
||||
"{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\"," +
|
||||
"\"version\" => \"5.1.0\"}," +
|
||||
"{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\"," +
|
||||
"\"version\" => \"4.2.0\"}" +
|
||||
"]" +
|
||||
"}," +
|
||||
"\"nginx\" => {" +
|
||||
"\"url\" => \"http://localhost:4000/cookbooks/nginx\"," +
|
||||
"\"versions\" => [" +
|
||||
"{\"url\" => \"http://localhost:4000/cookbooks/nginx/1.0.0\"," +
|
||||
"\"version\" => \"1.0.0\"}," +
|
||||
"{\"url\" => \"http://localhost:4000/cookbooks/nginx/0.3.0\"," +
|
||||
"\"version\" => \"0.3.0\"}" +
|
||||
"]" +
|
||||
"}" +
|
||||
"}"))),
|
||||
ImmutableSet.of("apache2", "nginx"));
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Attribute;
|
||||
import org.jclouds.chef.domain.CookbookVersion;
|
||||
|
@ -34,12 +35,14 @@ import org.jclouds.http.functions.ParseJson;
|
|||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -50,7 +53,7 @@ import com.google.inject.TypeLiteral;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" }, sequential = true)
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseCookbookVersionFromJsonTest {
|
||||
|
||||
private ParseJson<CookbookVersion> handler;
|
||||
|
@ -59,7 +62,14 @@ public class ParseCookbookVersionFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
json = injector.getInstance(Json.class);
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<CookbookVersion>>() {
|
||||
}));
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseCookbookVersionsCheckingChefVersion}.
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseCookbookVersionsCheckingChefVersionTest {
|
||||
|
||||
public void testParserFor09() {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8");
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
ParseCookbookVersionsCheckingChefVersion parser = injector.getInstance(ParseCookbookVersionsCheckingChefVersion.class);
|
||||
assertTrue(parser.parser instanceof ParseCookbookVersionsV09FromJson);
|
||||
}
|
||||
|
||||
public void testParserFor010() {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8");
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
ParseCookbookVersionsCheckingChefVersion parser = injector.getInstance(ParseCookbookVersionsCheckingChefVersion.class);
|
||||
assertTrue(parser.parser instanceof ParseCookbookVersionsV10FromJson);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseCookbookVersionsV09FromJson}
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseCookbookVersionsV09FromJsonTest {
|
||||
|
||||
private ParseCookbookVersionsV09FromJson handler;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(ParseCookbookVersionsV09FromJson.class);
|
||||
}
|
||||
|
||||
public void testRegex() {
|
||||
assertEquals(
|
||||
handler
|
||||
.apply(new HttpResponse(
|
||||
200,
|
||||
"ok",
|
||||
Payloads
|
||||
.newStringPayload("{\"apache2\": [\"0.1.8\", \"0.2\"]}"))),
|
||||
ImmutableSet.of("0.1.8", "0.2"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* 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.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseCookbookVersionsV10FromJson}
|
||||
*
|
||||
* @author Ignasi Barrera
|
||||
*/
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseCookbookVersionsV10FromJsonTest {
|
||||
|
||||
private ParseCookbookVersionsV10FromJson handler;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(ParseCookbookVersionsV10FromJson.class);
|
||||
}
|
||||
|
||||
public void testRegex() {
|
||||
assertEquals(
|
||||
handler
|
||||
.apply(new HttpResponse(
|
||||
200,
|
||||
"ok",
|
||||
Payloads
|
||||
.newStringPayload("{" +
|
||||
"\"apache2\" => {" +
|
||||
"\"url\" => \"http://localhost:4000/cookbooks/apache2\"," +
|
||||
"\"versions\" => [" +
|
||||
"{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\"," +
|
||||
"\"version\" => \"5.1.0\"}," +
|
||||
"{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\"," +
|
||||
"\"version\" => \"4.2.0\"}" +
|
||||
"]" +
|
||||
"}" +
|
||||
"}"))),
|
||||
ImmutableSet.of("5.1.0", "4.2.0"));
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.DatabagItem;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
@ -29,9 +30,11 @@ import org.jclouds.http.functions.ParseJson;
|
|||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -47,7 +50,14 @@ public class ParseDataBagItemFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<DatabagItem>>() {
|
||||
}));
|
||||
mapper = injector.getInstance(Json.class);
|
||||
|
|
|
@ -22,14 +22,17 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -38,14 +41,21 @@ import com.google.inject.Injector;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" }, sequential = true)
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseKeySetFromJsonTest {
|
||||
|
||||
private ParseKeySetFromJson handler;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(ParseKeySetFromJson.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Node;
|
||||
import org.jclouds.domain.JsonBall;
|
||||
|
@ -30,10 +31,12 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -44,14 +47,21 @@ import com.google.inject.TypeLiteral;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" }, sequential = true)
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseNodeFromJsonTest {
|
||||
|
||||
private ParseJson<Node> handler;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Node>>() {
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Sandbox;
|
||||
import org.jclouds.date.DateService;
|
||||
|
@ -29,10 +30,12 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -43,7 +46,7 @@ import com.google.inject.TypeLiteral;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" }, sequential = true)
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseSandboxFromJsonTest {
|
||||
|
||||
private ParseJson<Sandbox> handler;
|
||||
|
@ -51,7 +54,14 @@ public class ParseSandboxFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Sandbox>>() {
|
||||
}));
|
||||
dateService = injector.getInstance(DateService.class);
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.ChecksumStatus;
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
|
@ -32,11 +33,13 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -47,7 +50,7 @@ import com.google.inject.TypeLiteral;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = { "unit" }, sequential = true)
|
||||
@Test(groups = { "unit" }, singleThreaded = true)
|
||||
public class ParseUploadSandboxFromJsonTest {
|
||||
|
||||
private ParseJson<UploadSandbox> handler;
|
||||
|
@ -55,7 +58,14 @@ public class ParseUploadSandboxFromJsonTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<UploadSandbox>>() {
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -26,15 +26,18 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.ChefClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Client;
|
||||
import org.jclouds.chef.domain.DatabagItem;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -43,7 +46,14 @@ import com.google.inject.Injector;
|
|||
*/
|
||||
@Test(groups = { "unit" })
|
||||
public class RunListForTagTest {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
Json json = injector.getInstance(Json.class);
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
|
|
|
@ -29,12 +29,14 @@ import java.net.URI;
|
|||
import java.security.PrivateKey;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.chef.domain.Client;
|
||||
import org.jclouds.chef.statements.InstallChefGems;
|
||||
import org.jclouds.crypto.PemsTest;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -44,6 +46,7 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.common.io.Resources;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -53,7 +56,14 @@ import com.google.inject.Injector;
|
|||
@Test(groups = { "unit" })
|
||||
public class TagToBootScriptTest {
|
||||
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
|
||||
Json json = injector.getInstance(Json.class);
|
||||
Statement installChefGems = new InstallChefGems();
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.common.primitives.Bytes;
|
||||
/**
|
||||
|
@ -145,12 +146,11 @@ public abstract class BaseChefClientLiveTest extends BaseChefContextLiveTest {
|
|||
|
||||
@Test
|
||||
public void testListCookbooks() throws Exception {
|
||||
Set<String> cookbooksNames = context.getApi().listCookbooks();
|
||||
assertFalse(cookbooksNames.isEmpty());
|
||||
Set<String> cookbookNames = context.getApi().listCookbooks();
|
||||
assertFalse(cookbookNames.isEmpty());
|
||||
|
||||
for (String cookbook : cookbooksNames)
|
||||
for (String cookbook : cookbookNames)
|
||||
for (String version : context.getApi().getVersionsOfCookbook(cookbook)) {
|
||||
//System.err.printf("%s/%s:%n", cookbook, version);
|
||||
CookbookVersion cookbookO = context.getApi().getCookbook(cookbook, version);
|
||||
for (Resource resource : ImmutableList.<Resource> builder().addAll(cookbookO.getDefinitions()).addAll(
|
||||
cookbookO.getFiles()).addAll(cookbookO.getLibraries()).addAll(cookbookO.getSuppliers()).addAll(
|
||||
|
@ -163,11 +163,10 @@ public abstract class BaseChefClientLiveTest extends BaseChefContextLiveTest {
|
|||
} catch (NullPointerException e) {
|
||||
assert false : "resource not found: " + resource;
|
||||
}
|
||||
//System.err.printf("resource %s ok%n", resource.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = "testCreateNewCookbook")
|
||||
public void testUpdateCookbook() throws Exception {
|
||||
for (String cookbook : context.getApi().listCookbooks())
|
||||
|
@ -376,7 +375,13 @@ public abstract class BaseChefClientLiveTest extends BaseChefContextLiveTest {
|
|||
SearchResult<? extends DatabagItem> results = context.getApi().searchDatabag("whoopie");
|
||||
assertNotNull(results);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testListCookbookVersionsWithChefService() throws Exception {
|
||||
Iterable<? extends CookbookVersion> cookbooks = context.getChefService().listCookbookVersions();
|
||||
assertNotNull(cookbooks);
|
||||
}
|
||||
|
||||
@AfterClass(groups = { "live", "integration" })
|
||||
@Override
|
||||
public void tearDownContext() {
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.apis.BaseContextLiveTest;
|
||||
import org.jclouds.chef.ChefContext;
|
||||
import org.testng.annotations.Test;
|
||||
|
|
|
@ -28,15 +28,18 @@ import java.util.Map;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.ohai.Automatic;
|
||||
import org.jclouds.ohai.config.JMXOhaiModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -57,7 +60,13 @@ public class JMXTest {
|
|||
|
||||
replay(runtime);
|
||||
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule(), new JMXOhaiModule() {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule(), new JMXOhaiModule() {
|
||||
@Override
|
||||
protected RuntimeMXBean provideRuntimeMXBean() {
|
||||
return runtime;
|
||||
|
|
|
@ -27,12 +27,14 @@ import java.util.Properties;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.ohai.Automatic;
|
||||
import org.jclouds.ohai.config.multibindings.MapBinder;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -60,7 +62,13 @@ public class OhaiModuleTest {
|
|||
sysProperties.setProperty("os.version", "10.3.0");
|
||||
sysProperties.setProperty("user.name", "user");
|
||||
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule(), new OhaiModule() {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule(), new OhaiModule() {
|
||||
@Override
|
||||
protected Long millis() {
|
||||
return 127999291932529l;
|
||||
|
@ -89,7 +97,13 @@ public class OhaiModuleTest {
|
|||
sysProperties.setProperty("os.version", "10.3.0");
|
||||
sysProperties.setProperty("user.name", "user");
|
||||
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule(), new OhaiModule() {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule(), new OhaiModule() {
|
||||
@Override
|
||||
protected Long millis() {
|
||||
return 1279992919l;
|
||||
|
|
|
@ -26,9 +26,6 @@ import org.jclouds.crypto.CryptoStreams;
|
|||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ByteArrayToMacAddress}
|
||||
*
|
||||
|
@ -37,15 +34,8 @@ import com.google.inject.Injector;
|
|||
@Test(groups = { "unit" }, sequential = true)
|
||||
public class ByteArrayToMacAddressTest {
|
||||
|
||||
private ByteArrayToMacAddress converter;
|
||||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector();
|
||||
converter = injector.getInstance(ByteArrayToMacAddress.class);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
assertEquals(converter.apply(CryptoStreams.hex("0026bb09e6c4")), "00:26:bb:09:e6:c4");
|
||||
assertEquals(new ByteArrayToMacAddress().apply(CryptoStreams.hex("0026bb09e6c4")),
|
||||
"00:26:bb:09:e6:c4");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,16 +22,19 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.chef.ChefAsyncClient;
|
||||
import org.jclouds.chef.config.ChefParserModule;
|
||||
import org.jclouds.domain.JsonBall;
|
||||
import org.jclouds.json.Json;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -48,7 +51,13 @@ public class NestSlashKeysTest {
|
|||
|
||||
@BeforeTest
|
||||
protected void setUpInjector() throws IOException {
|
||||
Injector injector = Guice.createInjector(new ChefParserModule(), new GsonModule());
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncClient.VERSION);
|
||||
}
|
||||
}, new ChefParserModule(), new GsonModule());
|
||||
converter = injector.getInstance(NestSlashKeys.class);
|
||||
json = injector.getInstance(Json.class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue