integration test checks for reported dependencies
authorEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 19 Jul 2011 10:08:20 +0000 (14:08 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 19 Jul 2011 10:08:20 +0000 (14:08 +0400)
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackageUsages.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/NuGetActionFactoryImpl.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/impl/PackageUsagesImpl.java
nuget-common/src/jetbrains/buildServer/nuget/common/PackageDependencies.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/integration/InstallPackageIntegtatoinTest.java

index ba89c785f3be6a95c959c313fc5bdd0ca50d8167..bf1e3bcaa0596b830399cd56bbd25c3397c8c5e2 100644 (file)
@@ -16,7 +16,6 @@
 \r
 package jetbrains.buildServer.nuget.agent.install;\r
 \r
-import jetbrains.buildServer.agent.BuildProcess;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
 import java.io.File;\r
@@ -26,6 +25,5 @@ import java.io.File;
  * Date: 18.07.11 23:50\r
  */\r
 public interface PackageUsages {\r
-  @NotNull\r
-  BuildProcess createReport(@NotNull File packagesConfig);\r
+  void createReport(@NotNull File packagesConfig);\r
 }\r
index 236d4d549cd0e1c7446eeff6bdccb0ac34633610..640a7f7189ce666b27eb1c14adcdfbac168199be 100644 (file)
@@ -16,7 +16,9 @@
 \r
 package jetbrains.buildServer.nuget.agent.install.impl;\r
 \r
+import com.intellij.openapi.diagnostic.Logger;\r
 import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
 import jetbrains.buildServer.agent.BuildProcess;\r
 import jetbrains.buildServer.agent.BuildRunnerContext;\r
 import jetbrains.buildServer.nuget.agent.install.NuGetActionFactory;\r
@@ -24,6 +26,7 @@ import jetbrains.buildServer.nuget.agent.install.PackageUsages;
 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.BuildProcessBase;\r
 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
 import jetbrains.buildServer.util.FileUtil;\r
 import org.jetbrains.annotations.NotNull;\r
@@ -38,6 +41,8 @@ import java.util.List;
  * Date: 07.07.11 17:49\r
  */\r
 public class NuGetActionFactoryImpl implements NuGetActionFactory {\r
+  private static final Logger LOG = Logger.getInstance(NuGetActionFactoryImpl.class.getName());\r
+\r
   private final CommandlineBuildProcessFactory myFactory;\r
   private final PackageUsages myPackageUsages;\r
 \r
@@ -89,11 +94,18 @@ public class NuGetActionFactoryImpl implements NuGetActionFactory {
   }\r
 \r
   @NotNull\r
-  public BuildProcess createUsageReport(@NotNull BuildRunnerContext context,\r
-                                        @NotNull NuGetParameters params,\r
-                                        @NotNull File packagesConfig,\r
-                                        @NotNull File targetFolder) throws RunBuildException {\r
-    return myPackageUsages.createReport(packagesConfig);\r
+  public BuildProcess createUsageReport(@NotNull final BuildRunnerContext context,\r
+                                        @NotNull final NuGetParameters params,\r
+                                        @NotNull final File packagesConfig,\r
+                                        @NotNull final File targetFolder) throws RunBuildException {\r
+    return new BuildProcessBase() {\r
+      @NotNull\r
+      @Override\r
+      protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
+        myPackageUsages.createReport(packagesConfig);\r
+        return BuildFinishedStatus.FINISHED_SUCCESS;\r
+      }\r
+    };\r
   }\r
 \r
   @NotNull\r
index 5451df91538817007ee394acf0f750ee7fd0e6ee..b62aa8c51e2f3aa412cc7ad06e892460c0874db9 100644 (file)
 package jetbrains.buildServer.nuget.agent.install.impl;\r
 \r
 import com.intellij.openapi.diagnostic.Logger;\r
-import jetbrains.buildServer.RunBuildException;\r
-import jetbrains.buildServer.agent.BuildFinishedStatus;\r
-import jetbrains.buildServer.agent.BuildProcess;\r
 import jetbrains.buildServer.nuget.agent.install.NuGetPackagesCollector;\r
 import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
-import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
 import org.jetbrains.annotations.NotNull;\r
 \r
 import java.io.File;\r
@@ -44,25 +40,16 @@ public class PackageUsagesImpl implements PackageUsages {
     myParser = parser;\r
   }\r
 \r
-  @NotNull\r
-  public BuildProcess createReport(@NotNull final File packagesConfig) {\r
-    return new BuildProcessBase() {\r
-      @NotNull\r
-      @Override\r
-      protected BuildFinishedStatus waitForImpl() throws RunBuildException {\r
-        if (!packagesConfig.exists()) {\r
-          LOG.debug("Packages file: " + packagesConfig + " does not exit");\r
-          return BuildFinishedStatus.FINISHED_SUCCESS;\r
-        }\r
-\r
-        try {\r
-          myParser.parseNuGetPackages(packagesConfig, myCollector);\r
-        } catch (IOException e) {\r
-          LOG.warn("Failed to parse " + packagesConfig + ". " + e.getMessage(), e);\r
-        }\r
-\r
-        return BuildFinishedStatus.FINISHED_SUCCESS;\r
-      }\r
-    };\r
+  public void createReport(@NotNull final File packagesConfig) {\r
+    if (!packagesConfig.exists()) {\r
+      LOG.debug("Packages file: " + packagesConfig + " does not exit");\r
+      return;\r
+    }\r
+\r
+    try {\r
+      myParser.parseNuGetPackages(packagesConfig, myCollector);\r
+    } catch (IOException e) {\r
+      LOG.warn("Failed to parse " + packagesConfig + ". " + e.getMessage(), e);\r
+    }\r
   }\r
 }\r
index e8ac0991fc6c585fcb1f296de3487c849016efd7..a862f20fc6d47e69df90327d2ac21e750c3b89ef 100644 (file)
@@ -57,4 +57,12 @@ public class PackageDependencies {
   public boolean isEmpty() {\r
     return getPackages().isEmpty();\r
   }\r
+\r
+  @Override\r
+  public String toString() {\r
+    return "PackageDependencies{" +\r
+            "mySources=" + mySources +\r
+            ", myPackages=" + myPackages +\r
+            '}';\r
+  }\r
 }\r
index 89790dc54d71b38b12f85bbcb47be6e431c21e56..510a30b9ceccc7d03c3c0e71f72a19ea5c99a940 100644 (file)
@@ -24,27 +24,29 @@ import jetbrains.buildServer.agent.*;
 import jetbrains.buildServer.nuget.agent.install.PackageUsages;\r
 import jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner;\r
 import jetbrains.buildServer.nuget.agent.install.impl.NuGetActionFactoryImpl;\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.NuGetParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory;\r
 import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters;\r
 import jetbrains.buildServer.nuget.agent.util.BuildProcessBase;\r
 import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
+import jetbrains.buildServer.nuget.common.PackageInfo;\r
 import jetbrains.buildServer.nuget.common.PackagesUpdateMode;\r
 import jetbrains.buildServer.nuget.tests.util.BuildProcessTestCase;\r
 import jetbrains.buildServer.util.ArchiveUtil;\r
-import junit.framework.Assert;\r
 import org.jetbrains.annotations.NotNull;\r
+import org.jetbrains.annotations.Nullable;\r
 import org.jmock.Expectations;\r
 import org.jmock.Mockery;\r
+import org.testng.Assert;\r
 import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
 import java.io.File;\r
-import java.util.Arrays;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.List;\r
+import java.util.*;\r
 \r
 /**\r
  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
@@ -78,19 +80,25 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     myNuGet = m.mock(NuGetParameters.class);\r
 \r
     m.checking(new Expectations() {{\r
-      allowing(myContext).getBuild();  will(returnValue(myBuild));\r
-      allowing(myBuild).getBuildLogger(); will(returnValue(myLogger));\r
-      allowing(myBuild).getCheckoutDirectory(); will(returnValue(myRoot));\r
+      allowing(myContext).getBuild();\r
+      will(returnValue(myBuild));\r
+      allowing(myBuild).getBuildLogger();\r
+      will(returnValue(myLogger));\r
+      allowing(myBuild).getCheckoutDirectory();\r
+      will(returnValue(myRoot));\r
 \r
       allowing(myMockProcess).start();\r
-      allowing(myMockProcess).waitFor(); will(returnValue(BuildFinishedStatus.FINISHED_SUCCESS));\r
+      allowing(myMockProcess).waitFor();\r
+      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(); will(returnValue(myNuGet));\r
-      allowing(myUpdate).getNuGetParameters(); will(returnValue(myNuGet));\r
+      allowing(myInstall).getNuGetParameters();\r
+      will(returnValue(myNuGet));\r
+      allowing(myUpdate).getNuGetParameters();\r
+      will(returnValue(myNuGet));\r
     }});\r
   }\r
 \r
@@ -98,7 +106,12 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   public void test_01_online_sources() throws RunBuildException {\r
     ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, false);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, false,\r
+            Arrays.asList(\r
+                    new PackageInfo("Machine.Specifications", "0.4.13.0"),\r
+                    new PackageInfo("NUnit", "2.5.7.10213"),\r
+                    new PackageInfo("Ninject", "2.2.1.4"))\r
+    );\r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
     System.out.println("installed packageses = " + packageses);\r
@@ -115,10 +128,10 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   }\r
 \r
   @Test\r
-  public void test_01_online_sources_update() throws RunBuildException {\r
+  public void test_01_online_sources_update_forConfig() throws RunBuildException {\r
     ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
-    m.checking(new Expectations(){{\r
+    m.checking(new Expectations() {{\r
       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
       allowing(myLogger).activityFinished(with(equal("update")), with(equal("nuget")));\r
 \r
@@ -127,7 +140,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
       allowing(myUpdate).getUpdateMode(); will(returnValue(PackagesUpdateMode.FOR_EACH_PACKAGES_CONFIG));\r
     }});\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true, null);\r
 \r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
@@ -144,16 +157,19 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   public void test_01_online_sources_update_forSln() throws RunBuildException {\r
     ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
-    m.checking(new Expectations(){{\r
+    m.checking(new Expectations() {{\r
       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
       allowing(myLogger).activityFinished(with(equal("update")), with(equal("nuget")));\r
 \r
-      allowing(myUpdate).getUseSafeUpdate(); will(returnValue(false));\r
-      allowing(myUpdate).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));\r
-      allowing(myUpdate).getUpdateMode(); will(returnValue(PackagesUpdateMode.FOR_SLN));\r
+      allowing(myUpdate).getUseSafeUpdate();\r
+      will(returnValue(false));\r
+      allowing(myUpdate).getPackagesToUpdate();\r
+      will(returnValue(Collections.<String>emptyList()));\r
+      allowing(myUpdate).getUpdateMode();\r
+      will(returnValue(PackagesUpdateMode.FOR_SLN));\r
     }});\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true, null);\r
 \r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
@@ -170,16 +186,19 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   public void test_01_online_sources_update_safe() throws RunBuildException {\r
     ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
-    m.checking(new Expectations(){{\r
+    m.checking(new Expectations() {{\r
       allowing(myLogger).activityStarted(with(equal("update")), with(any(String.class)), with(equal("nuget")));\r
       allowing(myLogger).activityFinished(with(equal("update")), with(equal("nuget")));\r
 \r
-      allowing(myUpdate).getUseSafeUpdate(); will(returnValue(true));\r
-      allowing(myUpdate).getPackagesToUpdate(); will(returnValue(Collections.<String>emptyList()));\r
-      allowing(myUpdate).getUpdateMode(); will(returnValue(PackagesUpdateMode.FOR_EACH_PACKAGES_CONFIG));\r
+      allowing(myUpdate).getUseSafeUpdate();\r
+      will(returnValue(true));\r
+      allowing(myUpdate).getPackagesToUpdate();\r
+      will(returnValue(Collections.<String>emptyList()));\r
+      allowing(myUpdate).getUpdateMode();\r
+      will(returnValue(PackagesUpdateMode.FOR_EACH_PACKAGES_CONFIG));\r
     }});\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), false, true, null);\r
 \r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
@@ -196,7 +215,11 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   public void test_01_online_sources_ecludeVersion() throws RunBuildException {\r
     ArchiveUtil.unpackZip(getTestDataPath(), "", myRoot);\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), true, false);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Collections.<String>emptyList(), true, false,\r
+            Arrays.asList(\r
+                    new PackageInfo("Machine.Specifications", "0.4.13.0"),\r
+                    new PackageInfo("NUnit", "2.5.7.10213"),\r
+                    new PackageInfo("Ninject", "2.2.1.4")));\r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
     System.out.println("installed packageses = " + packageses);\r
@@ -213,7 +236,7 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
     File sourcesDir = new File(myRoot, "js");\r
     ArchiveUtil.unpackZip(Paths.getTestDataPath("test-01-sources.zip"), "", sourcesDir);\r
 \r
-    fetchPackages(new File(myRoot, "sln1-lib.sln"), Arrays.asList("file:///" + sourcesDir.getPath()), false, false);\r
+    fetchPackages(new File(myRoot, "sln1-lib.sln"), Arrays.asList("file:///" + sourcesDir.getPath()), false, false, null);\r
 \r
     List<File> packageses = Arrays.asList(new File(myRoot, "packages").listFiles());\r
     System.out.println("installed packageses = " + packageses);\r
@@ -227,27 +250,33 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
   private void fetchPackages(final File sln,\r
                              final List<String> sources,\r
                              final boolean excludeVersion,\r
-                             final boolean update) throws RunBuildException {\r
-    final PackageUsages pu = m.mock(PackageUsages.class);\r
-    final BuildProcess pup = m.mock(BuildProcess.class, "report usages");\r
+                             final boolean update,\r
+                             @Nullable Collection<PackageInfo> detectedPackages) throws RunBuildException {\r
+\r
     m.checking(new Expectations() {{\r
-      allowing(myParametersFactory).loadNuGetParameters(myContext);  will(returnValue(myNuGet));\r
-      allowing(myParametersFactory).loadInstallPackagesParameters(myContext, myNuGet);  will(returnValue(myInstall));\r
+      allowing(myParametersFactory).loadNuGetParameters(myContext);\r
+      will(returnValue(myNuGet));\r
+      allowing(myParametersFactory).loadInstallPackagesParameters(myContext, myNuGet);\r
+      will(returnValue(myInstall));\r
 \r
       allowing(myNuGet).getNuGetExeFile();\r
       will(returnValue(Paths.getPathToNuGet()));\r
-      allowing(myNuGet).getSolutionFile(); will(returnValue(sln));\r
-      allowing(myNuGet).getNuGetPackageSources(); will(returnValue(sources));\r
-      allowing(myInstall).getExcludeVersion(); will(returnValue(excludeVersion));\r
-      allowing(myParametersFactory).loadUpdatePackagesParameters(myContext, myNuGet);  will(returnValue(update ? myUpdate : null));\r
-\r
-      allowing(pu).createReport(with(any(File.class)));\r
-      will(returnValue(pup));\r
-\r
-      allowing(pup).start();\r
-      allowing(pup).waitFor(); will(returnValue(BuildFinishedStatus.FINISHED_SUCCESS));\r
+      allowing(myNuGet).getSolutionFile();\r
+      will(returnValue(sln));\r
+      allowing(myNuGet).getNuGetPackageSources();\r
+      will(returnValue(sources));\r
+      allowing(myInstall).getExcludeVersion();\r
+      will(returnValue(excludeVersion));\r
+      allowing(myParametersFactory).loadUpdatePackagesParameters(myContext, myNuGet);\r
+      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),\r
             myParametersFactory\r
@@ -255,6 +284,13 @@ public class InstallPackageIntegtatoinTest extends BuildProcessTestCase {
 \r
     assertRunSuccessfully(proc, BuildFinishedStatus.FINISHED_SUCCESS);\r
 \r
+    System.out.println(collector.getPackages());\r
+    if (detectedPackages != null) {\r
+      Assert.assertEquals(\r
+              new TreeSet<PackageInfo>(collector.getPackages().getPackages()),\r
+              new TreeSet<PackageInfo>(detectedPackages));\r
+    }\r
+\r
     m.assertIsSatisfied();\r
   }\r
 \r