"trigger does not work" fix
authorEugene Petrenko <eugene.petrenko@gmail.com>
Wed, 20 Jul 2011 11:24:28 +0000 (15:24 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Wed, 20 Jul 2011 11:24:28 +0000 (15:24 +0400)
nuget-server/src/jetbrains/buildServer/nuget/server/trigger/NamedPackagesUpdateChecker.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/server/NamedPackagesUpdateCheckerTest.java

index ffbdfe6139b1ea31d5e74705cd17acce04136875..109e91ec735327add075dcd14263629a55a18abb 100644 (file)
@@ -52,10 +52,13 @@ public class NamedPackagesUpdateChecker implements TriggerUpdateChecker {
     final String hash = serializeHashcode(result);\r
 \r
     String oldHash = storage.getValue(KEY);\r
-    if (oldHash != null && !hash.equals(oldHash)) {\r
+    if (!hash.equals(oldHash)) {\r
       storage.putValue(KEY, hash);\r
       storage.flush();\r
-      return new BuildStartReason("NuGet Package " + pkgId + " updated");\r
+\r
+      if (oldHash != null) {\r
+        return new BuildStartReason("NuGet Package " + pkgId + " updated");\r
+      }\r
     }\r
 \r
     return null;\r
@@ -68,7 +71,9 @@ public class NamedPackagesUpdateChecker implements TriggerUpdateChecker {
         int i;\r
         String s1 = o1.getSource();\r
         String s2 = o2.getSource();\r
-        if (s1 != null && s2 != null && 0 != (i = s1.compareTo(s2))) return i;\r
+        if (s1 == null && s2 == null) return 0;\r
+        if (s1 == null ^ s2 == null) return 1;\r
+        if (0 != (i = s1.compareTo(s2))) return i;\r
         if (0 != (i = o1.getPackageId().compareTo(o2.getPackageId()))) return i;\r
         if (0 != (i = o1.getVersion().compareTo(o2.getVersion()))) return i;\r
         return 0;\r
index ebb15bbc90f84950de68cf2a7411e7dd529b6537..41b2454eb4b986e827cb3f3ecc19d7acadeab91e 100644 (file)
@@ -82,6 +82,106 @@ public class NamedPackagesUpdateCheckerTest extends BaseTestCase {
       oneOf(store).flush();\r
     }});\r
     Assert.assertNull(checker.checkChanges(desr, store));\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_should_trigger_on_new_package() {\r
+    final String source = "\\\\ServerNameRemoved\\NugetTest\\Repository";\r
+\r
+    params.put(TriggerConstants.PACKAGE, "Common");\r
+    params.put(TriggerConstants.SOURCE, source);\r
+    m.checking(new Expectations(){{\r
+      oneOf(cmd).checkForChanges(nugetFakePath, source, "Common", null);\r
+      will(returnValue(Arrays.asList(new SourcePackageInfo(source, "Common", "1.0.0.21"))));\r
+\r
+      oneOf(cmd).checkForChanges(nugetFakePath, source, "Common", null);\r
+      will(returnValue(Arrays.asList(\r
+              new SourcePackageInfo(source, "Common", "1.0.0.21"),\r
+              new SourcePackageInfo(source, "Common", "2.0.0.22")\r
+              )));\r
+\r
+      final String hash1 = "|s:\\\\ServerNameRemoved\\NugetTest\\Repository|p:Common|v:1.0.0.21";\r
+      final String hash2 = "|s:\\\\ServerNameRemoved\\NugetTest\\Repository|p:Common|v:1.0.0.21|s:\\\\ServerNameRemoved\\NugetTest\\Repository|p:Common|v:2.0.0.22";\r
+\r
+      oneOf(store).getValue("hash"); will(returnValue(null));\r
+      oneOf(store).putValue("hash", hash1);\r
+      oneOf(store).flush();\r
+\r
+      oneOf(store).getValue("hash"); will(returnValue(hash1));\r
+      oneOf(store).putValue("hash", hash2);\r
+      oneOf(store).flush();\r
+\r
+    }});\r
+    Assert.assertNull(checker.checkChanges(desr, store));\r
+\r
+\r
+    Assert.assertNotNull(checker.checkChanges(desr, store));\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_should_trigger_on_new_package2() {\r
+    final String source = "\\\\ServerNameRemoved\\NugetTest\\Repository";\r
+\r
+    params.put(TriggerConstants.PACKAGE, "Common");\r
+    params.put(TriggerConstants.SOURCE, source);\r
+    m.checking(new Expectations(){{\r
+      oneOf(cmd).checkForChanges(nugetFakePath, source, "Common", null);\r
+      will(returnValue(Arrays.asList(new SourcePackageInfo(source, "Common", "1.0.0.21"))));\r
+\r
+      oneOf(cmd).checkForChanges(nugetFakePath, source, "Common", null);\r
+      will(returnValue(Arrays.asList(\r
+              new SourcePackageInfo(source, "Common", "1.0.0.21"),\r
+              new SourcePackageInfo(source, "Common", "2.0.0.22")\r
+              )));\r
+\r
+      final String hash1 = "|s:\\\\ServerNameRemoved\\NugetTest\\Repository|p:Common|v:1.0.0.21";\r
+      final String hash2 = "|s:\\\\ServerNameRemoved\\NugetTest\\Repository|p:Common|v:1.0.0.21|s:\\\\ServerNameRemoved\\NugetTest\\Repository|p:Common|v:2.0.0.22";\r
+\r
+      oneOf(store).getValue("hash"); will(returnValue(hash1));\r
+      oneOf(store).getValue("hash"); will(returnValue(hash1));\r
+      oneOf(store).putValue("hash", hash2);\r
+      oneOf(store).flush();\r
+\r
+    }});\r
+    Assert.assertNull(checker.checkChanges(desr, store));\r
+\r
+\r
+    Assert.assertNotNull(checker.checkChanges(desr, store));\r
+\r
+    m.assertIsSatisfied();\r
+  }\r
+\r
+  @Test\r
+  public void test_should_sort_packages() {\r
+    final String source = "\\\\ServerNameRemoved\\NugetTest\\Repository";\r
+\r
+    params.put(TriggerConstants.PACKAGE, "Common");\r
+    params.put(TriggerConstants.SOURCE, source);\r
+    m.checking(new Expectations(){{\r
+      oneOf(cmd).checkForChanges(nugetFakePath, source, "Common", null);\r
+      will(returnValue(Arrays.asList(\r
+              new SourcePackageInfo(source, "Common", "1.0.0.21"),\r
+              new SourcePackageInfo(null, "Common", "2.0.0.22"),\r
+              new SourcePackageInfo("s2", "C3ommon", "2.0.0.22"),\r
+              new SourcePackageInfo(null, "C3ommon", "2.0.0.22"),\r
+              new SourcePackageInfo(null, "C3o4mmon", "2.0.0.22"),\r
+              new SourcePackageInfo("s4", "C3o3mmon", "2.0.0.22"),\r
+              new SourcePackageInfo(null, "C3omm5on", "2.0.0.22")\r
+              )));\r
+\r
+      final String hash1 = "|p:Common|v:2.0.0.22|s:\\\\ServerNameRemoved\\NugetTest\\Repository|p:Common|v:1.0.0.21|s:s2|p:C3ommon|v:2.0.0.22|s:s4|p:C3o3mmon|v:2.0.0.22|p:C3ommon|v:2.0.0.22|p:C3o4mmon|v:2.0.0.22|p:C3omm5on|v:2.0.0.22";\r
+      oneOf(store).getValue("hash"); will(returnValue("foo"));\r
+      oneOf(store).putValue("hash", hash1);\r
+      oneOf(store).flush();\r
+\r
+    }});\r
+    Assert.assertNotNull(checker.checkChanges(desr, store));\r
+\r
+    m.assertIsSatisfied();\r
   }\r
 \r
   @Test\r
@@ -101,6 +201,8 @@ public class NamedPackagesUpdateCheckerTest extends BaseTestCase {
 \r
     Assert.assertNotNull(checker.checkChanges(desr, store));\r
     Assert.assertNull(checker.checkChanges(desr, store));\r
+\r
+    m.assertIsSatisfied();\r
   }\r
 \r
   @Test\r
@@ -111,9 +213,11 @@ public class NamedPackagesUpdateCheckerTest extends BaseTestCase {
     }});\r
     try {\r
       checker.checkChanges(desr, store);\r
+      Assert.fail("should throw an exception");\r
     } catch (BuildTriggerException e) {\r
-      return;\r
+      //NOP\r
     }\r
-    Assert.fail("should throw an exception");\r
+\r
+    m.assertIsSatisfied();\r
   }\r
 }\r