Skip to content

Commit

Permalink
增加点测试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Apr 25, 2020
1 parent 5477429 commit 55c6f2a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<artifactId>weixin-java-mp-demo-springboot</artifactId>
<packaging>jar</packaging>

<name>Wechat mp demo with Spring Boot and WxJava </name>
<name>Wechat mp demo with Spring Boot and WxJava</name>
<description>基于 WxJava 和 Spring Boot 实现的微信公众号后端开发演示项目</description>

<properties>
Expand Down Expand Up @@ -74,6 +74,19 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.binarywang.demo.wx.mp.controller;

import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.MalformedURLException;

/**
* jsapi 演示接口的 controller.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-04-25
*/
@AllArgsConstructor
@RestController
@RequestMapping("/wx/jsapi/{appid}")
public class WxJsapiController {
private final WxMpService wxService;

@GetMapping("/getJsapiTicket")
public String getJsapiTicket(@PathVariable String appid) throws WxErrorException {
final WxJsapiSignature jsapiSignature = this.wxService.switchoverTo(appid).createJsapiSignature("111");
System.out.println(jsapiSignature);
return this.wxService.getJsapiTicket(true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.binarywang.demo.wx.mp.controller;

import io.restassured.RestAssured;
import org.testng.annotations.BeforeTest;

import java.util.Base64;

import static org.assertj.core.api.Assertions.assertThat;

/**
* 公共测试方法和参数.
*
* @author Binary Wang
* @date 2019-06-14
*/
public abstract class BaseControllerTest {
private static final String ROOT_URL = "http://127.0.0.1:8080/";

@BeforeTest
public void setup() {
RestAssured.baseURI = ROOT_URL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.binarywang.demo.wx.mp.controller;

import org.testng.annotations.Test;

import static io.restassured.RestAssured.given;

/**
* jsapi 测试.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-04-25
*/
@Test
public class WxJsapiControllerTest extends BaseControllerTest {
@Test(invocationCount = 1000, threadPoolSize = 5)
public void testGetJsapiTicket() {
given()
.when().get("/wx/jsapi/xxxx/getJsapiTicket")
.then()
.log().everything();
}
}

0 comments on commit 55c6f2a

Please sign in to comment.