add more tests
authorEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 18 Jul 2011 17:57:46 +0000 (21:57 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 18 Jul 2011 17:57:46 +0000 (21:57 +0400)
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/PackagesInstallerBuilderTest.java [new file with mode: 0644]
nuget-tests/src/testng-nuget-tests..xml

diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/PackagesInstallerBuilderTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/PackagesInstallerBuilderTest.java
new file mode 100644 (file)
index 0000000..c063287
--- /dev/null
@@ -0,0 +1,272 @@
+/*\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.agent;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.nuget.agent.install.NuGetActionFactory;\r
+import jetbrains.buildServer.nuget.agent.install.PackagesInstallerBuilder;\r
+import jetbrains.buildServer.nuget.agent.parameters.NuGetParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
+import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
+import jetbrains.buildServer.nuget.agent.util.BuildProcessContinuation;\r
+import jetbrains.buildServer.nuget.common.PackagesUpdateMode;\r
+import org.jmock.Expectations;\r
+import org.jmock.Mockery;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.io.File;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 18.07.11 20:26\r
+ */\r
+public class PackagesInstallerBuilderTest extends BaseTestCase {\r
+  private Mockery m;\r
+  private PackagesInstallerBuilder builderUpdate;\r
+  private PackagesInstallerBuilder builderInstall;\r
+  private NuGetActionFactory factory;\r
+  private BuildProcessContinuation install;\r
+  private BuildProcessContinuation update;\r
+  private BuildProcessContinuation postUpdate;\r
+  private BuildRunnerContext context;\r
+  private NuGetParameters nugetSettings;\r
+  private PackagesInstallParameters installParameters;\r
+  private PackagesUpdateParameters updateParameters;\r
+  private File myTaget;\r
+  private File mySln;\r
+  private File myConfig;\r
+  private File myConfig2;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+\r
+    final File root = createTempDir();\r
+    myTaget = new File(root, "packages"){{mkdirs();}};\r
+    mySln = new File(root, "project.sln") {{createNewFile();}};\r
+    myConfig = new File(new File(root, "project"){{mkdirs();}}, "packages.config"){{createNewFile();}};\r
+    myConfig2 = new File(new File(root, "project2"){{mkdirs();}}, "packages.config"){{createNewFile();}};\r
+\r
+    m = new Mockery();\r
+    factory = m.mock(NuGetActionFactory.class);\r
+    install = m.mock(BuildProcessContinuation.class, "install");\r
+    update = m.mock(BuildProcessContinuation.class, "update");\r
+    postUpdate = m.mock(BuildProcessContinuation.class, "post-install");\r
+    context = m.mock(BuildRunnerContext.class);\r
+    installParameters = m.mock(PackagesInstallParameters.class);\r
+    updateParameters = m.mock(PackagesUpdateParameters.class);\r
+    nugetSettings = m.mock(NuGetParameters.class);\r
+\r
+    builderUpdate = new PackagesInstallerBuilder(\r
+            factory,\r
+            install,\r
+            update,\r
+            postUpdate,\r
+            context,\r
+            installParameters,\r
+            updateParameters);\r
+\r
+    builderInstall = new PackagesInstallerBuilder(\r
+            factory,\r
+            install,\r
+            update,\r
+            postUpdate,\r
+            context,\r
+            installParameters,\r
+            null);\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(installParameters).getNuGetParameters(); will(returnValue(nugetSettings));\r
+      allowing(updateParameters).getNuGetParameters(); will(returnValue(nugetSettings));\r
+    }});\r
+  }\r
+\r
+  @Test\r
+  public void test_install() throws RunBuildException {\r
+    final BuildProcess bp = m.mock(BuildProcess.class);\r
+    m.checking(new Expectations(){{\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bp));\r
+\r
+      oneOf(install).pushBuildProcess(bp);\r
+    }});\r
+\r
+    builderInstall.onSolutionFileFound(mySln, myTaget);\r
+    builderInstall.onPackagesConfigFound(myConfig, myTaget);\r
+  }\r
+\r
+  @Test\r
+  public void test_install_may() throws RunBuildException {\r
+    final BuildProcess bp1 = m.mock(BuildProcess.class, "bp-install-1");\r
+    final BuildProcess bp2 = m.mock(BuildProcess.class, "bp-install-2");\r
+    m.checking(new Expectations(){{\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bp1));\r
+      oneOf(factory).createInstall(context, installParameters, myConfig2, myTaget);\r
+      will(returnValue(bp2));\r
+\r
+      oneOf(install).pushBuildProcess(bp1);\r
+      oneOf(install).pushBuildProcess(bp2);\r
+    }});\r
+\r
+    builderInstall.onSolutionFileFound(mySln, myTaget);\r
+    builderInstall.onPackagesConfigFound(myConfig, myTaget);\r
+    builderInstall.onPackagesConfigFound(myConfig2, myTaget);\r
+  }\r
+\r
+  @Test\r
+  public void test_install_update_per_sln() throws RunBuildException {\r
+    final BuildProcess bpInstall = m.mock(BuildProcess.class, "bp-install");\r
+    final BuildProcess bpUpdate = m.mock(BuildProcess.class, "bp-update");\r
+    final BuildProcess bpPostInstall = m.mock(BuildProcess.class, "bp-post-install");\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(updateParameters).getUpdateMode();\r
+      will(returnValue(PackagesUpdateMode.FOR_SLN));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bpInstall));\r
+\r
+      oneOf(factory).createUpdate(context, updateParameters, mySln, myTaget);\r
+      will(returnValue(bpUpdate));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bpPostInstall));\r
+\r
+      oneOf(update).pushBuildProcess(bpUpdate);\r
+      oneOf(install).pushBuildProcess(bpInstall);\r
+      oneOf(postUpdate).pushBuildProcess(bpPostInstall);\r
+\r
+    }});\r
+\r
+    builderUpdate.onSolutionFileFound(mySln, myTaget);\r
+    builderUpdate.onPackagesConfigFound(myConfig, myTaget);\r
+  }\r
+\r
+  @Test\r
+  public void test_install_update_per_sln_many() throws RunBuildException {\r
+    final BuildProcess bpInstall1 = m.mock(BuildProcess.class, "bp-install-1");\r
+    final BuildProcess bpInstall2 = m.mock(BuildProcess.class, "bp-install-2");\r
+    final BuildProcess bpUpdate = m.mock(BuildProcess.class, "bp-update");\r
+    final BuildProcess bpPostInstall1 = m.mock(BuildProcess.class, "bp-post-install-1");\r
+    final BuildProcess bpPostInstall2 = m.mock(BuildProcess.class, "bp-post-install-2");\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(updateParameters).getUpdateMode();\r
+      will(returnValue(PackagesUpdateMode.FOR_SLN));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bpInstall1));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig2, myTaget);\r
+      will(returnValue(bpInstall2));\r
+\r
+      oneOf(factory).createUpdate(context, updateParameters, mySln, myTaget);\r
+      will(returnValue(bpUpdate));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bpPostInstall1));\r
+      oneOf(factory).createInstall(context, installParameters, myConfig2, myTaget);\r
+      will(returnValue(bpPostInstall2));\r
+\r
+      oneOf(update).pushBuildProcess(bpUpdate);\r
+      oneOf(install).pushBuildProcess(bpInstall1);\r
+      oneOf(install).pushBuildProcess(bpInstall2);\r
+      oneOf(postUpdate).pushBuildProcess(bpPostInstall1);\r
+      oneOf(postUpdate).pushBuildProcess(bpPostInstall2);\r
+\r
+    }});\r
+\r
+    builderUpdate.onSolutionFileFound(mySln, myTaget);\r
+    builderUpdate.onPackagesConfigFound(myConfig, myTaget);\r
+    builderUpdate.onPackagesConfigFound(myConfig2, myTaget);\r
+  }\r
+  @Test\r
+  public void test_install_update_per_config() throws RunBuildException {\r
+    final BuildProcess bpInstall = m.mock(BuildProcess.class, "bp-install");\r
+    final BuildProcess bpUpdate = m.mock(BuildProcess.class, "bp-update");\r
+    final BuildProcess bpPostInstall = m.mock(BuildProcess.class, "bp-post-install");\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(updateParameters).getUpdateMode();\r
+      will(returnValue(PackagesUpdateMode.FOR_EACH_PACKAGES_CONFIG));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bpInstall));\r
+\r
+      oneOf(factory).createUpdate(context, updateParameters, myConfig, myTaget);\r
+      will(returnValue(bpUpdate));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bpPostInstall));\r
+\r
+      oneOf(update).pushBuildProcess(bpUpdate);\r
+      oneOf(install).pushBuildProcess(bpInstall);\r
+      oneOf(postUpdate).pushBuildProcess(bpPostInstall);\r
+\r
+    }});\r
+\r
+    builderUpdate.onSolutionFileFound(mySln, myTaget);\r
+    builderUpdate.onPackagesConfigFound(myConfig, myTaget);\r
+  }\r
+\r
+  @Test\r
+  public void test_install_update_per_config_many() throws RunBuildException {\r
+    final BuildProcess bpInstall1 = m.mock(BuildProcess.class, "bp-install-1");\r
+    final BuildProcess bpInstall2 = m.mock(BuildProcess.class, "bp-install-2");\r
+    final BuildProcess bpUpdate1 = m.mock(BuildProcess.class, "bp-update-1");\r
+    final BuildProcess bpUpdate2 = m.mock(BuildProcess.class, "bp-update-2");\r
+    final BuildProcess bpPostInstall1 = m.mock(BuildProcess.class, "bp-post-install-1");\r
+    final BuildProcess bpPostInstall2 = m.mock(BuildProcess.class, "bp-post-install-2");\r
+\r
+    m.checking(new Expectations(){{\r
+      allowing(updateParameters).getUpdateMode();\r
+      will(returnValue(PackagesUpdateMode.FOR_EACH_PACKAGES_CONFIG));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bpInstall1));\r
+      oneOf(factory).createInstall(context, installParameters, myConfig2, myTaget);\r
+      will(returnValue(bpInstall2));\r
+\r
+      oneOf(factory).createUpdate(context, updateParameters, myConfig, myTaget);\r
+      will(returnValue(bpUpdate1));\r
+      oneOf(factory).createUpdate(context, updateParameters, myConfig2, myTaget);\r
+      will(returnValue(bpUpdate2));\r
+\r
+      oneOf(factory).createInstall(context, installParameters, myConfig, myTaget);\r
+      will(returnValue(bpPostInstall1));\r
+      oneOf(factory).createInstall(context, installParameters, myConfig2, myTaget);\r
+      will(returnValue(bpPostInstall2));\r
+\r
+      oneOf(update).pushBuildProcess(bpUpdate1);\r
+      oneOf(update).pushBuildProcess(bpUpdate2);\r
+      oneOf(install).pushBuildProcess(bpInstall1);\r
+      oneOf(install).pushBuildProcess(bpInstall2);\r
+      oneOf(postUpdate).pushBuildProcess(bpPostInstall1);\r
+      oneOf(postUpdate).pushBuildProcess(bpPostInstall2);\r
+    }});\r
+\r
+    builderUpdate.onSolutionFileFound(mySln, myTaget);\r
+    builderUpdate.onPackagesConfigFound(myConfig, myTaget);\r
+    builderUpdate.onPackagesConfigFound(myConfig2, myTaget);\r
+  }\r
+}\r
index e589277c35d092c0c257f1b86bd0c82228ebdea9..8c25e055686b7fd3fcad1d02affc1d75228a8727 100644 (file)
@@ -4,6 +4,7 @@
   <test name="fast tests">\r
     <classes>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.LocateNuGetConfigBuildProcessTest"/>\r
   <test name="fast tests">\r
     <classes>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.LocateNuGetConfigBuildProcessTest"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.agent.PackagesInstallerBuilderTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetInstallPackageActionFactoryTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetUpdatePackageActionFactoryTest"/>\r
 \r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetInstallPackageActionFactoryTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetUpdatePackageActionFactoryTest"/>\r
 \r