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;
28 import org.onap.so.bpmn.common.WorkflowTestTransformer;
29 import org.springframework.cloud.contract.wiremock.WireMockConfigurationCustomizer;
30 import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.Configuration;
32 import org.springframework.context.annotation.Profile;
34 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
35 import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
39 public class TestApplicationConfig {
42 protected ResponseTransformer[] transformerArray() {
43 // Process WorkflowTestTransformer annotations
44 List<ResponseTransformer> transformerList = new ArrayList<ResponseTransformer>();
46 for (Field field : getClass().getFields()) {
47 WorkflowTestTransformer annotation = field.getAnnotation(WorkflowTestTransformer.class);
49 if (annotation == null) {
53 if (!Modifier.isStatic(field.getModifiers())) {
54 throw new RuntimeException(field.getDeclaringClass().getName()
55 + "#" + field.getName() + " has a @WorkflowTestTransformer "
56 + " annotation but it is not declared static");
59 ResponseTransformer transformer;
62 transformer = (ResponseTransformer) field.get(null);
63 } catch (IllegalAccessException e) {
64 throw new RuntimeException(field.getDeclaringClass().getName()
65 + "#" + field.getName() + " is not accessible", e);
66 } catch (ClassCastException e) {
67 throw new RuntimeException(field.getDeclaringClass().getName()
68 + "#" + field.getName() + " is not a ResponseTransformer", e);
71 if (transformer == null) {
75 transformerList.add(transformer);
78 ResponseTransformer[] transformerArray =
79 transformerList.toArray(new ResponseTransformer[transformerList.size()]);
81 optionsCustomizer(transformerArray);
83 return transformerArray;
87 WireMockConfigurationCustomizer optionsCustomizer(ResponseTransformer[] transformerArray) {
88 return new WireMockConfigurationCustomizer() {
90 public void customize(WireMockConfiguration options) {
91 options.extensions(transformerArray);