This commit is contained in:
lsy
2017-12-04 20:09:35 +08:00
parent 0e2e8ce302
commit 3795a81cb3
6 changed files with 47 additions and 9 deletions
@@ -16,6 +16,11 @@
</parent>
<dependencies>
<dependency>
<groupId>com.micro.fast</groupId>
<artifactId>boot-starter-util</artifactId>
<version>${micro.fast.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
@@ -44,8 +44,7 @@
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<plugins>
<plugin>
@@ -1,15 +1,31 @@
package com.micro.fast.security.demo.mock;
import com.github.tomakehurst.wiremock.client.WireMock;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
public class WireMockMian {
//进行对wiremock服务器进行设置
public static void main(String[] args) {
//1.设置配置哪个wiremock服务器
WireMock.configureFor("39.106.98.205",9090);
//2.删除所有的mock
WireMock.removeAllMappings();
WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/order/1")).willReturn(WireMock.aResponse().withBody("{\"id\":1}").withStatus(200)));
//1.从classpath下加载资源文件
ClassPathResource classPathResource = new ClassPathResource("mock/response/1.txt");
String content = null;
try {
//2.把文件转换成字符串
content = StringUtils.join(FileUtils.readLines(classPathResource.getFile(),"UTF-8").toArray(),"\n");
} catch (IOException e) {
e.printStackTrace();
}
//3.设置配置哪个wiremock服务器
WireMock.configureFor("39.106.98.205",9990);
//4.删除所有的mock
WireMock.removeAllMappings();
//5.设置请求访问格式
WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/order/1")).willReturn(WireMock.aResponse().withBody(content).withStatus(200)));
}
}
@@ -0,0 +1,4 @@
{
"id":1,
"type":"百货"
}
@@ -0,0 +1,16 @@
package com.micro.fast.security.demo.mock;
import com.github.tomakehurst.wiremock.client.WireMock;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by root on 12/4/17.
*/
public class WireMockMianTest {
@Test
public void testWireMock(){
}
}
-2
View File
@@ -145,8 +145,6 @@
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--使用注解简化pojo代码-->
<dependency>