@@ -74,67 +74,49 @@ public void shouldAppendPipelineFromDirectory() throws Exception
7474 assertThat (result .getPipelines ().size (), is (1 ));
7575 }
7676 @ Test
77- public void shouldThrowErrorsWithLocationWhenInvalidContent () throws Exception
77+ public void shouldAppendErrorsWithLocationWhenInvalidContent () throws Exception
7878 {
7979 createFileWithContent ("pipe1.gopipeline.json" , this .pipe1String );
8080 createFileWithContent ("pipeBad1.gopipeline.json" , "bad pipeline" );
81- try {
82- parser .parseDirectory (directory );
83- fail ("should have thrown" );
84- }
85- catch (ConfigDirectoryParseException parseException )
86- {
87- assertThat (parseException .getErrors ().size (),is (1 ));
88- assertThat (parseException .getErrors ().get (0 ).getLocation (), is ("pipeBad1.gopipeline.json" ));
89- assertThat (parseException .getErrors ().get (0 ).getMessage (), startsWith ("Failed to parse pipeline file as JSON: " ));
90- }
81+ JsonConfigCollection result = parser .parseDirectory (directory );
82+ assertThat (result .getErrors ().size (),is (1 ));
83+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("location" ).getAsString (), is ("pipeBad1.gopipeline.json" ));
84+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("message" ).getAsString (), startsWith ("Failed to parse pipeline file as JSON: " ));
85+
9186 }
9287 @ Test
93- public void shouldThrowAllErrorsWhenManyFilesHaveInvalidContent () throws Exception
88+ public void shouldAppendAllErrorsWhenManyFilesHaveInvalidContent () throws Exception
9489 {
9590 createFileWithContent ("pipe1.gopipeline.json" , this .pipe1String );
9691 createFileWithContent ("pipeBad1.gopipeline.json" , "bad pipeline" );
9792 createFileWithContent ("pipeBad2.gopipeline.json" , "bad pipeline 2" );
98- try {
99- parser .parseDirectory (directory );
100- fail ("should have thrown" );
101- }
102- catch (ConfigDirectoryParseException parseException )
103- {
104- assertThat (parseException .getErrors ().size (),is (2 ));
105- }
93+
94+ JsonConfigCollection result = parser .parseDirectory (directory );
95+ assertThat (result .getErrors ().size (),is (2 ));
10696 }
10797 @ Test
108- public void shouldThrowErrorWhenPipelineFileIsEmpty () throws Exception
98+ public void shouldAppendErrorWhenPipelineFileIsEmpty () throws Exception
10999 {
110100 createFileWithContent ("pipe1.gopipeline.json" , this .pipe1String );
111101 createFileWithContent ("pipeBad1.gopipeline.json" , "" );
112- try {
113- parser .parseDirectory (directory );
114- fail ("should have thrown" );
115- }
116- catch (ConfigDirectoryParseException parseException )
117- {
118- assertThat (parseException .getErrors ().size (),is (1 ));
119- assertThat (parseException .getErrors ().get (0 ).getLocation (), is ("pipeBad1.gopipeline.json" ));
120- assertThat (parseException .getErrors ().get (0 ).getMessage (), is ("Pipeline file is empty" ));
121- }
102+
103+ JsonConfigCollection result = parser .parseDirectory (directory );
104+ assertThat (result .getErrors ().size (),is (1 ));
105+
106+ assertThat (result .getErrors ().size (),is (1 ));
107+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("location" ).getAsString (), is ("pipeBad1.gopipeline.json" ));
108+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("message" ).getAsString (), is ("Pipeline file is empty" ));
122109 }
123110 @ Test
124- public void shouldThrowErrorWhenPipelineBlockIsEmpty () throws Exception
111+ public void shouldAppendErrorWhenPipelineBlockIsEmpty () throws Exception
125112 {
126113 createFileWithContent ("pipe1.gopipeline.json" , this .pipe1String );
127114 createFileWithContent ("pipeBad1.gopipeline.json" , "{}" );
128- try {
129- parser .parseDirectory (directory );
130- fail ("should have thrown" );
131- }
132- catch (ConfigDirectoryParseException parseException )
133- {
134- assertThat (parseException .getErrors ().size (),is (1 ));
135- assertThat (parseException .getErrors ().get (0 ).getLocation (), is ("pipeBad1.gopipeline.json" ));
136- assertThat (parseException .getErrors ().get (0 ).getMessage (), is ("Pipeline definition is empty" ));
137- }
115+
116+ JsonConfigCollection result = parser .parseDirectory (directory );
117+ assertThat (result .getErrors ().size (),is (1 ));
118+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("location" ).getAsString (), is ("pipeBad1.gopipeline.json" ));
119+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("message" ).getAsString (), is ("Pipeline definition is empty" ));
138120 }
139121
140122
@@ -146,67 +128,49 @@ public void shouldAppendEnvironmentFromDirectory() throws Exception
146128 assertThat (result .getEnvironments ().size (), is (1 ));
147129 }
148130 @ Test
149- public void shouldThrowErrorsWithLocationWhenInvalidContentInEnvironment () throws Exception
131+ public void shouldAppendErrorsWithLocationWhenInvalidContentInEnvironment () throws Exception
150132 {
151133 createFileWithContent ("devenv.goenvironment.json" , this .pipe1String );
152134 createFileWithContent ("badEnv.goenvironment.json" , "bad environment" );
153- try {
154- parser .parseDirectory (directory );
155- fail ("should have thrown" );
156- }
157- catch (ConfigDirectoryParseException parseException )
158- {
159- assertThat (parseException .getErrors ().size (),is (1 ));
160- assertThat (parseException .getErrors ().get (0 ).getLocation (), is ("badEnv.goenvironment.json" ));
161- assertThat (parseException .getErrors ().get (0 ).getMessage (), startsWith ("Failed to parse environment file as JSON: " ));
162- }
135+ JsonConfigCollection result = parser .parseDirectory (directory );
136+ assertThat (result .getErrors ().size (),is (1 ));
137+
138+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("location" ).getAsString (), is ("badEnv.goenvironment.json" ));
139+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("message" ).getAsString (), startsWith ("Failed to parse environment file as JSON: " ));
163140 }
164141 @ Test
165- public void shouldThrowAllErrorsWhenManyEnvironmentFilesHaveInvalidContent () throws Exception
142+ public void shouldAppendAllErrorsWhenManyEnvironmentFilesHaveInvalidContent () throws Exception
166143 {
167144 createFileWithContent ("pipe1.gopipeline.json" , this .pipe1String );
168145 createFileWithContent ("badEnv.goenvironment.json" , "bad env" );
169146 createFileWithContent ("badEnv2.goenvironment.json" , "bad env 2" );
170- try {
171- parser .parseDirectory (directory );
172- fail ("should have thrown" );
173- }
174- catch (ConfigDirectoryParseException parseException )
175- {
176- assertThat (parseException .getErrors ().size (),is (2 ));
177- }
147+ JsonConfigCollection result = parser .parseDirectory (directory );
148+
149+ assertThat (result .getErrors ().size (),is (2 ));
178150 }
179151 @ Test
180- public void shouldThrowErrorWhenEnvironmentFileIsEmpty () throws Exception
152+ public void shouldAppendErrorWhenEnvironmentFileIsEmpty () throws Exception
181153 {
182154 createFileWithContent ("devenv.goenvironment.json" , this .devenvString );
183155 createFileWithContent ("badEnv.goenvironment.json" , "" );
184- try {
185- parser .parseDirectory (directory );
186- fail ("should have thrown" );
187- }
188- catch (ConfigDirectoryParseException parseException )
189- {
190- assertThat (parseException .getErrors ().size (),is (1 ));
191- assertThat (parseException .getErrors ().get (0 ).getLocation (), is ("badEnv.goenvironment.json" ));
192- assertThat (parseException .getErrors ().get (0 ).getMessage (), is ("Environment file is empty" ));
193- }
156+
157+ JsonConfigCollection result = parser .parseDirectory (directory );
158+ assertThat (result .getErrors ().size (),is (1 ));
159+
160+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("location" ).getAsString (), is ("badEnv.goenvironment.json" ));
161+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("message" ).getAsString (), is ("Environment file is empty" ));
194162 }
195163 @ Test
196164 public void shouldThrowErrorWhenEnvironmentBlockIsEmpty () throws Exception
197165 {
198166 createFileWithContent ("devenv.goenvironment.json" , this .devenvString );
199167 createFileWithContent ("badEnv.goenvironment.json" , "{}" );
200- try {
201- parser .parseDirectory (directory );
202- fail ("should have thrown" );
203- }
204- catch (ConfigDirectoryParseException parseException )
205- {
206- assertThat (parseException .getErrors ().size (),is (1 ));
207- assertThat (parseException .getErrors ().get (0 ).getLocation (), is ("badEnv.goenvironment.json" ));
208- assertThat (parseException .getErrors ().get (0 ).getMessage (), is ("Environment definition is empty" ));
209- }
168+
169+ JsonConfigCollection result = parser .parseDirectory (directory );
170+ assertThat (result .getErrors ().size (),is (1 ));
171+
172+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("location" ).getAsString (), is ("badEnv.goenvironment.json" ));
173+ assertThat (result .getErrors ().get (0 ).getAsJsonObject ().getAsJsonPrimitive ("message" ).getAsString (), is ("Environment definition is empty" ));
210174 }
211175
212176 private void createFileWithContent (String filePath , String content ) throws FileNotFoundException , UnsupportedEncodingException {
0 commit comments