Updated Branches: refs/heads/master e433c094c -> 756fe9bff
Renamed test methods and file names to match the new api naming convention Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/commit/c49bec7c Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/tree/c49bec7c Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/diff/c49bec7c Branch: refs/heads/master Commit: c49bec7c8fa590a672ea56c514dacadaf48b9048 Parents: e433c09 Author: Noorul Islam K M <[email protected]> Authored: Tue Sep 17 08:49:41 2013 +0530 Committer: Ignasi Barrera <[email protected]> Committed: Tue Sep 17 14:44:23 2013 +0200 ---------------------------------------------------------------------- .../jclouds/chef/internal/BaseChefService.java | 10 +- .../chef/strategy/ListEnvironmentNodes.java | 45 -------- .../chef/strategy/ListNodesInEnvironment.java | 45 ++++++++ .../internal/ListEnvironmentNodesImpl.java | 109 ------------------- .../internal/ListNodesInEnvironmentImpl.java | 109 +++++++++++++++++++ .../GetEnvironmentNodesImplLiveTest.java | 81 -------------- .../strategy/internal/GetNodesImplLiveTest.java | 81 -------------- .../internal/ListNodesImplLiveTest.java | 81 ++++++++++++++ .../ListNodesInEnvironmentImplLiveTest.java | 81 ++++++++++++++ 9 files changed, 321 insertions(+), 321 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/main/java/org/jclouds/chef/internal/BaseChefService.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/internal/BaseChefService.java b/core/src/main/java/org/jclouds/chef/internal/BaseChefService.java index 9d33570..4600ffc 100644 --- a/core/src/main/java/org/jclouds/chef/internal/BaseChefService.java +++ b/core/src/main/java/org/jclouds/chef/internal/BaseChefService.java @@ -49,7 +49,7 @@ import org.jclouds.chef.strategy.DeleteAllClientsInList; import org.jclouds.chef.strategy.DeleteAllNodesInList; import org.jclouds.chef.strategy.ListClients; import org.jclouds.chef.strategy.ListCookbookVersions; -import org.jclouds.chef.strategy.ListEnvironmentNodes; +import org.jclouds.chef.strategy.ListNodesInEnvironment; import org.jclouds.chef.strategy.ListEnvironments; import org.jclouds.chef.strategy.ListNodes; import org.jclouds.chef.strategy.UpdateAutomaticAttributesOnNode; @@ -89,7 +89,7 @@ public class BaseChefService implements ChefService { private final RunListForGroup runListForGroup; private final ListCookbookVersions listCookbookVersions; private final ListEnvironments listEnvironments; - private final ListEnvironmentNodes listEnvironmentNodes; + private final ListNodesInEnvironment listNodesInEnvironment; private final Json json; @Resource @Named(ChefProperties.CHEF_LOGGER) @@ -104,7 +104,7 @@ public class BaseChefService implements ChefService { UpdateAutomaticAttributesOnNode updateAutomaticAttributesOnNode, Supplier<PrivateKey> privateKey, @Named(CHEF_BOOTSTRAP_DATABAG) String databag, GroupToBootScript groupToBootScript, BootstrapConfigForGroup bootstrapConfigForGroup, RunListForGroup runListForGroup, - ListEnvironments listEnvironments, ListEnvironmentNodes listEnvironmentNodes, Json json) { + ListEnvironments listEnvironments, ListNodesInEnvironment listNodesInEnvironment, Json json) { this.chefContext = checkNotNull(chefContext, "chefContext"); this.api = checkNotNull(api, "api"); this.cleanupStaleNodesAndClients = checkNotNull(cleanupStaleNodesAndClients, "cleanupStaleNodesAndClients"); @@ -123,7 +123,7 @@ public class BaseChefService implements ChefService { this.bootstrapConfigForGroup = checkNotNull(bootstrapConfigForGroup, "bootstrapConfigForGroup"); this.runListForGroup = checkNotNull(runListForGroup, "runListForGroup"); this.listEnvironments = checkNotNull(listEnvironments, "listEnvironments"); - this.listEnvironmentNodes = checkNotNull(listEnvironmentNodes, "listEnvironmentNodes"); + this.listNodesInEnvironment = checkNotNull(listNodesInEnvironment, "listNodesInEnvironment"); this.json = checkNotNull(json, "json"); } @@ -244,7 +244,7 @@ public class BaseChefService implements ChefService { @Override public Iterable<? extends Node> listNodesInEnvironment(String environmentName) { - return listEnvironmentNodes.execute(environmentName); + return listNodesInEnvironment.execute(environmentName); } } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/main/java/org/jclouds/chef/strategy/ListEnvironmentNodes.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/ListEnvironmentNodes.java b/core/src/main/java/org/jclouds/chef/strategy/ListEnvironmentNodes.java deleted file mode 100644 index 6414994..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/ListEnvironmentNodes.java +++ /dev/null @@ -1,45 +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.strategy; - -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.internal.ListEnvironmentNodesImpl; - -import com.google.common.base.Predicate; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.ImplementedBy; - -/** - * - * - * @author Noorul Islam K M - */ -@ImplementedBy(ListEnvironmentNodesImpl.class) -public interface ListEnvironmentNodes { - - public Iterable<? extends Node> execute(String environmentName); - - public Iterable<? extends Node> execute(String environmentName, Predicate<String> nodeNameSelector); - - public Iterable<? extends Node> execute(String environmentName, Iterable<String> toGet); - - public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName); - - public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName, Predicate<String> nodeNameSelector); - - public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName, Iterable<String> toGet); -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/main/java/org/jclouds/chef/strategy/ListNodesInEnvironment.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/ListNodesInEnvironment.java b/core/src/main/java/org/jclouds/chef/strategy/ListNodesInEnvironment.java new file mode 100644 index 0000000..c007d0e --- /dev/null +++ b/core/src/main/java/org/jclouds/chef/strategy/ListNodesInEnvironment.java @@ -0,0 +1,45 @@ +/* + * 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.strategy; + +import org.jclouds.chef.domain.Node; +import org.jclouds.chef.strategy.internal.ListNodesInEnvironmentImpl; + +import com.google.common.base.Predicate; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.inject.ImplementedBy; + +/** + * + * + * @author Noorul Islam K M + */ +@ImplementedBy(ListNodesInEnvironmentImpl.class) +public interface ListNodesInEnvironment { + + public Iterable<? extends Node> execute(String environmentName); + + public Iterable<? extends Node> execute(String environmentName, Predicate<String> nodeNameSelector); + + public Iterable<? extends Node> execute(String environmentName, Iterable<String> toGet); + + public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName); + + public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName, Predicate<String> nodeNameSelector); + + public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName, Iterable<String> toGet); +} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/main/java/org/jclouds/chef/strategy/internal/ListEnvironmentNodesImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/ListEnvironmentNodesImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/ListEnvironmentNodesImpl.java deleted file mode 100644 index c017828..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/ListEnvironmentNodesImpl.java +++ /dev/null @@ -1,109 +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.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.ListEnvironmentNodes; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.Inject; - -/** - * - * - * @author Noorul Islam K M - */ -@Singleton -public class ListEnvironmentNodesImpl implements ListEnvironmentNodes { - - protected final ChefApi api; - protected final ListeningExecutorService userExecutor; - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - ListEnvironmentNodesImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ChefApi api) { - this.userExecutor = checkNotNull(userExecutor, "userExecuor"); - this.api = checkNotNull(api, "api"); - } - - @Override - public Iterable<? extends Node> execute(String environmentName) { - return execute(userExecutor, environmentName); - } - - @Override - public Iterable<? extends Node> execute(String environmentName, Predicate<String> nodeNameSelector) { - return execute(userExecutor, environmentName, nodeNameSelector); - } - - @Override - public Iterable<? extends Node> execute(String environmentName, Iterable<String> toGet) { - return execute(userExecutor, environmentName, toGet); - } - - @Override - public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName) { - return execute(executor, environmentName, api.listNodesInEnvironment(environmentName)); - } - - @Override - public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName, Predicate<String> nodeNameSelector) { - return execute(executor, environmentName, filter(api.listNodesInEnvironment(environmentName), nodeNameSelector)); - } - - @Override - public Iterable<? extends Node> execute(final ListeningExecutorService executor, String environmentName, Iterable<String> toGet) { - ListenableFuture<List<Node>> futures = allAsList(transform(toGet, new Function<String, ListenableFuture<Node>>() { - @Override - public ListenableFuture<Node> apply(final String input) { - return executor.submit(new Callable<Node>() { - @Override - public Node call() throws Exception { - return api.getNode(input); - } - }); - } - })); - - logger.trace(String.format("getting nodes in environment %s: %s", environmentName, Joiner.on(',').join(toGet))); - return getUnchecked(futures); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImpl.java new file mode 100644 index 0000000..c430b95 --- /dev/null +++ b/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImpl.java @@ -0,0 +1,109 @@ +/* + * 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.strategy.internal; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; +import static com.google.common.util.concurrent.Futures.allAsList; +import static com.google.common.util.concurrent.Futures.getUnchecked; + +import java.util.List; +import java.util.concurrent.Callable; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.Constants; +import org.jclouds.chef.ChefApi; +import org.jclouds.chef.config.ChefProperties; +import org.jclouds.chef.domain.Node; +import org.jclouds.chef.strategy.ListNodesInEnvironment; +import org.jclouds.logging.Logger; + +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.base.Predicate; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.inject.Inject; + +/** + * + * + * @author Noorul Islam K M + */ +@Singleton +public class ListNodesInEnvironmentImpl implements ListNodesInEnvironment { + + protected final ChefApi api; + protected final ListeningExecutorService userExecutor; + @Resource + @Named(ChefProperties.CHEF_LOGGER) + protected Logger logger = Logger.NULL; + + @Inject + ListNodesInEnvironmentImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ChefApi api) { + this.userExecutor = checkNotNull(userExecutor, "userExecuor"); + this.api = checkNotNull(api, "api"); + } + + @Override + public Iterable<? extends Node> execute(String environmentName) { + return execute(userExecutor, environmentName); + } + + @Override + public Iterable<? extends Node> execute(String environmentName, Predicate<String> nodeNameSelector) { + return execute(userExecutor, environmentName, nodeNameSelector); + } + + @Override + public Iterable<? extends Node> execute(String environmentName, Iterable<String> toGet) { + return execute(userExecutor, environmentName, toGet); + } + + @Override + public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName) { + return execute(executor, environmentName, api.listNodesInEnvironment(environmentName)); + } + + @Override + public Iterable<? extends Node> execute(ListeningExecutorService executor, String environmentName, Predicate<String> nodeNameSelector) { + return execute(executor, environmentName, filter(api.listNodesInEnvironment(environmentName), nodeNameSelector)); + } + + @Override + public Iterable<? extends Node> execute(final ListeningExecutorService executor, String environmentName, Iterable<String> toGet) { + ListenableFuture<List<Node>> futures = allAsList(transform(toGet, new Function<String, ListenableFuture<Node>>() { + @Override + public ListenableFuture<Node> apply(final String input) { + return executor.submit(new Callable<Node>() { + @Override + public Node call() throws Exception { + return api.getNode(input); + } + }); + } + })); + + logger.trace(String.format("getting nodes in environment %s: %s", environmentName, Joiner.on(',').join(toGet))); + return getUnchecked(futures); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/test/java/org/jclouds/chef/strategy/internal/GetEnvironmentNodesImplLiveTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/strategy/internal/GetEnvironmentNodesImplLiveTest.java b/core/src/test/java/org/jclouds/chef/strategy/internal/GetEnvironmentNodesImplLiveTest.java deleted file mode 100644 index 706f275..0000000 --- a/core/src/test/java/org/jclouds/chef/strategy/internal/GetEnvironmentNodesImplLiveTest.java +++ /dev/null @@ -1,81 +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.strategy.internal; - -import static com.google.common.collect.Iterables.size; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.internal.BaseChefLiveTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code GetEnvironmentNodesImpl} strategies - * - * @author Noorul Islam K M - */ -@Test(groups = "live", testName = "GetEnvironmentNodesImplLiveTest") -public class GetEnvironmentNodesImplLiveTest extends BaseChefLiveTest<ChefApi> { - - private ListEnvironmentNodesImpl strategy; - private CreateNodeAndPopulateAutomaticAttributesImpl creator; - - @Override - protected void initialize() { - super.initialize(); - this.creator = injector.getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class); - this.strategy = injector.getInstance(ListEnvironmentNodesImpl.class); - creator.execute(prefix, ImmutableSet.<String> of()); - creator.execute(prefix + 1, ImmutableSet.<String> of()); - } - - @AfterClass(groups = { "integration", "live" }) - @Override - protected void tearDown() { - api.deleteNode(prefix); - api.deleteNode(prefix + 1); - super.tearDown(); - } - - @Test - public void testExecute() { - assertTrue(size(strategy.execute("_default")) > 0, "Expected one or more elements"); - } - - @Test - public void testExecutePredicateOfString() { - assertEquals(size(strategy.execute("_default", new Predicate<String>() { - - @Override - public boolean apply(String input) { - return input.startsWith(prefix); - } - - })), 2); - } - - @Test - public void testExecuteIterableOfString() { - assertEquals(size(strategy.execute("_default", ImmutableSet.of(prefix, prefix + 1))), 2); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/test/java/org/jclouds/chef/strategy/internal/GetNodesImplLiveTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/strategy/internal/GetNodesImplLiveTest.java b/core/src/test/java/org/jclouds/chef/strategy/internal/GetNodesImplLiveTest.java deleted file mode 100644 index 1b36471..0000000 --- a/core/src/test/java/org/jclouds/chef/strategy/internal/GetNodesImplLiveTest.java +++ /dev/null @@ -1,81 +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.strategy.internal; - -import static com.google.common.collect.Iterables.size; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.internal.BaseChefLiveTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code GetNodesImpl} strategies - * - * @author Adrian Cole - */ -@Test(groups = "live", testName = "GetNodesImplLiveTest") -public class GetNodesImplLiveTest extends BaseChefLiveTest<ChefApi> { - - private ListNodesImpl strategy; - private CreateNodeAndPopulateAutomaticAttributesImpl creator; - - @Override - protected void initialize() { - super.initialize(); - this.creator = injector.getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class); - this.strategy = injector.getInstance(ListNodesImpl.class); - creator.execute(prefix, ImmutableSet.<String> of()); - creator.execute(prefix + 1, ImmutableSet.<String> of()); - } - - @AfterClass(groups = { "integration", "live" }) - @Override - protected void tearDown() { - api.deleteNode(prefix); - api.deleteNode(prefix + 1); - super.tearDown(); - } - - @Test - public void testExecute() { - assertTrue(size(strategy.execute()) > 0, "Expected one or more elements"); - } - - @Test - public void testExecutePredicateOfString() { - assertEquals(size(strategy.execute(new Predicate<String>() { - - @Override - public boolean apply(String input) { - return input.startsWith(prefix); - } - - })), 2); - } - - @Test - public void testExecuteIterableOfString() { - assertEquals(size(strategy.execute(ImmutableSet.of(prefix, prefix + 1))), 2); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/test/java/org/jclouds/chef/strategy/internal/ListNodesImplLiveTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/strategy/internal/ListNodesImplLiveTest.java b/core/src/test/java/org/jclouds/chef/strategy/internal/ListNodesImplLiveTest.java new file mode 100644 index 0000000..80b9678 --- /dev/null +++ b/core/src/test/java/org/jclouds/chef/strategy/internal/ListNodesImplLiveTest.java @@ -0,0 +1,81 @@ +/* + * 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.strategy.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.jclouds.chef.ChefApi; +import org.jclouds.chef.internal.BaseChefLiveTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code ListNodesImpl} strategies + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "ListNodesImplLiveTest") +public class ListNodesImplLiveTest extends BaseChefLiveTest<ChefApi> { + + private ListNodesImpl strategy; + private CreateNodeAndPopulateAutomaticAttributesImpl creator; + + @Override + protected void initialize() { + super.initialize(); + this.creator = injector.getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class); + this.strategy = injector.getInstance(ListNodesImpl.class); + creator.execute(prefix, ImmutableSet.<String> of()); + creator.execute(prefix + 1, ImmutableSet.<String> of()); + } + + @AfterClass(groups = { "integration", "live" }) + @Override + protected void tearDown() { + api.deleteNode(prefix); + api.deleteNode(prefix + 1); + super.tearDown(); + } + + @Test + public void testExecute() { + assertTrue(size(strategy.execute()) > 0, "Expected one or more elements"); + } + + @Test + public void testExecutePredicateOfString() { + assertEquals(size(strategy.execute(new Predicate<String>() { + + @Override + public boolean apply(String input) { + return input.startsWith(prefix); + } + + })), 2); + } + + @Test + public void testExecuteIterableOfString() { + assertEquals(size(strategy.execute(ImmutableSet.of(prefix, prefix + 1))), 2); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/c49bec7c/core/src/test/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImplLiveTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImplLiveTest.java b/core/src/test/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImplLiveTest.java new file mode 100644 index 0000000..0d19c12 --- /dev/null +++ b/core/src/test/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImplLiveTest.java @@ -0,0 +1,81 @@ +/* + * 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.strategy.internal; + +import static com.google.common.collect.Iterables.size; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.jclouds.chef.ChefApi; +import org.jclouds.chef.internal.BaseChefLiveTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code ListNodesInEnvironmentImpl} strategies + * + * @author Noorul Islam K M + */ +@Test(groups = "live", testName = "ListNodesInEnvironmentImplLiveTest") +public class ListNodesInEnvironmentImplLiveTest extends BaseChefLiveTest<ChefApi> { + + private ListNodesInEnvironmentImpl strategy; + private CreateNodeAndPopulateAutomaticAttributesImpl creator; + + @Override + protected void initialize() { + super.initialize(); + this.creator = injector.getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class); + this.strategy = injector.getInstance(ListNodesInEnvironmentImpl.class); + creator.execute(prefix, ImmutableSet.<String> of()); + creator.execute(prefix + 1, ImmutableSet.<String> of()); + } + + @AfterClass(groups = { "integration", "live" }) + @Override + protected void tearDown() { + api.deleteNode(prefix); + api.deleteNode(prefix + 1); + super.tearDown(); + } + + @Test + public void testExecute() { + assertTrue(size(strategy.execute("_default")) > 0, "Expected one or more elements"); + } + + @Test + public void testExecutePredicateOfString() { + assertEquals(size(strategy.execute("_default", new Predicate<String>() { + + @Override + public boolean apply(String input) { + return input.startsWith(prefix); + } + + })), 2); + } + + @Test + public void testExecuteIterableOfString() { + assertEquals(size(strategy.execute("_default", ImmutableSet.of(prefix, prefix + 1))), 2); + } + +}
