add packages watcher test
authorEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 19 Jul 2011 10:23:25 +0000 (14:23 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 19 Jul 2011 10:23:25 +0000 (14:23 +0400)
nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/PackagesWatcherTest.java [new file with mode: 0644]
nuget-tests/src/testng-nuget-tests..xml

diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/PackagesWatcherTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/agent/PackagesWatcherTest.java
new file mode 100644 (file)
index 0000000..b98a740
--- /dev/null
@@ -0,0 +1,122 @@
+/*\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.agent.AgentLifeCycleListener;\r
+import jetbrains.buildServer.agent.AgentRunningBuild;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.agent.artifacts.ArtifactsWatcher;\r
+import jetbrains.buildServer.nuget.agent.install.NuGetPackagesCollector;\r
+import jetbrains.buildServer.nuget.agent.install.impl.NuGetPackagesCollectorImpl;\r
+import jetbrains.buildServer.nuget.agent.install.impl.PackagesInfoUploader;\r
+import jetbrains.buildServer.nuget.agent.install.impl.PackagesWatcher;\r
+import jetbrains.buildServer.nuget.common.PackageDependenciesStore;\r
+import jetbrains.buildServer.util.EventDispatcher;\r
+import org.hamcrest.BaseMatcher;\r
+import org.hamcrest.Description;\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.io.IOException;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 19.07.11 14:10\r
+ */\r
+public class PackagesWatcherTest extends BaseTestCase {\r
+  private Mockery m;\r
+  private ArtifactsWatcher watcher;\r
+  private NuGetPackagesCollector collector;\r
+  private AgentLifeCycleListener multicaster;\r
+  private AgentRunningBuild build;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+    m = new Mockery();\r
+    watcher = m.mock(ArtifactsWatcher.class);\r
+    build = m.mock(AgentRunningBuild.class);\r
+\r
+    final EventDispatcher<AgentLifeCycleListener> events = EventDispatcher.create(AgentLifeCycleListener.class);\r
+    multicaster = events.getMulticaster();\r
+\r
+    final NuGetPackagesCollectorImpl nuGetPackagesCollector = new NuGetPackagesCollectorImpl();\r
+    collector = nuGetPackagesCollector;\r
+\r
+    new PackagesWatcher(\r
+            events,\r
+            nuGetPackagesCollector,\r
+            new PackagesInfoUploader(watcher, new PackageDependenciesStore())\r
+    );\r
+  }\r
+\r
+  @Test\r
+  public void test_upload_packages_in_before_build_finish_no_packages() {\r
+    multicaster.beforeBuildFinish(build, BuildFinishedStatus.FINISHED_FAILED);\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_upload_packages_in_before_build_finish_with_packages() throws IOException {\r
+    final File tempDir = createTempDir();\r
+    m.checking(new Expectations(){{\r
+      allowing(build).getBuildTempDirectory();  will(returnValue(tempDir));\r
+      oneOf(watcher).addNewArtifactsPath(with(new NuGetUploadPathMatcher(tempDir)));\r
+    }});\r
+\r
+    collector.addPackage("aaa", "1.2.4", null);\r
+    multicaster.beforeBuildFinish(build, BuildFinishedStatus.FINISHED_FAILED);\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_clean_packages_on_build_start() {\r
+    collector.addPackage("aaa", "bbb", null);\r
+    multicaster.buildStarted(build);\r
+\r
+    Assert.assertTrue(collector.getPackages().isEmpty());\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  private static class NuGetUploadPathMatcher extends BaseMatcher<String> {\r
+    private final File myTempDir;\r
+\r
+    public NuGetUploadPathMatcher(File tempDir) {\r
+      myTempDir = tempDir;\r
+    }\r
+\r
+    public boolean matches(Object o) {\r
+      String path = ((String) o).trim();\r
+      if (!path.startsWith(myTempDir.getPath())) return false;\r
+      return (path.endsWith("/nuget.xml => .teamcity/nuget")\r
+              || path.endsWith("\\nuget.xml => .teamcity/nuget"));\r
+    }\r
+\r
+    public void describeTo(Description description) {\r
+    }\r
+  }\r
+}\r
index 1b4d1883f1d5633e2f5c6f144325d76ee45ab57b..866a2b0ee6f12c19e93d8a9cd09ef1b67d5f329e 100644 (file)
@@ -4,6 +4,7 @@
   <test name="fast tests">\r
     <classes>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetPackagesConfigParserTest"/>\r
   <test name="fast tests">\r
     <classes>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetPackagesConfigParserTest"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.agent.PackagesWatcherTest"/>\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.LocateNuGetConfigBuildProcessTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.PackagesInstallerBuilderTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.NuGetInstallPackageActionFactoryTest"/>\r