integration tests for pack runner
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Tue, 23 Aug 2011 14:21:51 +0000 (16:21 +0200)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Tue, 23 Aug 2011 14:21:51 +0000 (16:21 +0200)
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/IntegrationTestBase.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/PackIntegrationTest.java [new file with mode: 0644]
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/PackagesPublishIntegrationTest.java
nuget-tests/src/testng-nuget-integration.xml
nuget-tests/testData/integration/solution.zip [new file with mode: 0644]

index cc213a86013612c036426c85b94d57641dd4f24b..da6ff646de4a458b60a4af43dcfee2feb6bf369a 100644 (file)
@@ -19,19 +19,17 @@ package jetbrains.buildServer.nuget.tests.integration;
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
 import jetbrains.buildServer.agent.BuildProcess;\r
-import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
-import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
-import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner;\r
 import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesCollectorImpl;\r
-import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesConfigParser;\r
-import jetbrains.buildServer.nuget.agent.install.impl.PackageUsagesImpl;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
 import jetbrains.buildServer.nuget.common.PackageInfo;\r
 import jetbrains.buildServer.nuget.common.PackagesUpdateMode;\r
 import jetbrains.buildServer.util.ArchiveUtil;\r
 import org.jetbrains.annotations.Nullable;\r
 import org.jmock.Expectations;\r
 import org.testng.Assert;\r
+import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
 import java.io.File;\r
@@ -42,6 +40,27 @@ import java.util.*;
  * Date: 08.07.11 2:15\r
  */\r
 public class InstallPackageIntegtatoinTest extends IntegrationTestBase {\r
+  protected PackagesInstallParameters myInstall;\r
+  protected PackagesUpdateParameters myUpdate;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+\r
+    myInstall = m.mock(PackagesInstallParameters.class);\r
+    myUpdate = m.mock(PackagesUpdateParameters.class);\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(myInstall).getNuGetParameters();\r
+      will(returnValue(myNuGet));\r
+      allowing(myUpdate).getNuGetParameters();\r
+      will(returnValue(myNuGet));\r
+\r
+      allowing(myLogger).activityStarted(with(equal("install")), with(any(String.class)), with(any(String.class)));\r
+      allowing(myLogger).activityFinished(with(equal("install")), with(any(String.class)));\r
+    }});\r
+  }\r
 \r
   @Test\r
   public void test_01_online_sources() throws RunBuildException {\r
@@ -207,23 +226,18 @@ public class InstallPackageIntegtatoinTest extends IntegrationTestBase {
       will(returnValue(update ? myUpdate : null));\r
     }});\r
 \r
-    NuGetPackagesCollectorImpl collector = new NuGetPackagesCollectorImpl();\r
-    PackageUsages pu = new PackageUsagesImpl(\r
-            collector,\r
-            new NuGetPackagesConfigParser()\r
-    );\r
-\r
     BuildProcess proc = new PackagesInstallerRunner(\r
-            new NuGetActionFactoryImpl(executingFactory(), pu, new CommandFactoryImpl()),\r
+            myActionFactory,\r
             myParametersFactory\r
     ).createBuildProcess(myBuild, myContext);\r
+    ((NuGetPackagesCollectorImpl)myCollector).removeAllPackages();\r
 \r
     assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);\r
 \r
-    System.out.println(collector.getPackages());\r
+    System.out.println(myCollector.getPackages());\r
     if (detectedPackages != null) {\r
       Assert.assertEquals(\r
-              new TreeSet<PackageInfo>(collector.getPackages().getPackages()),\r
+              new TreeSet<PackageInfo>(myCollector.getPackages().getPackages()),\r
               new TreeSet<PackageInfo>(detectedPackages));\r
     }\r
 \r
index e92b6ede2956500cc2b63b58f273f025a9f91b54..633e1e3c5a04dac0ea6449e247c33519923ee247 100644 (file)
@@ -21,6 +21,15 @@ import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.RunBuildException;\r
 import jetbrains.buildServer.SimpleCommandLineProcessRunner;\r
 import jetbrains.buildServer.agent.*;\r
+import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.LoggingNuGetActionFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
+import jetbrains.buildServer.nuget.agent.install.NuGetPackagesCollector;\r
+import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
+import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesCollectorImpl;\r
+import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesConfigParser;\r
+import jetbrains.buildServer.nuget.agent.install.impl.PackageUsagesImpl;\r
 import jetbrains.buildServer.nuget.agent.parameters.*;\r
 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
@@ -45,10 +54,9 @@ public class IntegrationTestBase extends BuildProcessTestCase {
   protected BuildRunnerContext myContext;\r
   protected BuildProgressLogger myLogger;\r
   protected PackagesParametersFactory myParametersFactory;\r
-  protected PackagesInstallParameters myInstall;\r
-  protected PackagesUpdateParameters myUpdate;\r
-  protected NuGetPublishParameters myPublishParameters;\r
   protected NuGetFetchParameters myNuGet;\r
+  protected NuGetPackagesCollector myCollector;\r
+  protected NuGetActionFactory myActionFactory;\r
   private BuildProcess myMockProcess;\r
 \r
   @NotNull\r
@@ -67,11 +75,8 @@ public class IntegrationTestBase extends BuildProcessTestCase {
     myContext = m.mock(BuildRunnerContext.class);\r
     myLogger = m.mock(BuildProgressLogger.class);\r
     myParametersFactory = m.mock(PackagesParametersFactory.class);\r
-    myInstall = m.mock(PackagesInstallParameters.class);\r
-    myUpdate = m.mock(PackagesUpdateParameters.class);\r
     myMockProcess = m.mock(BuildProcess.class);\r
     myNuGet = m.mock(NuGetFetchParameters.class);\r
-    myPublishParameters = m.mock(NuGetPublishParameters.class);\r
 \r
     m.checking(new Expectations() {{\r
       allowing(myContext).getBuild();\r
@@ -86,14 +91,15 @@ public class IntegrationTestBase extends BuildProcessTestCase {
       will(returnValue(BuildFinishedStatus.FINISHED_SUCCESS));\r
 \r
       allowing(myLogger).message(with(any(String.class)));\r
-      allowing(myLogger).activityStarted(with(equal("install")), with(any(String.class)), with(any(String.class)));\r
-      allowing(myLogger).activityFinished(with(equal("install")), with(any(String.class)));\r
-\r
-      allowing(myInstall).getNuGetParameters();\r
-      will(returnValue(myNuGet));\r
-      allowing(myUpdate).getNuGetParameters();\r
-      will(returnValue(myNuGet));\r
     }});\r
+\r
+    myCollector = new NuGetPackagesCollectorImpl();\r
+    PackageUsages pu = new PackageUsagesImpl(\r
+            myCollector,\r
+            new NuGetPackagesConfigParser()\r
+    );\r
+\r
+    myActionFactory = new LoggingNuGetActionFactoryImpl(new NuGetActionFactoryImpl(executingFactory(), pu, new CommandFactoryImpl()));\r
   }\r
 \r
   @NotNull\r
@@ -101,7 +107,8 @@ public class IntegrationTestBase extends BuildProcessTestCase {
     return Paths.getTestDataPath("integration/" + path);\r
   }\r
 \r
-  protected CommandlineBuildProcessFactory executingFactory() {\r
+  @NotNull\r
+  private CommandlineBuildProcessFactory executingFactory() {\r
     return new CommandlineBuildProcessFactory() {\r
       public BuildProcess executeCommandLine(@NotNull final BuildRunnerContext hostContext,\r
                                              @NotNull final File program,\r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/PackIntegrationTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/PackIntegrationTest.java
new file mode 100644 (file)
index 0000000..2e55be2
--- /dev/null
@@ -0,0 +1,208 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.tests.integration;\r
+\r
+import com.intellij.execution.configurations.GeneralCommandLine;\r
+import com.intellij.util.io.ZipUtil;\r
+import jetbrains.buildServer.ExecResult;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.SimpleCommandLineProcessRunner;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import jetbrains.buildServer.nuget.agent.pack.PackRunner;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPackParameters;\r
+import jetbrains.buildServer.util.FileUtil;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.jmock.Expectations;\r
+import org.testng.Assert;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.*;\r
+import java.util.Collections;\r
+import java.util.zip.ZipEntry;\r
+import java.util.zip.ZipInputStream;\r
+\r
+/**\r
+ * @author Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ *         Date: 23.08.11 12:58\r
+ */\r
+public class PackIntegrationTest extends IntegrationTestBase {\r
+  protected NuGetPackParameters myPackParameters;\r
+  private File myOutputDir;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+    myPackParameters = m.mock(NuGetPackParameters.class);\r
+\r
+    m.checking(new Expectations(){{\r
+      oneOf(myParametersFactory).loadPackParameters(myContext); will(returnValue(myPackParameters));\r
+\r
+      allowing(myLogger).activityStarted(with(equal("pack")), with(any(String.class)), with(any(String.class)));\r
+      allowing(myLogger).activityFinished(with(equal("pack")), with(any(String.class)));\r
+\r
+    }});\r
+    myOutputDir = new File(myRoot, "out");\r
+    myOutputDir.mkdirs();\r
+  }\r
+\r
+  @Test\r
+  public void test_simple() throws IOException, RunBuildException {\r
+    final File spec = new File(myRoot, "SamplePackage.nuspec");\r
+    FileUtil.copy(getTestDataPath("SamplePackage.nuspec"), spec);\r
+\r
+    callRunner(spec, false, false);\r
+\r
+    Assert.assertTrue(myOutputDir.list(new FilenameFilter() {\r
+      public boolean accept(File dir, String name) {\r
+        return name.endsWith(".nupkg");\r
+      }\r
+    }).length == 1, "There should be only one package created");\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_vs_solution() throws IOException, RunBuildException {\r
+    ZipUtil.extract(getTestDataPath("solution.zip"), myRoot, null);\r
+    final File spec = new File(myRoot, "nuget-proj/nuget-proj.csproj");\r
+\r
+    msbuild(new File(myRoot, "nuget-proj.sln"));\r
+\r
+    callRunner(spec, false, false);\r
+\r
+    Assert.assertTrue(nupkgs().length == 1, "There should be only one package created");\r
+\r
+    final File nupkg = nupkgs()[0];\r
+\r
+    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(nupkg)));\r
+    for(ZipEntry ze; (ze = zis.getNextEntry()) != null;) {\r
+      System.out.println(ze.getName());\r
+    }\r
+    zis.close();\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_vs_solution_tool() throws IOException, RunBuildException {\r
+    ZipUtil.extract(getTestDataPath("solution.zip"), myRoot, null);\r
+    final File spec = new File(myRoot, "nuget-proj/nuget-proj.csproj");\r
+\r
+    msbuild(new File(myRoot, "nuget-proj.sln"));\r
+\r
+    callRunner(spec, true, false);\r
+\r
+    Assert.assertTrue(nupkgs().length == 1, "There should be only one package created");\r
+    final File nupkg = nupkgs()[0];\r
+\r
+    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(nupkg)));\r
+    for(ZipEntry ze; (ze = zis.getNextEntry()) != null;) {\r
+      System.out.println(ze.getName());\r
+    }\r
+    zis.close();\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_vs_solution_symbols() throws IOException, RunBuildException {\r
+    ZipUtil.extract(getTestDataPath("solution.zip"), myRoot, null);\r
+    final File spec = new File(myRoot, "nuget-proj/nuget-proj.csproj");\r
+\r
+    msbuild(new File(myRoot, "nuget-proj.sln"));\r
+\r
+    callRunner(spec, false, true);\r
+\r
+    Assert.assertTrue(nupkgs().length == 1, "There should be only one package created");\r
+    Assert.assertTrue(symbolsNupkgs().length == 1, "There should be only one symbols package created");\r
+\r
+    for (String s : myOutputDir.list()) {\r
+      System.out.println("s = " + s);\r
+    }\r
+\r
+    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(nupkgs()[0])));\r
+    for(ZipEntry ze; (ze = zis.getNextEntry()) != null;) {\r
+      System.out.println(ze.getName());\r
+    }\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  private File[] nupkgs() {\r
+    final File[] files = myOutputDir.listFiles(NUPKG);\r
+    for (File file : files) {\r
+      System.out.println("Found create file: " + file);\r
+    }\r
+    return files;\r
+  }\r
+\r
+  private File[] symbolsNupkgs() {\r
+    final File[] files = myOutputDir.listFiles(SYMBOLS_NUPKG);\r
+    for (File file : files) {\r
+      System.out.println("Found create file: " + file);\r
+    }\r
+    return files;\r
+  }\r
+\r
+  private void msbuild(File spec) {\r
+    GeneralCommandLine cmd = new GeneralCommandLine();\r
+    cmd.setExePath("cmd.exe");\r
+    cmd.addParameter("/c");\r
+    cmd.addParameter("%SYSTEMROOT%\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe");\r
+    cmd.addParameter(spec.getPath());\r
+    cmd.addParameter("/t:Rebuild");\r
+\r
+    final ExecResult result = SimpleCommandLineProcessRunner.runCommand(cmd, new byte[0]);\r
+    Assert.assertEquals(0, result.getExitCode());\r
+  }\r
+\r
+  private void callRunner(@NotNull final File spec, final boolean packAsTool, final boolean symbols) throws RunBuildException {\r
+    m.checking(new Expectations(){{\r
+      allowing(myPackParameters).getCustomCommandline(); will(returnValue(Collections.<String>emptyList()));\r
+      allowing(myPackParameters).getProperties(); will(returnValue(Collections.<String>emptyList()));\r
+      allowing(myPackParameters).getSpecFile(); will(returnValue(spec));\r
+      allowing(myPackParameters).getNuGetExeFile(); will(returnValue(Paths.getPathToNuGet()));\r
+      allowing(myPackParameters).getBaseDirectory(); will(returnValue(myRoot));\r
+      allowing(myPackParameters).getExclude(); will(returnValue(Collections.<String>emptyList()));\r
+      allowing(myPackParameters).getVersion(); will(returnValue("45.239.32.12"));\r
+      allowing(myPackParameters).getOutputDirectory(); will(returnValue(myOutputDir));\r
+\r
+      allowing(myPackParameters).packTool(); will(returnValue(packAsTool));\r
+      allowing(myPackParameters).packSymbols(); will(returnValue(symbols));\r
+    }});\r
+\r
+    final PackRunner runner = new PackRunner(myActionFactory, myParametersFactory);\r
+    final BuildProcess proc = runner.createBuildProcess(myBuild, myContext);\r
+    assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);\r
+  }\r
+\r
+\r
+  private static FilenameFilter NUPKG = new FilenameFilter() {\r
+      public boolean accept(File dir, String name) {\r
+        return name.endsWith(".nupkg") && !SYMBOLS_NUPKG.accept(dir, name);\r
+      }\r
+    };\r
+\r
+  private static FilenameFilter SYMBOLS_NUPKG = new FilenameFilter() {\r
+      public boolean accept(File dir, String name) {\r
+        return name.endsWith(".symbols.nupkg");\r
+      }\r
+    };\r
+}\r
index 82c2c10e3e35e2f1f083708465ac0a5a1fd7d9f6..138ce0b1214c973cab456daa2bf0d14af88926cb 100644 (file)
@@ -22,17 +22,13 @@ import jetbrains.buildServer.RunBuildException;
 import jetbrains.buildServer.SimpleCommandLineProcessRunner;\r
 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
 import jetbrains.buildServer.agent.BuildProcess;\r
-import jetbrains.buildServer.nuget.agent.commands.impl.CommandFactoryImpl;\r
-import jetbrains.buildServer.nuget.agent.commands.impl.NuGetActionFactoryImpl;\r
-import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
-import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesCollectorImpl;\r
-import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesConfigParser;\r
-import jetbrains.buildServer.nuget.agent.install.impl.PackageUsagesImpl;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters;\r
 import jetbrains.buildServer.nuget.agent.publish.PackagesPublishRunner;\r
 import jetbrains.buildServer.util.FileUtil;\r
 import org.jetbrains.annotations.NotNull;\r
 import org.jmock.Expectations;\r
 import org.testng.Assert;\r
+import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
 import java.io.File;\r
@@ -44,6 +40,14 @@ import java.util.Arrays;
  * Date: 22.07.11 1:25\r
  */\r
 public class PackagesPublishIntegrationTest extends IntegrationTestBase {\r
+  protected NuGetPublishParameters myPublishParameters;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+    myPublishParameters = m.mock(NuGetPublishParameters.class);\r
+  }\r
 \r
   @Test\r
   public void test_publish_packages() throws IOException, RunBuildException {\r
@@ -103,14 +107,7 @@ public class PackagesPublishIntegrationTest extends IntegrationTestBase {
       allowing(myParametersFactory).loadPublishParameters(myContext);will(returnValue(myPublishParameters));\r
     }});\r
 \r
-    NuGetPackagesCollectorImpl collector = new NuGetPackagesCollectorImpl();\r
-        PackageUsages pu = new PackageUsagesImpl(\r
-                collector,\r
-                new NuGetPackagesConfigParser()\r
-        );\r
-\r
-    final PackagesPublishRunner runner = new PackagesPublishRunner(\r
-            new NuGetActionFactoryImpl(executingFactory(), pu, new CommandFactoryImpl()), myParametersFactory);\r
+    final PackagesPublishRunner runner = new PackagesPublishRunner(myActionFactory, myParametersFactory);\r
 \r
     final BuildProcess proc = runner.createBuildProcess(myBuild, myContext);\r
     assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);\r
index 4112e5236b6d651a4fde8f075b374367521c4ea9..0efaf0de1f26037b67bea12aa3faf92a6ccd1f32 100644 (file)
@@ -2,6 +2,7 @@
 <suite name="nuget">\r
   <test name="nuget integration test">\r
     <classes>\r
+      <class name="jetbrains.buildServer.nuget.tests.integration.PackIntegrationTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.integration.InstallPackageIntegtatoinTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.integration.NuGetExecutorTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.integration.PackagesPublishIntegrationTest"/>\r
diff --git a/nuget-tests/testData/integration/solution.zip b/nuget-tests/testData/integration/solution.zip
new file mode 100644 (file)
index 0000000..01d1083
Binary files /dev/null and b/nuget-tests/testData/integration/solution.zip differ