http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonTest.java deleted file mode 100644 index 736b283..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.http.HttpResponse; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code ParseCookbookDefinitionFromJson}. - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseCookbookDefinitionFromJsonTest { - - private ParseCookbookDefinitionFromJson handler; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(ParseCookbookDefinitionFromJson.class); - } - - public void testParse010Response() { - assertEquals(handler.apply(HttpResponse - .builder() - .statusCode(200) - .message("ok") - .payload( - "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\"," - + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\"," - + "\"version\" => \"5.1.0\"}," - + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\"," - + "\"version\" => \"4.2.0\"}" + "]" + "}," + "\"nginx\" => {" - + "\"url\" => \"http://localhost:4000/cookbooks/nginx\"," + "\"versions\" => [" - + "{\"url\" => \"http://localhost:4000/cookbooks/nginx/1.0.0\"," + "\"version\" => \"1.0.0\"}," - + "{\"url\" => \"http://localhost:4000/cookbooks/nginx/0.3.0\"," + "\"version\" => \"0.3.0\"}" - + "]" + "}" + "}").build()), ImmutableSet.of("apache2", "nginx")); - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonv10Test.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonv10Test.java b/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonv10Test.java deleted file mode 100644 index b5d8a8b..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonv10Test.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.CookbookDefinition; -import org.jclouds.http.HttpResponse; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseCookbookDefinitionFromJsonv10Test { - - private ParseCookbookDefinitionFromJsonv10 handler; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(ParseCookbookDefinitionFromJsonv10.class); - } - - public void testCookbokDefinitionParsing() throws URISyntaxException { - CookbookDefinition.Version v510 = CookbookDefinition.Version.builder() - .url(new URI("http://localhost:4000/cookbooks/apache2/5.1.0")).version("5.1.0").build(); - CookbookDefinition.Version v420 = CookbookDefinition.Version.builder() - .url(new URI("http://localhost:4000/cookbooks/apache2/4.2.0")).version("4.2.0").build(); - CookbookDefinition definition = CookbookDefinition.builder() - .name("apache2").url(new URI("http://localhost:4000/cookbooks/apache2")).version(v510).version(v420).build(); - - assertEquals(handler.apply(HttpResponse - .builder() - .statusCode(200) - .message("ok") - .payload( - "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\"," - + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\"," - + "\"version\" => \"5.1.0\"}," - + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\"," - + "\"version\" => \"4.2.0\"}" + "]" + "}" + "}").build()), definition); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionListFromJsonv10Test.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionListFromJsonv10Test.java b/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionListFromJsonv10Test.java deleted file mode 100644 index 04f8e35..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionListFromJsonv10Test.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.CookbookDefinition; -import org.jclouds.http.HttpResponse; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -@Test(groups = {"unit"}, singleThreaded = true) -public class ParseCookbookDefinitionListFromJsonv10Test { - - private ParseCookbookDefinitionListFromJsonv10 handler; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(ParseCookbookDefinitionListFromJsonv10.class); - } - - public void testCookbokDefinitionListParsing() throws URISyntaxException { - CookbookDefinition.Version v510 = CookbookDefinition.Version.builder() - .url(new URI("http://localhost:4000/cookbooks/apache2/5.1.0")).version("5.1.0").build(); - CookbookDefinition.Version v420 = CookbookDefinition.Version.builder() - .url(new URI("http://localhost:4000/cookbooks/apache2/4.2.0")).version("4.2.0").build(); - CookbookDefinition apache2 = CookbookDefinition.builder() - .name("apache2").url(new URI("http://localhost:4000/cookbooks/apache2")).version(v510).version(v420).build(); - - CookbookDefinition.Version v100 = CookbookDefinition.Version.builder() - .url(new URI("http://localhost:4000/cookbooks/nginx/1.0.0")).version("1.0.0").build(); - CookbookDefinition.Version v030 = CookbookDefinition.Version.builder() - .url(new URI("http://localhost:4000/cookbooks/nginx/0.3.0")).version("0.3.0").build(); - CookbookDefinition nginx = CookbookDefinition.builder() - .name("nginx").url(new URI("http://localhost:4000/cookbooks/nginx")).version(v100).version(v030).build(); - - assertEquals(handler.apply(HttpResponse - .builder() - .statusCode(200) - .message("ok") - .payload( - "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\"," - + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\"," - + "\"version\" => \"5.1.0\"}," - + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\"," - + "\"version\" => \"4.2.0\"}" + "]" + "}," - + "\"nginx\" => {" - + "\"url\" => \"http://localhost:4000/cookbooks/nginx\"," - + "\"versions\" => [" - + "{\"url\" => \"http://localhost:4000/cookbooks/nginx/1.0.0\"," - + "\"version\" => \"1.0.0\"}," - + "{\"url\" => \"http://localhost:4000/cookbooks/nginx/0.3.0\"," - + "\"version\" => \"0.3.0\"}" - + "]}" + - "}").build()), - ImmutableSet.of(apache2, nginx)); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java deleted file mode 100644 index 7bc19bf..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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 static com.google.common.io.BaseEncoding.base16; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.chef.domain.Metadata; -import org.jclouds.chef.domain.Resource; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.Json; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; - -/** - * Tests behavior of {@code ParseCookbookVersionFromJson} - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseCookbookVersionFromJsonTest { - - private ParseJson<CookbookVersion> handler; - private Injector injector; - private Json json; - - @BeforeTest - protected void setUpInjector() throws IOException { - injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - json = injector.getInstance(Json.class); - handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<CookbookVersion>>() { - })); - } - - public void testBrew() throws IOException { - CookbookVersion cookbook = handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/brew-cookbook.json")).build()); - - assertEquals(cookbook, - handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json.toJson(cookbook)).build())); - } - - public void testTomcat() { - CookbookVersion cookbook = handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/tomcat-cookbook.json")).build()); - - assertEquals(cookbook, - handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json.toJson(cookbook)).build())); - } - - public void testMysql() throws IOException { - CookbookVersion cookbook = handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/mysql-cookbook.json")).build()); - - assertEquals(cookbook, - handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json.toJson(cookbook)).build())); - } - - public void testApache() { - CookbookVersion fromJson = handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/apache-chef-demo-cookbook.json")) - .build()); - - CookbookVersion expected = CookbookVersion - .builder("apache-chef-demo", "0.0.0") - .metadata(Metadata.builder() // - .license("Apache v2.0") // - .maintainer("Your Name") // - .maintainerEmail("[email protected]") // - .description("A fabulous new cookbook") // - .version("0.0.0").name("apache-chef-demo") // - .longDescription("") // - .build()) - .rootFile( - Resource - .builder() - .name("README") - .path("README") - .checksum(base16().lowerCase().decode("11637f98942eafbf49c71b7f2f048b78")) - .url(URI - .create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-11637f98942eafbf49c71b7f2f048b78?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=zgpNl6wSxjTNovqZu2nJq0JztU8%3D")) // - .build()) - .rootFile( - Resource - .builder() - .name("Rakefile") - .path("Rakefile") - .checksum(base16().lowerCase().decode("ebcf925a1651b4e04b9cd8aac2bc54eb")) - .url(URI - .create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/checksum-ebcf925a1651b4e04b9cd8aac2bc54eb?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277766181&Signature=EFzzDSKKytTl7b%2FxrCeNLh05zj4%3D")) - .build()) // - .build(); - - assertEquals(fromJson, expected); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsCheckingChefVersionTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsCheckingChefVersionTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsCheckingChefVersionTest.java deleted file mode 100644 index bad0edf..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsCheckingChefVersionTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 static org.testng.Assert.assertTrue; - -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code ParseCookbookVersionsCheckingChefVersion}. - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseCookbookVersionsCheckingChefVersionTest { - - public void testParserFor09() { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8"); - } - }, new ChefParserModule(), new GsonModule()); - - ParseCookbookVersionsCheckingChefVersion parser = injector - .getInstance(ParseCookbookVersionsCheckingChefVersion.class); - assertTrue(parser.parser instanceof ParseCookbookVersionsV09FromJson); - } - - public void testParserFor010() { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8"); - } - }, new ChefParserModule(), new GsonModule()); - - ParseCookbookVersionsCheckingChefVersion parser = injector - .getInstance(ParseCookbookVersionsCheckingChefVersion.class); - assertTrue(parser.parser instanceof ParseCookbookVersionsV10FromJson); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV09FromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV09FromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV09FromJsonTest.java deleted file mode 100644 index 08cf1d2..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV09FromJsonTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.http.HttpResponse; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code ParseCookbookVersionsV09FromJson} - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseCookbookVersionsV09FromJsonTest { - - private ParseCookbookVersionsV09FromJson handler; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(ParseCookbookVersionsV09FromJson.class); - } - - public void testRegex() { - assertEquals( - handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload("{\"apache2\": [\"0.1.8\", \"0.2\"]}").build()), ImmutableSet.of("0.1.8", "0.2")); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV10FromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV10FromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV10FromJsonTest.java deleted file mode 100644 index e8b396a..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV10FromJsonTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.http.HttpResponse; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code ParseCookbookVersionsV10FromJson} - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseCookbookVersionsV10FromJsonTest { - - private ParseCookbookVersionsV10FromJson handler; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(ParseCookbookVersionsV10FromJson.class); - } - - public void testRegex() { - assertEquals(handler.apply(HttpResponse - .builder() - .statusCode(200) - .message("ok") - .payload( - "{" + "\"apache2\" => {" + "\"url\" => \"http://localhost:4000/cookbooks/apache2\"," - + "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\"," - + "\"version\" => \"5.1.0\"}," - + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\"," - + "\"version\" => \"4.2.0\"}" + "]" + "}" + "}").build()), ImmutableSet.of("5.1.0", "4.2.0")); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseDataBagItemFromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseDataBagItemFromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseDataBagItemFromJsonTest.java deleted file mode 100644 index 5dde523..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseDataBagItemFromJsonTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.DatabagItem; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.Json; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; - -@Test(groups = { "unit" }) -public class ParseDataBagItemFromJsonTest { - private ParseJson<DatabagItem> handler; - private Json mapper; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<DatabagItem>>() { - })); - mapper = injector.getInstance(Json.class); - } - - public void test1() { - String json = "{\"my_key\":\"my_data\",\"id\":\"item1\"}"; - DatabagItem item = new DatabagItem("item1", json); - assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), item); - assertEquals(mapper.toJson(item), json); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseErrorFromJsonOrReturnBodyTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseErrorFromJsonOrReturnBodyTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseErrorFromJsonOrReturnBodyTest.java deleted file mode 100644 index 940e858..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseErrorFromJsonOrReturnBodyTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.net.UnknownHostException; - -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ReturnStringIf2xx; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -@Test(groups = { "unit" }) -public class ParseErrorFromJsonOrReturnBodyTest { - - @Test - public void testApplyInputStreamDetails() throws UnknownHostException { - InputStream is = Strings2 - .toInputStream("{\"error\":[\"invalid tarball: tarball root must contain java-bytearray\"]}"); - - ParseErrorFromJsonOrReturnBody parser = new ParseErrorFromJsonOrReturnBody(new ReturnStringIf2xx()); - String response = parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build()); - assertEquals(response, "invalid tarball: tarball root must contain java-bytearray"); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java deleted file mode 100644 index 8c646b2..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.http.HttpResponse; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code ParseKeySetFromJson} - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseKeySetFromJsonTest { - - private ParseKeySetFromJson handler; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(ParseKeySetFromJson.class); - } - - public void testRegex() { - assertEquals( - handler.apply(HttpResponse - .builder() - .statusCode(200) - .message("ok") - .payload( - "{\n\"opscode-validator\": \"https://api.opscode.com/...\", \"pimp-validator\": \"https://api.opscode.com/...\"}") - .build()), ImmutableSet.of("opscode-validator", "pimp-validator")); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseNodeFromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseNodeFromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseNodeFromJsonTest.java deleted file mode 100644 index 72b4956..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseNodeFromJsonTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.Node; -import org.jclouds.domain.JsonBall; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; - -/** - * Tests behavior of {@code ParseNodeFromJson} - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseNodeFromJsonTest { - - private ParseJson<Node> handler; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Node>>() { - })); - } - - public void test() { - Node node = Node.builder() // - .name("adrian-jcloudstest") // - .normalAttribute("tomcat6", new JsonBall("{\"ssl_port\":8433}")) // - .runListElement("recipe[java]") // - .environment("prod") // - .build(); - - assertEquals( - handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/node.json")).build()), node); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java deleted file mode 100644 index dd31d38..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.Sandbox; -import org.jclouds.date.DateService; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; - -/** - * Tests behavior of {@code ParseSandboxFromJson} - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseSandboxFromJsonTest { - - private ParseJson<Sandbox> handler; - private DateService dateService; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<Sandbox>>() { - })); - dateService = injector.getInstance(DateService.class); - } - - public void test() { - assertEquals( - handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload(ParseSandboxFromJsonTest.class.getResourceAsStream("/sandbox.json")).build()), - Sandbox.builder().rev("1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2").isCompleted(false) - .createTime(dateService.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00")) - .name("f9d6d9b72bae465890aae87969f98a9c").guid("f9d6d9b72bae465890aae87969f98a9c").build()); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseSearchDataBagItemFromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseSearchDataBagItemFromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseSearchDataBagItemFromJsonTest.java deleted file mode 100644 index 3daf3a8..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseSearchDataBagItemFromJsonTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.DatabagItem; -import org.jclouds.chef.domain.SearchResult; -import org.jclouds.http.HttpResponse; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -@Test(groups = { "unit" }) -public class ParseSearchDataBagItemFromJsonTest { - private ParseSearchDatabagFromJson handler; - - @BeforeTest - protected void setUpInjector() throws IOException { - Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(ParseSearchDatabagFromJson.class); - } - - public void test1() { - String itemJson = "{\"my_key\":\"my_data\"}"; - String searchJson = "{\"rows\":[{\"raw_data\": {\"id\":\"item1\",\"my_key\":\"my_data\"}}]}"; - DatabagItem item = new DatabagItem("item1", itemJson); - SearchResult<DatabagItem> result = handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload(searchJson).build()); - assertEquals(result.size(), 1); - assertEquals(result.iterator().next(), item); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java b/core/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java deleted file mode 100644 index b92fb3a..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 static com.google.common.io.BaseEncoding.base16; -import static com.google.common.primitives.Bytes.asList; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.ChecksumStatus; -import org.jclouds.chef.domain.UploadSandbox; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; - -/** - * Tests behavior of {@code ParseUploadSiteFromJson} - */ -@Test(groups = { "unit" }, singleThreaded = true) -public class ParseUploadSandboxFromJsonTest { - - private ParseJson<UploadSandbox> handler; - private Injector injector; - - @BeforeTest - protected void setUpInjector() throws IOException { - injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - handler = injector.getInstance(Key.get(new TypeLiteral<ParseJson<UploadSandbox>>() { - })); - } - - public void test() { - assertEquals( - handler.apply(HttpResponse.builder().statusCode(200).message("ok") - .payload(ParseUploadSandboxFromJsonTest.class.getResourceAsStream("/upload-site.json")).build()), - UploadSandbox - .builder() - .uri(URI - .create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c")) - .checksum( - asList(base16().lowerCase().decode("0c5ecd7788cf4f6c7de2a57193897a6c")), - ChecksumStatus - .builder() - .url(URI - .create("https://s3.amazonaws.com/opscode-platform-production-data/organization-486ca3ac66264fea926aa0b4ff74341c/sandbox-d454f71e2a5f400c808d0c5d04c2c88c/checksum-0c5ecd7788cf4f6c7de2a57193897a6c?AWSAccessKeyId=AKIAJOZTD2N26S7W6APA&Expires=1277344702&Signature=FtKyqvYEjhhEKmRY%2B0M8aGPMM7g%3D")) - .needsUpload(true).build()) - .checksum(asList(base16().lowerCase().decode("0189e76ccc476701d6b374e5a1a27347")), - ChecksumStatus.builder().build()) - .checksum(asList(base16().lowerCase().decode("1dda05ed139664f1f89b9dec482b77c0")), - ChecksumStatus.builder().build()).sandboxId("d454f71e2a5f400c808d0c5d04c2c88c").build() - - ); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/RunListForGroupTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/RunListForGroupTest.java b/core/src/test/java/org/jclouds/chef/functions/RunListForGroupTest.java deleted file mode 100644 index 28b8833..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/RunListForGroupTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.domain.Client; -import org.jclouds.chef.domain.DatabagItem; -import org.jclouds.json.Json; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.Api; -import org.jclouds.rest.annotations.ApiVersion; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -@Test(groups = "unit", testName = "RunListForGroupTest") -public class RunListForGroupTest { - private Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - private Json json = injector.getInstance(Json.class); - - @Test(expectedExceptions = IllegalStateException.class) - public void testWhenNoDatabagItem() throws IOException { - ChefApi chefApi = createMock(ChefApi.class); - Client client = createMock(Client.class); - - RunListForGroup fn = new RunListForGroup(new BootstrapConfigForGroup("jclouds", chefApi), json); - - expect(chefApi.getDatabagItem("jclouds", "foo")).andReturn(null); - - replay(client); - replay(chefApi); - - fn.apply("foo"); - - verify(client); - verify(chefApi); - } - - @Test - public void testReadRunList() throws IOException { - ChefApi chefApi = createMock(ChefApi.class); - Api api = createMock(Api.class); - - RunListForGroup fn = new RunListForGroup(new BootstrapConfigForGroup("jclouds", chefApi), json); - DatabagItem config = new DatabagItem("foo", - "{\"tomcat6\":{\"ssl_port\":8433},\"run_list\":[\"recipe[apache2]\",\"role[webserver]\"]}"); - - expect(chefApi.getDatabagItem("jclouds", "foo")).andReturn(config); - - replay(api); - replay(chefApi); - - assertEquals(fn.apply("foo"), ImmutableList.of("recipe[apache2]", "role[webserver]")); - - verify(api); - verify(chefApi); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/functions/UriForResourceTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/functions/UriForResourceTest.java b/core/src/test/java/org/jclouds/chef/functions/UriForResourceTest.java deleted file mode 100644 index 3285a1c..0000000 --- a/core/src/test/java/org/jclouds/chef/functions/UriForResourceTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.chef.domain.Resource; -import org.testng.annotations.Test; - -import com.google.common.base.Function; - -/** - * Tests behavior of {@code UriForResource} - */ -@Test(groups = { "unit" }) -public class UriForResourceTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testWithNullInput() { - Function<Object, URI> function = new UriForResource(); - function.apply(null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testWithInvalidInput() { - Function<Object, URI> function = new UriForResource(); - function.apply(new Object()); - } - - @Test - public void testWithValidResource() { - Function<Object, URI> function = new UriForResource(); - Resource res = Resource.builder().name("test").url(URI.create("http://foo/bar")).build(); - URI result = function.apply(res); - assertEquals(res.getUrl().toString(), result.toString()); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/handlers/ChefApiErrorRetryHandlerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/handlers/ChefApiErrorRetryHandlerTest.java b/core/src/test/java/org/jclouds/chef/handlers/ChefApiErrorRetryHandlerTest.java deleted file mode 100644 index 5e99675..0000000 --- a/core/src/test/java/org/jclouds/chef/handlers/ChefApiErrorRetryHandlerTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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.handlers; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.handlers.BackoffLimitedRetryHandler; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code ChefClientErrorRetryHandler} - */ -@Test(groups = { "unit" }) -public class ChefApiErrorRetryHandlerTest { - @Test - public void test401DoesNotRetry() { - - HttpCommand command = createMock(HttpCommand.class); - HttpResponse response = createMock(HttpResponse.class); - BackoffLimitedRetryHandler retry = createMock(BackoffLimitedRetryHandler.class); - - expect(command.getFailureCount()).andReturn(0); - expect(response.getStatusCode()).andReturn(401).atLeastOnce(); - - replay(response); - replay(retry); - replay(command); - - ChefApiErrorRetryHandler handler = new ChefApiErrorRetryHandler(retry); - - assert !handler.shouldRetryRequest(command, response); - - verify(retry); - verify(command); - verify(response); - - } - - @Test - public void test400DoesNotRetry() { - - HttpCommand command = createMock(HttpCommand.class); - HttpResponse response = createMock(HttpResponse.class); - BackoffLimitedRetryHandler retry = createMock(BackoffLimitedRetryHandler.class); - - expect(command.getFailureCount()).andReturn(0); - expect(response.getStatusCode()).andReturn(401).atLeastOnce(); - - replay(response); - replay(retry); - replay(command); - - ChefApiErrorRetryHandler handler = new ChefApiErrorRetryHandler(retry); - - assert !handler.shouldRetryRequest(command, response); - - verify(retry); - verify(command); - verify(response); - - } - - @Test - public void testRetryOn400PutSandbox() { - - HttpCommand command = createMock(HttpCommand.class); - BackoffLimitedRetryHandler retry = createMock(BackoffLimitedRetryHandler.class); - - HttpRequest request = HttpRequest.builder().method("PUT") - .endpoint("https://api.opscode.com/organizations/jclouds/sandboxes/bfd68d4052f44053b2e593a33b5e1cd5") - .build(); - HttpResponse response = HttpResponse - .builder() - .statusCode(400) - .message("400 Bad Request") - .payload( - "{\"error\":[\"Cannot update sandbox bfd68d4052f44053b2e593a33b5e1cd5: checksum 9b7c23369f4b576451216c39f214af6c was not uploaded\"]}") - .build(); - - expect(command.getFailureCount()).andReturn(0); - expect(command.getCurrentRequest()).andReturn(request).atLeastOnce(); - expect(retry.shouldRetryRequest(command, response)).andReturn(true); - - replay(retry); - replay(command); - - ChefApiErrorRetryHandler handler = new ChefApiErrorRetryHandler(retry); - - assert handler.shouldRetryRequest(command, response); - - verify(retry); - verify(command); - - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java b/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java deleted file mode 100644 index a477be0..0000000 --- a/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java +++ /dev/null @@ -1,535 +0,0 @@ -/* - * 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.internal; - -import static com.google.common.collect.Iterables.any; -import static com.google.common.collect.Iterables.isEmpty; -import static com.google.common.hash.Hashing.md5; -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.jclouds.util.Closeables2.closeQuietly; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -import java.io.File; -import java.io.InputStream; -import java.util.Collections; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.domain.ChecksumStatus; -import org.jclouds.chef.domain.Client; -import org.jclouds.chef.domain.CookbookDefinition; -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.chef.domain.DatabagItem; -import org.jclouds.chef.domain.Environment; -import org.jclouds.chef.domain.Metadata; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.domain.Resource; -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.options.CreateClientOptions; -import org.jclouds.chef.options.SearchOptions; -import org.jclouds.crypto.Pems; -import org.jclouds.io.ByteStreams2; -import org.jclouds.io.Payloads; -import org.jclouds.io.payloads.FilePayload; -import org.jclouds.rest.ResourceNotFoundException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.hash.Hashing; -import com.google.common.io.Files; -import com.google.common.primitives.Bytes; - -/** - * Tests behavior of {@code ChefApi} - */ -@Test(groups = { "live", "integration" }) -public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiveTest<A> { - public static final String PREFIX = "jcloudstest-" + System.getProperty("user.name"); - public static final String ADMIN_PREFIX = "jcloudstest-adm-" + System.getProperty("user.name"); - public static final String ENV_NODE = PREFIX + "-env-node"; - - // It may take a bit until the search index is populated - protected int maxWaitForIndexInMs = 60000; - - // The id of the data bag item used in search tests - private String databagitemId; - - public void testCreateNewCookbook() throws Exception { - // Define the file you want in the cookbook - File file = new File(System.getProperty("user.dir"), "pom.xml"); - FilePayload content = Payloads.newFilePayload(file); - content.getContentMetadata().setContentType("application/x-binary"); - - // Get an md5 so that you can see if the server already has it or not - content.getContentMetadata().setContentMD5(Files.asByteSource(file).hash(Hashing.md5()).asBytes()); - - // Note that java collections cannot effectively do equals or hashcodes on - // byte arrays, so let's convert to a list of bytes. - List<Byte> md5 = Bytes.asList(content.getContentMetadata().getContentMD5()); - - // Request an upload site for this file - UploadSandbox site = api.createUploadSandboxForChecksums(ImmutableSet.of(md5)); - assertTrue(site.getChecksums().containsKey(md5), md5 + " not in " + site.getChecksums()); - - try { - // Upload the file contents, if still not uploaded - ChecksumStatus status = site.getChecksums().get(md5); - if (status.needsUpload()) { - api.uploadContent(status.getUrl(), content); - } - Sandbox sandbox = api.commitSandbox(site.getSandboxId(), true); - assertTrue(sandbox.isCompleted(), "Sandbox should be completed after uploading"); - } catch (RuntimeException e) { - api.commitSandbox(site.getSandboxId(), false); - fail("Could not upload content"); - } - - // Create the metadata of the cookbook - Metadata metadata = Metadata.builder() // - .name(PREFIX) // - .version("0.0.0") // - .description("Jclouds test uploaded cookbook") // - .maintainer("jclouds") // - .maintainerEmail("[email protected]") // - .license("Apache 2.0") // - .build(); - - // Create a new cookbook - CookbookVersion cookbook = CookbookVersion.builder(PREFIX, "0.0.0") // - .metadata(metadata) // - .rootFile(Resource.builder().fromPayload(content).build()) // - .build(); - - // upload the cookbook to the remote server - api.updateCookbook(PREFIX, "0.0.0", cookbook); - } - - public void testListCookbooks() throws Exception { - Set<String> cookbookNames = api.listCookbooks(); - assertFalse(cookbookNames.isEmpty(), "No cookbooks were found"); - - for (String cookbookName : cookbookNames) { - Set<String> versions = api.listVersionsOfCookbook(cookbookName); - assertFalse(versions.isEmpty(), "There are no versions of the cookbook: " + cookbookName); - - for (String version : api.listVersionsOfCookbook(cookbookName)) { - CookbookVersion cookbook = api.getCookbook(cookbookName, version); - assertNotNull(cookbook, "Could not get cookbook: " + cookbookName); - } - } - } - - @Test(dependsOnMethods = "testListCookbooks") - public void testListCookbookVersionsWithChefService() throws Exception { - Iterable<? extends CookbookVersion> cookbooks = chefService.listCookbookVersions(); - assertFalse(isEmpty(cookbooks), "No cookbooks were found"); - } - - @Test(dependsOnMethods = "testListCookbookVersionsWithChefService") - public void testDownloadCookbooks() throws Exception { - Iterable<? extends CookbookVersion> cookbooks = chefService.listCookbookVersions(); - for (CookbookVersion cookbook : cookbooks) { - for (Resource resource : ImmutableList.<Resource> builder().addAll(cookbook.getDefinitions()) - .addAll(cookbook.getFiles()).addAll(cookbook.getLibraries()).addAll(cookbook.getSuppliers()) - .addAll(cookbook.getRecipes()).addAll(cookbook.getResources()).addAll(cookbook.getRootFiles()) - .addAll(cookbook.getTemplates()).build()) { - - InputStream stream = api.getResourceContents(resource); - assertNotNull(stream, "Resource contents are null for resource: " + resource.getName()); - - byte[] md5 = ByteStreams2.hashAndClose(stream, md5()).asBytes(); - assertEquals(md5, resource.getChecksum()); - } - } - } - - @Test(dependsOnMethods = "testCreateNewCookbook") - public void testUpdateCookbook() throws Exception { - CookbookVersion cookbook = api.getCookbook(PREFIX, "0.0.0"); - assertNotNull(cookbook, "Cookbook not found: " + PREFIX); - assertNotNull(api.updateCookbook(PREFIX, "0.0.0", cookbook), "Updated cookbook was null"); - } - - @Test(dependsOnMethods = { "testCreateNewCookbook", "testUpdateCookbook" }) - public void testDeleteCookbook() throws Exception { - assertNotNull(api.deleteCookbook(PREFIX, "0.0.0"), "Deleted cookbook was null"); - } - - @Test - public void testCreateClient() throws Exception { - api.deleteClient(PREFIX); - String credential = Pems.pem(api.createClient(PREFIX).getPrivateKey()); - assertClientCreated(PREFIX, credential); - } - - @Test - public void testCreateAdminClient() throws Exception { - api.deleteClient(ADMIN_PREFIX); - String credential = Pems.pem(api.createClient(ADMIN_PREFIX, CreateClientOptions.Builder.admin()).getPrivateKey()); - assertClientCreated(ADMIN_PREFIX, credential); - } - - @Test(dependsOnMethods = "testCreateClient") - public void testGenerateKeyForClient() throws Exception { - String credential = Pems.pem(api.generateKeyForClient(PREFIX).getPrivateKey()); - assertClientCreated(PREFIX, credential); - } - - @Test - public void testListNodes() throws Exception { - Set<String> nodes = api.listNodes(); - assertNotNull(nodes, "No nodes were found"); - } - - @Test(dependsOnMethods = "testCreateRole") - public void testCreateNode() throws Exception { - api.deleteNode(PREFIX); - api.createNode(Node.builder().name(PREFIX).runListElement("role[" + PREFIX + "]").environment("_default").build()); - Node node = api.getNode(PREFIX); - // TODO check recipes - assertNotNull(node, "Created node should not be null"); - Set<String> nodes = api.listNodes(); - assertTrue(nodes.contains(PREFIX), String.format("node %s not in %s", PREFIX, nodes)); - } - - @Test(dependsOnMethods = "testCreateNode") - public void testUpdateNode() throws Exception { - for (String nodename : api.listNodes()) { - Node node = api.getNode(nodename); - api.updateNode(node); - } - } - - @Test - public void testListRoles() throws Exception { - Set<String> roles = api.listRoles(); - assertNotNull(roles, "Role list was null"); - } - - @Test - public void testCreateRole() throws Exception { - api.deleteRole(PREFIX); - api.createRole(Role.builder().name(PREFIX).runListElement("recipe[java]").build()); - Role role = api.getRole(PREFIX); - assertNotNull(role, "Created role should not be null"); - assertEquals(role.getName(), PREFIX); - assertEquals(role.getRunList(), Collections.singleton("recipe[java]")); - } - - @Test(dependsOnMethods = "testCreateRole") - public void testUpdateRole() throws Exception { - for (String rolename : api.listRoles()) { - Role role = api.getRole(rolename); - api.updateRole(role); - } - } - - @Test - public void testListDatabags() throws Exception { - Set<String> databags = api.listDatabags(); - assertNotNull(databags, "Data bag list was null"); - } - - @Test - public void testCreateDatabag() throws Exception { - api.deleteDatabag(PREFIX); - api.createDatabag(PREFIX); - } - - @Test(dependsOnMethods = "testCreateDatabagItem") - public void testListDatabagItems() throws Exception { - Set<String> databagItems = api.listDatabagItems(PREFIX); - assertNotNull(databagItems, "Data bag item list was null"); - } - - @Test(dependsOnMethods = "testCreateDatabag") - public void testCreateDatabagItem() throws Exception { - Properties config = new Properties(); - config.setProperty("foo", "bar"); - api.deleteDatabagItem(PREFIX, PREFIX); - DatabagItem databagItem = api.createDatabagItem(PREFIX, new DatabagItem("config", json.toJson(config))); - databagitemId = databagItem.getId(); - assertNotNull(databagItem, "Created data bag item should not be null"); - assertEquals(databagItem.getId(), "config"); - - // The databagItem json contains extra keys: (the name and the type if the - // item) - Properties props = json.fromJson(databagItem.toString(), Properties.class); - for (Object key : config.keySet()) { - assertTrue(props.containsKey(key)); - assertEquals(config.get(key), props.get(key)); - } - } - - @Test(dependsOnMethods = "testCreateDatabagItem") - public void testUpdateDatabagItem() throws Exception { - for (String databagItemId : api.listDatabagItems(PREFIX)) { - DatabagItem databagItem = api.getDatabagItem(PREFIX, databagItemId); - api.updateDatabagItem(PREFIX, databagItem); - } - } - - @Test(dependsOnMethods = "testSearchDatabagWithOptions") - public void testDeleteDatabagItem() throws Exception { - for (String databagItemId : api.listDatabagItems(PREFIX)) { - DatabagItem databagItem = api.deleteDatabagItem(PREFIX, databagItemId); - assertNotNull(databagItem, "Deleted data bag item should not be null"); - assertEquals(databagItem.getId(), databagItemId, "Deleted data bag item id must match the original id"); - assertNull(api.getDatabagItem(PREFIX, databagItemId), "Data bag item should not exist"); - } - } - - @Test - public void testListSearchIndexes() throws Exception { - Set<String> indexes = api.listSearchIndexes(); - assertNotNull(indexes, "The index list should not be null"); - assertTrue(indexes.contains("node")); - assertTrue(indexes.contains("client")); - assertTrue(indexes.contains("role")); - } - - @Test - public void testSearchNodes() throws Exception { - SearchResult<? extends Node> results = api.searchNodes(); - assertNotNull(results, "Node result list should not be null"); - } - - @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateNode" }) - public void testSearchNodesWithOptions() throws Exception { - Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() { - @Override - public boolean apply(SearchOptions input) { - SearchResult<? extends Node> results = api.searchNodes(input); - assertNotNull(results); - if (results.size() > 0) { - assertEquals(results.size(), 1); - assertEquals(results.iterator().next().getName(), PREFIX); - return true; - } else { - // The index may still not be populated - return false; - } - } - }, maxWaitForIndexInMs, 5000L, MILLISECONDS); - - SearchOptions options = SearchOptions.Builder.query("name:" + PREFIX); - assertTrue(waitForIndex.apply(options)); - } - - @Test - public void testSearchClients() throws Exception { - SearchResult<? extends Client> results = api.searchClients(); - assertNotNull(results, "Client result list should not be null"); - } - - @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateClient" }) - public void testSearchClientsWithOptions() throws Exception { - Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() { - @Override - public boolean apply(SearchOptions input) { - SearchResult<? extends Client> results = api.searchClients(input); - assertNotNull(results); - if (results.size() > 0) { - assertEquals(results.size(), 1); - assertEquals(results.iterator().next().getName(), PREFIX); - return true; - } else { - // The index may still not be populated - return false; - } - } - }, maxWaitForIndexInMs, 5000L, MILLISECONDS); - - SearchOptions options = SearchOptions.Builder.query("name:" + PREFIX); - assertTrue(waitForIndex.apply(options)); - } - - @Test - public void testSearchRoles() throws Exception { - SearchResult<? extends Role> results = api.searchRoles(); - assertNotNull(results, "Role result list should not be null"); - } - - @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateRole" }) - public void testSearchRolesWithOptions() throws Exception { - Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() { - @Override - public boolean apply(SearchOptions input) { - SearchResult<? extends Role> results = api.searchRoles(input); - assertNotNull(results); - if (results.size() > 0) { - assertEquals(results.size(), 1); - assertEquals(results.iterator().next().getName(), PREFIX); - return true; - } else { - // The index may still not be populated - return false; - } - } - }, maxWaitForIndexInMs, 5000L, MILLISECONDS); - - SearchOptions options = SearchOptions.Builder.query("name:" + PREFIX); - assertTrue(waitForIndex.apply(options)); - } - - @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateDatabagItem" }) - public void testSearchDatabag() throws Exception { - SearchResult<? extends DatabagItem> results = api.searchDatabagItems(PREFIX); - assertNotNull(results, "Data bag item result list should not be null"); - } - - @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateDatabagItem" }) - public void testSearchDatabagWithOptions() throws Exception { - Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() { - @Override - public boolean apply(SearchOptions input) { - SearchResult<? extends DatabagItem> results = api.searchDatabagItems(PREFIX, input); - assertNotNull(results); - if (results.size() > 0) { - assertEquals(results.size(), 1); - assertEquals(results.iterator().next().getId(), databagitemId); - return true; - } else { - // The index may still not be populated - return false; - } - } - }, maxWaitForIndexInMs, 5000L, MILLISECONDS); - - SearchOptions options = SearchOptions.Builder.query("id:" + databagitemId); - assertTrue(waitForIndex.apply(options)); - } - - @Test(expectedExceptions = ResourceNotFoundException.class, dependsOnMethods = "testListSearchIndexes") - public void testSearchDatabagNotFound() throws Exception { - SearchResult<? extends DatabagItem> results = api.searchDatabagItems("whoopie"); - assertNotNull(results, "Data bag item result list should not be null"); - } - - @Test - public void testCreateEnvironment() { - api.deleteEnvironment(PREFIX); - api.createEnvironment(Environment.builder().name(PREFIX).description(PREFIX).build()); - Environment env = api.getEnvironment(PREFIX); - assertNotNull(env, "Created environment should not be null"); - assertEquals(env.getName(), PREFIX); - assertEquals(env.getDescription(), PREFIX); - } - - @Test(dependsOnMethods = "testCreateEnvironment") - public void testListEnvironment() { - Set<String> envList = api.listEnvironments(); - assertNotNull(envList, "Environment list was null"); - assertTrue(envList.contains(PREFIX)); - } - - @Test(dependsOnMethods = "testCreateEnvironment") - public void testSearchEnvironments() throws Exception { - SearchResult<? extends Environment> results = api.searchEnvironments(); - assertNotNull(results, "Environment result list was null"); - } - - @Test(dependsOnMethods = { "testListSearchIndexes", "testCreateEnvironment" }) - public void testSearchEnvironmentsWithOptions() throws Exception { - Predicate<SearchOptions> waitForIndex = retry(new Predicate<SearchOptions>() { - @Override - public boolean apply(SearchOptions input) { - SearchResult<? extends Environment> results = api.searchEnvironments(input); - assertNotNull(results); - if (results.size() > 0) { - assertEquals(results.size(), 1); - assertEquals(results.iterator().next().getName(), PREFIX); - return true; - } else { - // The index may still not be populated - return false; - } - } - }, maxWaitForIndexInMs, 5000L, MILLISECONDS); - - SearchOptions options = SearchOptions.Builder.query("name:" + PREFIX); - assertTrue(waitForIndex.apply(options)); - } - - @Test(dependsOnMethods = "testCreateEnvironment") - public void testListRecipesInEnvironment() { - Set<String> recipeList = api.listRecipesInEnvironment(PREFIX); - assertTrue(!recipeList.isEmpty()); - } - - @Test(dependsOnMethods = "testCreateEnvironment") - public void testListNodesInEnvironment() { - api.deleteNode(ENV_NODE); - api.createNode(Node.builder().name(ENV_NODE).runListElement("role[" + PREFIX + "]").environment(PREFIX).build()); - Node node = api.getNode(ENV_NODE); - assertNotNull(node, "Created node should not be null"); - Set<String> nodeList = api.listNodesInEnvironment(PREFIX); - assertTrue(!nodeList.isEmpty()); - } - - @Test(dependsOnMethods = "testCreateNewCookbook") - public void testListCookbooksInEnvironment() throws Exception { - Set<CookbookDefinition> cookbooks = api.listCookbooksInEnvironment("_default"); - assertTrue(any(cookbooks, new Predicate<CookbookDefinition>() { - @Override - public boolean apply(CookbookDefinition input) { - return PREFIX.equals(input.getName()); - }}), String.format("Cookbook %s not in %s", PREFIX, cookbooks)); - } - - @AfterClass(groups = { "live", "integration" }) - @Override - public void tearDown() { - api.deleteClient(PREFIX); - api.deleteClient(ADMIN_PREFIX); - api.deleteNode(PREFIX); - api.deleteNode(ENV_NODE); - api.deleteRole(PREFIX); - api.deleteDatabag(PREFIX); - api.deleteEnvironment(PREFIX); - super.tearDown(); - } - - private void assertClientCreated(String identity, String credential) { - Properties overrides = super.setupProperties(); - overrides.setProperty(provider + ".identity", identity); - overrides.setProperty(provider + ".credential", credential); - - A clientApi = create(overrides, setupModules()); - - try { - Client client = clientApi.getClient(identity); - assertNotNull(client, "Client not found: " + identity); - } finally { - closeQuietly(clientApi); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/test/java/org/jclouds/chef/internal/BaseChefLiveTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/internal/BaseChefLiveTest.java b/core/src/test/java/org/jclouds/chef/internal/BaseChefLiveTest.java deleted file mode 100644 index e314418..0000000 --- a/core/src/test/java/org/jclouds/chef/internal/BaseChefLiveTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.internal; - -import static org.jclouds.reflect.Types2.checkBound; - -import java.io.File; -import java.io.IOException; -import java.util.Properties; - -import org.jclouds.apis.BaseApiLiveTest; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.ChefService; -import org.jclouds.json.Json; -import org.testng.annotations.Test; - -import com.google.common.base.Charsets; -import com.google.common.base.Throwables; -import com.google.common.io.Files; -import com.google.common.reflect.TypeToken; -import com.google.inject.Injector; -import com.google.inject.Module; - -@Test(groups = "live") -public abstract class BaseChefLiveTest<A extends ChefApi> extends BaseApiLiveTest<A> { - - protected Injector injector; - protected ChefService chefService; - protected Json json; - - protected BaseChefLiveTest() { - provider = "chef"; - } - - /** - * the credential is a path to the pem file. - */ - @Override - protected Properties setupProperties() { - Properties overrides = super.setupProperties(); - credential = setCredentialFromPemFile(overrides, identity, provider + ".credential"); - return overrides; - } - - @Override - protected void initialize() { - super.initialize(); - chefService = injector.getInstance(ChefService.class); - json = injector.getInstance(Json.class); - } - - @Override - protected A create(Properties props, Iterable<Module> modules) { - injector = newBuilder().modules(modules).overrides(props).buildInjector(); - return injector.getInstance(resolveApiClass()); - } - - protected String setCredentialFromPemFile(Properties overrides, String identity, String key) { - String val = null; - String credentialFromFile = null; - if (System.getProperties().containsKey("test." + key)) { - val = System.getProperty("test." + key); - } else { - val = System.getProperty("user.home") + "/.chef/" + identity + ".pem"; - } - try { - credentialFromFile = Files.toString(new File(val), Charsets.UTF_8); - } catch (IOException e) { - throw Throwables.propagate(e); - } - overrides.setProperty(key, credentialFromFile); - return credentialFromFile; - } - - @SuppressWarnings("unchecked") - private Class<A> resolveApiClass() { - return Class.class.cast(checkBound(new TypeToken<A>(getClass()) { - private static final long serialVersionUID = 1L; - }).getRawType()); - } - -}
