Commit c1b142af authored by 技术部-任文超's avatar 技术部-任文超

提交Web层jUnit

parent d47e10bf
package service; package service;
import cn.quantgroup.xyqb.Bootstrap; import cn.quantgroup.xyqb.Bootstrap;
import cn.quantgroup.xyqb.entity.UserAuthorized;
import cn.quantgroup.xyqb.model.AuthPattern; import cn.quantgroup.xyqb.model.AuthPattern;
import cn.quantgroup.xyqb.model.UserAuthorizedParam; import cn.quantgroup.xyqb.model.UserAuthorizedParam;
import cn.quantgroup.xyqb.service.auth.IUserAuthorizedService; import cn.quantgroup.xyqb.service.auth.IUserAuthorizedService;
...@@ -12,12 +11,12 @@ import org.junit.Assert; ...@@ -12,12 +11,12 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback; import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
...@@ -35,7 +34,7 @@ import java.util.Optional; ...@@ -35,7 +34,7 @@ import java.util.Optional;
@ContextConfiguration(initializers = ApolloPropertySourceInitializer.class) @ContextConfiguration(initializers = ApolloPropertySourceInitializer.class)
public class UserAuthorizedServiceTests extends BaseParametersTests { public class UserAuthorizedServiceTests extends BaseParametersTests {
@Autowired @Resource
private IUserAuthorizedService userAuthorizedService; private IUserAuthorizedService userAuthorizedService;
UserAuthorizedParam obj = new UserAuthorizedParam(); UserAuthorizedParam obj = new UserAuthorizedParam();
......
package web;
import cn.quantgroup.xyqb.Bootstrap;
import cn.quantgroup.xyqb.model.AuthPattern;
import cn.quantgroup.xyqb.model.UserAuthorizedParam;
import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import demo.BaseParametersTests;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Optional;
/**
* 业务层测试用例
* @author renwc
* @date 2018-01-05
*/
@Slf4j
@Rollback
@Transactional
@RunWith(value = SpringRunner.class)
@SpringBootTest(classes = Bootstrap.class, webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration(initializers = ApolloPropertySourceInitializer.class)
public class UserAuthorizedControllerTests extends BaseParametersTests {
@Resource
private TestRestTemplate restTemplate;
private UserAuthorizedParam obj = new UserAuthorizedParam();
{
Long userId = 1L;
String idNo = "350504198805144101";
String name = "史书一";
AuthPattern authPattern = AuthPattern.ZMXY;
Boolean available = true;
obj.setUserId(userId);
obj.setIdNo(idNo);
obj.setName(name);
obj.setAuthPattern(Optional.ofNullable(authPattern).orElse(AuthPattern.ZMXY).name());
}
@Test
public void testExist() throws Exception {
ResponseEntity<String> phil = restTemplate.getForEntity("/user/auth/{model}?idNo={idNo}", String.class, "hasUserAuthorized", obj.getIdNo());
log.info("testExist: name:{}, idNo:{}, userId:{}, authPattern:{}", obj.getName(), obj.getIdNo(), obj.getUserId(), obj.getAuthPattern());
Assert.assertEquals(phil.getStatusCode(), HttpStatus.OK);
}
@Test
public void testSave() throws Exception {
ResponseEntity<String> phil = restTemplate.postForEntity("/user/auth/{model}", this.obj, String.class, "createUserAuthorized");
log.info("testSave: name:{}, idNo:{}, userId:{}, authPattern:{}", obj.getName(), obj.getIdNo(), obj.getUserId(), obj.getAuthPattern());
Assert.assertEquals(phil.getStatusCode(), HttpStatus.OK);
}
@Test
public void testQuery(){
ResponseEntity<String> phil = restTemplate.getForEntity("/user/auth/{model}?userId={userId}", String.class, "getUserAuthorizedId", obj.getUserId());
Assert.assertEquals(phil.getStatusCode(), HttpStatus.OK);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment