2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
23 import java.lang.reflect.Field;
24 import java.lang.reflect.Modifier;
25 import java.util.ArrayList;
26 import java.util.List;
27 import org.onap.so.bpmn.common.WorkflowTestTransformer;
28 import org.springframework.cloud.contract.wiremock.WireMockConfigurationCustomizer;
29 import org.springframework.context.annotation.Bean;
30 import org.springframework.context.annotation.Configuration;
31 import org.springframework.context.annotation.Profile;
32 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
33 import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
37 public class TestApplicationConfig {
40 protected ResponseTransformer[] transformerArray() {
41 // Process WorkflowTestTransformer annotations
42 List<ResponseTransformer> transformerList = new ArrayList<ResponseTransformer>();
44 for (Field field : getClass().getFields()) {
45 WorkflowTestTransformer annotation = field.getAnnotation(WorkflowTestTransformer.class);
47 if (annotation == null) {
51 if (!Modifier.isStatic(field.getModifiers())) {
52 throw new RuntimeException(field.getDeclaringClass().getName() + "#" + field.getName()
53 + " has a @WorkflowTestTransformer " + " annotation but it is not declared static");
56 ResponseTransformer transformer;
59 transformer = (ResponseTransformer) field.get(null);
60 } catch (IllegalAccessException e) {
61 throw new RuntimeException(
62 field.getDeclaringClass().getName() + "#" + field.getName() + " is not accessible", e);
63 } catch (ClassCastException e) {
64 throw new RuntimeException(
65 field.getDeclaringClass().getName() + "#" + field.getName() + " is not a ResponseTransformer",
69 if (transformer == null) {
73 transformerList.add(transformer);
76 ResponseTransformer[] transformerArray =
77 transformerList.toArray(new ResponseTransformer[transformerList.size()]);
79 optionsCustomizer(transformerArray);
81 return transformerArray;
85 WireMockConfigurationCustomizer optionsCustomizer(ResponseTransformer[] transformerArray) {
86 return new WireMockConfigurationCustomizer() {
88 public void customize(WireMockConfiguration options) {
89 options.extensions(transformerArray);