package jetbrains.buildServer.eclipse.tests; import java.io.File; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.eclipse.java.PlatformDescriptor; import jetbrains.buildServer.eclipse.java.PlatformDescriptor.IFeatureDescriptor; import jetbrains.buildServer.eclipse.tests.helper.EclipseBuilderFactoryTestAdapter; import org.junit.Assert; import org.junit.Test; public class FeatureDescriptorTests extends AbstractEclipseBuilderTest { @Test public void find_existing_exact() throws Exception { final File eclipseHome = getEclipseHome(); Assert.assertTrue(String.format("Eclipse home directory '%s' does not exist", eclipseHome), eclipseHome.exists()); BuildRunnerContext context = createRunnerContext(null, null, eclipseHome.getAbsolutePath()); final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final PlatformDescriptor platform = testAdapter.getPlatform(context); Assert.assertNotNull(platform); final IFeatureDescriptor bundledSwtbot = new PlatformDescriptor.IFeatureDescriptor() { public File[] plugins() { return new File[] { new File("org\\.eclipse\\.swtbot\\.eclipse\\.junit4\\.headless_2\\.0\\.1\\.20101106_1831-73ca7af-dev-e36"), new File("org\\.eclipse\\.swtbot\\.ant\\.optional\\.junit4_2\\.0\\.1\\.20101106_1831-73ca7af-dev-e36\\.jar") }; } public File[] features() { return new File[] { new File("org\\.eclipse\\.swtbot\\.eclipse\\.test\\.junit4_2\\.0\\.1\\.20101106_1831-73ca7af-dev-e36") }; } }; IFeatureDescriptor swtbotDescription = platform.findFeature(bundledSwtbot); Assert.assertNotNull(swtbotDescription); Assert.assertNotNull(swtbotDescription.features()); Assert.assertNotNull(swtbotDescription.plugins()); Assert.assertEquals(1, swtbotDescription.features().length); Assert.assertEquals(2, swtbotDescription.plugins().length); } @Test public void find_existing_by_pattern() throws Exception { final File eclipseHome = getEclipseHome(); Assert.assertTrue(String.format("Eclipse home directory '%s' does not exist", eclipseHome), eclipseHome.exists()); BuildRunnerContext context = createRunnerContext(null, null, eclipseHome.getAbsolutePath()); final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final PlatformDescriptor platform = testAdapter.getPlatform(context); Assert.assertNotNull(platform); final IFeatureDescriptor bundledSwtbot = new PlatformDescriptor.IFeatureDescriptor() { public File[] plugins() { return new File[] { new File("org\\.eclipse\\.swtbot\\.eclipse\\.junit(.*)\\.(.*)"), new File("org\\.eclipse\\.swtbot\\.ant\\.optional\\.(.*)") }; } public File[] features() { return new File[] { new File("org\\.eclipse\\.swtbot\\.eclipse\\.test\\.(.*)") }; } }; IFeatureDescriptor swtbotDescription = platform.findFeature(bundledSwtbot); Assert.assertNotNull(swtbotDescription); Assert.assertNotNull(swtbotDescription.features()); Assert.assertNotNull(swtbotDescription.plugins()); Assert.assertEquals(1, swtbotDescription.features().length); Assert.assertEquals(2, swtbotDescription.plugins().length); Assert.assertEquals("org.eclipse.swtbot.eclipse.test.junit4_2.0.1.20101106_1831-73ca7af-dev-e36", swtbotDescription.features()[0].getName()); Assert.assertEquals("org.eclipse.swtbot.ant.optional.junit4_2.0.1.20101106_1831-73ca7af-dev-e36.jar", swtbotDescription.plugins()[0].getName()); Assert.assertEquals("org.eclipse.swtbot.eclipse.junit4.headless_2.0.1.20101106_1831-73ca7af-dev-e36", swtbotDescription.plugins()[1].getName()); } @Test public void find_non_existing_by_pattern() throws Exception { final File eclipseHome = getEclipseHome(); Assert.assertTrue(String.format("Eclipse home directory '%s' does not exist", eclipseHome), eclipseHome.exists()); BuildRunnerContext context = createRunnerContext(null, null, eclipseHome.getAbsolutePath()); final EclipseBuilderFactoryTestAdapter testAdapter = new EclipseBuilderFactoryTestAdapter(); final PlatformDescriptor platform = testAdapter.getPlatform(context); Assert.assertNotNull(platform); final IFeatureDescriptor bundledSwtbot = new PlatformDescriptor.IFeatureDescriptor() { public File[] plugins() { return new File[] { new File("org\\.eclipse\\.swtbotAAA\\.eclipse\\.junit(.*)\\.(.*)"), new File("org\\.eclipse\\.swtbot\\.BBB\\.ant\\.optional\\.(.*)") }; } public File[] features() { return new File[] { new File("org\\.eclipse\\.swtbot-ccc\\.eclipse\\.test\\.(.*)") }; } }; IFeatureDescriptor swtbotDescription = platform.findFeature(bundledSwtbot); Assert.assertNotNull(swtbotDescription); Assert.assertNotNull(swtbotDescription.features()); Assert.assertNotNull(swtbotDescription.plugins()); Assert.assertEquals(0, swtbotDescription.features().length); Assert.assertEquals(0, swtbotDescription.plugins().length); } }