add new ant paths matcher
[teamcity/dotNetPackagesSupport.git] / nuget-tests / src / jetbrains / buildServer / nuget / tests / util / CompositeBuildProcessTest.java
1 /*\r
2  * Copyright 2000-2011 JetBrains s.r.o.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package jetbrains.buildServer.nuget.tests.util;\r
18 \r
19 import jetbrains.buildServer.RunBuildException;\r
20 import jetbrains.buildServer.agent.BuildFinishedStatus;\r
21 import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl;\r
22 import org.jetbrains.annotations.NotNull;\r
23 import org.testng.Assert;\r
24 import org.testng.annotations.Test;\r
25 \r
26 import java.util.ArrayList;\r
27 import java.util.List;\r
28 \r
29 /**\r
30  * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
31  * Date: 07.07.11 19:04\r
32  */\r
33 public class CompositeBuildProcessTest extends BuildProcessTestCase {\r
34   @Test\r
35   public void test_empty_build_process() {\r
36     CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
37     assertRunSuccessfully(i, BuildFinishedStatus.FINISHED_SUCCESS);\r
38   }\r
39 \r
40   @Test(dataProvider = "buildFinishStatuses")\r
41   public void test_one_build_process(BuildFinishedStatus result) throws RunBuildException {\r
42     CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
43     i.pushBuildProcess(new RecordingBuildProcess("1", result));\r
44     assertRunSuccessfully(i, result == BuildFinishedStatus.INTERRUPTED ? BuildFinishedStatus.FINISHED_SUCCESS : result);\r
45 \r
46     assertLog("start-1", "waitFor-1");\r
47   }\r
48 \r
49   @Test\r
50   public void test_stopOnFirstError() throws RunBuildException {\r
51     CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
52     i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_FAILED));\r
53     i.pushBuildProcess(new RecordingBuildProcess("2", BuildFinishedStatus.FINISHED_SUCCESS));\r
54 \r
55     assertRunSuccessfully(i, BuildFinishedStatus.FINISHED_FAILED);\r
56     assertLog("start-1", "waitFor-1");\r
57   }\r
58 \r
59   @Test\r
60   public void test_stopOnFirstError2() throws RunBuildException {\r
61     CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
62     i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS));\r
63     i.pushBuildProcess(new RecordingBuildProcess("2", BuildFinishedStatus.FINISHED_FAILED));\r
64     i.pushBuildProcess(new RecordingBuildProcess("3", BuildFinishedStatus.FINISHED_SUCCESS));\r
65 \r
66     assertRunSuccessfully(i, BuildFinishedStatus.FINISHED_FAILED);\r
67     assertLog("start-1", "waitFor-1", "start-2", "waitFor-2");\r
68   }\r
69 \r
70   @Test\r
71   public void test_stopOnStartException() throws RunBuildException {\r
72     CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
73     i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS));\r
74     i.pushBuildProcess(new RecordingBuildProcess("2", BuildFinishedStatus.FINISHED_SUCCESS) {{\r
75       setStartException(new RunBuildException("aaa"));\r
76     }});\r
77     i.pushBuildProcess(new RecordingBuildProcess("3", BuildFinishedStatus.FINISHED_SUCCESS));\r
78 \r
79     assertRunException(i, "aaa");\r
80     assertLog("start-1", "waitFor-1", "start-2");\r
81   }\r
82 \r
83   @Test\r
84   public void test_stopOnWaitForException() throws RunBuildException {\r
85     CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
86     i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS));\r
87     i.pushBuildProcess(new RecordingBuildProcess("2", BuildFinishedStatus.FINISHED_SUCCESS) {{\r
88       setFinishException(new RunBuildException("aaa"));\r
89     }});\r
90     i.pushBuildProcess(new RecordingBuildProcess("3", BuildFinishedStatus.FINISHED_SUCCESS));\r
91 \r
92     assertRunException(i, "aaa");\r
93     assertLog("start-1", "waitFor-1", "start-2", "waitFor-2");\r
94   }\r
95 \r
96   @Test\r
97   public void test_emptyInterrupted() {\r
98     CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
99     i.interrupt();\r
100 \r
101     Assert.assertFalse(i.isFinished());\r
102     Assert.assertTrue(i.isInterrupted());\r
103     assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
104 \r
105     Assert.assertTrue(i.isInterrupted());\r
106     Assert.assertTrue(i.isFinished());\r
107   }\r
108 \r
109   @Test\r
110   public void test_interruptCalledForFirst() {\r
111     final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
112     final List<String> log = new ArrayList<String>();\r
113     i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS) {\r
114       @Override\r
115       public void start() throws RunBuildException {\r
116         super.start();\r
117         i.interrupt();\r
118       }\r
119     });\r
120     i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS));\r
121 \r
122     assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
123     assertLog("start-1", "interrupt-1", "waitFor-1");\r
124   }\r
125 \r
126   @Test\r
127   public void test_interruptCalledForFirst_WaitFor() {\r
128     final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
129     i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS) {\r
130       @NotNull\r
131       @Override\r
132       public BuildFinishedStatus waitFor() throws RunBuildException {\r
133         i.interrupt();\r
134         return super.waitFor();\r
135       }\r
136     });\r
137     i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS));\r
138 \r
139     assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
140     assertLog("start-1", "interrupt-1", "waitFor-1");\r
141   }\r
142 \r
143   @Test\r
144   public void test_interruptCalledForTwo() {\r
145     final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
146     i.pushBuildProcess(new RecordingBuildProcess("0", BuildFinishedStatus.FINISHED_SUCCESS));\r
147     i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS) {\r
148       @Override\r
149       public void start() throws RunBuildException {\r
150         super.start();\r
151         i.interrupt();\r
152       }\r
153     });\r
154     i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS));\r
155 \r
156     assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
157     assertLog("start-0", "waitFor-0", "start-1", "interrupt-1", "waitFor-1");\r
158   }\r
159 \r
160   @Test\r
161   public void test_interruptCalledForTwo_WaitFor() {\r
162     final CompositeBuildProcessImpl i = new CompositeBuildProcessImpl();\r
163     i.pushBuildProcess(new RecordingBuildProcess("0", BuildFinishedStatus.FINISHED_SUCCESS));\r
164     i.pushBuildProcess(new RecordingBuildProcess("1", BuildFinishedStatus.FINISHED_SUCCESS) {\r
165       @NotNull\r
166       @Override\r
167       public BuildFinishedStatus waitFor() throws RunBuildException {\r
168         i.interrupt();\r
169         return super.waitFor();\r
170       }\r
171     });\r
172     i.pushBuildProcess(new RecordingBuildProcess("f", BuildFinishedStatus.FINISHED_SUCCESS));\r
173 \r
174     assertRunSuccessfully(i, BuildFinishedStatus.INTERRUPTED);\r
175     assertLog("start-0", "waitFor-0", "start-1", "interrupt-1", "waitFor-1");\r
176   }\r
177 }\r