Removed all compile warnings and applied formatting to all classes

This commit is contained in:
Ignasi Barrera 2013-01-20 13:10:23 +01:00
parent efb5190023
commit 7cf428657e
90 changed files with 1430 additions and 1441 deletions

View File

@ -54,8 +54,8 @@ public interface ChefApi {
* the URLs against which to PUT files that need to be uploaded. * the URLs against which to PUT files that need to be uploaded.
* *
* @param md5s * @param md5s
* raw md5s; uses {@code Bytes.asList()} and {@code * raw md5s; uses {@code Bytes.asList()} and
* Bytes.toByteArray()} as necessary * {@code Bytes.toByteArray()} as necessary
* @return The URLs against which to PUT files that need to be uploaded. * @return The URLs against which to PUT files that need to be uploaded.
*/ */
UploadSandbox getUploadSandboxForChecksums(Set<List<Byte>> md5s); UploadSandbox getUploadSandboxForChecksums(Set<List<Byte>> md5s);
@ -64,7 +64,8 @@ public interface ChefApi {
* *
* Uploads the given content to the sandbox at the given URI. * Uploads the given content to the sandbox at the given URI.
* <p> * <p>
* The URI must be obtained, after uploading a sandbox, from the {@link UploadSandbox#getUri()}. * The URI must be obtained, after uploading a sandbox, from the
* {@link UploadSandbox#getUri()}.
*/ */
void uploadContent(URI location, Payload content); void uploadContent(URI location, Payload content);
@ -492,8 +493,7 @@ public interface ChefApi {
/** /**
* Show indexes you can search on * Show indexes you can search on
* <p/> * <p/>
* By default, the "role", "node" and "api" indexes will always be * By default, the "role", "node" and "api" indexes will always be available.
* available.
* <p/> * <p/>
* Note that the search indexes may lag behind the most current data by at * Note that the search indexes may lag behind the most current data by at
* least 10 seconds at any given time - so if you need to write data and * least 10 seconds at any given time - so if you need to write data and
@ -594,7 +594,9 @@ public interface ChefApi {
/** /**
* Get the contents of the given resource. * Get the contents of the given resource.
* @param resource The resource to get. *
* @param resource
* The resource to get.
* @return An input stream for the content of the requested resource. * @return An input stream for the content of the requested resource.
*/ */
InputStream getResourceContents(Resource resource); InputStream getResourceContents(Resource resource);

View File

@ -88,7 +88,9 @@ public class ChefApiMetadata extends BaseRestApiMetadata {
.defaultEndpoint("http://localhost:4000") .defaultEndpoint("http://localhost:4000")
.defaultProperties(ChefApiMetadata.defaultProperties()) .defaultProperties(ChefApiMetadata.defaultProperties())
.context(typeToken(ChefContext.class)) .context(typeToken(ChefContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(ChefRestClientModule.class, ChefParserModule.class, JMXOhaiModule.class)); .defaultModules(
ImmutableSet.<Class<? extends Module>> of(ChefRestClientModule.class, ChefParserModule.class,
JMXOhaiModule.class));
} }
@Override @Override

View File

@ -70,24 +70,23 @@ public class ChefContextFactory {
/** /**
* @see #createContext(String, String,String, Iterable, Properties) * @see #createContext(String, String,String, Iterable, Properties)
*/ */
public ChefContext createContext(String providerOrApi, Iterable<? extends Module> wiring, public ChefContext createContext(String providerOrApi, Iterable<? extends Module> wiring, Properties overrides) {
Properties overrides) {
return createContext(providerOrApi, null, null, wiring, overrides); return createContext(providerOrApi, null, null, wiring, overrides);
} }
/** /**
* @see #createContext(String, String,String, Iterable, Properties) * @see #createContext(String, String,String, Iterable, Properties)
*/ */
public ChefContext createContext(String providerOrApi, @Nullable String identity, public ChefContext createContext(String providerOrApi, @Nullable String identity, @Nullable String credential,
@Nullable String credential, Properties overrides) { Properties overrides) {
return createContext(providerOrApi, identity, credential, ImmutableSet.<Module> of(), overrides); return createContext(providerOrApi, identity, credential, ImmutableSet.<Module> of(), overrides);
} }
/** /**
* @see createContext(String, String,String, Iterable, Properties) * @see createContext(String, String,String, Iterable, Properties)
*/ */
public ChefContext createContext(String providerOrApi, @Nullable String identity, public ChefContext createContext(String providerOrApi, @Nullable String identity, @Nullable String credential,
@Nullable String credential, Iterable<? extends Module> wiring) { Iterable<? extends Module> wiring) {
return createContext(providerOrApi, identity, credential, wiring, new Properties()); return createContext(providerOrApi, identity, credential, wiring, new Properties());
} }
@ -107,8 +106,8 @@ public class ChefContextFactory {
* @return initialized context ready for use * @return initialized context ready for use
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ChefContext createContext(String providerOrApi, @Nullable String identity, public ChefContext createContext(String providerOrApi, @Nullable String identity, @Nullable String credential,
@Nullable String credential, Iterable<? extends Module> wiring, Properties overrides) { Iterable<? extends Module> wiring, Properties overrides) {
ContextBuilder builder = null; ContextBuilder builder = null;
try { try {
ProviderMetadata pm = Providers.withId(providerOrApi); ProviderMetadata pm = Providers.withId(providerOrApi);

View File

@ -63,8 +63,8 @@ public interface ChefService {
* *
* @param group * @param group
* corresponds to a configured * corresponds to a configured
* {@link org.jclouds.chef.config.ChefProperties#CHEF_BOOTSTRAP_DATABAG databag} * {@link org.jclouds.chef.config.ChefProperties#CHEF_BOOTSTRAP_DATABAG
* where run_list and other information are stored * databag} where run_list and other information are stored
* @return boot script * @return boot script
* @see #updateRunListForTag * @see #updateRunListForTag
*/ */
@ -74,13 +74,13 @@ public interface ChefService {
* assigns a run list to all nodes bootstrapped with a certain group * assigns a run list to all nodes bootstrapped with a certain group
* *
* @param runList * @param runList
* list of recipes or roles to assign. syntax is {@code recipe[name]} and {@code * list of recipes or roles to assign. syntax is
* role[name]} * {@code recipe[name]} and {@code role[name]}
* *
* @param group * @param group
* corresponds to a configured * corresponds to a configured
* {@link org.jclouds.chef.config.ChefProperties#CHEF_BOOTSTRAP_DATABAG databag} * {@link org.jclouds.chef.config.ChefProperties#CHEF_BOOTSTRAP_DATABAG
* where run_list and other information are stored * databag} where run_list and other information are stored
* @see #makeChefApiBootstrapScriptForTag * @see #makeChefApiBootstrapScriptForTag
*/ */
void updateRunListForGroup(Iterable<String> runList, String group); void updateRunListForGroup(Iterable<String> runList, String group);
@ -88,8 +88,8 @@ public interface ChefService {
/** /**
* @param group * @param group
* corresponds to a configured * corresponds to a configured
* {@link org.jclouds.chef.config.ChefProperties#CHEF_BOOTSTRAP_DATABAG databag} * {@link org.jclouds.chef.config.ChefProperties#CHEF_BOOTSTRAP_DATABAG
* where run_list and other information are stored * databag} where run_list and other information are stored
* @return run list for all nodes bootstrapped with a certain group * @return run list for all nodes bootstrapped with a certain group
* @see #updateRunListForTag * @see #updateRunListForTag
*/ */

View File

@ -40,8 +40,7 @@ import com.google.common.collect.Iterables;
* *
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
public class BindCreateClientOptionsToJsonPayload extends BindToJsonPayload public class BindCreateClientOptionsToJsonPayload extends BindToJsonPayload {
{
@Inject @Inject
public BindCreateClientOptionsToJsonPayload(Json jsonBinder) { public BindCreateClientOptionsToJsonPayload(Json jsonBinder) {
super(jsonBinder); super(jsonBinder);
@ -62,8 +61,7 @@ public class BindCreateClientOptionsToJsonPayload extends BindToJsonPayload
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static class CreateClientParams private static class CreateClientParams {
{
private String name; private String name;
private boolean admin; private boolean admin;

View File

@ -34,8 +34,7 @@ public class BindGenerateKeyForClientToJsonPayload extends BindToStringPayload {
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) { public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
super.bindToRequest(request, String.format("{\"name\":\"%s\", \"private_key\": true}", super.bindToRequest(request, String.format("{\"name\":\"%s\", \"private_key\": true}", payload));
payload));
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON);
return request; return request;
} }

View File

@ -122,8 +122,9 @@ public class BaseChefRestClientModule<S, A> extends RestClientModule<S, A> {
} }
/** /**
* it is relatively expensive to extract a private key from a PEM. cache the relationship between current credentials * it is relatively expensive to extract a private key from a PEM. cache the
* so that the private key is only recalculated once. * relationship between current credentials so that the private key is only
* recalculated once.
*/ */
@VisibleForTesting @VisibleForTesting
@Singleton @Singleton
@ -151,7 +152,8 @@ public class BaseChefRestClientModule<S, A> extends RestClientModule<S, A> {
@Singleton @Singleton
@Validator @Validator
public Optional<String> provideValidatorName(Injector injector) { public Optional<String> provideValidatorName(Injector injector) {
// Named properties can not be injected as optional here, so let's use the injector to bypass it // Named properties can not be injected as optional here, so let's use the
// injector to bypass it
Key<String> key = Key.get(String.class, Names.named(CHEF_VALIDATOR_NAME)); Key<String> key = Key.get(String.class, Names.named(CHEF_VALIDATOR_NAME));
try { try {
return Optional.<String> of(injector.getInstance(key)); return Optional.<String> of(injector.getInstance(key));
@ -165,7 +167,8 @@ public class BaseChefRestClientModule<S, A> extends RestClientModule<S, A> {
@Validator @Validator
public Optional<PrivateKey> provideValidatorCredential(Crypto crypto, Injector injector) public Optional<PrivateKey> provideValidatorCredential(Crypto crypto, Injector injector)
throws InvalidKeySpecException, IOException { throws InvalidKeySpecException, IOException {
// Named properties can not be injected as optional here, so let's use the injector to bypass it // Named properties can not be injected as optional here, so let's use the
// injector to bypass it
Key<String> key = Key.get(String.class, Names.named(CHEF_VALIDATOR_CREDENTIAL)); Key<String> key = Key.get(String.class, Names.named(CHEF_VALIDATOR_CREDENTIAL));
try { try {
String validatorCredential = injector.getInstance(key); String validatorCredential = injector.getInstance(key);

View File

@ -169,13 +169,13 @@ public class ChefParserModule extends AbstractModule {
} }
} }
/** /**
* writes or reads the literal directly * writes or reads the literal directly
*/ */
@Singleton @Singleton
public static class DataBagItemAdapter extends NullHackJsonLiteralAdapter<DatabagItem> { public static class DataBagItemAdapter extends NullHackJsonLiteralAdapter<DatabagItem> {
final Gson gson = new Gson(); final Gson gson = new Gson();
@Override @Override
protected DatabagItem createJsonLiteralFromRawJson(String text) { protected DatabagItem createJsonLiteralFromRawJson(String text) {
IdHolder idHolder = gson.fromJson(text, IdHolder.class); IdHolder idHolder = gson.fromJson(text, IdHolder.class);

View File

@ -50,18 +50,16 @@ public interface ChefProperties {
* the Chef server. * the Chef server.
* <p> * <p>
* This property must be set prior to running the * This property must be set prior to running the
* {@link ChefService#createBootstrapScriptForGroup(String)} * {@link ChefService#createBootstrapScriptForGroup(String)} method.
* method.
*/ */
public static final String CHEF_VALIDATOR_NAME = "chef.validator-name"; public static final String CHEF_VALIDATOR_NAME = "chef.validator-name";
/** /**
* The credential of the validator client used to allow nodes to * The credential of the validator client used to allow nodes to autoregister
* autoregister in the Chef server. * in the Chef server.
* <p> * <p>
* This property must be set prior to running the * This property must be set prior to running the
* {@link ChefService#createBootstrapScriptForGroup(String)} * {@link ChefService#createBootstrapScriptForGroup(String)} method.
* method.
*/ */
public static final String CHEF_VALIDATOR_CREDENTIAL = "chef.validator-credential"; public static final String CHEF_VALIDATOR_CREDENTIAL = "chef.validator-credential";

View File

@ -31,15 +31,15 @@ import javax.inject.Qualifier;
/** /**
* Used to configure the cookbook Json parser. * Used to configure the cookbook Json parser.
* <p> * <p>
* Chef Server version 0.9 and 0.10 return a different Json when rquesting the cookbook * Chef Server version 0.9 and 0.10 return a different Json when rquesting the
* definitions. This annotation can be used to setup the cookbook parser. * cookbook definitions. This annotation can be used to setup the cookbook
* parser.
* *
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
@Target({ METHOD, PARAMETER, FIELD }) @Target({ METHOD, PARAMETER, FIELD })
@Retention(RUNTIME) @Retention(RUNTIME)
@Qualifier @Qualifier
public @interface CookbookParser public @interface CookbookParser {
{
} }

View File

@ -31,15 +31,15 @@ import javax.inject.Qualifier;
/** /**
* Used to configure the cookbook versions Json parser. * Used to configure the cookbook versions Json parser.
* <p> * <p>
* Chef Server version 0.9 and 0.10 return a different Json when rquesting the cookbook * Chef Server version 0.9 and 0.10 return a different Json when rquesting the
* versions. This annotation can be used to setup the cookbook versions parser. * cookbook versions. This annotation can be used to setup the cookbook versions
* parser.
* *
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
@Target({ METHOD, PARAMETER, FIELD }) @Target({ METHOD, PARAMETER, FIELD })
@Retention(RUNTIME) @Retention(RUNTIME)
@Qualifier @Qualifier
public @interface CookbookVersionsParser public @interface CookbookVersionsParser {
{
} }

View File

@ -69,19 +69,15 @@ public class CookbookDefinition {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
CookbookDefinition other = (CookbookDefinition) obj; CookbookDefinition other = (CookbookDefinition) obj;
if (url == null) if (url == null) {
{
if (other.url != null) if (other.url != null)
return false; return false;
} } else if (!url.equals(other.url))
else if (!url.equals(other.url))
return false; return false;
if (versions == null) if (versions == null) {
{
if (other.versions != null) if (other.versions != null)
return false; return false;
} } else if (!versions.equals(other.versions))
else if (!versions.equals(other.versions))
return false; return false;
return true; return true;
} }
@ -91,7 +87,6 @@ public class CookbookDefinition {
return "CookbookDefinition [url=" + url + ", versions=" + versions + "]"; return "CookbookDefinition [url=" + url + ", versions=" + versions + "]";
} }
public static class Version { public static class Version {
private URI url; private URI url;
private String version; private String version;
@ -132,19 +127,15 @@ public class CookbookDefinition {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Version other = (Version) obj; Version other = (Version) obj;
if (url == null) if (url == null) {
{
if (other.url != null) if (other.url != null)
return false; return false;
} } else if (!url.equals(other.url))
else if (!url.equals(other.url))
return false; return false;
if (version == null) if (version == null) {
{
if (other.version != null) if (other.version != null)
return false; return false;
} } else if (!version.equals(other.version))
else if (!version.equals(other.version))
return false; return false;
return true; return true;
} }

View File

@ -51,10 +51,10 @@ public class Metadata {
private Map<String, String> recommendations = Maps.newLinkedHashMap(); private Map<String, String> recommendations = Maps.newLinkedHashMap();
public Metadata(String license, String maintainer, Map<String, String> suggestions, public Metadata(String license, String maintainer, Map<String, String> suggestions,
Map<String, String> dependencies, String maintainerEmail, Map<String, String> conflicting, Map<String, String> dependencies, String maintainerEmail, Map<String, String> conflicting, String description,
String description, Map<String,String> providing, Map<String, String> platforms, String version, Map<String, String> providing, Map<String, String> platforms, String version, Map<String, String> recipes,
Map<String, String> recipes, Map<String, String> replacing, String name, Map<String, String> groupings, Map<String, String> replacing, String name, Map<String, String> groupings, String longDescription,
String longDescription, Map<String, Attribute> attributes, Map<String, String> recommendations) { Map<String, Attribute> attributes, Map<String, String> recommendations) {
this.license = license; this.license = license;
this.maintainer = maintainer; this.maintainer = maintainer;
this.suggestions.putAll(suggestions); this.suggestions.putAll(suggestions);

View File

@ -127,8 +127,8 @@ public class Resource {
@Override @Override
public String toString() { public String toString() {
return "Resource [checksum=" + Bytes.asList(checksum) + ", name=" + name + ", path=" + path return "Resource [checksum=" + Bytes.asList(checksum) + ", name=" + name + ", path=" + path + ", specificity="
+ ", specificity=" + specificity + ", url=" + url + "]"; + specificity + ", url=" + url + "]";
} }
} }

View File

@ -83,7 +83,6 @@ public class SignedHeaderAuth implements HttpRequestFilter {
@Named(Constants.LOGGER_SIGNATURE) @Named(Constants.LOGGER_SIGNATURE)
Logger signatureLog = Logger.NULL; Logger signatureLog = Logger.NULL;
@Inject @Inject
public SignedHeaderAuth(SignatureWire signatureWire, @org.jclouds.location.Provider Supplier<Credentials> creds, public SignedHeaderAuth(SignatureWire signatureWire, @org.jclouds.location.Provider Supplier<Credentials> creds,
Supplier<PrivateKey> supplyKey, @TimeStamp Provider<String> timeStampProvider, HttpUtils utils) { Supplier<PrivateKey> supplyKey, @TimeStamp Provider<String> timeStampProvider, HttpUtils utils) {
@ -145,8 +144,8 @@ public class SignedHeaderAuth implements HttpRequestFilter {
} }
/** /**
* Build the canonicalized path, which collapses multiple slashes (/) and removes a trailing * Build the canonicalized path, which collapses multiple slashes (/) and
* slash unless the path is only "/" * removes a trailing slash unless the path is only "/"
*/ */
@VisibleForTesting @VisibleForTesting
String canonicalPath(String path) { String canonicalPath(String path) {

View File

@ -31,7 +31,8 @@ import org.jclouds.http.functions.ParseJson;
import com.google.common.base.Function; import com.google.common.base.Function;
/** /**
* Parses a cookbook definition from a Json response, assuming a Chef Server >= 0.10.8. * Parses a cookbook definition from a Json response, assuming a Chef Server >=
* 0.10.8.
* *
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */

View File

@ -32,6 +32,7 @@ import com.google.common.collect.Iterables;
/** /**
* Parses the cookbook versions in a Chef Server <= 0.9.8. * Parses the cookbook versions in a Chef Server <= 0.9.8.
*
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
@Singleton @Singleton

View File

@ -35,6 +35,7 @@ import com.google.common.collect.Sets;
/** /**
* Parses the cookbook versions in a Chef Server >= 0.10.8. * Parses the cookbook versions in a Chef Server >= 0.10.8.
*
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
@Singleton @Singleton
@ -53,10 +54,9 @@ public class ParseCookbookVersionsV10FromJson implements Function<HttpResponse,
CookbookDefinition def = Iterables.getFirst(parser.apply(response).values(), null); CookbookDefinition def = Iterables.getFirst(parser.apply(response).values(), null);
return Sets.newLinkedHashSet(Iterables.transform(def.getVersions(), new Function<Version, String>() { return Sets.newLinkedHashSet(Iterables.transform(def.getVersions(), new Function<Version, String>() {
@Override @Override
public String apply(Version input) public String apply(Version input) {
{
return input.getVersion(); return input.getVersion();
}}) }
); }));
} }
} }

View File

@ -37,7 +37,8 @@ import com.google.gson.annotations.SerializedName;
/** /**
* Parses the search result into a {@link DatabagItem} object. * Parses the search result into a {@link DatabagItem} object.
* <p> * <p>
* When searching databags, the items are contained inside the <code>raw_data</code> list. * When searching databags, the items are contained inside the
* <code>raw_data</code> list.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -67,8 +68,7 @@ public class ParseSearchDatabagFromJson implements Function<HttpResponse, Search
@Override @Override
public SearchResult<DatabagItem> apply(HttpResponse arg0) { public SearchResult<DatabagItem> apply(HttpResponse arg0) {
Response returnVal = responseParser.apply(arg0); Response returnVal = responseParser.apply(arg0);
Iterable<DatabagItem> items = Iterable<DatabagItem> items = Iterables.transform(returnVal.rows, new Function<Row, DatabagItem>() {
Iterables.transform(returnVal.rows, new Function<Row, DatabagItem>() {
@Override @Override
public DatabagItem apply(Row input) { public DatabagItem apply(Row input) {
return json.fromJson(input.rawData.toString(), DatabagItem.class); return json.fromJson(input.rawData.toString(), DatabagItem.class);

View File

@ -89,11 +89,11 @@ public class BaseChefService implements ChefService {
@Inject @Inject
protected BaseChefService(ChefContext chefContext, CleanupStaleNodesAndClients cleanupStaleNodesAndClients, protected BaseChefService(ChefContext chefContext, CleanupStaleNodesAndClients cleanupStaleNodesAndClients,
CreateNodeAndPopulateAutomaticAttributes createNodeAndPopulateAutomaticAttributes, CreateNodeAndPopulateAutomaticAttributes createNodeAndPopulateAutomaticAttributes,
DeleteAllNodesInList deleteAllNodesInList, ListNodes listNodes, DeleteAllNodesInList deleteAllNodesInList, ListNodes listNodes, DeleteAllClientsInList deleteAllClientsInList,
DeleteAllClientsInList deleteAllClientsInList, ListClients listClients, ListClients listClients, ListCookbookVersions listCookbookVersions,
ListCookbookVersions listCookbookVersions, UpdateAutomaticAttributesOnNode updateAutomaticAttributesOnNode, UpdateAutomaticAttributesOnNode updateAutomaticAttributesOnNode, Supplier<PrivateKey> privateKey,
Supplier<PrivateKey> privateKey, @Named(CHEF_BOOTSTRAP_DATABAG) String databag, @Named(CHEF_BOOTSTRAP_DATABAG) String databag, GroupToBootScript groupToBootScript,
GroupToBootScript groupToBootScript, RunListForGroup runListForGroup) { RunListForGroup runListForGroup) {
this.chefContext = checkNotNull(chefContext, "chefContext"); this.chefContext = checkNotNull(chefContext, "chefContext");
this.cleanupStaleNodesAndClients = checkNotNull(cleanupStaleNodesAndClients, "cleanupStaleNodesAndClients"); this.cleanupStaleNodesAndClients = checkNotNull(cleanupStaleNodesAndClients, "cleanupStaleNodesAndClients");
this.createNodeAndPopulateAutomaticAttributes = checkNotNull(createNodeAndPopulateAutomaticAttributes, this.createNodeAndPopulateAutomaticAttributes = checkNotNull(createNodeAndPopulateAutomaticAttributes,
@ -176,7 +176,6 @@ public class BaseChefService implements ChefService {
return listCookbookVersions.execute(names); return listCookbookVersions.execute(names);
} }
@Override @Override
public void updateAutomaticAttributesOnNode(String nodeName) { public void updateAutomaticAttributesOnNode(String nodeName) {
updateAutomaticAttributesOnNode.execute(nodeName); updateAutomaticAttributesOnNode.execute(nodeName);
@ -200,8 +199,10 @@ public class BaseChefService implements ChefService {
} }
DatabagItem runlist = new DatabagItem(group, chefContext.utils().json().toJson( DatabagItem runlist = new DatabagItem(group, chefContext
ImmutableMap.<String, List<String>> of("run_list", Lists.newArrayList(runList)), .utils()
.json()
.toJson(ImmutableMap.<String, List<String>> of("run_list", Lists.newArrayList(runList)),
RunListForGroup.RUN_LIST_TYPE)); RunListForGroup.RUN_LIST_TYPE));
if (chefContext.getApi().getDatabagItem(databag, group) == null) { if (chefContext.getApi().getDatabagItem(databag, group) == null) {

View File

@ -18,14 +18,12 @@
*/ */
package org.jclouds.chef.options; package org.jclouds.chef.options;
/** /**
* Options for the create client method. * Options for the create client method.
* *
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
public class CreateClientOptions implements Cloneable public class CreateClientOptions implements Cloneable {
{
/** Administrator flag. This flag will be ignored in Opscode Hosted Chef. */ /** Administrator flag. This flag will be ignored in Opscode Hosted Chef. */
private boolean admin; private boolean admin;
@ -56,8 +54,7 @@ public class CreateClientOptions implements Cloneable
return "[admin=" + admin + "]"; return "[admin=" + admin + "]";
} }
public static class Builder public static class Builder {
{
/** /**
* @see CreateClientOptions#admin() * @see CreateClientOptions#admin()
*/ */

View File

@ -47,9 +47,10 @@ public class CookbookVersionPredicates {
} }
/** /**
* Note that the default recipe of a cookbook is its name. Otherwise, you prefix the recipe with * Note that the default recipe of a cookbook is its name. Otherwise, you
* the name of the cookbook. ex. {@code apache2} will be the default recipe where {@code * prefix the recipe with the name of the cookbook. ex. {@code apache2} will
* apache2::mod_proxy} is a specific one in the cookbook. * be the default recipe where {@code apache2::mod_proxy} is a specific one
* in the cookbook.
* *
* @param recipes * @param recipes
* names of the recipes. * names of the recipes.

View File

@ -60,8 +60,8 @@ public class DeleteAllClientsInListImpl implements DeleteAllClientsInList {
protected Long maxTime; protected Long maxTime;
@Inject @Inject
DeleteAllClientsInListImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ChefApi getAllApi, DeleteAllClientsInListImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
ChefAsyncApi ablobstore) { ChefApi getAllApi, ChefAsyncApi ablobstore) {
this.userExecutor = userExecutor; this.userExecutor = userExecutor;
this.chefAsyncApi = ablobstore; this.chefAsyncApi = ablobstore;
this.chefApi = getAllApi; this.chefApi = getAllApi;
@ -75,7 +75,8 @@ public class DeleteAllClientsInListImpl implements DeleteAllClientsInList {
responses.put(name, chefAsyncApi.deleteClient(name)); responses.put(name, chefAsyncApi.deleteClient(name));
} }
try { try {
exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, String.format("deleting apis: %s", names)); exceptions = awaitCompletion(responses, userExecutor, maxTime, logger,
String.format("deleting apis: %s", names));
} catch (TimeoutException e) { } catch (TimeoutException e) {
propagate(e); propagate(e);
} }

View File

@ -60,8 +60,8 @@ public class DeleteAllNodesInListImpl implements DeleteAllNodesInList {
protected Long maxTime; protected Long maxTime;
@Inject @Inject
DeleteAllNodesInListImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ChefApi getAllNode, DeleteAllNodesInListImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
ChefAsyncApi ablobstore) { ChefApi getAllNode, ChefAsyncApi ablobstore) {
this.userExecutor = userExecutor; this.userExecutor = userExecutor;
this.chefAsyncApi = ablobstore; this.chefAsyncApi = ablobstore;
this.chefApi = getAllNode; this.chefApi = getAllNode;
@ -75,7 +75,8 @@ public class DeleteAllNodesInListImpl implements DeleteAllNodesInList {
responses.put(name, chefAsyncApi.deleteNode(name)); responses.put(name, chefAsyncApi.deleteNode(name));
} }
try { try {
exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, String.format("deleting nodes: %s", names)); exceptions = awaitCompletion(responses, userExecutor, maxTime, logger,
String.format("deleting nodes: %s", names));
} catch (TimeoutException e) { } catch (TimeoutException e) {
propagate(e); propagate(e);
} }

View File

@ -54,8 +54,7 @@ public class UpdateAutomaticAttributesOnNodeImpl implements UpdateAutomaticAttri
private final Supplier<Map<String, JsonBall>> automaticSupplier; private final Supplier<Map<String, JsonBall>> automaticSupplier;
@Inject @Inject
public UpdateAutomaticAttributesOnNodeImpl(ChefApi chef, public UpdateAutomaticAttributesOnNodeImpl(ChefApi chef, @Automatic Supplier<Map<String, JsonBall>> automaticSupplier) {
@Automatic Supplier<Map<String, JsonBall>> automaticSupplier) {
this.chef = checkNotNull(chef, "chef"); this.chef = checkNotNull(chef, "chef");
this.automaticSupplier = checkNotNull(automaticSupplier, "automaticSupplier"); this.automaticSupplier = checkNotNull(automaticSupplier, "automaticSupplier");
} }

View File

@ -56,9 +56,10 @@ public class TransientChefApiMetadata extends ChefApiMetadata {
.defaultIdentity("api") .defaultIdentity("api")
.defaultCredential( .defaultCredential(
"-----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") "-----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")
.defaultEndpoint("transientchef").defaultModules( .defaultEndpoint("transientchef")
ImmutableSet.<Class<? extends Module>> of(TransientChefApiModule.class, .defaultModules(
ChefParserModule.class, JMXOhaiModule.class)); ImmutableSet.<Class<? extends Module>> of(TransientChefApiModule.class, ChefParserModule.class,
JMXOhaiModule.class));
} }
@Override @Override

View File

@ -100,8 +100,8 @@ public class TransientChefAsyncApi implements ChefAsyncApi {
private final StorageMetadataToName storageMetadataToName; private final StorageMetadataToName storageMetadataToName;
@Inject @Inject
TransientChefAsyncApi(@Named("databags") LocalAsyncBlobStore databags, TransientChefAsyncApi(@Named("databags") LocalAsyncBlobStore databags, StorageMetadataToName storageMetadataToName,
StorageMetadataToName storageMetadataToName, BlobToDatabagItem blobToDatabagItem, BlobToDatabagItem blobToDatabagItem,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) { @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) {
this.databags = checkNotNull(databags, "databags"); this.databags = checkNotNull(databags, "databags");
this.storageMetadataToName = checkNotNull(storageMetadataToName, "storageMetadataToName"); this.storageMetadataToName = checkNotNull(storageMetadataToName, "storageMetadataToName");
@ -182,7 +182,8 @@ public class TransientChefAsyncApi implements ChefAsyncApi {
@Override @Override
public ListenableFuture<DatabagItem> deleteDatabagItem(String databagName, String databagItemId) { public ListenableFuture<DatabagItem> deleteDatabagItem(String databagName, String databagItemId) {
return immediateFuture(blobToDatabagItem.apply(databags.getContext().createBlobMap(databagName).remove(databagItemId))); return immediateFuture(blobToDatabagItem.apply(databags.getContext().createBlobMap(databagName)
.remove(databagItemId)));
} }
@Override @Override
@ -286,8 +287,7 @@ public class TransientChefAsyncApi implements ChefAsyncApi {
} }
@Override @Override
public ListenableFuture<? extends SearchResult<? extends Client>> searchClients( public ListenableFuture<? extends SearchResult<? extends Client>> searchClients(SearchOptions options) {
SearchOptions options) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -297,8 +297,8 @@ public class TransientChefAsyncApi implements ChefAsyncApi {
} }
@Override @Override
public ListenableFuture<? extends SearchResult<? extends DatabagItem>> searchDatabag( public ListenableFuture<? extends SearchResult<? extends DatabagItem>> searchDatabag(String databagName,
String databagName, SearchOptions options) { SearchOptions options) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -308,8 +308,7 @@ public class TransientChefAsyncApi implements ChefAsyncApi {
} }
@Override @Override
public ListenableFuture<? extends SearchResult<? extends Node>> searchNodes( public ListenableFuture<? extends SearchResult<? extends Node>> searchNodes(SearchOptions options) {
SearchOptions options) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -319,8 +318,7 @@ public class TransientChefAsyncApi implements ChefAsyncApi {
} }
@Override @Override
public ListenableFuture<? extends SearchResult<? extends Role>> searchRoles( public ListenableFuture<? extends SearchResult<? extends Role>> searchRoles(SearchOptions options) {
SearchOptions options) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -71,12 +71,13 @@ public class TransientChefApiModule extends AbstractModule {
bindBlockingApi(binder(), TransientChefApi.class, ChefAsyncApi.class); bindBlockingApi(binder(), TransientChefApi.class, ChefAsyncApi.class);
bind(ChefApi.class).to(TransientChefApi.class); bind(ChefApi.class).to(TransientChefApi.class);
bind(LocalAsyncBlobStore.class).annotatedWith(Names.named("databags")).toInstance( bind(LocalAsyncBlobStore.class).annotatedWith(Names.named("databags"))
.toInstance(
ContextBuilder ContextBuilder
.newBuilder(new TransientApiMetadata()) .newBuilder(new TransientApiMetadata())
.modules(ImmutableSet.<Module> of( .modules(
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))) ImmutableSet.<Module> of(new ExecutorServiceModule(sameThreadExecutor(),
.buildInjector().getInstance(LocalAsyncBlobStore.class)); sameThreadExecutor()))).buildInjector().getInstance(LocalAsyncBlobStore.class));
bind(Statement.class).annotatedWith(Names.named("installChefGems")).to(InstallChefGems.class); bind(Statement.class).annotatedWith(Names.named("installChefGems")).to(InstallChefGems.class);
} }

View File

@ -24,14 +24,16 @@ import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
/** /**
* An internal binding annotation applied to each element in a multibinding. * An internal binding annotation applied to each element in a multibinding. All
* All elements are assigned a globally-unique id to allow different modules * elements are assigned a globally-unique id to allow different modules to
* to contribute multibindings independently. * contribute multibindings independently.
* *
* @author jessewilson@google.com (Jesse Wilson) * @author jessewilson@google.com (Jesse Wilson)
*/ */
@Retention(RUNTIME) @BindingAnnotation @Retention(RUNTIME)
@BindingAnnotation
@interface Element { @interface Element {
String setName(); String setName();
int uniqueId(); int uniqueId();
} }

View File

@ -75,8 +75,8 @@ import com.google.inject.util.Types;
* </pre> * </pre>
* *
* <p> * <p>
* In addition to binding {@code Map<K, V>}, a mapbinder will also bind {@code * In addition to binding {@code Map<K, V>}, a mapbinder will also bind
* Map<K, Provider<V>>} for lazy value provision: * {@code Map<K, Provider<V>>} for lazy value provision:
* *
* <pre> * <pre>
* <code> * <code>
@ -131,20 +131,21 @@ public abstract class MapBinder<K, V> {
} }
/** /**
* Returns a new mapbinder that collects entries of {@code keyType}/{@code * Returns a new mapbinder that collects entries of {@code keyType}/
* valueType} in a {@link Map} that is itself bound with no binding * {@code valueType} in a {@link Map} that is itself bound with no binding
* annotation. * annotation.
*/ */
public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType) { public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType) {
binder = binder.skipSources(MapBinder.class, RealMapBinder.class); binder = binder.skipSources(MapBinder.class, RealMapBinder.class);
return newMapBinder(binder, valueType, Key.get(mapOf(keyType, valueType)), Key.get(mapOfProviderOf(keyType, return newMapBinder(binder, valueType, Key.get(mapOf(keyType, valueType)),
valueType)), Key.get(mapOf(keyType, setOf(valueType))), Key.get(mapOfSetOfProviderOf(keyType, valueType)), Key.get(mapOfProviderOf(keyType, valueType)), Key.get(mapOf(keyType, setOf(valueType))),
Key.get(mapOfSetOfProviderOf(keyType, valueType)),
Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType))); Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType)));
} }
/** /**
* Returns a new mapbinder that collects entries of {@code keyType}/{@code * Returns a new mapbinder that collects entries of {@code keyType}/
* valueType} in a {@link Map} that is itself bound with no binding * {@code valueType} in a {@link Map} that is itself bound with no binding
* annotation. * annotation.
*/ */
public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, Class<K> keyType, Class<V> valueType) { public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, Class<K> keyType, Class<V> valueType) {
@ -152,21 +153,24 @@ public abstract class MapBinder<K, V> {
} }
/** /**
* Returns a new mapbinder that collects entries of {@code keyType}/{@code * Returns a new mapbinder that collects entries of {@code keyType}/
* valueType} in a {@link Map} that is itself bound with {@code annotation}. * {@code valueType} in a {@link Map} that is itself bound with
* {@code annotation}.
*/ */
public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType,
Annotation annotation) { Annotation annotation) {
binder = binder.skipSources(MapBinder.class, RealMapBinder.class); binder = binder.skipSources(MapBinder.class, RealMapBinder.class);
return newMapBinder(binder, valueType, Key.get(mapOf(keyType, valueType), annotation), Key.get(mapOfProviderOf( return newMapBinder(binder, valueType, Key.get(mapOf(keyType, valueType), annotation),
keyType, valueType), annotation), Key.get(mapOf(keyType, setOf(valueType)), annotation), Key.get( Key.get(mapOfProviderOf(keyType, valueType), annotation),
mapOfSetOfProviderOf(keyType, valueType), annotation), Multibinder.newSetBinder(binder, entryOfProviderOf( Key.get(mapOf(keyType, setOf(valueType)), annotation),
keyType, valueType), annotation)); Key.get(mapOfSetOfProviderOf(keyType, valueType), annotation),
Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType), annotation));
} }
/** /**
* Returns a new mapbinder that collects entries of {@code keyType}/{@code * Returns a new mapbinder that collects entries of {@code keyType}/
* valueType} in a {@link Map} that is itself bound with {@code annotation}. * {@code valueType} in a {@link Map} that is itself bound with
* {@code annotation}.
*/ */
public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, Class<K> keyType, Class<V> valueType, public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, Class<K> keyType, Class<V> valueType,
Annotation annotation) { Annotation annotation) {
@ -174,23 +178,24 @@ public abstract class MapBinder<K, V> {
} }
/** /**
* Returns a new mapbinder that collects entries of {@code keyType}/{@code * Returns a new mapbinder that collects entries of {@code keyType}/
* valueType} in a {@link Map} that is itself bound with {@code * {@code valueType} in a {@link Map} that is itself bound with
* annotationType}. * {@code annotationType}.
*/ */
public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType, public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, TypeLiteral<K> keyType, TypeLiteral<V> valueType,
Class<? extends Annotation> annotationType) { Class<? extends Annotation> annotationType) {
binder = binder.skipSources(MapBinder.class, RealMapBinder.class); binder = binder.skipSources(MapBinder.class, RealMapBinder.class);
return newMapBinder(binder, valueType, Key.get(mapOf(keyType, valueType), annotationType), Key.get( return newMapBinder(binder, valueType, Key.get(mapOf(keyType, valueType), annotationType),
mapOfProviderOf(keyType, valueType), annotationType), Key.get(mapOf(keyType, setOf(valueType)), Key.get(mapOfProviderOf(keyType, valueType), annotationType),
annotationType), Key.get(mapOfSetOfProviderOf(keyType, valueType), annotationType), Multibinder Key.get(mapOf(keyType, setOf(valueType)), annotationType),
.newSetBinder(binder, entryOfProviderOf(keyType, valueType), annotationType)); Key.get(mapOfSetOfProviderOf(keyType, valueType), annotationType),
Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType), annotationType));
} }
/** /**
* Returns a new mapbinder that collects entries of {@code keyType}/{@code * Returns a new mapbinder that collects entries of {@code keyType}/
* valueType} in a {@link Map} that is itself bound with {@code * {@code valueType} in a {@link Map} that is itself bound with
* annotationType}. * {@code annotationType}.
*/ */
public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, Class<K> keyType, Class<V> valueType, public static <K, V> MapBinder<K, V> newMapBinder(Binder binder, Class<K> keyType, Class<V> valueType,
Class<? extends Annotation> annotationType) { Class<? extends Annotation> annotationType) {
@ -207,16 +212,16 @@ public abstract class MapBinder<K, V> {
// a provider map <K, V> is safely a Map<K, Provider<V>> // a provider map <K, V> is safely a Map<K, Provider<V>>
private static <K, V> TypeLiteral<Map<K, Provider<V>>> mapOfProviderOf(TypeLiteral<K> keyType, private static <K, V> TypeLiteral<Map<K, Provider<V>>> mapOfProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) { TypeLiteral<V> valueType) {
return (TypeLiteral<Map<K, Provider<V>>>) TypeLiteral.get(Types.mapOf(keyType.getType(), Types return (TypeLiteral<Map<K, Provider<V>>>) TypeLiteral.get(Types.mapOf(keyType.getType(),
.providerOf(valueType.getType()))); Types.providerOf(valueType.getType())));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>> // a provider map <K, Set<V>> is safely a Map<K, Set<Provider<V>>>
private static <K, V> TypeLiteral<Map<K, Set<Provider<V>>>> mapOfSetOfProviderOf(TypeLiteral<K> keyType, private static <K, V> TypeLiteral<Map<K, Set<Provider<V>>>> mapOfSetOfProviderOf(TypeLiteral<K> keyType,
TypeLiteral<V> valueType) { TypeLiteral<V> valueType) {
return (TypeLiteral<Map<K, Set<Provider<V>>>>) TypeLiteral.get(Types.mapOf(keyType.getType(), Types.setOf(Types return (TypeLiteral<Map<K, Set<Provider<V>>>>) TypeLiteral.get(Types.mapOf(keyType.getType(),
.providerOf(valueType.getType())))); Types.setOf(Types.providerOf(valueType.getType()))));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -260,8 +265,8 @@ public abstract class MapBinder<K, V> {
* time the map is injected. * time the map is injected.
* *
* <p> * <p>
* It is an error to call this method without also calling one of the {@code * It is an error to call this method without also calling one of the
* to} methods on the returned binding builder. * {@code to} methods on the returned binding builder.
* *
* <p> * <p>
* Scoping elements independently is supported. Use the {@code in} method to * Scoping elements independently is supported. Use the {@code in} method to

View File

@ -139,8 +139,8 @@ public abstract class Multibinder<T> {
*/ */
public static <T> Multibinder<T> newSetBinder(Binder binder, TypeLiteral<T> type, Annotation annotation) { public static <T> Multibinder<T> newSetBinder(Binder binder, TypeLiteral<T> type, Annotation annotation) {
binder = binder.skipSources(RealMultibinder.class, Multibinder.class); binder = binder.skipSources(RealMultibinder.class, Multibinder.class);
RealMultibinder<T> result = new RealMultibinder<T>(binder, type, annotation.toString(), Key.get(Multibinder RealMultibinder<T> result = new RealMultibinder<T>(binder, type, annotation.toString(), Key.get(
.<T> setOf(type), annotation)); Multibinder.<T> setOf(type), annotation));
binder.install(result); binder.install(result);
return result; return result;
} }
@ -198,8 +198,8 @@ public abstract class Multibinder<T> {
* time the set is injected. * time the set is injected.
* *
* <p> * <p>
* It is an error to call this method without also calling one of the {@code * It is an error to call this method without also calling one of the
* to} methods on the returned binding builder. * {@code to} methods on the returned binding builder.
* *
* <p> * <p>
* Scoping elements independently is supported. Use the {@code in} method to * Scoping elements independently is supported. Use the {@code in} method to

View File

@ -17,13 +17,11 @@
* under the License. * under the License.
*/ */
package org.jclouds.ohai.config.multibindings; package org.jclouds.ohai.config.multibindings;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @author jessewilson@google.com (Jesse Wilson) * @author jessewilson@google.com (Jesse Wilson)
*/ */
@ -50,19 +48,19 @@ class RealElement implements Element {
return Element.class; return Element.class;
} }
@Override public String toString() { @Override
return "@" + Element.class.getName() + "(setName=" + setName public String toString() {
+ ",uniqueId=" + uniqueId + ")"; return "@" + Element.class.getName() + "(setName=" + setName + ",uniqueId=" + uniqueId + ")";
} }
@Override public boolean equals(Object o) { @Override
return o instanceof Element public boolean equals(Object o) {
&& ((Element) o).setName().equals(setName()) return o instanceof Element && ((Element) o).setName().equals(setName())
&& ((Element) o).uniqueId() == uniqueId(); && ((Element) o).uniqueId() == uniqueId();
} }
@Override public int hashCode() { @Override
return 127 * ("setName".hashCode() ^ setName.hashCode()) public int hashCode() {
+ 127 * ("uniqueId".hashCode() ^ uniqueId); return 127 * ("setName".hashCode() ^ setName.hashCode()) + 127 * ("uniqueId".hashCode() ^ uniqueId);
} }
} }

View File

@ -42,14 +42,12 @@ public class ChefApiLiveTest extends BaseChefApiLiveTest<ChefContext> {
} }
@Override @Override
protected ChefApi getChefApi(ChefContext context) protected ChefApi getChefApi(ChefContext context) {
{
return context.getApi(); return context.getApi();
} }
@Override @Override
protected TypeToken<ChefContext> contextType() protected TypeToken<ChefContext> contextType() {
{
return typeToken(ChefContext.class); return typeToken(ChefContext.class);
} }

View File

@ -60,6 +60,7 @@ import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.io.payloads.StringPayload; import org.jclouds.io.payloads.StringPayload;
import org.jclouds.reflect.Invocation;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.BaseAsyncApiTest; import org.jclouds.rest.internal.BaseAsyncApiTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
@ -70,6 +71,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.Invokable; import com.google.common.reflect.Invokable;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
* Tests annotation parsing of {@code ChefAsyncApi} * Tests annotation parsing of {@code ChefAsyncApi}
* *
@ -81,11 +83,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCommitSandbox() throws SecurityException, NoSuchMethodException, IOException { public void testCommitSandbox() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "commitSandbox", String.class, boolean.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "commitSandbox", String.class, boolean.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableList.<Object> of("0189e76ccc476701d6b374e5a1a27347", true)); ImmutableList.<Object> of("0189e76ccc476701d6b374e5a1a27347", true)));
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1"); "PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"is_completed\":true}", "application/json", false); assertPayloadEquals(httpRequest, "{\"is_completed\":true}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -98,17 +101,16 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testGetUploadSandboxForChecksums() throws SecurityException, NoSuchMethodException, IOException { public void testGetUploadSandboxForChecksums() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "getUploadSandboxForChecksums", Set.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "getUploadSandboxForChecksums", Set.class);
GeneratedHttpRequest httpRequest = processor.createRequest( GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList
method, ImmutableList.<Object> of( .<Object> of(ImmutableSet.of(asList(base16().lowerCase().decode("0189e76ccc476701d6b374e5a1a27347")),
ImmutableSet.of(asList(base16().lowerCase().decode("0189e76ccc476701d6b374e5a1a27347")), asList(base16().lowerCase().decode("0c5ecd7788cf4f6c7de2a57193897a6c")), asList(base16().lowerCase()
asList(base16().lowerCase().decode("0c5ecd7788cf4f6c7de2a57193897a6c")), .decode("1dda05ed139664f1f89b9dec482b77c0"))))));
asList(base16().lowerCase().decode("1dda05ed139664f1f89b9dec482b77c0")))));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
assertPayloadEquals( + "-test\n");
httpRequest, assertPayloadEquals(httpRequest,
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}", "{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,"
"application/json", false); + "\"1dda05ed139664f1f89b9dec482b77c0\":null}}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
@ -119,10 +121,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testUploadContent() throws SecurityException, NoSuchMethodException, IOException { public void testUploadContent() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "uploadContent", URI.class, Payload.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "uploadContent", URI.class, Payload.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(URI.create("http://foo/bar"), GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
new StringPayload("{\"foo\": \"bar\"}"))); ImmutableList.<Object> of(URI.create("http://foo/bar"), new StringPayload("{\"foo\": \"bar\"}"))));
assertRequestLineEquals(httpRequest, "PUT http://foo/bar HTTP/1.1"); assertRequestLineEquals(httpRequest, "PUT http://foo/bar HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"foo\": \"bar\"}", "application/x-binary", false); assertPayloadEquals(httpRequest, "{\"foo\": \"bar\"}", "application/x-binary", false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
@ -135,9 +138,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testGetCookbook() throws SecurityException, NoSuchMethodException, IOException { public void testGetCookbook() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "getCookbook", String.class, String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "getCookbook", String.class, String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("cookbook", "1.0.0")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableList.<Object> of("cookbook", "1.0.0")));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -150,9 +155,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testDeleteCookbook() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteCookbook() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteCookbook", String.class, String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteCookbook", String.class, String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("cookbook", "1.0.0")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableList.<Object> of("cookbook", "1.0.0")));
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1"); assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -166,15 +173,21 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testUpdateCookbook() throws SecurityException, NoSuchMethodException, IOException { public void testUpdateCookbook() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "updateCookbook", String.class, String.class, Invokable<?, ?> method = method(ChefAsyncApi.class, "updateCookbook", String.class, String.class,
CookbookVersion.class); CookbookVersion.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("cookbook", "1.0.1", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
new CookbookVersion("cookbook", "1.0.1"))); ImmutableList.<Object> of("cookbook", "1.0.1", new CookbookVersion("cookbook", "1.0.1"))));
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1"); assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
assertPayloadEquals( + "-test\n");
httpRequest, assertPayloadEquals(httpRequest,
"{\"name\":\"cookbook-1.0.1\",\"definitions\":[],\"attributes\":[],\"files\":[],\"metadata\":{\"suggestions\":{},\"dependencies\":{},\"conflicting\":{},\"providing\":{},\"platforms\":{},\"recipes\":{},\"replacing\":{},\"groupings\":{},\"attributes\":{},\"recommendations\":{}},\"providers\":[],\"cookbook_name\":\"cookbook\",\"resources\":[],\"templates\":[],\"libraries\":[],\"version\":\"1.0.1\",\"recipes\":[],\"root_files\":[],\"json_class\":\"Chef::CookbookVersion\",\"chef_type\":\"cookbook_version\"}", "{\"name\":\"cookbook-1.0.1\",\"definitions\":[],\"attributes\":[],\"files\":[],"
"application/json", false); + "\"metadata\":{\"suggestions\":{},\"dependencies\":{},\"conflicting\":{},\"providing\":{},"
+ "\"platforms\":{},\"recipes\":{},\"replacing\":{},"
+ "\"groupings\":{},\"attributes\":{},\"recommendations\":{}},"
+ "\"providers\":[],\"cookbook_name\":\"cookbook\",\"resources\":[],\"templates\":[],"
+ "\"libraries\":[],\"version\":\"1.0.1\","
+ "\"recipes\":[],\"root_files\":[],\"json_class\":\"Chef::CookbookVersion\","
+ "\"chef_type\":\"cookbook_version\"}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, null); assertFallbackClassEquals(method, null);
@ -185,10 +198,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testListCookbooks() throws SecurityException, NoSuchMethodException, IOException { public void testListCookbooks() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "listCookbooks"); Invokable<?, ?> method = method(ChefAsyncApi.class, "listCookbooks");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseCookbookDefinitionCheckingChefVersion.class); assertResponseParserClassEquals(method, httpRequest, ParseCookbookDefinitionCheckingChefVersion.class);
@ -201,10 +215,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testGetVersionsOfCookbook() throws SecurityException, NoSuchMethodException, IOException { public void testGetVersionsOfCookbook() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "getVersionsOfCookbook", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "getVersionsOfCookbook", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("apache2"));; GeneratedHttpRequest httpRequest = processor
.apply(Invocation.create(method, ImmutableList.<Object> of("apache2")));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks/apache2 HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks/apache2 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionsCheckingChefVersion.class); assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionsCheckingChefVersion.class);
@ -217,9 +233,10 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testApiExists() throws SecurityException, NoSuchMethodException, IOException { public void testApiExists() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "clientExists", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "clientExists", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("api")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("api")));
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/api HTTP/1.1"); assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/api HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
@ -232,9 +249,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testDeleteClient() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteClient() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteClient", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteClient", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("client")); GeneratedHttpRequest httpRequest = processor
.apply(Invocation.create(method, ImmutableList.<Object> of("client")));
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1"); assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -247,10 +266,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateApi() throws SecurityException, NoSuchMethodException, IOException { public void testCreateApi() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createClient", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createClient", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("api")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("api")));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"name\":\"api\"}", "application/json", false); assertPayloadEquals(httpRequest, "{\"name\":\"api\"}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -263,10 +283,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateAdminApi() throws SecurityException, NoSuchMethodException, IOException { public void testCreateAdminApi() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createClient", String.class, CreateClientOptions.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createClient", String.class, CreateClientOptions.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("api", CreateClientOptions.Builder.admin())); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableList.<Object> of("api", CreateClientOptions.Builder.admin())));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"name\":\"api\",\"admin\":true}", "application/json", false); assertPayloadEquals(httpRequest, "{\"name\":\"api\",\"admin\":true}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -279,10 +301,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testListClients() throws SecurityException, NoSuchMethodException, IOException { public void testListClients() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "listClients"); Invokable<?, ?> method = method(ChefAsyncApi.class, "listClients");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
@ -295,9 +318,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testGenerateKeyForClient() throws SecurityException, NoSuchMethodException, IOException { public void testGenerateKeyForClient() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "generateKeyForClient", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "generateKeyForClient", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("client")); GeneratedHttpRequest httpRequest = processor
.apply(Invocation.create(method, ImmutableList.<Object> of("client")));
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1"); assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"name\":\"client\", \"private_key\": true}", "application/json", false); assertPayloadEquals(httpRequest, "{\"name\":\"client\", \"private_key\": true}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -310,8 +335,9 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testNodeExists() throws SecurityException, NoSuchMethodException, IOException { public void testNodeExists() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "nodeExists", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "nodeExists", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("node")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("node")));
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
@ -324,9 +350,10 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteNode", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteNode", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("node")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("node")));
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/nodes/node HTTP/1.1"); assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/nodes/node HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -339,15 +366,16 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateNode() throws SecurityException, NoSuchMethodException, IOException { public void testCreateNode() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createNode", Node.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createNode", Node.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(new Node("testnode", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableSet.of("recipe[java]"), "_default"))); ImmutableList.<Object> of(new Node("testnode", ImmutableSet.of("recipe[java]"), "_default"))));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/nodes HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/nodes HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
assertPayloadEquals( + "-test\n");
httpRequest, assertPayloadEquals(httpRequest,
"{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},\"run_list\":[\"recipe[java]\"],\"chef_environment\":\"_default\",\"json_class\":\"Chef::Node\",\"chef_type\":\"node\"}", "{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},"
"application/json", false); + "\"run_list\":[\"recipe[java]\"],\"chef_environment\":\"_default\",\"json_class\":\"Chef::Node\","
+ "\"chef_type\":\"node\"}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
@ -359,15 +387,16 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testUpdateNode() throws SecurityException, NoSuchMethodException, IOException { public void testUpdateNode() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "updateNode", Node.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "updateNode", Node.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(new Node("testnode", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableSet.of("recipe[java]"), "_default"))); ImmutableList.<Object> of(new Node("testnode", ImmutableSet.of("recipe[java]"), "_default"))));
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/nodes/testnode HTTP/1.1"); assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/nodes/testnode HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
assertPayloadEquals( + "-test\n");
httpRequest, assertPayloadEquals(httpRequest,
"{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},\"run_list\":[\"recipe[java]\"],\"chef_environment\":\"_default\",\"json_class\":\"Chef::Node\",\"chef_type\":\"node\"}", "{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},"
"application/json", false); + "\"run_list\":[\"recipe[java]\"],\"chef_environment\":\"_default\",\"json_class\":\"Chef::Node\","
+ "\"chef_type\":\"node\"}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
@ -379,10 +408,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testListNodes() throws SecurityException, NoSuchMethodException, IOException { public void testListNodes() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "listNodes"); Invokable<?, ?> method = method(ChefAsyncApi.class, "listNodes");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/nodes HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/nodes HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
@ -395,9 +425,10 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testRoleExists() throws SecurityException, NoSuchMethodException, IOException { public void testRoleExists() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "roleExists", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "roleExists", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("role")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("role")));
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/roles/role HTTP/1.1"); assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/roles/role HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
@ -410,9 +441,10 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testDeleteRole() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteRole() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteRole", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteRole", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("role")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("role")));
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/roles/role HTTP/1.1"); assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/roles/role HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -425,14 +457,14 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateRole() throws SecurityException, NoSuchMethodException, IOException { public void testCreateRole() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createRole", Role.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createRole", Role.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(new Role("testrole", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableSet.of("recipe[java]")))); ImmutableList.<Object> of(new Role("testrole", ImmutableSet.of("recipe[java]")))));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/roles HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/roles HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
assertPayloadEquals( + "-test\n");
httpRequest, assertPayloadEquals(httpRequest, "{\"name\":\"testrole\",\"override_attributes\":{},\"default_attributes\":{},"
"{\"name\":\"testrole\",\"override_attributes\":{},\"default_attributes\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Role\",\"chef_type\":\"role\"}", + "\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Role\",\"chef_type\":\"role\"}",
"application/json", false); "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
@ -445,14 +477,14 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testUpdateRole() throws SecurityException, NoSuchMethodException, IOException { public void testUpdateRole() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "updateRole", Role.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "updateRole", Role.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(new Role("testrole", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableSet.of("recipe[java]")))); ImmutableList.<Object> of(new Role("testrole", ImmutableSet.of("recipe[java]")))));
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/roles/testrole HTTP/1.1"); assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/roles/testrole HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
assertPayloadEquals( + "-test\n");
httpRequest, assertPayloadEquals(httpRequest, "{\"name\":\"testrole\",\"override_attributes\":{},\"default_attributes\":{},"
"{\"name\":\"testrole\",\"override_attributes\":{},\"default_attributes\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Role\",\"chef_type\":\"role\"}", + "\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Role\",\"chef_type\":\"role\"}",
"application/json", false); "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -465,10 +497,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testListRoles() throws SecurityException, NoSuchMethodException, IOException { public void testListRoles() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "listRoles"); Invokable<?, ?> method = method(ChefAsyncApi.class, "listRoles");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/roles HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/roles HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
@ -481,9 +514,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testDatabagExists() throws SecurityException, NoSuchMethodException, IOException { public void testDatabagExists() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "databagExists", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "databagExists", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("databag")); GeneratedHttpRequest httpRequest = processor
.apply(Invocation.create(method, ImmutableList.<Object> of("databag")));
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/data/databag HTTP/1.1"); assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/data/databag HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
@ -496,9 +531,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testDeleteDatabag() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteDatabag() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteDatabag", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteDatabag", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("databag")); GeneratedHttpRequest httpRequest = processor
.apply(Invocation.create(method, ImmutableList.<Object> of("databag")));
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/data/databag HTTP/1.1"); assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/data/databag HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
@ -511,10 +548,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateDatabag() throws SecurityException, NoSuchMethodException, IOException { public void testCreateDatabag() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabag", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabag", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("name")));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"name\":\"name\"}", "application/json", false); assertPayloadEquals(httpRequest, "{\"name\":\"name\"}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
@ -527,10 +565,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testListDatabags() throws SecurityException, NoSuchMethodException, IOException { public void testListDatabags() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "listDatabags"); Invokable<?, ?> method = method(ChefAsyncApi.class, "listDatabags");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/data HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/data HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
@ -543,9 +582,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testDatabagItemExists() throws SecurityException, NoSuchMethodException, IOException { public void testDatabagItemExists() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "databagItemExists", String.class, String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "databagItemExists", String.class, String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name", "databagItem")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
ImmutableList.<Object> of("name", "databagItem")));
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/data/name/databagItem HTTP/1.1"); assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/data/name/databagItem HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
@ -558,8 +599,10 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testDeleteDatabagItem() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteDatabagItem() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteDatabagItem", String.class, String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "deleteDatabagItem", String.class, String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name", "databagItem")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); ImmutableList.<Object> of("name", "databagItem")));
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -574,14 +617,16 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateDatabagItemThrowsIllegalArgumentOnPrimitive() throws SecurityException, NoSuchMethodException, public void testCreateDatabagItemThrowsIllegalArgumentOnPrimitive() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabagItem", String.class, DatabagItem.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabagItem", String.class, DatabagItem.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name", new DatabagItem("id", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
"100"))); ImmutableList.<Object> of("name", new DatabagItem("id", "100"))));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data/name HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data/name HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals( assertPayloadEquals(
httpRequest, httpRequest,
"{\"name\":\"testdatabagItem\",\"override_attributes\":{},\"default_attributes\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::DatabagItem\",\"chef_type\":\"databagItem\"}", "{\"name\":\"testdatabagItem\",\"override_attributes\":{},\"default_attributes\":{},"
+ "\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::DatabagItem\",\"chef_type\":\"databagItem\"}",
"application/json", false); "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -596,14 +641,16 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateDatabagItemThrowsIllegalArgumentOnWrongId() throws SecurityException, NoSuchMethodException, public void testCreateDatabagItemThrowsIllegalArgumentOnWrongId() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabagItem", String.class, DatabagItem.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabagItem", String.class, DatabagItem.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name", new DatabagItem("id", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
"{\"id\": \"item1\",\"my_key\": \"my_data\"}"))); ImmutableList.<Object> of("name", new DatabagItem("id", "{\"id\": \"item1\",\"my_key\": \"my_data\"}"))));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data/name HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data/name HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals( assertPayloadEquals(
httpRequest, httpRequest,
"{\"name\":\"testdatabagItem\",\"override_attributes\":{},\"default_attributes\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::DatabagItem\",\"chef_type\":\"databagItem\"}", "{\"name\":\"testdatabagItem\",\"override_attributes\":{},\"default_attributes\":{},"
+ "\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::DatabagItem\",\"chef_type\":\"databagItem\"}",
"application/json", false); "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -616,11 +663,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateDatabagItem() throws SecurityException, NoSuchMethodException, IOException { public void testCreateDatabagItem() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabagItem", String.class, DatabagItem.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabagItem", String.class, DatabagItem.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name", new DatabagItem("id", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
"{\"id\": \"id\",\"my_key\": \"my_data\"}"))); ImmutableList.<Object> of("name", new DatabagItem("id", "{\"id\": \"id\",\"my_key\": \"my_data\"}"))));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data/name HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data/name HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"id\": \"id\",\"my_key\": \"my_data\"}", "application/json", false); assertPayloadEquals(httpRequest, "{\"id\": \"id\",\"my_key\": \"my_data\"}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -633,11 +681,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testCreateDatabagItemEvenWhenUserForgotId() throws SecurityException, NoSuchMethodException, IOException { public void testCreateDatabagItemEvenWhenUserForgotId() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabagItem", String.class, DatabagItem.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "createDatabagItem", String.class, DatabagItem.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name", new DatabagItem("id", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
"{\"my_key\": \"my_data\"}"))); ImmutableList.<Object> of("name", new DatabagItem("id", "{\"my_key\": \"my_data\"}"))));
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data/name HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST http://localhost:4000/data/name HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"id\":\"id\",\"my_key\": \"my_data\"}", "application/json", false); assertPayloadEquals(httpRequest, "{\"id\":\"id\",\"my_key\": \"my_data\"}", "application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseJson.class); assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
@ -650,11 +699,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testUpdateDatabagItem() throws SecurityException, NoSuchMethodException, IOException { public void testUpdateDatabagItem() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "updateDatabagItem", String.class, DatabagItem.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "updateDatabagItem", String.class, DatabagItem.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name", new DatabagItem("id", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
"{\"my_key\": \"my_data\"}"))); ImmutableList.<Object> of("name", new DatabagItem("id", "{\"my_key\": \"my_data\"}"))));
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/data/name/id HTTP/1.1"); assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/data/name/id HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, "{\"id\":\"id\",\"my_key\": \"my_data\"}", "application/json", false); assertPayloadEquals(httpRequest, "{\"id\":\"id\",\"my_key\": \"my_data\"}", "application/json", false);
@ -668,10 +718,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testListDatabagItems() throws SecurityException, NoSuchMethodException, IOException { public void testListDatabagItems() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "listDatabagItems", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "listDatabagItems", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("name")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("name")));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/data/name HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/data/name HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
@ -684,10 +735,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testListSearchIndexes() throws SecurityException, NoSuchMethodException, IOException { public void testListSearchIndexes() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "listSearchIndexes"); Invokable<?, ?> method = method(ChefAsyncApi.class, "listSearchIndexes");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
@ -700,10 +752,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testSearchRoles() throws SecurityException, NoSuchMethodException, IOException { public void testSearchRoles() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "searchRoles"); Invokable<?, ?> method = method(ChefAsyncApi.class, "searchRoles");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/role HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/role HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSearchRolesFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseSearchRolesFromJson.class);
@ -716,11 +769,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testSearchRolesWithOptions() throws SecurityException, NoSuchMethodException, IOException { public void testSearchRolesWithOptions() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "searchRoles", SearchOptions.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "searchRoles", SearchOptions.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
SearchOptions.Builder.query("text"))); ImmutableList.<Object> of(SearchOptions.Builder.query("text"))));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/role?q=text HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/role?q=text HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSearchRolesFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseSearchRolesFromJson.class);
@ -733,10 +787,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testSearchClients() throws SecurityException, NoSuchMethodException, IOException { public void testSearchClients() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "searchClients"); Invokable<?, ?> method = method(ChefAsyncApi.class, "searchClients");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/client HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/client HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSearchClientsFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseSearchClientsFromJson.class);
@ -749,11 +804,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testSearchClientsWithOptions() throws SecurityException, NoSuchMethodException, IOException { public void testSearchClientsWithOptions() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "searchClients", SearchOptions.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "searchClients", SearchOptions.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
SearchOptions.Builder.query("text").rows(5))); ImmutableList.<Object> of(SearchOptions.Builder.query("text").rows(5))));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/client?q=text&rows=5 HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/client?q=text&rows=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSearchClientsFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseSearchClientsFromJson.class);
@ -766,10 +822,11 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testSearchNodes() throws SecurityException, NoSuchMethodException, IOException { public void testSearchNodes() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "searchNodes"); Invokable<?, ?> method = method(ChefAsyncApi.class, "searchNodes");
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.of()));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/node HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/node HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSearchNodesFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseSearchNodesFromJson.class);
@ -782,11 +839,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testSearchNodesWithOptions() throws SecurityException, NoSuchMethodException, IOException { public void testSearchNodesWithOptions() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "searchNodes", SearchOptions.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "searchNodes", SearchOptions.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
SearchOptions.Builder.query("foo:foo").start(3))); ImmutableList.<Object> of(SearchOptions.Builder.query("foo:foo").start(3))));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/node?q=foo%3Afoo&start=3 HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/node?q=foo%3Afoo&start=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSearchNodesFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseSearchNodesFromJson.class);
@ -797,13 +855,13 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
} }
public void testSearchDatabag() throws SecurityException, NoSuchMethodException, IOException { public void testSearchDatabag() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "searchDatabag", String.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "searchDatabag", String.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("foo")); GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method, ImmutableList.<Object> of("foo")));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/foo HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/foo HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSearchDatabagFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseSearchDatabagFromJson.class);
@ -816,11 +874,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testSearchDatabagWithOptions() throws SecurityException, NoSuchMethodException, IOException { public void testSearchDatabagWithOptions() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "searchDatabag", String.class, SearchOptions.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "searchDatabag", String.class, SearchOptions.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("foo", GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
SearchOptions.Builder.query("bar").sort("name DESC"))); ImmutableList.<Object> of("foo", SearchOptions.Builder.query("bar").sort("name DESC"))));
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/foo?q=bar&sort=name%20DESC HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/foo?q=bar&sort=name%20DESC HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseSearchDatabagFromJson.class); assertResponseParserClassEquals(method, httpRequest, ParseSearchDatabagFromJson.class);
@ -833,11 +892,12 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
public void testGetResourceContents() throws SecurityException, NoSuchMethodException, IOException { public void testGetResourceContents() throws SecurityException, NoSuchMethodException, IOException {
Invokable<?, ?> method = method(ChefAsyncApi.class, "getResourceContents", Resource.class); Invokable<?, ?> method = method(ChefAsyncApi.class, "getResourceContents", Resource.class);
GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( GeneratedHttpRequest httpRequest = processor.apply(Invocation.create(method,
new Resource("test", URI.create("http://foo/bar"), new byte[]{}, null, null))); ImmutableList.<Object> of(new Resource("test", URI.create("http://foo/bar"), new byte[] {}, null, null))));
assertRequestLineEquals(httpRequest, "GET http://foo/bar HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://foo/bar HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReturnInputStream.class); assertResponseParserClassEquals(method, httpRequest, ReturnInputStream.class);

View File

@ -45,8 +45,7 @@ public class BindHexEncodedMD5sToJsonPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -62,7 +61,8 @@ public class BindHexEncodedMD5sToJsonPayloadTest {
@Test(enabled = false) @Test(enabled = false)
public void testCorrect() { public void testCorrect() {
HttpRequest request = HttpRequest.builder().method(HttpMethod.POST).endpoint("http://localhost").build(); HttpRequest request = HttpRequest.builder().method(HttpMethod.POST).endpoint("http://localhost").build();
binder.bindToRequest(request, ImmutableSet.of(base16().lowerCase().decode("abddef"), base16().lowerCase().decode("1234"))); binder.bindToRequest(request,
ImmutableSet.of(base16().lowerCase().decode("abddef"), base16().lowerCase().decode("1234")));
assertEquals(request.getPayload().getRawContent(), "{\"checksums\":{\"abddef\":null,\"1234\":null}}"); assertEquals(request.getPayload().getRawContent(), "{\"checksums\":{\"abddef\":null,\"1234\":null}}");
} }

View File

@ -80,30 +80,31 @@ public class SignedHeaderAuthTest {
"NMzYZgyooSvU85qkIUmKuCqgG2AIlvYa2Q/2ctrMhoaHhLOCWWoqYNMaEqPc", "NMzYZgyooSvU85qkIUmKuCqgG2AIlvYa2Q/2ctrMhoaHhLOCWWoqYNMaEqPc",
"3tKHE+CfvP+WuPdWk4jv4wpIkAz6ZLxToxcGhXmZbXpk56YTmqgBW2cbbw4O", "3tKHE+CfvP+WuPdWk4jv4wpIkAz6ZLxToxcGhXmZbXpk56YTmqgBW2cbbw4O",
"IWPZDHSiPcw//AYNgW1CCDptt+UFuaFYbtqZegcBd2n/jzcWODA7zL4KWEUy", "IWPZDHSiPcw//AYNgW1CCDptt+UFuaFYbtqZegcBd2n/jzcWODA7zL4KWEUy",
"9q4rlh/+1tBReg60QdsmDRsw/cdO1GZrKtuCwbuD4+nbRdVBKv72rqHX9cu0", "9q4rlh/+1tBReg60QdsmDRsw/cdO1GZrKtuCwbuD4+nbRdVBKv72rqHX9cu0", "utju9jzczCyB+sSAQWrxSsXB/b8vV2qs0l4VD2ML+w==" };
"utju9jzczCyB+sSAQWrxSsXB/b8vV2qs0l4VD2ML+w==" };
// We expect Mixlib::Authentication::SignedHeaderAuth//sign to return this // We expect Mixlib::Authentication::SignedHeaderAuth//sign to return this
// if passed the BODY above. // if passed the BODY above.
public static final Multimap<String, String> EXPECTED_SIGN_RESULT = ImmutableMultimap.<String, String> builder() public static final Multimap<String, String> EXPECTED_SIGN_RESULT = ImmutableMultimap.<String, String> builder()
.put("X-Ops-Content-Hash", X_OPS_CONTENT_HASH).put("X-Ops-Userid", USER_ID).put("X-Ops-Sign", "version=1.0") .put("X-Ops-Content-Hash", X_OPS_CONTENT_HASH).put("X-Ops-Userid", USER_ID).put("X-Ops-Sign", "version=1.0")
.put("X-Ops-Authorization-1", X_OPS_AUTHORIZATION_LINES[0]).put("X-Ops-Authorization-2", .put("X-Ops-Authorization-1", X_OPS_AUTHORIZATION_LINES[0])
X_OPS_AUTHORIZATION_LINES[1]).put("X-Ops-Authorization-3", X_OPS_AUTHORIZATION_LINES[2]).put( .put("X-Ops-Authorization-2", X_OPS_AUTHORIZATION_LINES[1])
"X-Ops-Authorization-4", X_OPS_AUTHORIZATION_LINES[3]).put("X-Ops-Authorization-5", .put("X-Ops-Authorization-3", X_OPS_AUTHORIZATION_LINES[2])
X_OPS_AUTHORIZATION_LINES[4]).put("X-Ops-Authorization-6", X_OPS_AUTHORIZATION_LINES[5]).put( .put("X-Ops-Authorization-4", X_OPS_AUTHORIZATION_LINES[3])
"X-Ops-Timestamp", TIMESTAMP_ISO8601).build(); .put("X-Ops-Authorization-5", X_OPS_AUTHORIZATION_LINES[4])
.put("X-Ops-Authorization-6", X_OPS_AUTHORIZATION_LINES[5]).put("X-Ops-Timestamp", TIMESTAMP_ISO8601).build();
// Content hash for empty string // Content hash for empty string
public static final String X_OPS_CONTENT_HASH_EMPTY = "2jmj7l5rSw0yVb/vlWAYkK/YBwk="; public static final String X_OPS_CONTENT_HASH_EMPTY = "2jmj7l5rSw0yVb/vlWAYkK/YBwk=";
public static final Multimap<String, String> EXPECTED_SIGN_RESULT_EMPTY = ImmutableMultimap public static final Multimap<String, String> EXPECTED_SIGN_RESULT_EMPTY = ImmutableMultimap
.<String, String> builder().put("X-Ops-Content-Hash", X_OPS_CONTENT_HASH_EMPTY).put("X-Ops-Userid", USER_ID) .<String, String> builder().put("X-Ops-Content-Hash", X_OPS_CONTENT_HASH_EMPTY).put("X-Ops-Userid", USER_ID)
.put("X-Ops-Sign", "version=1.0").put("X-Ops-Authorization-1", .put("X-Ops-Sign", "version=1.0")
"N6U75kopDK64cEFqrB6vw+PnubnXr0w5LQeXnIGNGLRP2LvifwIeisk7QxEx").put("X-Ops-Authorization-2", .put("X-Ops-Authorization-1", "N6U75kopDK64cEFqrB6vw+PnubnXr0w5LQeXnIGNGLRP2LvifwIeisk7QxEx")
"mtpQOWAw8HvnWErjzuk9AvUsqVmWpv14ficvkaD79qsPMvbje+aLcIrCGT1P").put("X-Ops-Authorization-3", .put("X-Ops-Authorization-2", "mtpQOWAw8HvnWErjzuk9AvUsqVmWpv14ficvkaD79qsPMvbje+aLcIrCGT1P")
"3d2uvf4w7iqwzrIscPnkxLR6o6pymR90gvJXDPzV7Le0jbfD8kmZ8AAK0sGG").put("X-Ops-Authorization-4", .put("X-Ops-Authorization-3", "3d2uvf4w7iqwzrIscPnkxLR6o6pymR90gvJXDPzV7Le0jbfD8kmZ8AAK0sGG")
"09F1ftW80bLatJTA66Cw2wBz261r6x/abZhIKFJFDWLzyQGJ8ZNOkUrDDtgI").put("X-Ops-Authorization-5", .put("X-Ops-Authorization-4", "09F1ftW80bLatJTA66Cw2wBz261r6x/abZhIKFJFDWLzyQGJ8ZNOkUrDDtgI")
"svLVXpOJKZZfKunsElpWjjsyNt3k8vpI1Y4ANO8Eg2bmeCPeEK+YriGm5fbC").put("X-Ops-Authorization-6", .put("X-Ops-Authorization-5", "svLVXpOJKZZfKunsElpWjjsyNt3k8vpI1Y4ANO8Eg2bmeCPeEK+YriGm5fbC")
"DzWNPylHJqMeGKVYwGQKpg62QDfe5yXh3wZLiQcXow==").put("X-Ops-Timestamp", TIMESTAMP_ISO8601).build(); .put("X-Ops-Authorization-6", "DzWNPylHJqMeGKVYwGQKpg62QDfe5yXh3wZLiQcXow==")
.put("X-Ops-Timestamp", TIMESTAMP_ISO8601).build();
public static String PUBLIC_KEY; public static String PUBLIC_KEY;
public static String PRIVATE_KEY; public static String PRIVATE_KEY;
@ -131,8 +132,7 @@ public class SignedHeaderAuthTest {
@Test @Test
void shouldGenerateTheCorrectStringToSignAndSignature() { void shouldGenerateTheCorrectStringToSignAndSignature() {
HttpRequest request = HttpRequest.builder().method(HttpMethod.POST) HttpRequest request = HttpRequest.builder().method(HttpMethod.POST).endpoint("http://localhost/" + PATH)
.endpoint("http://localhost/" + PATH)
.payload(BODY).build(); .payload(BODY).build();
String expected_string_to_sign = new StringBuilder().append("Method:POST").append("\n").append("Hashed Path:") String expected_string_to_sign = new StringBuilder().append("Method:POST").append("\n").append("Hashed Path:")
@ -153,12 +153,13 @@ public class SignedHeaderAuthTest {
@Test @Test
void shouldGenerateTheCorrectStringToSignAndSignatureWithNoBody() { void shouldGenerateTheCorrectStringToSignAndSignatureWithNoBody() {
HttpRequest request = HttpRequest.builder().method(HttpMethod.DELETE) HttpRequest request = HttpRequest.builder().method(HttpMethod.DELETE).endpoint("http://localhost/" + PATH)
.endpoint("http://localhost/" + PATH).build(); .build();
request = signing_obj.filter(request); request = signing_obj.filter(request);
Multimap<String, String> headersWithoutContentLength = LinkedHashMultimap.create(request.getHeaders()); Multimap<String, String> headersWithoutContentLength = LinkedHashMultimap.create(request.getHeaders());
assertEqualsNoOrder(headersWithoutContentLength.entries().toArray(), EXPECTED_SIGN_RESULT_EMPTY.entries().toArray()); assertEqualsNoOrder(headersWithoutContentLength.entries().toArray(), EXPECTED_SIGN_RESULT_EMPTY.entries()
.toArray());
} }
@Test @Test
@ -167,8 +168,7 @@ public class SignedHeaderAuthTest {
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
path.append('A'); path.append('A');
HttpRequest request = HttpRequest.builder().method(HttpMethod.PUT) HttpRequest request = HttpRequest.builder().method(HttpMethod.PUT)
.endpoint("http://localhost/" + path.toString()) .endpoint("http://localhost/" + path.toString()).payload(BODY).build();
.payload(BODY).build();
signing_obj.filter(request); signing_obj.filter(request);
} }

View File

@ -67,8 +67,7 @@ public class ParseClientFromJsonTest {
protected void setUpInjector() throws IOException, CertificateException, InvalidKeySpecException { protected void setUpInjector() throws IOException, CertificateException, InvalidKeySpecException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -88,10 +87,12 @@ public class ParseClientFromJsonTest {
byte[] encrypted = ByteStreams.toByteArray(new RSAEncryptingPayload(Payloads.newPayload("fooya"), user byte[] encrypted = ByteStreams.toByteArray(new RSAEncryptingPayload(Payloads.newPayload("fooya"), user
.getCertificate().getPublicKey())); .getCertificate().getPublicKey()));
assertEquals(ByteStreams.toByteArray(new RSADecryptingPayload(Payloads.newPayload(encrypted), user assertEquals(
.getPrivateKey())), "fooya".getBytes()); ByteStreams.toByteArray(new RSADecryptingPayload(Payloads.newPayload(encrypted), user.getPrivateKey())),
"fooya".getBytes());
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(ParseClientFromJsonTest.class assertEquals(
.getResourceAsStream("/client.json")).build()), user); handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.payload(ParseClientFromJsonTest.class.getResourceAsStream("/client.json")).build()), user);
} }
} }

View File

@ -40,26 +40,26 @@ public class ParseCookbookDefinitionCheckingChefVersionTest {
public void testParserFor09() { public void testParserFor09() {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8"); bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8");
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
ParseCookbookDefinitionCheckingChefVersion parser = injector.getInstance(ParseCookbookDefinitionCheckingChefVersion.class); ParseCookbookDefinitionCheckingChefVersion parser = injector
.getInstance(ParseCookbookDefinitionCheckingChefVersion.class);
assertTrue(parser.parser instanceof ParseKeySetFromJson); assertTrue(parser.parser instanceof ParseKeySetFromJson);
} }
public void testParserFor010() { public void testParserFor010() {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8"); bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8");
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
ParseCookbookDefinitionCheckingChefVersion parser = injector.getInstance(ParseCookbookDefinitionCheckingChefVersion.class); ParseCookbookDefinitionCheckingChefVersion parser = injector
.getInstance(ParseCookbookDefinitionCheckingChefVersion.class);
assertTrue(parser.parser instanceof ParseCookbookDefinitionFromJson); assertTrue(parser.parser instanceof ParseCookbookDefinitionFromJson);
} }

View File

@ -49,8 +49,7 @@ public class ParseCookbookDefinitionFromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -59,31 +58,19 @@ public class ParseCookbookDefinitionFromJsonTest {
} }
public void testParse010Response() { public void testParse010Response() {
assertEquals( assertEquals(handler.apply(HttpResponse
handler .builder()
.apply(HttpResponse.builder()
.statusCode(200) .statusCode(200)
.message("ok") .message("ok")
.payload("{" + .payload(
"\"apache2\" => {" + "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\","
"\"url\" => \"http://localhost:4000/cookbooks/apache2\"," + + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\","
"\"versions\" => [" + + "\"version\" => \"5.1.0\"},"
"{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\"," + + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\","
"\"version\" => \"5.1.0\"}," + + "\"version\" => \"4.2.0\"}" + "]" + "}," + "\"nginx\" => {"
"{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\"," + + "\"url\" => \"http://localhost:4000/cookbooks/nginx\"," + "\"versions\" => ["
"\"version\" => \"4.2.0\"}" + + "{\"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\"}"
"}," + + "]" + "}" + "}").build()), ImmutableSet.of("apache2", "nginx"));
"\"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\"}" +
"]" +
"}" +
"}").build()),
ImmutableSet.of("apache2", "nginx"));
} }
} }

View File

@ -62,8 +62,7 @@ public class ParseCookbookVersionFromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
injector = Guice.createInjector(new AbstractModule() { injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -75,67 +74,53 @@ public class ParseCookbookVersionFromJsonTest {
@Test(enabled = false) @Test(enabled = false)
public void testBrew() throws IOException { public void testBrew() throws IOException {
CookbookVersion cookbook = handler.apply(HttpResponse.builder() CookbookVersion cookbook = handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.statusCode(200)
.message("ok")
.payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/brew-cookbook.json")).build()); .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/brew-cookbook.json")).build());
assertEquals(cookbook, handler.apply(HttpResponse.builder() assertEquals(cookbook,
.statusCode(200) handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json.toJson(cookbook)).build()));
.message("ok")
.payload(json
.toJson(cookbook)).build()));
} }
@Test(enabled = false) @Test(enabled = false)
public void testTomcat() { public void testTomcat() {
CookbookVersion cookbook = handler.apply(HttpResponse.builder() CookbookVersion cookbook = handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.statusCode(200)
.message("ok")
.payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/tomcat-cookbook.json")).build()); .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/tomcat-cookbook.json")).build());
assertEquals(cookbook, handler.apply(HttpResponse.builder() assertEquals(cookbook,
.statusCode(200) handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json.toJson(cookbook)).build()));
.message("ok")
.payload(json
.toJson(cookbook)).build()));
} }
@Test(enabled = false) @Test(enabled = false)
public void testMysql() throws IOException { public void testMysql() throws IOException {
CookbookVersion cookbook = handler.apply(HttpResponse.builder() CookbookVersion cookbook = handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.statusCode(200)
.message("ok")
.payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/mysql-cookbook.json")).build()); .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/mysql-cookbook.json")).build());
assertEquals(cookbook, handler.apply(HttpResponse.builder() assertEquals(cookbook,
.statusCode(200) handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json.toJson(cookbook)).build()));
.message("ok")
.payload(json
.toJson(cookbook)).build()));
} }
@Test(enabled = false) @Test(enabled = false)
public void testApache() { public void testApache() {
assertEquals( assertEquals(
handler.apply(HttpResponse.builder() handler.apply(HttpResponse
.builder()
.statusCode(200) .statusCode(200)
.message("ok") .message("ok")
.payload(ParseCookbookVersionFromJsonTest.class .payload(
.getResourceAsStream("/apache-chef-demo-cookbook.json")).build()), ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/apache-chef-demo-cookbook.json"))
.build()),
new CookbookVersion( new CookbookVersion(
"apache-chef-demo-0.0.0", "apache-chef-demo-0.0.0",
ImmutableSet.<Resource> of(), ImmutableSet.<Resource> of(),
ImmutableSet.<Attribute> of(), ImmutableSet.<Attribute> of(),
ImmutableSet.<Resource> of(), ImmutableSet.<Resource> of(),
new Metadata("Apache v2.0", "Your Name", ImmutableMap.<String, String> of(), ImmutableMap new Metadata("Apache v2.0", "Your Name", ImmutableMap.<String, String> of(), ImmutableMap
.<String, String> of(), "youremail@example.com", ImmutableMap .<String, String> of(), "youremail@example.com", ImmutableMap.<String, String> of(),
.<String, String> of(), "A fabulous new cookbook", ImmutableMap "A fabulous new cookbook", ImmutableMap.<String, String> of(), ImmutableMap
.<String, String> of(), ImmutableMap.<String, String> of(), "0.0.0", .<String, String> of(), "0.0.0", ImmutableMap.<String, String> of(), ImmutableMap
ImmutableMap.<String, String> of(), ImmutableMap.<String, String> of(), .<String, String> of(), "apache-chef-demo", ImmutableMap.<String, String> of(), "",
"apache-chef-demo", ImmutableMap.<String, String> of(), "", ImmutableMap ImmutableMap.<String, Attribute> of(), ImmutableMap.<String, String> of()),
.<String, Attribute> of(), ImmutableMap.<String, String> of()),
ImmutableSet.<Resource> of(), ImmutableSet.<Resource> of(),
"apache-chef-demo", "apache-chef-demo",
ImmutableSet.<Resource> of(), ImmutableSet.<Resource> of(),
@ -143,20 +128,15 @@ public class ParseCookbookVersionFromJsonTest {
ImmutableSet.<Resource> of(), ImmutableSet.<Resource> of(),
"0.0.0", "0.0.0",
ImmutableSet.<Resource> of(), ImmutableSet.<Resource> of(),
ImmutableSet ImmutableSet.<Resource> of(
.<Resource> of(
new Resource( new Resource(
"README", "README",
URI URI.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-11637f98942eafbf49c71b7f2f048b78?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=zgpNl6wSxjTNovqZu2nJq0JztU8%3D"),
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-11637f98942eafbf49c71b7f2f048b78?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=zgpNl6wSxjTNovqZu2nJq0JztU8%3D"), base16().lowerCase().decode("11637f98942eafbf49c71b7f2f048b78"), "README", "default"),
base16().lowerCase().decode("11637f98942eafbf49c71b7f2f048b78"), "README",
"default"),
new Resource( new Resource(
"Rakefile", "Rakefile",
URI URI.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-ebcf925a1651b4e04b9cd8aac2bc54eb?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=EFzzDSKKytTl7b%2FxrCeNLh05zj4%3D"),
.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-ebcf925a1651b4e04b9cd8aac2bc54eb?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=EFzzDSKKytTl7b%2FxrCeNLh05zj4%3D"), base16().lowerCase().decode("ebcf925a1651b4e04b9cd8aac2bc54eb"), "Rakefile", "default"))));
base16().lowerCase().decode("ebcf925a1651b4e04b9cd8aac2bc54eb"), "Rakefile",
"default"))));
} }
} }

View File

@ -40,26 +40,26 @@ public class ParseCookbookVersionsCheckingChefVersionTest {
public void testParserFor09() { public void testParserFor09() {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8"); bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8");
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
ParseCookbookVersionsCheckingChefVersion parser = injector.getInstance(ParseCookbookVersionsCheckingChefVersion.class); ParseCookbookVersionsCheckingChefVersion parser = injector
.getInstance(ParseCookbookVersionsCheckingChefVersion.class);
assertTrue(parser.parser instanceof ParseCookbookVersionsV09FromJson); assertTrue(parser.parser instanceof ParseCookbookVersionsV09FromJson);
} }
public void testParserFor010() { public void testParserFor010() {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8"); bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8");
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
ParseCookbookVersionsCheckingChefVersion parser = injector.getInstance(ParseCookbookVersionsCheckingChefVersion.class); ParseCookbookVersionsCheckingChefVersion parser = injector
.getInstance(ParseCookbookVersionsCheckingChefVersion.class);
assertTrue(parser.parser instanceof ParseCookbookVersionsV10FromJson); assertTrue(parser.parser instanceof ParseCookbookVersionsV10FromJson);
} }

View File

@ -49,8 +49,7 @@ public class ParseCookbookVersionsV09FromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -60,11 +59,7 @@ public class ParseCookbookVersionsV09FromJsonTest {
public void testRegex() { public void testRegex() {
assertEquals( assertEquals(
handler handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.apply(HttpResponse.builder() .payload("{\"apache2\": [\"0.1.8\", \"0.2\"]}").build()), ImmutableSet.of("0.1.8", "0.2"));
.statusCode(200)
.message("ok")
.payload("{\"apache2\": [\"0.1.8\", \"0.2\"]}").build()),
ImmutableSet.of("0.1.8", "0.2"));
} }
} }

View File

@ -49,8 +49,7 @@ public class ParseCookbookVersionsV10FromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -59,22 +58,15 @@ public class ParseCookbookVersionsV10FromJsonTest {
} }
public void testRegex() { public void testRegex() {
assertEquals( assertEquals(handler.apply(HttpResponse
handler .builder()
.apply(HttpResponse.builder()
.statusCode(200) .statusCode(200)
.message("ok") .message("ok")
.payload("{" + .payload(
"\"apache2\" => {" + "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\","
"\"url\" => \"http://localhost:4000/cookbooks/apache2\"," + + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\","
"\"versions\" => [" + + "\"version\" => \"5.1.0\"},"
"{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\"," + + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\","
"\"version\" => \"5.1.0\"}," + + "\"version\" => \"4.2.0\"}" + "]" + "}" + "}").build()), ImmutableSet.of("5.1.0", "4.2.0"));
"{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\"," +
"\"version\" => \"4.2.0\"}" +
"]" +
"}" +
"}").build()),
ImmutableSet.of("5.1.0", "4.2.0"));
} }
} }

View File

@ -51,8 +51,7 @@ public class ParseDataBagItemFromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -65,10 +64,7 @@ public class ParseDataBagItemFromJsonTest {
public void test1() { public void test1() {
String json = "{\"my_key\":\"my_data\",\"id\":\"item1\"}"; String json = "{\"my_key\":\"my_data\",\"id\":\"item1\"}";
DatabagItem item = new DatabagItem("item1", json); DatabagItem item = new DatabagItem("item1", json);
assertEquals(handler.apply(HttpResponse.builder() assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), item);
.statusCode(200)
.message("ok")
.payload(json).build()), item);
assertEquals(mapper.toJson(item), json); assertEquals(mapper.toJson(item), json);
} }
} }

View File

@ -39,12 +39,8 @@ public class ParseErrorFromJsonOrReturnBodyTest {
InputStream is = Strings2 InputStream is = Strings2
.toInputStream("{\"error\":[\"invalid tarball: tarball root must contain java-bytearray\"]}"); .toInputStream("{\"error\":[\"invalid tarball: tarball root must contain java-bytearray\"]}");
ParseErrorFromJsonOrReturnBody parser = new ParseErrorFromJsonOrReturnBody( ParseErrorFromJsonOrReturnBody parser = new ParseErrorFromJsonOrReturnBody(new ReturnStringIf2xx());
new ReturnStringIf2xx()); String response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());
String response = parser.apply(HttpResponse.builder()
.statusCode(200)
.message("ok")
.payload(is).build());
assertEquals(response, "invalid tarball: tarball root must contain java-bytearray"); assertEquals(response, "invalid tarball: tarball root must contain java-bytearray");
} }

View File

@ -49,8 +49,7 @@ public class ParseKeySetFromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -60,11 +59,12 @@ public class ParseKeySetFromJsonTest {
public void testRegex() { public void testRegex() {
assertEquals( assertEquals(
handler handler.apply(HttpResponse
.apply(HttpResponse.builder() .builder()
.statusCode(200) .statusCode(200)
.message("ok") .message("ok")
.payload("{\n\"opscode-validator\": \"https://api.opscode.com/...\", \"pimp-validator\": \"https://api.opscode.com/...\"}").build()), .payload(
ImmutableSet.of("opscode-validator", "pimp-validator")); "{\n\"opscode-validator\": \"https://api.opscode.com/...\", \"pimp-validator\": \"https://api.opscode.com/...\"}")
.build()), ImmutableSet.of("opscode-validator", "pimp-validator"));
} }
} }

View File

@ -55,8 +55,7 @@ public class ParseNodeFromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -71,10 +70,8 @@ public class ParseNodeFromJsonTest {
"{\"ssl_port\":8433}")), ImmutableMap.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), "{\"ssl_port\":8433}")), ImmutableMap.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(),
ImmutableMap.<String, JsonBall> of(), Collections.singleton("recipe[java]"), "prod"); ImmutableMap.<String, JsonBall> of(), Collections.singleton("recipe[java]"), "prod");
assertEquals(handler.apply(HttpResponse.builder() assertEquals(
.statusCode(200) handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.message("ok") .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/node.json")).build()), node);
.payload(ParseCookbookVersionFromJsonTest.class
.getResourceAsStream("/node.json")).build()), node);
} }
} }

View File

@ -55,8 +55,7 @@ public class ParseSandboxFromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -67,12 +66,11 @@ public class ParseSandboxFromJsonTest {
} }
public void test() { public void test() {
assertEquals(handler.apply(HttpResponse.builder() assertEquals(
.statusCode(200) handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.message("ok") .payload(ParseSandboxFromJsonTest.class.getResourceAsStream("/sandbox.json")).build()),
.payload(ParseSandboxFromJsonTest.class new Sandbox("1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
.getResourceAsStream("/sandbox.json")).build()), new Sandbox("1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, .iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"), ImmutableSet.<String> of(),
dateService.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"), ImmutableSet.<String> of(),
"f9d6d9b72bae465890aae87969f98a9c", "f9d6d9b72bae465890aae87969f98a9c")); "f9d6d9b72bae465890aae87969f98a9c", "f9d6d9b72bae465890aae87969f98a9c"));
} }
} }

View File

@ -47,8 +47,7 @@ public class ParseSearchDataBagItemFromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -60,9 +59,7 @@ public class ParseSearchDataBagItemFromJsonTest {
String itemJson = "{\"my_key\":\"my_data\"}"; String itemJson = "{\"my_key\":\"my_data\"}";
String searchJson = "{\"rows\":[{\"raw_data\": {\"id\":\"item1\",\"my_key\":\"my_data\"}}]}"; String searchJson = "{\"rows\":[{\"raw_data\": {\"id\":\"item1\",\"my_key\":\"my_data\"}}]}";
DatabagItem item = new DatabagItem("item1", itemJson); DatabagItem item = new DatabagItem("item1", itemJson);
SearchResult<DatabagItem> result = handler.apply(HttpResponse.builder() SearchResult<DatabagItem> result = handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.statusCode(200)
.message("ok")
.payload(searchJson).build()); .payload(searchJson).build());
assertEquals(result.size(), 1); assertEquals(result.size(), 1);
assertEquals(result.iterator().next(), item); assertEquals(result.iterator().next(), item);

View File

@ -59,8 +59,7 @@ public class ParseUploadSandboxFromJsonTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
injector = Guice.createInjector(new AbstractModule() { injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -71,21 +70,16 @@ public class ParseUploadSandboxFromJsonTest {
public void test() { public void test() {
assertEquals( assertEquals(
handler.apply(HttpResponse.builder() handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.statusCode(200) .payload(ParseUploadSandboxFromJsonTest.class.getResourceAsStream("/upload-site.json")).build()),
.message("ok")
.payload(ParseUploadSandboxFromJsonTest.class
.getResourceAsStream("/upload-site.json")).build()),
new UploadSandbox( new UploadSandbox(
URI URI.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"),
.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"), ImmutableMap.<List<Byte>, ChecksumStatus> of(
ImmutableMap
.<List<Byte>, ChecksumStatus> of(
asList(base16().lowerCase().decode("0c5ecd7788cf4f6c7de2a57193897a6c")), asList(base16().lowerCase().decode("0c5ecd7788cf4f6c7de2a57193897a6c")),
new ChecksumStatus( new ChecksumStatus(
URI.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D"), URI.create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D"),
true), asList(base16().lowerCase().decode("0189e76ccc476701d6b374e5a1a27347")), new ChecksumStatus(), true), asList(base16().lowerCase().decode("0189e76ccc476701d6b374e5a1a27347")),
asList(base16().lowerCase().decode("1dda05ed139664f1f89b9dec482b77c0")), new ChecksumStatus(), asList(base16().lowerCase().decode("1dda05ed139664f1f89b9dec482b77c0")),
new ChecksumStatus()), "d454f71e2a5f400c808d0c5d04c2c88c")); new ChecksumStatus()), "d454f71e2a5f400c808d0c5d04c2c88c"));
} }
} }

View File

@ -49,8 +49,7 @@ import com.google.inject.Injector;
public class RunListForGroupTest { public class RunListForGroupTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());

View File

@ -91,11 +91,15 @@ public class ChefApiErrorRetryHandlerTest {
BackoffLimitedRetryHandler retry = createMock(BackoffLimitedRetryHandler.class); BackoffLimitedRetryHandler retry = createMock(BackoffLimitedRetryHandler.class);
HttpRequest request = HttpRequest.builder().method("PUT") HttpRequest request = HttpRequest.builder().method("PUT")
.endpoint("https://api.opscode.com/organizations/jclouds/sandboxes/bfd68d4052f44053b2e593a33b5e1cd5").build(); .endpoint("https://api.opscode.com/organizations/jclouds/sandboxes/bfd68d4052f44053b2e593a33b5e1cd5")
HttpResponse response = HttpResponse.builder() .build();
HttpResponse response = HttpResponse
.builder()
.statusCode(400) .statusCode(400)
.message("400 Bad Request") .message("400 Bad Request")
.payload("{\"error\":[\"Cannot update sandbox bfd68d4052f44053b2e593a33b5e1cd5: checksum 9b7c23369f4b576451216c39f214af6c was not uploaded\"]}").build(); .payload(
"{\"error\":[\"Cannot update sandbox bfd68d4052f44053b2e593a33b5e1cd5: checksum 9b7c23369f4b576451216c39f214af6c was not uploaded\"]}")
.build();
expect(command.getFailureCount()).andReturn(0); expect(command.getFailureCount()).andReturn(0);
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce(); expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();

View File

@ -354,8 +354,7 @@ public abstract class BaseChefApiLiveTest<C extends Context> extends BaseChefCon
@Test(dependsOnMethods = { "testListSearchIndexes", "testCreateNode" }) @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateNode" })
public void testSearchNodesWithOptions() throws Exception { public void testSearchNodesWithOptions() throws Exception {
Predicate<SearchOptions> waitForIndex = retry( Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() {
new Predicate<SearchOptions>() {
@Override @Override
public boolean apply(SearchOptions input) { public boolean apply(SearchOptions input) {
SearchResult<? extends Node> results = chefApi.searchNodes(input); SearchResult<? extends Node> results = chefApi.searchNodes(input);
@ -383,8 +382,7 @@ public abstract class BaseChefApiLiveTest<C extends Context> extends BaseChefCon
@Test(dependsOnMethods = { "testListSearchIndexes", "testCreateClient" }) @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateClient" })
public void testSearchClientsWithOptions() throws Exception { public void testSearchClientsWithOptions() throws Exception {
Predicate<SearchOptions> waitForIndex = retry( Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() {
new Predicate<SearchOptions>() {
@Override @Override
public boolean apply(SearchOptions input) { public boolean apply(SearchOptions input) {
SearchResult<? extends Client> results = chefApi.searchClients(input); SearchResult<? extends Client> results = chefApi.searchClients(input);
@ -412,8 +410,7 @@ public abstract class BaseChefApiLiveTest<C extends Context> extends BaseChefCon
@Test(dependsOnMethods = { "testListSearchIndexes", "testCreateRole" }) @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateRole" })
public void testSearchRolesWithOptions() throws Exception { public void testSearchRolesWithOptions() throws Exception {
Predicate<SearchOptions> waitForIndex = retry( Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() {
new Predicate<SearchOptions>() {
@Override @Override
public boolean apply(SearchOptions input) { public boolean apply(SearchOptions input) {
SearchResult<? extends Role> results = chefApi.searchRoles(input); SearchResult<? extends Role> results = chefApi.searchRoles(input);
@ -441,8 +438,7 @@ public abstract class BaseChefApiLiveTest<C extends Context> extends BaseChefCon
@Test(dependsOnMethods = { "testListSearchIndexes", "testDatabagItemExists" }) @Test(dependsOnMethods = { "testListSearchIndexes", "testDatabagItemExists" })
public void testSearchDatabagWithOptions() throws Exception { public void testSearchDatabagWithOptions() throws Exception {
Predicate<SearchOptions> waitForIndex = retry( Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() {
new Predicate<SearchOptions>() {
@Override @Override
public boolean apply(SearchOptions input) { public boolean apply(SearchOptions input) {
SearchResult<? extends DatabagItem> results = chefApi.searchDatabag(PREFIX, input); SearchResult<? extends DatabagItem> results = chefApi.searchDatabag(PREFIX, input);

View File

@ -60,19 +60,20 @@ public class BaseStubbedOhaiLiveTest extends BaseChefContextLiveTest<ChefContext
@Override @Override
protected ApiMetadata createApiMetadata() { protected ApiMetadata createApiMetadata() {
return new ChefApiMetadata().toBuilder().defaultModules( return new ChefApiMetadata()
ImmutableSet.<Class<? extends Module>> of(ChefRestClientModule.class, ChefParserModule.class, TestOhaiModule.class)).build(); .toBuilder()
.defaultModules(
ImmutableSet.<Class<? extends Module>> of(ChefRestClientModule.class, ChefParserModule.class,
TestOhaiModule.class)).build();
} }
@Override @Override
protected ChefApi getChefApi(ChefContext context) protected ChefApi getChefApi(ChefContext context) {
{
return context.getApi(); return context.getApi();
} }
@Override @Override
protected TypeToken<ChefContext> contextType() protected TypeToken<ChefContext> contextType() {
{
return typeToken(ChefContext.class); return typeToken(ChefContext.class);
} }
} }

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.chef.strategy.internal; package org.jclouds.chef.strategy.internal;
import static org.jclouds.reflect.Reflection2.typeToken; import static org.jclouds.reflect.Reflection2.typeToken;
import org.jclouds.chef.ChefApi; import org.jclouds.chef.ChefApi;
@ -67,14 +66,12 @@ public class CleanupStaleNodesAndClientsImplLiveTest extends BaseChefContextLive
} }
@Override @Override
protected ChefApi getChefApi(ChefContext context) protected ChefApi getChefApi(ChefContext context) {
{
return context.getApi(); return context.getApi();
} }
@Override @Override
protected TypeToken<ChefContext> contextType() protected TypeToken<ChefContext> contextType() {
{
return typeToken(ChefContext.class); return typeToken(ChefContext.class);
} }

View File

@ -35,7 +35,8 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
/** /**
* Tests behavior of {@code CreateNodeAndPopulateAutomaticAttributesImpl} strategies * Tests behavior of {@code CreateNodeAndPopulateAutomaticAttributesImpl}
* strategies
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -55,8 +56,8 @@ public class CreateNodeAndPopulateAutomaticAttributesImplLiveTest extends BaseCh
public void testExecute() { public void testExecute() {
Set<String> runList = ImmutableSet.of("role[" + prefix + "]"); Set<String> runList = ImmutableSet.of("role[" + prefix + "]");
try { try {
context.utils().injector().getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class).execute(prefix, context.utils().injector().getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class)
runList); .execute(prefix, runList);
Node node = context.getApi().getNode(prefix); Node node = context.getApi().getNode(prefix);
assertEquals(node.getName(), prefix); assertEquals(node.getName(), prefix);
assertEquals(node.getRunList(), runList); assertEquals(node.getRunList(), runList);
@ -67,14 +68,12 @@ public class CreateNodeAndPopulateAutomaticAttributesImplLiveTest extends BaseCh
} }
@Override @Override
protected ChefApi getChefApi(ChefContext context) protected ChefApi getChefApi(ChefContext context) {
{
return context.getApi(); return context.getApi();
} }
@Override @Override
protected TypeToken<ChefContext> contextType() protected TypeToken<ChefContext> contextType() {
{
return typeToken(ChefContext.class); return typeToken(ChefContext.class);
} }

View File

@ -52,16 +52,17 @@ public class CreateNodeAndPopulateAutomaticAttributesImplTest {
Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic); Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic);
Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(), ImmutableMap Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(),
.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic, ImmutableSet.<String> of(), ImmutableMap.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic,
"_default"); ImmutableSet.<String> of(), "_default");
node.getAutomatic().putAll(automaticSupplier.get()); node.getAutomatic().putAll(automaticSupplier.get());
chef.createNode(nodeWithAutomatic); chef.createNode(nodeWithAutomatic);
replay(chef); replay(chef);
CreateNodeAndPopulateAutomaticAttributesImpl updater = new CreateNodeAndPopulateAutomaticAttributesImpl(chef, automaticSupplier); CreateNodeAndPopulateAutomaticAttributesImpl updater = new CreateNodeAndPopulateAutomaticAttributesImpl(chef,
automaticSupplier);
updater.execute("name", ImmutableSet.<String> of()); updater.execute("name", ImmutableSet.<String> of());
verify(chef); verify(chef);

View File

@ -18,7 +18,6 @@
*/ */
package org.jclouds.chef.strategy.internal; package org.jclouds.chef.strategy.internal;
import static org.jclouds.reflect.Reflection2.typeToken; import static org.jclouds.reflect.Reflection2.typeToken;
import org.jclouds.chef.ChefApi; import org.jclouds.chef.ChefApi;
@ -72,14 +71,12 @@ public class DeleteAllApisAndNodesInListImplLiveTest extends BaseChefContextLive
} }
@Override @Override
protected ChefApi getChefApi(ChefContext context) protected ChefApi getChefApi(ChefContext context) {
{
return context.getApi(); return context.getApi();
} }
@Override @Override
protected TypeToken<ChefContext> contextType() protected TypeToken<ChefContext> contextType() {
{
return typeToken(ChefContext.class); return typeToken(ChefContext.class);
} }
} }

View File

@ -87,14 +87,12 @@ public class GetNodesImplLiveTest extends BaseChefContextLiveTest<ChefContext> {
} }
@Override @Override
protected ChefApi getChefApi(ChefContext context) protected ChefApi getChefApi(ChefContext context) {
{
return context.getApi(); return context.getApi();
} }
@Override @Override
protected TypeToken<ChefContext> contextType() protected TypeToken<ChefContext> contextType() {
{
return typeToken(ChefContext.class); return typeToken(ChefContext.class);
} }

View File

@ -50,6 +50,7 @@ public class UpdateAutomaticAttributesOnNodeImplLiveTest extends BaseChefContext
super.setupContext(); super.setupContext();
this.currentUserProvider = context.utils().injector().getInstance(CurrentUserProvider.class); this.currentUserProvider = context.utils().injector().getInstance(CurrentUserProvider.class);
} }
@Test @Test
public void testExecute() { public void testExecute() {
Set<String> runList = ImmutableSet.of("role[" + prefix + "]"); Set<String> runList = ImmutableSet.of("role[" + prefix + "]");
@ -66,14 +67,12 @@ public class UpdateAutomaticAttributesOnNodeImplLiveTest extends BaseChefContext
} }
@Override @Override
protected ChefApi getChefApi(ChefContext context) protected ChefApi getChefApi(ChefContext context) {
{
return context.getApi(); return context.getApi();
} }
@Override @Override
protected TypeToken<ChefContext> contextType() protected TypeToken<ChefContext> contextType() {
{
return typeToken(ChefContext.class); return typeToken(ChefContext.class);
} }
} }

View File

@ -53,9 +53,9 @@ public class UpdateAutomaticAttributesOnNodeImplTest {
Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic); Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic);
Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(), ImmutableMap Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(),
.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic, ImmutableSet.<String> of(), ImmutableMap.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic,
"_default"); ImmutableSet.<String> of(), "_default");
expect(chef.getNode("name")).andReturn(node); expect(chef.getNode("name")).andReturn(node);
node.getAutomatic().putAll(automaticSupplier.get()); node.getAutomatic().putAll(automaticSupplier.get());

View File

@ -44,6 +44,7 @@ public class RunListBuilderTest {
options.addRecipe("test"); options.addRecipe("test");
assertEquals(options.build(), ImmutableList.of("recipe[test]")); assertEquals(options.build(), ImmutableList.of("recipe[test]"));
} }
@Test @Test
public void testRecipes() { public void testRecipes() {
RunListBuilder options = new RunListBuilder(); RunListBuilder options = new RunListBuilder();
@ -57,6 +58,7 @@ public class RunListBuilderTest {
options.addRole("test"); options.addRole("test");
assertEquals(options.build(), ImmutableList.of("role[test]")); assertEquals(options.build(), ImmutableList.of("role[test]"));
} }
@Test @Test
public void testRoles() { public void testRoles() {
RunListBuilder options = new RunListBuilder(); RunListBuilder options = new RunListBuilder();

View File

@ -62,8 +62,7 @@ public class JMXTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule(), new JMXOhaiModule() { }, new ChefParserModule(), new GsonModule(), new JMXOhaiModule() {

View File

@ -64,8 +64,7 @@ public class OhaiModuleTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule(), new OhaiModule() { }, new ChefParserModule(), new GsonModule(), new OhaiModule() {
@ -99,8 +98,7 @@ public class OhaiModuleTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule(), new OhaiModule() { }, new ChefParserModule(), new GsonModule(), new OhaiModule() {

View File

@ -32,7 +32,6 @@ import org.testng.annotations.Test;
public class ByteArrayToMacAddressTest { public class ByteArrayToMacAddressTest {
public void test() { public void test() {
assertEquals(new ByteArrayToMacAddress().apply(base16().lowerCase().decode("0026bb09e6c4")), assertEquals(new ByteArrayToMacAddress().apply(base16().lowerCase().decode("0026bb09e6c4")), "00:26:bb:09:e6:c4");
"00:26:bb:09:e6:c4");
} }
} }

View File

@ -53,8 +53,7 @@ public class NestSlashKeysTest {
protected void setUpInjector() throws IOException { protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
protected void configure() protected void configure() {
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION); bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
} }
}, new ChefParserModule(), new GsonModule()); }, new ChefParserModule(), new GsonModule());
@ -64,47 +63,59 @@ public class NestSlashKeysTest {
@Test @Test
public void testBase() { public void testBase() {
assertEquals(json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", Suppliers assertEquals(
.ofInstance(new JsonBall("java"))))), "{\"java\":\"java\"}"); json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java",
Suppliers.ofInstance(new JsonBall("java"))))), "{\"java\":\"java\"}");
} }
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testIllegal() { public void testIllegal() {
json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", Suppliers json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java",
.ofInstance(new JsonBall("java")), "java/system", Suppliers.ofInstance(new JsonBall("system"))))); Suppliers.ofInstance(new JsonBall("java")), "java/system", Suppliers.ofInstance(new JsonBall("system")))));
} }
@Test @Test
public void testOne() { public void testOne() {
assertEquals(json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", Suppliers assertEquals(
.ofInstance(new JsonBall("{\"time\":\"time\"}")), "java/system", Suppliers json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java",
.ofInstance(new JsonBall("system"))))), "{\"java\":{\"time\":\"time\",\"system\":\"system\"}}"); Suppliers.ofInstance(new JsonBall("{\"time\":\"time\"}")), "java/system",
Suppliers.ofInstance(new JsonBall("system"))))),
"{\"java\":{\"time\":\"time\",\"system\":\"system\"}}");
} }
@Test @Test
public void testOneDuplicate() { public void testOneDuplicate() {
assertEquals(json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", Suppliers assertEquals(
.ofInstance(new JsonBall("{\"time\":\"time\"}")), "java", Suppliers.ofInstance(new JsonBall( json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java",
"{\"system\":\"system\"}"))))), "{\"java\":{\"time\":\"time\",\"system\":\"system\"}}"); Suppliers.ofInstance(new JsonBall("{\"time\":\"time\"}")), "java",
Suppliers.ofInstance(new JsonBall("{\"system\":\"system\"}"))))),
"{\"java\":{\"time\":\"time\",\"system\":\"system\"}}");
} }
@Test @Test
public void testMerge() { public void testMerge() {
assertEquals(json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", Suppliers assertEquals(
.ofInstance(new JsonBall("{\"time\":{\"1\":\"hello\"}}")), "java/time", Suppliers.ofInstance(new JsonBall( json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java",
"{\"2\":\"goodbye\"}"))))), "{\"java\":{\"time\":{\"1\":\"hello\",\"2\":\"goodbye\"}}}"); Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":\"hello\"}}")), "java/time",
Suppliers.ofInstance(new JsonBall("{\"2\":\"goodbye\"}"))))),
"{\"java\":{\"time\":{\"1\":\"hello\",\"2\":\"goodbye\"}}}");
} }
@Test @Test
public void testMergeNestedTwice() { public void testMergeNestedTwice() {
assertEquals(json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", Suppliers assertEquals(
.ofInstance(new JsonBall("{\"time\":{\"1\":\"hello\"}}")), "java", Suppliers.ofInstance(new JsonBall( json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java",
"{\"time\":{\"2\":\"goodbye\"}}"))))), "{\"java\":{\"time\":{\"1\":\"hello\",\"2\":\"goodbye\"}}}"); Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":\"hello\"}}")), "java",
Suppliers.ofInstance(new JsonBall("{\"time\":{\"2\":\"goodbye\"}}"))))),
"{\"java\":{\"time\":{\"1\":\"hello\",\"2\":\"goodbye\"}}}");
} }
@Test @Test
public void testReplaceList() { public void testReplaceList() {
assertEquals(json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java", Suppliers assertEquals(
.ofInstance(new JsonBall("{\"time\":{\"1\":[\"hello\"]}}")), "java/time", Suppliers.ofInstance(new JsonBall( json.toJson(converter.apply(ImmutableMultimap.<String, Supplier<JsonBall>> of("java",
"{\"1\":[\"goodbye\"]}"))))), "{\"java\":{\"time\":{\"1\":[\"goodbye\"]}}}"); Suppliers.ofInstance(new JsonBall("{\"time\":{\"1\":[\"hello\"]}}")), "java/time",
Suppliers.ofInstance(new JsonBall("{\"1\":[\"goodbye\"]}"))))),
"{\"java\":{\"time\":{\"1\":[\"goodbye\"]}}}");
} }
} }