more tests on commandline output parsing
authorEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 14 Jul 2011 10:55:15 +0000 (14:55 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Thu, 14 Jul 2011 10:55:15 +0000 (14:55 +0400)
nuget-server/src/jetbrains/buildServer/nuget/server/exec/ListPackagesCommandProcessor.java
nuget-tests/src/jetbrains/buildServer/nuget/tests/server/ListPackagesCommandProcessorTest.java [new file with mode: 0644]
nuget-tests/src/testng-nuget-tests..xml

index 2a853f46cdad3ca637d061d4bdba6a057f1033bd..57dd71c543974a119c138020d1c2b8e34c5b2649 100644 (file)
@@ -37,7 +37,7 @@ public class ListPackagesCommandProcessor implements NuGetOutputProcessor<Collec
   private final String mySource;\r
   private final List<PackageInfo> myPackages = new ArrayList<PackageInfo>();\r
 \r
-  ListPackagesCommandProcessor(@NotNull final String source) {\r
+  public ListPackagesCommandProcessor(@NotNull final String source) {\r
     mySource = source;\r
   }\r
 \r
diff --git a/nuget-tests/src/jetbrains/buildServer/nuget/tests/server/ListPackagesCommandProcessorTest.java b/nuget-tests/src/jetbrains/buildServer/nuget/tests/server/ListPackagesCommandProcessorTest.java
new file mode 100644 (file)
index 0000000..000ef00
--- /dev/null
@@ -0,0 +1,90 @@
+/*\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.server;\r
+\r
+import jetbrains.buildServer.BaseTestCase;\r
+import jetbrains.buildServer.nuget.server.exec.ListPackagesCommandProcessor;\r
+import jetbrains.buildServer.nuget.server.exec.PackageInfo;\r
+import org.testng.Assert;\r
+import org.testng.annotations.BeforeMethod;\r
+import org.testng.annotations.Test;\r
+\r
+import java.util.Collection;\r
+import java.util.Iterator;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 14.07.11 14:28\r
+ */\r
+public class ListPackagesCommandProcessorTest extends BaseTestCase {\r
+  private  ListPackagesCommandProcessor p;\r
+\r
+  @BeforeMethod\r
+  @Override\r
+  protected void setUp() throws Exception {\r
+    super.setUp();\r
+    p = new ListPackagesCommandProcessor("source5");\r
+  }\r
+\r
+  @Test\r
+  public void test_empty() {\r
+    Assert.assertTrue(p.getResult().isEmpty());\r
+  }\r
+\r
+  @Test\r
+  public void test_some_output() {\r
+    for(int i =0; i <100; i++) {\r
+      p.onStdError("asdasd");\r
+      p.onStdOutput("3434");\r
+    }\r
+    Assert.assertTrue(p.getResult().isEmpty());\r
+  }\r
+\r
+  @Test\r
+  public void test_parse_service_message() {\r
+    p.onStdOutput("##teamcity[nuget-package Id='NUnit' Version='2.5.10.11092']");\r
+\r
+    Collection<PackageInfo> result = p.getResult();\r
+    Assert.assertEquals(result.size(), 1);\r
+    PackageInfo next = result.iterator().next();\r
+\r
+    Assert.assertEquals(next.getSource(), "source5");\r
+    Assert.assertEquals(next.getPackageId(), "NUnit");\r
+    Assert.assertEquals(next.getVersion(), "2.5.10.11092");\r
+  }\r
+\r
+  @Test\r
+  public void test_parse_service_message_multiple() {\r
+    p.onStdOutput("##teamcity[nuget-package Id='NUnit' Version='2.5.10.11092']");\r
+    p.onStdOutput("##teamcity[nuget-package Id='JUnit' Version='1.2.0.92']");\r
+\r
+    Collection<PackageInfo> result = p.getResult();\r
+    Assert.assertEquals(result.size(), 2);\r
+    Iterator<PackageInfo> it = result.iterator();\r
+    PackageInfo next = it.next();\r
+\r
+    Assert.assertEquals(next.getSource(), "source5");\r
+    Assert.assertEquals(next.getPackageId(), "NUnit");\r
+    Assert.assertEquals(next.getVersion(), "2.5.10.11092");\r
+\r
+    next = it.next();\r
+    Assert.assertEquals(next.getSource(), "source5");\r
+    Assert.assertEquals(next.getPackageId(), "JUnit");\r
+    Assert.assertEquals(next.getVersion(), "1.2.0.92");\r
+  }\r
+\r
+}\r
index b3f4b5f4f805eb765b1563bb63291aca1fb60cef..85cd5df4e8046f134f67cfd66dde666499ee5f6c 100644 (file)
@@ -11,6 +11,7 @@
       <class name="jetbrains.buildServer.nuget.tests.util.DelegatingBuildProcessTest"/>\r
 \r
       <class name="jetbrains.buildServer.nuget.tests.server.ListPackagesCommandTest"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.server.ListPackagesCommandProcessorTest"/>\r
     </classes>\r
   </test>\r
 \r