Made @AutoConfigureWireMock @Inherited; fixes gh-1201

This commit is contained in:
Marcin Grzejszczak
2019-09-05 13:44:37 +02:00
parent b7b6a22c5f
commit 8d6336c73f
3 changed files with 33 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.contract.wiremock;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@@ -41,6 +42,7 @@ import org.springframework.context.annotation.Import;
@Import(WireMockConfiguration.class)
@PropertyMapping("wiremock.server")
@AutoConfigureHttpClient
@Inherited
public @interface AutoConfigureWireMock {
int port() default 8080;

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.contract.wiremock;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -37,14 +39,22 @@ import static org.assertj.core.api.Assertions.assertThat;
@AutoConfigureWireMock(port = 0)
public class AutoConfigureWireMockRandomPortApplicationTests {
@Autowired
private WireMockServer wireMockServer;
@Autowired
private Service service;
@Test
public void contextLoads() throws Exception {
wireMockServer.verify(0, RequestPatternBuilder.allRequests());
stubFor(get(urlEqualTo("/test")).willReturn(aResponse()
.withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
wireMockServer.verify(1, RequestPatternBuilder.allRequests());
}
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.wiremock;
public class AutoConfigureWireMockRandomPortInheretedApplicationTests extends AutoConfigureWireMockRandomPortApplicationTests {
}