From 96178f56476efa9887a4924f98b7eb1c5bc65ccb Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 2 Aug 2010 14:25:55 -0400 Subject: [PATCH] Issue 191: added preliminary support for search --- .../org/jclouds/chef/ChefAsyncClient.java | 60 +++++++++++-- .../java/org/jclouds/chef/ChefClient.java | 68 +++++++++++++++ .../org/jclouds/chef/domain/SearchResult.java | 51 +++++++++++ .../functions/ParseSearchClientsFromJson.java | 64 ++++++++++++++ .../functions/ParseSearchDatabagFromJson.java | 64 ++++++++++++++ .../functions/ParseSearchNodesFromJson.java | 64 ++++++++++++++ .../functions/ParseSearchResultFromJson.java | 78 +++++++++++++++++ .../functions/ParseSearchRolesFromJson.java | 64 ++++++++++++++ .../jclouds/chef/BaseChefClientLiveTest.java | 42 +++++++++ .../org/jclouds/chef/ChefAsyncClientTest.java | 85 +++++++++++++++++++ 10 files changed, 633 insertions(+), 7 deletions(-) create mode 100644 chef/core/src/main/java/org/jclouds/chef/domain/SearchResult.java create mode 100644 chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchClientsFromJson.java create mode 100644 chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchDatabagFromJson.java create mode 100644 chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchNodesFromJson.java create mode 100644 chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchResultFromJson.java create mode 100644 chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchRolesFromJson.java diff --git a/chef/core/src/main/java/org/jclouds/chef/ChefAsyncClient.java b/chef/core/src/main/java/org/jclouds/chef/ChefAsyncClient.java index cf66b7d997..8d3ba7bf64 100644 --- a/chef/core/src/main/java/org/jclouds/chef/ChefAsyncClient.java +++ b/chef/core/src/main/java/org/jclouds/chef/ChefAsyncClient.java @@ -50,9 +50,14 @@ import org.jclouds.chef.domain.DatabagItem; import org.jclouds.chef.domain.Node; import org.jclouds.chef.domain.Role; import org.jclouds.chef.domain.Sandbox; +import org.jclouds.chef.domain.SearchResult; import org.jclouds.chef.domain.UploadSandbox; import org.jclouds.chef.filters.SignedHeaderAuth; import org.jclouds.chef.functions.ParseKeySetFromJson; +import org.jclouds.chef.functions.ParseSearchClientsFromJson; +import org.jclouds.chef.functions.ParseSearchDatabagFromJson; +import org.jclouds.chef.functions.ParseSearchNodesFromJson; +import org.jclouds.chef.functions.ParseSearchRolesFromJson; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.Headers; @@ -290,7 +295,7 @@ public interface ChefAsyncClient { ListenableFuture> listRoles(); /** - * @see ChefDatabag#listDatabags + * @see ChefClient#listDatabags */ @GET @Path("data") @@ -306,7 +311,7 @@ public interface ChefAsyncClient { ListenableFuture createDatabag(@BinderParam(BindNameToJsonPayload.class) String databagName); /** - * @see ChefDatabag#databagExists + * @see ChefClient#databagExists */ @HEAD @Path("data/{name}") @@ -314,7 +319,7 @@ public interface ChefAsyncClient { ListenableFuture databagExists(@PathParam("name") String databagName); /** - * @see ChefDatabag#deleteDatabag + * @see ChefClient#deleteDatabag */ @DELETE @Path("data/{name}") @@ -322,7 +327,7 @@ public interface ChefAsyncClient { ListenableFuture deleteDatabag(@PathParam("name") String databagName); /** - * @see ChefDatabag#listDatabagItems + * @see ChefClient#listDatabagItems */ @GET @Path("data/{name}") @@ -348,7 +353,7 @@ public interface ChefAsyncClient { @PathParam("databagItemId") @ParamParser(DatabagItemId.class) @BinderParam(BindToJsonPayload.class) DatabagItem item); /** - * @see ChefDatabag#databagItemExists + * @see ChefClient#databagItemExists */ @HEAD @Path("data/{databagName}/{databagItemId}") @@ -357,7 +362,7 @@ public interface ChefAsyncClient { @PathParam("databagItemId") String databagItemId); /** - * @see ChefDatabag#getDatabagItem + * @see ChefClient#getDatabagItem */ @GET @Path("data/{databagName}/{databagItemId}") @@ -366,7 +371,7 @@ public interface ChefAsyncClient { @PathParam("databagItemId") String databagItemId); /** - * @see ChefDatabag#deleteDatabagItem + * @see ChefClient#deleteDatabagItem */ @DELETE @Path("data/{databagName}/{databagItemId}") @@ -374,4 +379,45 @@ public interface ChefAsyncClient { ListenableFuture deleteDatabagItem(@PathParam("databagName") String databagName, @PathParam("databagItemId") String databagItemId); + /** + * @see ChefClient#listSearchIndexes + */ + @GET + @Path("search") + @ResponseParser(ParseKeySetFromJson.class) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listSearchIndexes(); + + /** + * @see ChefClient#searchRoles + */ + @GET + @Path("search/role") + @ResponseParser(ParseSearchRolesFromJson.class) + ListenableFuture> searchRoles(); + + /** + * @see ChefClient#searchClients + */ + @GET + @Path("search/client") + @ResponseParser(ParseSearchClientsFromJson.class) + ListenableFuture> searchClients(); + + /** + * @see ChefClient#searchNodes + */ + @GET + @Path("search/node") + @ResponseParser(ParseSearchNodesFromJson.class) + ListenableFuture> searchNodes(); + + /** + * @see ChefClient#searchDatabag + */ + @GET + @Path("search/{databagName}") + @ResponseParser(ParseSearchDatabagFromJson.class) + ListenableFuture> searchDatabag( + @PathParam("databagName") String databagName); } diff --git a/chef/core/src/main/java/org/jclouds/chef/ChefClient.java b/chef/core/src/main/java/org/jclouds/chef/ChefClient.java index a7356cd409..3e48609d9f 100644 --- a/chef/core/src/main/java/org/jclouds/chef/ChefClient.java +++ b/chef/core/src/main/java/org/jclouds/chef/ChefClient.java @@ -51,6 +51,7 @@ import org.jclouds.chef.domain.DatabagItem; import org.jclouds.chef.domain.Node; import org.jclouds.chef.domain.Role; import org.jclouds.chef.domain.Sandbox; +import org.jclouds.chef.domain.SearchResult; import org.jclouds.chef.domain.UploadSandbox; import org.jclouds.concurrent.Timeout; import org.jclouds.http.HttpResponseException; @@ -484,4 +485,71 @@ public interface ChefClient { */ DatabagItem deleteDatabagItem(String databagName, String databagItemId); + /** + * Show indexes you can search on + *

+ * By default, the "role", "node" and "client" indexes will always be + * available. + *

+ * 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 + * immediately query it, you likely need to produce an artificial delay (or + * simply retry until the data is available.) + * + * @throws AuthorizationException + *

+ * "401 Unauthorized" if you are not a recognized user. + *

+ * "403 Forbidden" if you do not have view rights on the databag. + */ + Set listSearchIndexes(); + + /** + * search all roles. + *

+ * Note that without any request parameters this will return all of the data + * within the index. + * + * @return The response contains the total number of rows that matched your + * request, the position this result set returns (useful for paging) + * and the rows themselves. + */ + SearchResult searchRoles(); + + /** + * search all clients. + *

+ * Note that without any request parameters this will return all of the data + * within the index. + * + * @return The response contains the total number of rows that matched your + * request, the position this result set returns (useful for paging) + * and the rows themselves. + */ + SearchResult searchClients(); + + /** + * search all nodes. + *

+ * Note that without any request parameters this will return all of the data + * within the index. + * + * @return The response contains the total number of rows that matched your + * request, the position this result set returns (useful for paging) + * and the rows themselves. + */ + SearchResult searchNodes(); + + /** + * search all items in a databag. + *

+ * Note that without any request parameters this will return all of the data + * within the index. + * + * @return The response contains the total number of rows that matched your + * request, the position this result set returns (useful for paging) + * and the rows themselves. + */ + SearchResult searchDatabag(String databagName); + } diff --git a/chef/core/src/main/java/org/jclouds/chef/domain/SearchResult.java b/chef/core/src/main/java/org/jclouds/chef/domain/SearchResult.java new file mode 100644 index 0000000000..8ca79e2d2a --- /dev/null +++ b/chef/core/src/main/java/org/jclouds/chef/domain/SearchResult.java @@ -0,0 +1,51 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.chef.domain; + +import java.util.LinkedHashSet; + +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + * + */ +public class SearchResult extends LinkedHashSet { + private long start; + + SearchResult() { + } + + public SearchResult(long start, Iterable results) { + this.start = start; + Iterables.addAll(this, results); + } + + private static final long serialVersionUID = 4000610660948065287L; + + /** + * + * @return the result position this started from from + */ + long getStart() { + return start; + } + +} \ No newline at end of file diff --git a/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchClientsFromJson.java b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchClientsFromJson.java new file mode 100644 index 0000000000..9b7a0a7d2f --- /dev/null +++ b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchClientsFromJson.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.chef.functions; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.chef.domain.Client; +import org.jclouds.http.functions.ParseJson; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ParseSearchClientsFromJson extends ParseSearchResultFromJson { + + // TODO add generic json parser detector + + @Inject + ParseSearchClientsFromJson(ParseJson> json) { + super(json); + } + +} \ No newline at end of file diff --git a/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchDatabagFromJson.java b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchDatabagFromJson.java new file mode 100644 index 0000000000..f7505ae2ea --- /dev/null +++ b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchDatabagFromJson.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.chef.functions; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.chef.domain.DatabagItem; +import org.jclouds.http.functions.ParseJson; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ParseSearchDatabagFromJson extends ParseSearchResultFromJson { + + // TODO add generic json parser detector + + @Inject + ParseSearchDatabagFromJson(ParseJson> json) { + super(json); + } + +} \ No newline at end of file diff --git a/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchNodesFromJson.java b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchNodesFromJson.java new file mode 100644 index 0000000000..186b6e1f75 --- /dev/null +++ b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchNodesFromJson.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.chef.functions; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.chef.domain.Node; +import org.jclouds.http.functions.ParseJson; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ParseSearchNodesFromJson extends ParseSearchResultFromJson { + + // TODO add generic json parser detector + + @Inject + ParseSearchNodesFromJson(ParseJson> json) { + super(json); + } + +} \ No newline at end of file diff --git a/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchResultFromJson.java b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchResultFromJson.java new file mode 100644 index 0000000000..68c4d6888c --- /dev/null +++ b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchResultFromJson.java @@ -0,0 +1,78 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.chef.functions; + +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.chef.domain.SearchResult; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseJson; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class ParseSearchResultFromJson implements Function> { + + private final ParseJson> json; + + static class Response { + long start; + List rows; + } + + @Inject + ParseSearchResultFromJson(ParseJson> json) { + this.json = json; + } + + @Override + public SearchResult apply(HttpResponse arg0) { + Response returnVal = json.apply(arg0); + return new SearchResult(returnVal.start, returnVal.rows); + } +} \ No newline at end of file diff --git a/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchRolesFromJson.java b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchRolesFromJson.java new file mode 100644 index 0000000000..9becd6753c --- /dev/null +++ b/chef/core/src/main/java/org/jclouds/chef/functions/ParseSearchRolesFromJson.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.chef.functions; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.chef.domain.Role; +import org.jclouds.http.functions.ParseJson; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ParseSearchRolesFromJson extends ParseSearchResultFromJson { + + // TODO add generic json parser detector + + @Inject + ParseSearchRolesFromJson(ParseJson> json) { + super(json); + } + +} \ No newline at end of file diff --git a/chef/core/src/test/java/org/jclouds/chef/BaseChefClientLiveTest.java b/chef/core/src/test/java/org/jclouds/chef/BaseChefClientLiveTest.java index 5d7c923e01..857b48c006 100644 --- a/chef/core/src/test/java/org/jclouds/chef/BaseChefClientLiveTest.java +++ b/chef/core/src/test/java/org/jclouds/chef/BaseChefClientLiveTest.java @@ -59,11 +59,13 @@ import java.util.Properties; import java.util.Set; import org.jclouds.chef.domain.ChecksumStatus; +import org.jclouds.chef.domain.Client; import org.jclouds.chef.domain.CookbookVersion; import org.jclouds.chef.domain.DatabagItem; import org.jclouds.chef.domain.Node; import org.jclouds.chef.domain.Resource; import org.jclouds.chef.domain.Role; +import org.jclouds.chef.domain.SearchResult; import org.jclouds.chef.domain.UploadSandbox; import org.jclouds.crypto.CryptoStreams; import org.jclouds.crypto.Pems; @@ -72,6 +74,7 @@ import org.jclouds.io.Payloads; import org.jclouds.io.payloads.FilePayload; import org.jclouds.json.Json; import org.jclouds.rest.HttpClient; +import org.jclouds.rest.ResourceNotFoundException; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -337,6 +340,45 @@ public abstract class BaseChefClientLiveTest { } } + @Test + public void testListSearchIndexes() throws Exception { + Set indexes = getAdminConnection().listSearchIndexes(); + assertNotNull(indexes); + assert indexes.contains("node") : indexes; + assert indexes.contains("client") : indexes; + assert indexes.contains("role") : indexes; + } + + @Test + public void testSearchNodes() throws Exception { + SearchResult results = getAdminConnection().searchNodes(); + assertNotNull(results); + } + + @Test + public void testSearchClients() throws Exception { + SearchResult results = getAdminConnection().searchClients(); + assertNotNull(results); + } + + @Test + public void testSearchRoles() throws Exception { + SearchResult results = getAdminConnection().searchRoles(); + assertNotNull(results); + } + + @Test(dependsOnMethods = "testDatabagItemExists") + public void testSearchDatabag() throws Exception { + SearchResult results = getAdminConnection().searchDatabag(PREFIX); + assertNotNull(results); + } + + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testSearchDatabagNotFound() throws Exception { + SearchResult results = getAdminConnection().searchDatabag("whoopie"); + assertNotNull(results); + } + @AfterClass(groups = { "live" }) public void teardownClient() throws IOException { if (getValidatorConnection().clientExists(PREFIX)) diff --git a/chef/core/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java b/chef/core/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java index eb93e560be..216ade3368 100644 --- a/chef/core/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java +++ b/chef/core/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java @@ -38,6 +38,10 @@ import org.jclouds.chef.domain.Role; import org.jclouds.chef.filters.SignedHeaderAuth; import org.jclouds.chef.filters.SignedHeaderAuthTest; import org.jclouds.chef.functions.ParseKeySetFromJson; +import org.jclouds.chef.functions.ParseSearchClientsFromJson; +import org.jclouds.chef.functions.ParseSearchDatabagFromJson; +import org.jclouds.chef.functions.ParseSearchNodesFromJson; +import org.jclouds.chef.functions.ParseSearchRolesFromJson; import org.jclouds.crypto.CryptoStreams; import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpRequest; @@ -49,6 +53,7 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory.ContextSpec; +import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; @@ -629,6 +634,86 @@ public class ChefAsyncClientTest extends RestClientTest { } + public void testListSearchIndexes() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("listSearchIndexes"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testSearchRoles() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("searchRoles"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/role HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseSearchRolesFromJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testSearchClients() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("searchClients"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/client HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseSearchClientsFromJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testSearchNodes() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("searchNodes"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/node HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseSearchNodesFromJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testSearchDatabag() throws SecurityException, NoSuchMethodException, IOException { + Method method = ChefAsyncClient.class.getMethod("searchDatabag", String.class); + GeneratedHttpRequest httpRequest = processor.createRequest(method, "foo"); + + assertRequestLineEquals(httpRequest, "GET http://localhost:4000/search/foo HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.8\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, ParseSearchDatabagFromJson.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + @Override protected void checkFilters(HttpRequest request) { assertEquals(request.getFilters().size(), 1);