@@ -112,14 +112,22 @@ public void shouldConsumePluginSettingsOnConfigChangeRequest() throws UnhandledR
112112 body .put (PLUGIN_SETTINGS_ENVIRONMENT_PATTERN , "*.foo.envs.json" );
113113 request .setRequestBody (JSONUtils .toJSON (body ));
114114
115- assertEquals (DEFAULT_PIPELINE_PATTERN , plugin .getPipelinePattern ());
116- assertEquals (DEFAULT_ENVIRONMENT_PATTERN , plugin .getEnvironmentPattern ());
115+ DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest ("configrepo" , "1.0" , "parse-directory" );
116+ String requestBody = "{\n " +
117+ " \" directory\" :\" emptyDir\" ,\n " +
118+ " \" configurations\" :[]\n " +
119+ "}" ;
120+ parseDirectoryRequest .setRequestBody (requestBody );
121+ ParsedRequest parsed = ParsedRequest .parse (parseDirectoryRequest );
122+
123+ assertEquals (DEFAULT_PIPELINE_PATTERN , plugin .getPipelinePattern (parsed ));
124+ assertEquals (DEFAULT_ENVIRONMENT_PATTERN , plugin .getEnvironmentPattern (parsed ));
117125
118126 GoPluginApiResponse response = plugin .handle (request );
119127
120128 assertThat (response .responseCode (), is (SUCCESS_RESPONSE_CODE ));
121- assertEquals ("*.foo.pipes.json" , plugin .getPipelinePattern ());
122- assertEquals ("*.foo.envs.json" , plugin .getEnvironmentPattern ());
129+ assertEquals ("*.foo.pipes.json" , plugin .getPipelinePattern (parsed ));
130+ assertEquals ("*.foo.envs.json" , plugin .getEnvironmentPattern (parsed ));
123131 }
124132
125133
@@ -157,6 +165,64 @@ public void shouldContainPipelinePatternInResponseToGetConfigurationRequest() th
157165 assertThat (pipelinePatternConfigAsJsonObject .get ("display-order" ).getAsInt (), is (0 ));
158166 }
159167
168+ @ Test
169+ public void getPipelinePatternShouldReturnValueAtConfigRepoLevelIfDefined () {
170+ DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest ("configrepo" , "1.0" , "parse-directory" );
171+ String requestBody = "{\n " +
172+ " \" directory\" :\" emptyDir\" ,\n " +
173+ " \" configurations\" :[" +
174+ "{" +
175+ "\" key\" : \" pipeline_pattern\" ," +
176+ "\" value\" : \" **/*.goprodpipeline.json\" " +
177+ "}" +
178+ "]\n " +
179+ "}" ;
180+ parseDirectoryRequest .setRequestBody (requestBody );
181+ ParsedRequest parsed = ParsedRequest .parse (parseDirectoryRequest );
182+ String pattern = plugin .getPipelinePattern (parsed );
183+ assertThat (pattern , is ("**/*.goprodpipeline.json" ));
184+ }
185+
186+ @ Test
187+ public void getEnvironmentPatternShouldReturnValueAtConfigRepoLevelIfDefined () {
188+ DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest ("configrepo" , "1.0" , "parse-directory" );
189+ String requestBody = "{\n " +
190+ " \" directory\" :\" emptyDir\" ,\n " +
191+ " \" configurations\" :[" +
192+ "{" +
193+ "\" key\" : \" environment_pattern\" ," +
194+ "\" value\" : \" **/*.goprodenvironment.json\" " +
195+ "}" +
196+ "]\n " +
197+ "}" ;
198+ parseDirectoryRequest .setRequestBody (requestBody );
199+ ParsedRequest parsed = ParsedRequest .parse (parseDirectoryRequest );
200+ String pattern = plugin .getEnvironmentPattern (parsed );
201+ assertThat (pattern , is ("**/*.goprodenvironment.json" ));
202+ }
203+
204+ @ Test
205+ public void getEnvironmentPatternShouldReturnValueAtConfigRepoLevelIfBothPatternsDefined () {
206+ DefaultGoPluginApiRequest parseDirectoryRequest = new DefaultGoPluginApiRequest ("configrepo" , "1.0" , "parse-directory" );
207+ String requestBody = "{\n " +
208+ " \" directory\" :\" emptyDir\" ,\n " +
209+ " \" configurations\" :[" +
210+ "{" +
211+ "\" key\" : \" environment_pattern\" ," +
212+ "\" value\" : \" **/*.goprodenvironment.json\" " +
213+ "}," +
214+ "{" +
215+ "\" key\" : \" pipeline_pattern\" ," +
216+ "\" value\" : \" **/*.goprodpipeline.json\" " +
217+ "}" +
218+ "]\n " +
219+ "}" ;
220+ parseDirectoryRequest .setRequestBody (requestBody );
221+ ParsedRequest parsed = ParsedRequest .parse (parseDirectoryRequest );
222+ String pattern = plugin .getEnvironmentPattern (parsed );
223+ assertThat (pattern , is ("**/*.goprodenvironment.json" ));
224+ }
225+
160226 private JsonObject getJsonObjectFromResponse (GoPluginApiResponse response ) {
161227 String responseBody = response .responseBody ();
162228 return parser .parse (responseBody ).getAsJsonObject ();
0 commit comments