http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/BasicDownloadsRegistryTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/BasicDownloadsRegistryTest.java b/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/BasicDownloadsRegistryTest.java deleted file mode 100644 index 386c25b..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/BasicDownloadsRegistryTest.java +++ /dev/null @@ -1,155 +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.apache.brooklyn.entity.drivers.downloads; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; - -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolver; -import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Attributes; -import org.apache.brooklyn.entity.core.BrooklynConfigKeys; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.core.SimulatedLocation; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -public class BasicDownloadsRegistryTest { - - private BrooklynProperties brooklynProperties; - private LocalManagementContext managementContext; - private Location loc; - private TestApplication app; - private TestEntity entity; - private MyEntityDriver driver; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - brooklynProperties = BrooklynProperties.Factory.newEmpty(); - managementContext = new LocalManagementContext(brooklynProperties); - loc = new SimulatedLocation(); - app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext); - entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - driver = new MyEntityDriver(entity, loc); - - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (app != null) Entities.destroyAll(app.getManagementContext()); - } - - @Test - public void testUsesDownloadUrlAttribute() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - entity.setAttribute(Attributes.DOWNLOAD_URL, "acme.com/version=${version},type=${type},simpletype=${simpletype}"); - String expectedFilename = String.format("version=%s,type=%s,simpletype=%s", "myversion", TestEntity.class.getName(), "TestEntity"); - - String expectedLocalRepo = String.format("file://$HOME/.brooklyn/repository/%s/%s/%s", "TestEntity", "myversion", expectedFilename); - String expectedDownloadUrl = String.format("acme.com/%s", expectedFilename); - String expectedCloudsoftRepo = String.format("http://downloads.cloudsoftcorp.com/brooklyn/repository/%s/%s/%s", "TestEntity", "myversion", expectedFilename); - assertResolves(expectedLocalRepo, expectedDownloadUrl, expectedCloudsoftRepo); - } - - @Test - public void testUsesDownloadAddonUrlsAttribute() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myentityversion"); - entity.setAttribute(Attributes.DOWNLOAD_ADDON_URLS, ImmutableMap.of("myaddon", "acme.com/addon=${addon},version=${addonversion},type=${type},simpletype=${simpletype}")); - String expectedFilename = String.format("addon=%s,version=%s,type=%s,simpletype=%s", "myaddon", "myaddonversion", TestEntity.class.getName(), "TestEntity"); - - String expectedLocalRepo = String.format("file://$HOME/.brooklyn/repository/%s/%s/%s", "TestEntity", "myentityversion", expectedFilename); - String expectedDownloadUrl = String.format("acme.com/%s", expectedFilename); - String expectedCloudsoftRepo = String.format("http://downloads.cloudsoftcorp.com/brooklyn/repository/%s/%s/%s", "TestEntity", "myentityversion", expectedFilename); - DownloadResolver actual = managementContext.getEntityDownloadsManager().newDownloader(driver, "myaddon", ImmutableMap.of("addonversion", "myaddonversion")); - assertEquals(actual.getTargets(), ImmutableList.of(expectedLocalRepo, expectedDownloadUrl, expectedCloudsoftRepo), "actual="+actual); - } - - @Test - public void testDefaultResolverSubstitutesDownloadUrlFailsIfVersionMissing() throws Exception { - entity.setAttribute(Attributes.DOWNLOAD_URL, "version=${version}"); - try { - DownloadResolver result = managementContext.getEntityDownloadsManager().newDownloader(driver); - fail("Should have failed, but got "+result); - } catch (IllegalArgumentException e) { - if (!e.toString().contains("${version}")) throw e; - } - } - - @Test - public void testReturnsLocalRepoThenOverrideThenAttributeValThenCloudsoftUrlThenFallback() throws Exception { - BrooklynProperties managementProperties = managementContext.getBrooklynProperties(); - managementProperties.put("brooklyn.downloads.all.url", "http://fromprops/${version}.allprimary"); - managementProperties.put("brooklyn.downloads.all.fallbackurl", "http://fromfallback/${version}.allfallback"); - entity.setAttribute(Attributes.DOWNLOAD_URL, "http://fromattrib/${version}.default"); - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - String expectedFilename = "myversion.allprimary"; - - String expectedLocalRepo = String.format("file://$HOME/.brooklyn/repository/%s/%s/%s", "TestEntity", "myversion", expectedFilename); - String expectedDownloadUrl = String.format("http://fromattrib/%s", "myversion.default"); - String expectedCloudsoftRepo = String.format("http://downloads.cloudsoftcorp.com/brooklyn/repository/%s/%s/%s", "TestEntity", "myversion", expectedFilename); - assertResolves( - expectedLocalRepo, - "http://fromprops/myversion.allprimary", - expectedDownloadUrl, - expectedCloudsoftRepo, - "http://fromfallback/myversion.allfallback"); - } - - @Test - public void testInfersFilenameFromDownloadUrl() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - entity.setAttribute(Attributes.DOWNLOAD_URL, "http://myhost.com/myfile-${version}.tar.gz"); - - DownloadResolver actual = managementContext.getEntityDownloadsManager().newDownloader(driver); - assertEquals(actual.getFilename(), "myfile-myversion.tar.gz"); - } - - @Test - public void testInfersAddonFilenameFromDownloadUrl() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - entity.setAttribute(Attributes.DOWNLOAD_ADDON_URLS, ImmutableMap.of("myaddon", "http://myhost.com/myfile-${addonversion}.tar.gz")); - - DownloadResolver actual = managementContext.getEntityDownloadsManager().newDownloader(driver, "myaddon", ImmutableMap.of("addonversion", "myaddonversion")); - assertEquals(actual.getFilename(), "myfile-myaddonversion.tar.gz"); - } - - @Test - public void testCanOverrideFilenameFromDownloadUrl() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - entity.setAttribute(Attributes.DOWNLOAD_URL, "http://myhost.com/download/"); - - DownloadResolver actual = managementContext.getEntityDownloadsManager().newDownloader(driver, ImmutableMap.of("filename", "overridden.filename.tar.gz")); - assertEquals(actual.getFilename(), "overridden.filename.tar.gz"); - } - - private void assertResolves(String... expected) { - DownloadResolver actual = managementContext.getEntityDownloadsManager().newDownloader(driver); - assertEquals(actual.getTargets(), ImmutableList.copyOf(expected), "actual="+actual); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadProducerFromLocalRepoTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadProducerFromLocalRepoTest.java b/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadProducerFromLocalRepoTest.java deleted file mode 100644 index 5e114d4..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadProducerFromLocalRepoTest.java +++ /dev/null @@ -1,130 +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.apache.brooklyn.entity.drivers.downloads; - -import static org.testng.Assert.assertEquals; - -import java.util.List; - -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolverManager.DownloadRequirement; -import org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolverManager.DownloadTargets; -import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.BrooklynConfigKeys; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.drivers.downloads.BasicDownloadRequirement; -import org.apache.brooklyn.entity.drivers.downloads.DownloadProducerFromLocalRepo; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.core.SimulatedLocation; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -public class DownloadProducerFromLocalRepoTest { - - private BrooklynProperties brooklynProperties; - private LocalManagementContext managementContext; - private Location loc; - private TestApplication app; - private TestEntity entity; - private MyEntityDriver driver; - private String entitySimpleType; - private DownloadProducerFromLocalRepo resolver; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - brooklynProperties = BrooklynProperties.Factory.newEmpty(); - managementContext = new LocalManagementContext(brooklynProperties); - - loc = new SimulatedLocation(); - app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext); - entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - driver = new MyEntityDriver(entity, loc); - entitySimpleType = TestEntity.class.getSimpleName(); - - resolver = new DownloadProducerFromLocalRepo(brooklynProperties); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (app != null) Entities.destroyAll(app.getManagementContext()); - } - - @Test - public void testReturnsEmptyWhenDisabled() throws Exception { - brooklynProperties.put(DownloadProducerFromLocalRepo.LOCAL_REPO_ENABLED, false); - assertResolves(ImmutableList.<String>of(), ImmutableList.<String>of()); - } - - @Test - public void testReturnsDefault() throws Exception { - // uses default of ${simpletype}-${version}.tar.gz"; - String entityVersion = "myversion"; - String downloadFilename = (entitySimpleType+"-"+entityVersion+".tar.gz").toLowerCase(); - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, entityVersion); - assertResolves(String.format("file://$HOME/.brooklyn/repository/%s/%s/%s", entitySimpleType, entityVersion, downloadFilename)); - } - - @Test - public void testReturnsFilenameFromDriver() throws Exception { - String entityVersion = "myversion"; - String filename = "my.file.name"; - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, entityVersion); - - BasicDownloadRequirement req = new BasicDownloadRequirement(driver, ImmutableMap.of("filename", filename)); - assertResolves(req, String.format("file://$HOME/.brooklyn/repository/%s/%s/%s", entitySimpleType, entityVersion, filename)); - } - - @Test - public void testReturnsFileSuffixFromRequirements() throws Exception { - // uses ${driver.downloadFileSuffix} - String entityVersion = "myversion"; - String fileSuffix = "mysuffix"; - String expectedFilename = (entitySimpleType+"-"+entityVersion+"."+fileSuffix).toLowerCase(); - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, entityVersion); - - BasicDownloadRequirement req = new BasicDownloadRequirement(driver, ImmutableMap.of("fileSuffix", fileSuffix)); - assertResolves(req, String.format("file://$HOME/.brooklyn/repository/%s/%s/%s", entitySimpleType, entityVersion, expectedFilename)); - } - - private void assertResolves(String... expected) { - assertResolves(ImmutableList.copyOf(expected), ImmutableList.<String>of()); - } - - private void assertResolves(List<String> expectedPrimaries, List<String> expectedFallbacks) { - assertResolves(new BasicDownloadRequirement(driver), expectedPrimaries, expectedFallbacks); - } - - private void assertResolves(DownloadRequirement req, String... expected) { - assertResolves(req, ImmutableList.copyOf(expected), ImmutableList.<String>of()); - } - - private void assertResolves(DownloadRequirement req, List<String> expectedPrimaries, List<String> expectedFallbacks) { - DownloadTargets actual = resolver.apply(req); - assertEquals(actual.getPrimaryLocations(), expectedPrimaries); - assertEquals(actual.getFallbackLocations(), expectedFallbacks); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadProducerFromPropertiesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadProducerFromPropertiesTest.java b/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadProducerFromPropertiesTest.java deleted file mode 100644 index 15b35e3..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadProducerFromPropertiesTest.java +++ /dev/null @@ -1,162 +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.apache.brooklyn.entity.drivers.downloads; - -import static org.testng.Assert.assertEquals; - -import java.util.List; - -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolverManager.DownloadRequirement; -import org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolverManager.DownloadTargets; -import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.BrooklynConfigKeys; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.drivers.downloads.BasicDownloadRequirement; -import org.apache.brooklyn.entity.drivers.downloads.DownloadProducerFromLocalRepo; -import org.apache.brooklyn.entity.drivers.downloads.DownloadProducerFromProperties; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.core.SimulatedLocation; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -public class DownloadProducerFromPropertiesTest { - - private BrooklynProperties brooklynProperties; - private LocalManagementContext managementContext; - private Location loc; - private TestApplication app; - private TestEntity entity; - private MyEntityDriver driver; - private DownloadProducerFromProperties resolver; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - brooklynProperties = BrooklynProperties.Factory.newEmpty(); - brooklynProperties.put(DownloadProducerFromLocalRepo.LOCAL_REPO_ENABLED, false); - managementContext = new LocalManagementContext(brooklynProperties); - - loc = new SimulatedLocation(); - app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext); - entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - driver = new MyEntityDriver(entity, loc); - - resolver = new DownloadProducerFromProperties(brooklynProperties); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (app != null) Entities.destroyAll(app.getManagementContext()); - } - - @Test - public void testReturnsEmptyWhenEmpty() throws Exception { - assertResolves(ImmutableList.<String>of(), ImmutableList.<String>of()); - } - - @Test - public void testReturnsGlobalUrl() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.url", "myurl"); - assertResolves("myurl"); - } - - @Test - public void testReturnsGlobalUrlsSplitOnSemicolon() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.url", "myurl; myurl2"); - assertResolves("myurl", "myurl2"); - } - - @Test - public void testReturnsGlobalFallbackUrl() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.fallbackurl", "myurl"); - assertResolves(ImmutableList.<String>of(), ImmutableList.of("myurl")); - } - - @Test - public void testSubstitutionsAppliedToFallbackUrl() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.fallbackurl", "version=${version}"); - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - assertResolves(ImmutableList.<String>of(), ImmutableList.of("version=myversion")); - } - - @Test - public void testReturnsGlobalFallbackUrlAsLast() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.url", "myurl"); - brooklynProperties.put("brooklyn.downloads.all.fallbackurl", "myurl2"); - assertResolves(ImmutableList.of("myurl"), ImmutableList.of("myurl2")); - } - - @Test - public void testReturnsGlobalUrlWithEntitySubstituions() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.url", "version=${version}"); - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - assertResolves("version=myversion"); - } - - @Test - public void testEntitySpecificUrlOverridesGlobalUrl() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.url", "version=${version}"); - brooklynProperties.put("brooklyn.downloads.entity.TestEntity.url", "overridden,version=${version}"); - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - assertResolves("overridden,version=myversion", "version=myversion"); - } - - @Test - public void testEntitySpecificAddonUsesGlobalUrl() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.url", "version=${version}"); - - DownloadRequirement req = new BasicDownloadRequirement(driver, "myaddon", ImmutableMap.of("version", "myversion")); - assertResolves(req, ImmutableList.of("version=myversion"), ImmutableList.<String>of()); - } - - @Test - public void testEntitySpecificAddonOverridesGlobalUrl() throws Exception { - brooklynProperties.put("brooklyn.downloads.all.url", "${addon}-${version}"); - brooklynProperties.put("brooklyn.downloads.entity.TestEntity.addon.myaddon.url", "overridden,${addon}-${version}"); - - DownloadRequirement req = new BasicDownloadRequirement(driver, "myaddon", ImmutableMap.of("version", "myversion")); - assertResolves(req, ImmutableList.of("overridden,myaddon-myversion", "myaddon-myversion"), ImmutableList.<String>of()); - } - - private void assertResolves(String... expected) { - assertResolves(ImmutableList.copyOf(expected), ImmutableList.<String>of()); - } - - private void assertResolves(List<String> expectedPrimaries, List<String> expectedFallbacks) { - assertResolves(new BasicDownloadRequirement(driver), expectedPrimaries, expectedFallbacks); - } - - private void assertResolves(DownloadRequirement req, String... expected) { - assertResolves(req, ImmutableList.copyOf(expected), ImmutableList.<String>of()); - } - - private void assertResolves(DownloadRequirement req, List<String> expectedPrimaries, List<String> expectedFallbacks) { - DownloadTargets actual = resolver.apply(req); - assertEquals(actual.getPrimaryLocations(), expectedPrimaries, "actual="+actual); - assertEquals(actual.getFallbackLocations(), expectedFallbacks, "actual="+actual); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java b/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java deleted file mode 100644 index 7b75f48..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/DownloadSubstitutersTest.java +++ /dev/null @@ -1,131 +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.apache.brooklyn.entity.drivers.downloads; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; - -import java.util.Map; - -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.entity.drivers.downloads.DownloadResolverManager.DownloadTargets; -import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.BrooklynConfigKeys; -import org.apache.brooklyn.entity.drivers.downloads.BasicDownloadRequirement; -import org.apache.brooklyn.entity.drivers.downloads.DownloadSubstituters; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.core.SimulatedLocation; - -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -public class DownloadSubstitutersTest extends BrooklynAppUnitTestSupport { - - private Location loc; - private TestEntity entity; - private MyEntityDriver driver; - - @BeforeMethod(alwaysRun=true) - @Override - public void setUp() throws Exception { - super.setUp(); - loc = new SimulatedLocation(); - entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - driver = new MyEntityDriver(entity, loc); - } - - @Test - public void testSimpleSubstitution() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - String pattern = "mykey1=${mykey1},mykey2=${mykey2}"; - String result = DownloadSubstituters.substitute(pattern, ImmutableMap.of("mykey1", "myval1", "mykey2", "myval2")); - assertEquals(result, "mykey1=myval1,mykey2=myval2"); - } - - @Test - public void testSubstitutionIncludesDefaultSubs() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - String pattern = "version=${version},type=${type},simpletype=${simpletype}"; - BasicDownloadRequirement req = new BasicDownloadRequirement(driver); - String result = DownloadSubstituters.substitute(req, pattern); - assertEquals(result, String.format("version=%s,type=%s,simpletype=%s", "myversion", TestEntity.class.getName(), TestEntity.class.getSimpleName())); - } - - @Test - public void testSubstitutionDoesMultipleMatches() throws Exception { - String simpleType = TestEntity.class.getSimpleName(); - String pattern = "simpletype=${simpletype},simpletype=${simpletype}"; - BasicDownloadRequirement req = new BasicDownloadRequirement(driver); - String result = DownloadSubstituters.substitute(req, pattern); - assertEquals(result, String.format("simpletype=%s,simpletype=%s", simpleType, simpleType)); - } - - @Test - public void testSubstitutionUsesEntityBean() throws Exception { - String entityid = entity.getId(); - String pattern = "id=${entity.id}"; - BasicDownloadRequirement req = new BasicDownloadRequirement(driver); - String result = DownloadSubstituters.substitute(req, pattern); - assertEquals(result, String.format("id=%s", entityid)); - } - - @Test - public void testSubstitutionUsesDriverBean() throws Exception { - String entityid = entity.getId(); - String pattern = "id=${driver.entity.id}"; - BasicDownloadRequirement req = new BasicDownloadRequirement(driver); - String result = DownloadSubstituters.substitute(req, pattern); - assertEquals(result, String.format("id=%s", entityid)); - } - - @Test - public void testSubstitutionUsesOverrides() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - String pattern = "version=${version},mykey1=${mykey1}"; - BasicDownloadRequirement req = new BasicDownloadRequirement(driver, ImmutableMap.of("version", "overriddenversion", "mykey1", "myval1")); - String result = DownloadSubstituters.substitute(req, pattern); - assertEquals(result, "version=overriddenversion,mykey1=myval1"); - } - - @Test - public void testThrowsIfUnmatchedSubstitutions() throws Exception { - String pattern = "nothere=${nothere}"; - BasicDownloadRequirement req = new BasicDownloadRequirement(driver); - try { - String result = DownloadSubstituters.substitute(req, pattern); - fail("Should have failed, but got "+result); - } catch (IllegalArgumentException e) { - if (!e.toString().contains("${nothere}")) throw e; - } - } - - @Test - public void testSubstituter() throws Exception { - entity.setConfig(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); - String baseurl = "version=${version},type=${type},simpletype=${simpletype}"; - Map<String,Object> subs = DownloadSubstituters.getBasicEntitySubstitutions(driver); - DownloadTargets result = DownloadSubstituters.substituter(Functions.constant(baseurl), Functions.constant(subs)).apply(new BasicDownloadRequirement(driver)); - String expected = String.format("version=%s,type=%s,simpletype=%s", "myversion", TestEntity.class.getName(), TestEntity.class.getSimpleName()); - assertEquals(result.getPrimaryLocations(), ImmutableList.of(expected)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/FilenameProducersTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/FilenameProducersTest.java b/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/FilenameProducersTest.java deleted file mode 100644 index da1ecf9..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/FilenameProducersTest.java +++ /dev/null @@ -1,34 +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.apache.brooklyn.entity.drivers.downloads; - -import static org.testng.Assert.assertEquals; - -import org.apache.brooklyn.entity.drivers.downloads.FilenameProducers; -import org.testng.annotations.Test; - -public class FilenameProducersTest { - - @Test - public void testInferFilename() throws Exception { - assertEquals(FilenameProducers.inferFilename("myname.tgz"), "myname.tgz"); - assertEquals(FilenameProducers.inferFilename("a/myname.tgz"), "myname.tgz"); - assertEquals(FilenameProducers.inferFilename("acme.com/download/"), null); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/MyEntityDriver.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/MyEntityDriver.java b/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/MyEntityDriver.java deleted file mode 100644 index 75e62f0..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/drivers/downloads/MyEntityDriver.java +++ /dev/null @@ -1,44 +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.apache.brooklyn.entity.drivers.downloads; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntityLocal; -import org.apache.brooklyn.api.entity.drivers.EntityDriver; -import org.apache.brooklyn.api.location.Location; - -public class MyEntityDriver implements EntityDriver { - private final Entity entity; - private final Location location; - - MyEntityDriver(Entity entity, Location location) { - this.entity = entity; - this.location = location; - } - - @Override - public EntityLocal getEntity() { - return (EntityLocal) entity; - } - - @Override - public Location getLocation() { - return location; - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java index 40dd6dd..5097a45 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java @@ -47,22 +47,22 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.mgmt.Task; import org.apache.brooklyn.api.sensor.SensorEvent; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.RecordingSensorEventListener; +import org.apache.brooklyn.core.entity.factory.EntityFactory; +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; +import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic; +import org.apache.brooklyn.core.entity.trait.Changeable; +import org.apache.brooklyn.core.entity.trait.FailingEntity; import org.apache.brooklyn.core.mgmt.BrooklynTaskTags; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestEntity; import org.apache.brooklyn.core.test.entity.TestEntityImpl; -import org.apache.brooklyn.entity.core.Attributes; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.RecordingSensorEventListener; -import org.apache.brooklyn.entity.factory.EntityFactory; import org.apache.brooklyn.entity.group.DynamicCluster; import org.apache.brooklyn.entity.group.QuarantineGroup; import org.apache.brooklyn.entity.group.StopFailedRuntimeException; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; import org.apache.brooklyn.entity.stock.BasicEntity; -import org.apache.brooklyn.entity.trait.Changeable; -import org.apache.brooklyn.entity.trait.FailingEntity; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.test.EntityTestUtils; import org.apache.brooklyn.util.collections.MutableMap; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java index 7d26e6c..47118e8 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterWithAvailabilityZonesTest.java @@ -34,12 +34,12 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.mgmt.ManagementContext; +import org.apache.brooklyn.core.entity.EntityPredicates; +import org.apache.brooklyn.core.entity.trait.FailingEntity; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.EntityPredicates; import org.apache.brooklyn.entity.group.DynamicCluster; import org.apache.brooklyn.entity.group.zoneaware.ProportionalZoneFailureDetector; -import org.apache.brooklyn.entity.trait.FailingEntity; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.util.time.Duration; import org.testng.annotations.BeforeMethod; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java index c5000ce..254fd03 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java @@ -36,14 +36,14 @@ import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.factory.EntityFactory; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.BlockingEntity; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Attributes; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.factory.EntityFactory; import org.apache.brooklyn.entity.stock.BasicEntity; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.location.core.PortRanges; import org.apache.brooklyn.location.core.SimulatedLocation; import org.apache.brooklyn.test.Asserts; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java index 553f0e0..7c43835 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicGroupTest.java @@ -39,11 +39,11 @@ import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.api.sensor.Sensor; import org.apache.brooklyn.api.sensor.SensorEvent; import org.apache.brooklyn.api.sensor.SensorEventListener; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.EntityPredicates; import org.apache.brooklyn.core.test.entity.TestApplication; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.EntityPredicates; import org.apache.brooklyn.entity.group.AbstractGroup; import org.apache.brooklyn.entity.group.DynamicGroup; import org.apache.brooklyn.entity.group.DynamicGroupImpl; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java index c914d98..0783db4 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicMultiGroupTest.java @@ -20,7 +20,7 @@ package org.apache.brooklyn.entity.group; import static com.google.common.base.Predicates.instanceOf; import static com.google.common.collect.Iterables.find; -import static org.apache.brooklyn.entity.core.EntityPredicates.displayNameEqualTo; +import static org.apache.brooklyn.core.entity.EntityPredicates.displayNameEqualTo; import static org.apache.brooklyn.entity.group.DynamicGroup.ENTITY_FILTER; import static org.apache.brooklyn.entity.group.DynamicMultiGroup.BUCKET_FUNCTION; import static org.apache.brooklyn.entity.group.DynamicMultiGroup.RESCAN_INTERVAL; @@ -34,11 +34,11 @@ import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.api.sensor.SensorEvent; import org.apache.brooklyn.api.sensor.SensorEventListener; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.factory.ApplicationBuilder; import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; import org.apache.brooklyn.core.test.entity.TestApplication; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.factory.ApplicationBuilder; import org.apache.brooklyn.entity.group.BasicGroup; import org.apache.brooklyn.entity.group.DynamicMultiGroup; import org.apache.brooklyn.sensor.core.Sensors; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java index 8ff76c2..f0ec721 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/GroupPickUpEntitiesTest.java @@ -25,12 +25,12 @@ import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.api.policy.PolicySpec; import org.apache.brooklyn.api.sensor.SensorEvent; import org.apache.brooklyn.api.sensor.SensorEventListener; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.EntityInternal; import org.apache.brooklyn.entity.group.BasicGroup; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.policy.core.AbstractPolicy; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.test.EntityTestUtils; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java index bf0a529..1ad81e6 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/GroupTest.java @@ -24,11 +24,11 @@ import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.api.location.LocationSpec; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.RecordingSensorEventListener; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.RecordingSensorEventListener; import org.apache.brooklyn.entity.group.BasicGroup; import org.apache.brooklyn.test.Asserts; import org.testng.annotations.BeforeMethod; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java index 4e3b346..88e2a36 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/MembershipTrackingPolicyTest.java @@ -31,12 +31,12 @@ import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.mgmt.EntityManager; import org.apache.brooklyn.api.policy.PolicySpec; import org.apache.brooklyn.api.sensor.Sensor; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Entities; import org.apache.brooklyn.entity.group.AbstractMembershipTrackingPolicy; import org.apache.brooklyn.entity.group.BasicGroup; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.test.Asserts; import org.apache.brooklyn.util.collections.MutableMap; import org.testng.annotations.BeforeMethod; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java index e85ce29..adcb5f8 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/QuarantineGroupTest.java @@ -23,9 +23,9 @@ import static org.testng.Assert.assertFalse; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.LocationSpec; +import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.core.Entities; import org.apache.brooklyn.entity.group.QuarantineGroup; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/hello/HelloEntity.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/hello/HelloEntity.java b/core/src/test/java/org/apache/brooklyn/entity/hello/HelloEntity.java deleted file mode 100644 index 4aed7fb..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/hello/HelloEntity.java +++ /dev/null @@ -1,53 +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.apache.brooklyn.entity.hello; - -import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.api.sensor.Sensor; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.effector.core.MethodEffector; -import org.apache.brooklyn.entity.annotation.Effector; -import org.apache.brooklyn.entity.annotation.EffectorParam; -import org.apache.brooklyn.entity.group.AbstractGroup; -import org.apache.brooklyn.sensor.core.BasicSensor; -import org.apache.brooklyn.sensor.core.Sensors; - -@ImplementedBy(HelloEntityImpl.class) -public interface HelloEntity extends AbstractGroup { - - /** records name of the person represented by this entity */ - public static ConfigKey<String> MY_NAME = ConfigKeys.newStringConfigKey("my.name"); - - /** this "person"'s favourite name */ - public static AttributeSensor<String> FAVOURITE_NAME = Sensors.newStringSensor("my.favourite.name"); - - /** records age (in years) of the person represented by this entity */ - public static AttributeSensor<Integer> AGE = Sensors.newIntegerSensor("my.age"); - - /** emits a "birthday" event whenever age is changed (tests non-attribute events) */ - public static Sensor<Void> ITS_MY_BIRTHDAY = new BasicSensor<Void>(Void.TYPE, "my.birthday"); - - /** */ - public static MethodEffector<Void> SET_AGE = new MethodEffector<Void>(HelloEntity.class, "setAge"); - - @Effector(description="allows setting the age") - public void setAge(@EffectorParam(name="age") Integer age); -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/hello/HelloEntityImpl.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/hello/HelloEntityImpl.java b/core/src/test/java/org/apache/brooklyn/entity/hello/HelloEntityImpl.java deleted file mode 100644 index 512a7f8..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/hello/HelloEntityImpl.java +++ /dev/null @@ -1,31 +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.apache.brooklyn.entity.hello; - -import org.apache.brooklyn.entity.group.AbstractGroupImpl; - - -public class HelloEntityImpl extends AbstractGroupImpl implements HelloEntity { - - @Override - public void setAge(Integer age) { - setAttribute(AGE, age); - emit(ITS_MY_BIRTHDAY, null); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/hello/LocalEntitiesTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/hello/LocalEntitiesTest.java b/core/src/test/java/org/apache/brooklyn/entity/hello/LocalEntitiesTest.java deleted file mode 100644 index c8ec519..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/hello/LocalEntitiesTest.java +++ /dev/null @@ -1,282 +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.apache.brooklyn.entity.hello; - -import static org.apache.brooklyn.sensor.core.DependentConfiguration.attributeWhenReady; -import static org.apache.brooklyn.sensor.core.DependentConfiguration.transform; -import static org.testng.Assert.assertEquals; -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 groovy.lang.Closure; - -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.brooklyn.api.entity.EntityLocal; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.mgmt.EntityManager; -import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.api.sensor.SensorEvent; -import org.apache.brooklyn.api.sensor.SensorEventListener; -import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.EntityInternal; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.testng.collections.Lists; -import org.apache.brooklyn.location.core.SimulatedLocation; -import org.apache.brooklyn.test.Asserts; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.time.Time; - -import com.google.common.base.Function; -import com.google.common.base.Predicates; -import com.google.common.base.Stopwatch; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -/** tests effector invocation and a variety of sensor accessors and subscribers */ -public class LocalEntitiesTest extends BrooklynAppUnitTestSupport { - - public static final Logger log = LoggerFactory.getLogger(LocalEntitiesTest.class); - - private SimulatedLocation loc; - private EntityManager entityManager; - - @BeforeMethod(alwaysRun=true) - @Override - public void setUp() throws Exception { - super.setUp(); - loc = new SimulatedLocation(); - entityManager = mgmt.getEntityManager(); - } - - @Test - public void testEffectorUpdatesAttributeSensor() { - HelloEntity h = app.createAndManageChild(EntitySpec.create(HelloEntity.class)); - app.start(ImmutableList.of(loc)); - - h.setAge(5); - assertEquals((Integer)5, h.getAttribute(HelloEntity.AGE)); - } - - //REVIEW 1459 - new test - //subscriptions get notified in separate thread - @Test - public void testEffectorEmitsAttributeSensor() throws Exception { - final HelloEntity h = app.createAndManageChild(EntitySpec.create(HelloEntity.class)); - app.start(ImmutableList.of(loc)); - - final AtomicReference<SensorEvent<?>> evt = new AtomicReference<SensorEvent<?>>(); - final CountDownLatch latch = new CountDownLatch(1); - - app.getSubscriptionContext().subscribe(h, HelloEntity.AGE, new SensorEventListener<Integer>() { - @Override public void onEvent(SensorEvent<Integer> event) { - evt.set(event); - latch.countDown(); - }}); - - long startTime = System.currentTimeMillis(); - - h.invoke(HelloEntity.SET_AGE, ImmutableMap.of("age", 5)); - assertTrue(latch.await(5000, TimeUnit.MILLISECONDS)); - - // observed intermittent failure 2 May 2012. and 14 Jun "after 2 ms". spurious wakeups. - // code added above to guard against this. (if problem does not recur, remove these comments!) - assertNotNull(evt.get(), "null response after "+(System.currentTimeMillis()-startTime)+" ms"); - assertEquals(HelloEntity.AGE, evt.get().getSensor()); - assertEquals(h, evt.get().getSource()); - assertEquals(5, evt.get().getValue()); - assertTrue(System.currentTimeMillis() - startTime < 5000); //shouldn't have blocked for all 5s - } - - //REVIEW 1459 - new test - @Test - public void testEffectorEmitsTransientSensor() throws Exception { - HelloEntity h = app.createAndManageChild(EntitySpec.create(HelloEntity.class)); - app.start(ImmutableList.of(loc)); - - final AtomicReference<SensorEvent<?>> evt = new AtomicReference<SensorEvent<?>>(); - app.getSubscriptionContext().subscribe(h, HelloEntity.ITS_MY_BIRTHDAY, new SensorEventListener<Object>() { - @Override public void onEvent(SensorEvent<Object> event) { - evt.set(event); - synchronized (evt) { - evt.notifyAll(); - } - }}); - - long startTime = System.currentTimeMillis(); - synchronized (evt) { - h.setAge(5); - evt.wait(5000); - } - assertNotNull(evt.get()); - assertEquals(HelloEntity.ITS_MY_BIRTHDAY, evt.get().getSensor()); - assertEquals(h, evt.get().getSource()); - assertNull(evt.get().getValue()); - assertTrue(System.currentTimeMillis() - startTime < 5000); //shouldn't have blocked for all 5s - } - - @Test - public void testSendMultipleInOrderThenUnsubscribe() throws Exception { - HelloEntity h = app.createAndManageChild(EntitySpec.create(HelloEntity.class)); - app.start(ImmutableList.of(loc)); - - final List<Integer> data = Lists.newArrayList(); - final CountDownLatch latch = new CountDownLatch(5); - - app.getSubscriptionContext().subscribe(h, HelloEntity.AGE, new SensorEventListener<Integer>() { - @Override public void onEvent(SensorEvent<Integer> event) { - data.add(event.getValue()); - Time.sleep((int)(20*Math.random())); - log.info("Thread "+Thread.currentThread()+" notify on subscription received for "+event.getValue()+", data is "+data); - latch.countDown(); - }}); - - Stopwatch stopwatch = Stopwatch.createStarted(); - for (int i = 1; i <= 5; i++) { - h.setAge(i); - } - assertTrue(latch.await(5000, TimeUnit.MILLISECONDS)); - - app.getSubscriptionContext().unsubscribeAll(); - h.setAge(6); - long totalTime = stopwatch.elapsed(TimeUnit.MILLISECONDS); - - // TODO guava util for (1..5) - Asserts.continually(MutableMap.of("timeout", 50), Suppliers.ofInstance(data), Predicates.<Object>equalTo(ImmutableList.of(1,2,3,4,5))); - assertTrue(totalTime < 2000, "totalTime="+totalTime); //shouldn't have blocked for anywhere close to 2s (Aled says TODO: too time sensitive for BuildHive?) - } - - @Test - public void testConfigSetFromAttribute() { - app.setConfig(HelloEntity.MY_NAME, "Bob"); - - HelloEntity dad = app.createAndManageChild(EntitySpec.create(HelloEntity.class)); - HelloEntity son = entityManager.createEntity(EntitySpec.create(HelloEntity.class).parent(dad)); - Entities.manage(son); - - //config is inherited - assertEquals("Bob", app.getConfig(HelloEntity.MY_NAME)); - assertEquals("Bob", dad.getConfig(HelloEntity.MY_NAME)); - assertEquals("Bob", son.getConfig(HelloEntity.MY_NAME)); - - //attributes are not - app.setAttribute(HelloEntity.FAVOURITE_NAME, "Carl"); - assertEquals("Carl", app.getAttribute(HelloEntity.FAVOURITE_NAME)); - assertEquals(null, dad.getAttribute(HelloEntity.FAVOURITE_NAME)); - } - @Test - public void testConfigSetFromAttributeWhenReady() throws Exception { - app.setConfig(HelloEntity.MY_NAME, "Bob"); - - final HelloEntity dad = app.createAndManageChild(EntitySpec.create(HelloEntity.class)); - final HelloEntity son = entityManager.createEntity(EntitySpec.create(HelloEntity.class) - .parent(dad) - .configure(HelloEntity.MY_NAME, attributeWhenReady(dad, HelloEntity.FAVOURITE_NAME - /* third param is closure; defaults to groovy truth (see google), but could be e.g. - , { it!=null && it.length()>0 && it!="Jebediah" } - */ ))); - Entities.manage(son); - - app.start(ImmutableList.of(loc)); - - final Semaphore s1 = new Semaphore(0); - final Object[] sonsConfig = new Object[1]; - Thread t = new Thread(new Runnable() { - public void run() { - log.info("started"); - s1.release(); - log.info("getting config "+sonsConfig[0]); - sonsConfig[0] = son.getConfig(HelloEntity.MY_NAME); - log.info("got config {}", sonsConfig[0]); - s1.release(); - }}); - - log.info("starting"); - long startTime = System.currentTimeMillis(); - t.start(); - log.info("waiting {}", System.identityHashCode(sonsConfig)); - if (!s1.tryAcquire(2, TimeUnit.SECONDS)) fail("race mismatch, missing permits"); - - //thread should be blocking on call to getConfig - assertTrue(t.isAlive()); - assertTrue(System.currentTimeMillis() - startTime < 1500); - synchronized (sonsConfig) { - assertEquals(null, sonsConfig[0]); - for (Task tt : ((EntityInternal)dad).getExecutionContext().getTasks()) { log.info("task at dad: {}, {}", tt, tt.getStatusDetail(false)); } - for (Task tt : ((EntityInternal)son).getExecutionContext().getTasks()) { log.info("task at son: {}, {}", tt, tt.getStatusDetail(false)); } - ((EntityLocal)dad).setAttribute(HelloEntity.FAVOURITE_NAME, "Dan"); - if (!s1.tryAcquire(2, TimeUnit.SECONDS)) fail("race mismatch, missing permits"); - } - log.info("dad: "+dad.getAttribute(HelloEntity.FAVOURITE_NAME)); - log.info("son: "+son.getConfig(HelloEntity.MY_NAME)); - - //shouldn't have blocked for very long at all - assertTrue(System.currentTimeMillis() - startTime < 1500); - //and sons config should now pick up the dad's attribute - assertEquals(sonsConfig[0], "Dan"); - } - - @Test - public void testConfigSetFromAttributeWhenReadyTransformations() { - app.setConfig(HelloEntity.MY_NAME, "Bob"); - - HelloEntity dad = app.createAndManageChild(EntitySpec.create(HelloEntity.class)); - HelloEntity son = entityManager.createEntity(EntitySpec.create(HelloEntity.class) - .parent(dad) - .configure(HelloEntity.MY_NAME, transform(attributeWhenReady(dad, HelloEntity.FAVOURITE_NAME), new Function<String,String>() { - public String apply(String input) { - return input+input.charAt(input.length()-1)+"y"; - }}))); - Entities.manage(son); - - app.start(ImmutableList.of(loc)); - ((EntityLocal)dad).setAttribute(HelloEntity.FAVOURITE_NAME, "Dan"); - assertEquals(son.getConfig(HelloEntity.MY_NAME), "Danny"); - } - - @Test - public void testConfigSetFromAttributeWhenReadyNullTransformations() { - app.setConfig(HelloEntity.MY_NAME, "Bob"); - - HelloEntity dad = app.createAndManageChild(EntitySpec.create(HelloEntity.class)); - // the unnecessary (HelloEntity) cast is required as a work-around to an IntelliJ issue that prevents Brooklyn from launching from the IDE - HelloEntity son = (HelloEntity)entityManager.createEntity(EntitySpec.create(HelloEntity.class) - .parent(dad) - .configure(HelloEntity.MY_NAME, transform(attributeWhenReady(dad, HelloEntity.FAVOURITE_NAME, (Closure)null), new Function<String,String>() { - public String apply(String input) { - return input+input.charAt(input.length()-1)+"y"; - }}))); - Entities.manage(son); - - app.start(ImmutableList.of(loc)); - ((EntityLocal)dad).setAttribute(HelloEntity.FAVOURITE_NAME, "Dan"); - assertEquals(son.getConfig(HelloEntity.MY_NAME), "Danny"); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/test/java/org/apache/brooklyn/entity/lifecycle/LifecycleTransitionTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/lifecycle/LifecycleTransitionTest.java b/core/src/test/java/org/apache/brooklyn/entity/lifecycle/LifecycleTransitionTest.java deleted file mode 100644 index c1263f0..0000000 --- a/core/src/test/java/org/apache/brooklyn/entity/lifecycle/LifecycleTransitionTest.java +++ /dev/null @@ -1,51 +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.apache.brooklyn.entity.lifecycle; - -import static org.testng.Assert.assertTrue; - -import java.util.Date; - -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.lifecycle.Lifecycle.Transition; -import org.apache.brooklyn.entity.lifecycle.Lifecycle.TransitionCoalesceFunction; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -public class LifecycleTransitionTest { - @DataProvider(name = "states") - public Object[][] generateLifecycleStates() { - Object[][] states = new Object[Lifecycle.values().length][]; - int i = 0; - for (Lifecycle state : Lifecycle.values()) { - System.out.println(":" + state); - states[i] = new Object[] {state}; - i++; - } - return states; - } - - @Test(dataProvider="states") - public void testTransitionCoalesce(Lifecycle state) { - Transition t = new Transition(state, new Date()); - String serialized = t.toString(); - Transition t2 = new TransitionCoalesceFunction().apply(serialized); - assertTrue(t.equals(t2), "Deserialized Lifecycle.Transition not equal to original"); - } -}
