Commit 72409013 authored by eddie.woo's avatar eddie.woo

modify

parent 95b91dbd
...@@ -57,7 +57,7 @@ public class AuthUserHelperImpl implements AuditorAware<String>, AuthUserHelper ...@@ -57,7 +57,7 @@ public class AuthUserHelperImpl implements AuditorAware<String>, AuthUserHelper
@Override @Override
public String getCurrentUserID() { public String getCurrentUserID() {
String userName = getCurrentAuditor(); String userName = getCurrentAuditor();
User user = userMapper.selectByUserNameIgnoreCase(userName); User user = userMapper.selectByUserNameIgnoreCase(userName); //todo 加缓存
if (user == null) { if (user == null) {
return ""; return "";
} }
......
...@@ -2,8 +2,20 @@ package pwc.taxtech.atms.controller; ...@@ -2,8 +2,20 @@ package pwc.taxtech.atms.controller;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class BaseController { public class BaseController {
protected final Logger logger = LoggerFactory.getLogger(this.getClass()); protected final Logger logger = LoggerFactory.getLogger(this.getClass());
protected HttpServletRequest request;
protected HttpServletResponse response;
@ModelAttribute
public void setReqAndRes(HttpServletRequest request, HttpServletResponse response) {
this.request = request;
this.response = response;
}
} }
package pwc.taxtech.atms.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import pwc.taxtech.atms.MyMapper;
import pwc.taxtech.atms.entitiy.ApiCache;
import pwc.taxtech.atms.entitiy.ApiCacheExample;
@Mapper
public interface ApiCacheMapper extends MyMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
long countByExample(ApiCacheExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
int deleteByExample(ApiCacheExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
int deleteByPrimaryKey(Long id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
int insert(ApiCache record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
int insertSelective(ApiCache record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
List<ApiCache> selectByExampleWithRowbounds(ApiCacheExample example, RowBounds rowBounds);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
List<ApiCache> selectByExample(ApiCacheExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
ApiCache selectByPrimaryKey(Long id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") ApiCache record, @Param("example") ApiCacheExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
int updateByExample(@Param("record") ApiCache record, @Param("example") ApiCacheExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(ApiCache record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
int updateByPrimaryKey(ApiCache record);
}
\ No newline at end of file
package pwc.taxtech.atms.entitiy;
import java.io.Serializable;
/**
*
* This class was generated by MyBatis Generator.
* This class corresponds to the database table api_cache
*
* @mbg.generated do_not_delete_during_merge
*/
public class ApiCache extends BaseEntity implements Serializable {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_cache.id
*
* @mbg.generated
*/
private Long id;
/**
* Database Column Remarks:
* 业务数据类型
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_cache.source_type
*
* @mbg.generated
*/
private Integer sourceType;
/**
* Database Column Remarks:
* 业务唯一键
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_cache.source_key
*
* @mbg.generated
*/
private String sourceKey;
/**
* Database Column Remarks:
* 更新时间
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_cache.last_modify_time
*
* @mbg.generated
*/
private Long lastModifyTime;
/**
* Database Column Remarks:
* 更新人
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column api_cache.modify_by
*
* @mbg.generated
*/
private String modifyBy;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table api_cache
*
* @mbg.generated
*/
private static final long serialVersionUID = 1L;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column api_cache.id
*
* @return the value of api_cache.id
*
* @mbg.generated
*/
public Long getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column api_cache.id
*
* @param id the value for api_cache.id
*
* @mbg.generated
*/
public void setId(Long id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column api_cache.source_type
*
* @return the value of api_cache.source_type
*
* @mbg.generated
*/
public Integer getSourceType() {
return sourceType;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column api_cache.source_type
*
* @param sourceType the value for api_cache.source_type
*
* @mbg.generated
*/
public void setSourceType(Integer sourceType) {
this.sourceType = sourceType;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column api_cache.source_key
*
* @return the value of api_cache.source_key
*
* @mbg.generated
*/
public String getSourceKey() {
return sourceKey;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column api_cache.source_key
*
* @param sourceKey the value for api_cache.source_key
*
* @mbg.generated
*/
public void setSourceKey(String sourceKey) {
this.sourceKey = sourceKey == null ? null : sourceKey.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column api_cache.last_modify_time
*
* @return the value of api_cache.last_modify_time
*
* @mbg.generated
*/
public Long getLastModifyTime() {
return lastModifyTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column api_cache.last_modify_time
*
* @param lastModifyTime the value for api_cache.last_modify_time
*
* @mbg.generated
*/
public void setLastModifyTime(Long lastModifyTime) {
this.lastModifyTime = lastModifyTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column api_cache.modify_by
*
* @return the value of api_cache.modify_by
*
* @mbg.generated
*/
public String getModifyBy() {
return modifyBy;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column api_cache.modify_by
*
* @param modifyBy the value for api_cache.modify_by
*
* @mbg.generated
*/
public void setModifyBy(String modifyBy) {
this.modifyBy = modifyBy == null ? null : modifyBy.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table api_cache
*
* @mbg.generated
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", sourceType=").append(sourceType);
sb.append(", sourceKey=").append(sourceKey);
sb.append(", lastModifyTime=").append(lastModifyTime);
sb.append(", modifyBy=").append(modifyBy);
sb.append("]");
return sb.toString();
}
}
\ No newline at end of file
...@@ -8,6 +8,12 @@ public class BaseEntity { ...@@ -8,6 +8,12 @@ public class BaseEntity {
private Date createTime; private Date createTime;
private Date updateTime; private Date updateTime;
public BaseEntity() {
Date now = new Date();
this.createTime = now;
this.updateTime = now;
}
public String getCreateBy() { public String getCreateBy() {
return createBy; return createBy;
} }
...@@ -33,7 +39,7 @@ public class BaseEntity { ...@@ -33,7 +39,7 @@ public class BaseEntity {
} }
public Date getUpdateTime() { public Date getUpdateTime() {
return updateTime; return updateTime == null ? new Date() : updateTime;
} }
public void setUpdateTime(Date updateTime) { public void setUpdateTime(Date updateTime) {
......
package pwc.taxtech.atms.security; package pwc.taxtech.atms.security;
import java.io.IOException; import io.jsonwebtoken.impl.DefaultClaims;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.FilterChain; import org.springframework.beans.factory.annotation.Value;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
public class JwtAuthenticationFilter extends AbstractAuthenticationProcessingFilter { public class JwtAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
@Value("${jwt.expireSecond}")
private Integer jwtExpireSecond;
@Value("${jwt.refreshSecond}")
private Integer jwtRefreshSecond;
@Autowired
private JwtUtil jwtUtil;
public JwtAuthenticationFilter() { public JwtAuthenticationFilter() {
super("/**"); super("/**");
} }
...@@ -58,6 +70,27 @@ public class JwtAuthenticationFilter extends AbstractAuthenticationProcessingFil ...@@ -58,6 +70,27 @@ public class JwtAuthenticationFilter extends AbstractAuthenticationProcessingFil
// As this authentication is in HTTP header, after success we need to continue // As this authentication is in HTTP header, after success we need to continue
// the request normally // the request normally
// and return the response as if the resource was not secured at all // and return the response as if the resource was not secured at all
try {
JwtUser jwtUser = (JwtUser) authResult.getPrincipal();
if (null != jwtUser) {
DefaultClaims claims = jwtUser.getDefaultClaims();
if (claims.getExpiration().getTime() - System.currentTimeMillis() <= jwtRefreshSecond * 1000) {
String newToken = jwtUtil.generateToken(jwtUser.getUsername(), jwtUser.getDatabaseUsername(),
jwtUser.getUserid());
response.setHeader("Access-Control-Expose-Headers", "refreshToken");
response.setHeader("refreshToken", newToken);
logger.debug("refreshToken: " + newToken);
}
}
} catch (Exception e) {
logger.error("", e);
}
chain.doFilter(request, response); chain.doFilter(request, response);
} }
@Override
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException, ServletException {
super.unsuccessfulAuthentication(request, response, failed);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
} }
\ No newline at end of file
package pwc.taxtech.atms.security; package pwc.taxtech.atms.security;
import io.jsonwebtoken.ExpiredJwtException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
...@@ -31,7 +32,14 @@ public class JwtAuthenticationProvider extends AbstractUserDetailsAuthentication ...@@ -31,7 +32,14 @@ public class JwtAuthenticationProvider extends AbstractUserDetailsAuthentication
JwtAuthenticationToken jwtAuthenticationToken = (JwtAuthenticationToken) authentication; JwtAuthenticationToken jwtAuthenticationToken = (JwtAuthenticationToken) authentication;
String token = jwtAuthenticationToken.getToken(); String token = jwtAuthenticationToken.getToken();
JwtUser parsedUser = jwtUtil.parseToken(token); JwtUser parsedUser;
try {
parsedUser = jwtUtil.parseToken(token);
} catch (ExpiredJwtException e) {
throw new BadCredentialsException("Expired jwt token");
} catch (Exception e) {
throw new BadCredentialsException("Bad jwt token", e);
}
if (parsedUser == null) { if (parsedUser == null) {
throw new BadCredentialsException("JWT token is not valid"); throw new BadCredentialsException("JWT token is not valid");
......
...@@ -2,6 +2,7 @@ package pwc.taxtech.atms.security; ...@@ -2,6 +2,7 @@ package pwc.taxtech.atms.security;
import java.util.Collection; import java.util.Collection;
import io.jsonwebtoken.impl.DefaultClaims;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
...@@ -14,12 +15,15 @@ public class JwtUser implements UserDetails { ...@@ -14,12 +15,15 @@ public class JwtUser implements UserDetails {
private final String databaseUsername; private final String databaseUsername;
private final Collection<? extends GrantedAuthority> authorities; private final Collection<? extends GrantedAuthority> authorities;
private DefaultClaims defaultClaims;
public JwtUser(String userid, String username, String databaseUsername, public JwtUser(String userid, String username, String databaseUsername,
Collection<? extends GrantedAuthority> authorities) { DefaultClaims defaultClaims, Collection<? extends GrantedAuthority> authorities) {
this.userid = userid; this.userid = userid;
this.username = username; this.username = username;
this.databaseUsername = databaseUsername; this.databaseUsername = databaseUsername;
this.authorities = authorities; this.authorities = authorities;
this.defaultClaims = defaultClaims;
} }
@Override @Override
...@@ -65,4 +69,11 @@ public class JwtUser implements UserDetails { ...@@ -65,4 +69,11 @@ public class JwtUser implements UserDetails {
return databaseUsername; return databaseUsername;
} }
public DefaultClaims getDefaultClaims() {
return defaultClaims;
}
public void setDefaultClaims(DefaultClaims defaultClaims) {
this.defaultClaims = defaultClaims;
}
} }
...@@ -4,21 +4,18 @@ import java.util.ArrayList; ...@@ -4,21 +4,18 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import io.jsonwebtoken.*;
import org.nutz.lang.Times; import org.nutz.lang.Times;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.DefaultClaims; import io.jsonwebtoken.impl.DefaultClaims;
import io.jsonwebtoken.impl.DefaultJws; import io.jsonwebtoken.impl.DefaultJws;
import io.jsonwebtoken.lang.Assert; import io.jsonwebtoken.lang.Assert;
...@@ -31,6 +28,8 @@ public class JwtUtil implements InitializingBean { ...@@ -31,6 +28,8 @@ public class JwtUtil implements InitializingBean {
@Autowired @Autowired
private AtmsApiSettings atmsApiSettings; private AtmsApiSettings atmsApiSettings;
@Value("${jwt.expireSecond}")
private Integer jwtExpireSecond;
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
...@@ -51,24 +50,17 @@ public class JwtUtil implements InitializingBean { ...@@ -51,24 +50,17 @@ public class JwtUtil implements InitializingBean {
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
public JwtUser parseToken(String token) { public JwtUser parseToken(String token) {
if (StringUtils.hasText(jwtPowerToken) && jwtPowerToken.equals(token)) { if (StringUtils.hasText(jwtPowerToken) && jwtPowerToken.equals(token)) {
return new JwtUser("test_userid", "admin", "Admin", getAuthorities()); return new JwtUser("test_userid", "admin", "Admin", null, getAuthorities());
} }
JwtParser parser = Jwts.parser().setSigningKey(jwtBase64Secret); JwtParser parser = Jwts.parser().setSigningKey(jwtBase64Secret);
Jwt jwt = null; Jwt jwt = parser.parseClaimsJws(token);
DefaultJws<DefaultClaims> defaultJws = null; DefaultJws<DefaultClaims> defaultJws = (DefaultJws<DefaultClaims>) jwt;
try {
jwt = parser.parseClaimsJws(token);
defaultJws = (DefaultJws<DefaultClaims>) jwt;
} catch (Exception e) {
logger.warn("Bad jwt token", e);
throw new BadCredentialsException("invalid token:" + e.getMessage());
}
DefaultClaims defaultClaims = defaultJws.getBody(); DefaultClaims defaultClaims = defaultJws.getBody();
String databaseUsername = String.valueOf(defaultClaims.get("databaseUsername")); String databaseUsername = String.valueOf(defaultClaims.get("databaseUsername"));
String username = String.valueOf(defaultClaims.get("username")); String username = String.valueOf(defaultClaims.get("username"));
String userid = String.valueOf(defaultClaims.get("userid")); String userid = String.valueOf(defaultClaims.get("userid"));
return new JwtUser(userid, username, databaseUsername, getAuthorities()); return new JwtUser(userid, username, databaseUsername, defaultClaims, getAuthorities());
} }
private List<SimpleGrantedAuthority> getAuthorities() { private List<SimpleGrantedAuthority> getAuthorities() {
...@@ -81,7 +73,7 @@ public class JwtUtil implements InitializingBean { ...@@ -81,7 +73,7 @@ public class JwtUtil implements InitializingBean {
/*** /***
* @param username * @param username
* 登录名,大小写不限,可以是全大写或全小写,如:admin, ADMIN * 登录名,大小写不限,可以是全大写或全小写,如:admin, ADMIN
* @param loginname * @param databaseUsername
* 数据库用户名, 比如Admin * 数据库用户名, 比如Admin
* @param userid * @param userid
* 用户ID * 用户ID
...@@ -97,7 +89,7 @@ public class JwtUtil implements InitializingBean { ...@@ -97,7 +89,7 @@ public class JwtUtil implements InitializingBean {
Date now = new Date(); Date now = new Date();
// 过期时间设置为2天 // 过期时间设置为2天
int expireSecond = 3600 * 24 * 2; int expireSecond = jwtExpireSecond;
Date expiration = Times.nextSecond(now, expireSecond); Date expiration = Times.nextSecond(now, expireSecond);
JwtBuilder jwtBuilder = Jwts.builder(); JwtBuilder jwtBuilder = Jwts.builder();
// 设置Subject为登录用户名 // 设置Subject为登录用户名
......
...@@ -13,6 +13,8 @@ web.url=${web.url} ...@@ -13,6 +13,8 @@ web.url=${web.url}
jwt.base64Secret=${jwt.base64Secret} jwt.base64Secret=${jwt.base64Secret}
jwt.powerToken=${jwt.powerToken} jwt.powerToken=${jwt.powerToken}
jwt.expireSecond=${jwt.expireSecond}
jwt.refreshSecond=${jwt.refreshSecond}
#FTP Config #FTP Config
ftp.host=${ftp.host} ftp.host=${ftp.host}
......
...@@ -13,6 +13,8 @@ web.url=http://localhost:8080 ...@@ -13,6 +13,8 @@ web.url=http://localhost:8080
#web.url=* #web.url=*
jwt.base64Secret=TXppQjFlZFBSbnJzMHc0Tg== jwt.base64Secret=TXppQjFlZFBSbnJzMHc0Tg==
jwt.powerToken=xxxx jwt.powerToken=xxxx
jwt.expireSecond=180000
jwt.refreshSecond=600
ftp.host=cnshaappulv004.asia.pwcinternal.com ftp.host=cnshaappulv004.asia.pwcinternal.com
ftp.port=21 ftp.port=21
......
...@@ -13,6 +13,8 @@ web.url=http://192.168.1.102:10000 ...@@ -13,6 +13,8 @@ web.url=http://192.168.1.102:10000
jwt.base64Secret=TXppQjFlZFBSbnJzMHc0Tg== jwt.base64Secret=TXppQjFlZFBSbnJzMHc0Tg==
jwt.powerToken= jwt.powerToken=
jwt.expireSecond=1800
jwt.refreshSecond=900
ftp.host=cnshaappulv004.asia.pwcinternal.com ftp.host=cnshaappulv004.asia.pwcinternal.com
ftp.port=21 ftp.port=21
......
...@@ -13,6 +13,8 @@ web.url=http://cnshaappulv004:8080 ...@@ -13,6 +13,8 @@ web.url=http://cnshaappulv004:8080
jwt.base64Secret=TXppQjFlZFBSbnJzMHc0Tg== jwt.base64Secret=TXppQjFlZFBSbnJzMHc0Tg==
jwt.powerToken=xxxx jwt.powerToken=xxxx
jwt.expireSecond=1800
jwt.refreshSecond=900
ftp.host=cnshaappulv004.asia.pwcinternal.com ftp.host=cnshaappulv004.asia.pwcinternal.com
ftp.port=21 ftp.port=21
......
package pwc.taxtech.atms; package pwc.taxtech.atms;
import java.io.InputStreamReader; import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.Reader;
import java.sql.Connection;
import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -13,67 +10,12 @@ import org.slf4j.LoggerFactory; ...@@ -13,67 +10,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import pwc.taxtech.atms.dao.*;
import pwc.taxtech.atms.entitiy.*;
import com.fasterxml.jackson.databind.ObjectMapper; import java.io.InputStreamReader;
import java.io.Reader;
import pwc.taxtech.atms.dao.AccountMappingMapper; import java.sql.Connection;
import pwc.taxtech.atms.dao.AreaMapper;
import pwc.taxtech.atms.dao.AreaRegionMapper;
import pwc.taxtech.atms.dao.BusinessUnitMapper;
import pwc.taxtech.atms.dao.CacheMapper;
import pwc.taxtech.atms.dao.CustomerMapper;
import pwc.taxtech.atms.dao.DictionaryMapper;
import pwc.taxtech.atms.dao.DimensionMapper;
import pwc.taxtech.atms.dao.DimensionValueMapper;
import pwc.taxtech.atms.dao.DimensionValueOrgMapper;
import pwc.taxtech.atms.dao.EnterpriseAccountMapper;
import pwc.taxtech.atms.dao.EnterpriseAccountSetMapper;
import pwc.taxtech.atms.dao.EnterpriseAccountSetOrgMapper;
import pwc.taxtech.atms.dao.IndustryMapper;
import pwc.taxtech.atms.dao.MailQueueMapper;
import pwc.taxtech.atms.dao.MenuMapper;
import pwc.taxtech.atms.dao.OperationLogBasicDataMapper;
import pwc.taxtech.atms.dao.OperationLogEnterPriseMapper;
import pwc.taxtech.atms.dao.OperationLogOrganizationMapper;
import pwc.taxtech.atms.dao.OperationLogRoleMapper;
import pwc.taxtech.atms.dao.OperationLogUserMapper;
import pwc.taxtech.atms.dao.OrganizationMapper;
import pwc.taxtech.atms.dao.OrganizationServiceTemplateGroupMapper;
import pwc.taxtech.atms.dao.OrganizationStructureMapper;
import pwc.taxtech.atms.dao.PermissionMapper;
import pwc.taxtech.atms.dao.ProjectClientMapper;
import pwc.taxtech.atms.dao.RegionMapper;
import pwc.taxtech.atms.dao.RoleCategoryMapper;
import pwc.taxtech.atms.dao.RoleMapper;
import pwc.taxtech.atms.dao.RolePermissionMapper;
import pwc.taxtech.atms.dao.ServiceTypeMapper;
import pwc.taxtech.atms.dao.StandardAccountMapper;
import pwc.taxtech.atms.dao.StatisticAttributeDimensionMapper;
import pwc.taxtech.atms.dao.StatisticAttributeMapper;
import pwc.taxtech.atms.dao.TemplateGroupMapper;
import pwc.taxtech.atms.dao.UserDimensionValueMapper;
import pwc.taxtech.atms.dao.UserDimensionValueOrgMapper;
import pwc.taxtech.atms.dao.UserDimensionValueRoleMapper;
import pwc.taxtech.atms.dao.UserMapper;
import pwc.taxtech.atms.dao.UserOrganizationMapper;
import pwc.taxtech.atms.dao.UserOrganizationRoleMapper;
import pwc.taxtech.atms.dao.UserRoleMapper;
import pwc.taxtech.atms.entitiy.AreaExample;
import pwc.taxtech.atms.entitiy.AreaRegionExample;
import pwc.taxtech.atms.entitiy.CustomerExample;
import pwc.taxtech.atms.entitiy.EnterpriseAccountExample;
import pwc.taxtech.atms.entitiy.EnterpriseAccountSetExample;
import pwc.taxtech.atms.entitiy.EnterpriseAccountSetOrgExample;
import pwc.taxtech.atms.entitiy.IndustryExample;
import pwc.taxtech.atms.entitiy.MenuExample;
import pwc.taxtech.atms.entitiy.OperationLogBasicDataExample;
import pwc.taxtech.atms.entitiy.OperationLogEnterPriseExample;
import pwc.taxtech.atms.entitiy.OrganizationExample;
import pwc.taxtech.atms.entitiy.ProjectClientExample;
import pwc.taxtech.atms.entitiy.RegionExample;
import pwc.taxtech.atms.entitiy.ServiceTypeExample;
import pwc.taxtech.atms.entitiy.StandardAccountExample;
import pwc.taxtech.atms.entitiy.TemplateGroupExample;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" }) @ContextConfiguration(locations = { "classpath:applicationContext.xml" })
...@@ -159,8 +101,6 @@ public abstract class CommonIT { ...@@ -159,8 +101,6 @@ public abstract class CommonIT {
@Autowired @Autowired
protected OrganizationStructureMapper organizationStructureMapper; protected OrganizationStructureMapper organizationStructureMapper;
@Autowired @Autowired
protected CacheMapper cacheMapper;
@Autowired
protected StatisticAttributeDimensionMapper statisticAttributeDimensionMapper; protected StatisticAttributeDimensionMapper statisticAttributeDimensionMapper;
@Autowired @Autowired
protected StatisticAttributeMapper statisticAttributeMapper; protected StatisticAttributeMapper statisticAttributeMapper;
......
package pwc.taxtech.atms.controller;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pwc.taxtech.atms.service.CacheService;
@RunWith(MockitoJUnitRunner.class)
public class CacheControllerTest {
@Mock
private CacheService cacheService;
@InjectMocks
private CacheController cacheController;
@Test
public void getCacheByKey() {
assertThat(cacheController.getCacheByKey("cacheKey1")).isNull();
}
@Test
public void getAllCache() {
assertThat(cacheController.getAllCache()).isEmpty();
}
}
package pwc.taxtech.atms.service.impl;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import pwc.taxtech.atms.CommonIT;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.entitiy.Cache;
import pwc.taxtech.atms.service.CacheService;
public class CacheServiceIT extends CommonIT {
@Autowired
private CacheService cacheService;
@Before
public void setUp() {
cacheMapper.deleteByExample(null);
}
@Test
public void getAllCache() {
insertData();
// see assertj document
// http://joel-costigliola.github.io/assertj/assertj-core-quick-start.html
assertThat(cacheService.getAllCache()).isNotEmpty().filteredOn(x -> x.getCacheKey().equals("cachekey1"))
.isNotEmpty().extracting("lastModifyTime").contains("2017-10-18T14:11:01.840+08:00");
}
@Test
public void shoudWork() {
insertData();
assertThat(cacheService.getCacheByKey("cachekey1")).isNotNull().extracting("lastModifyTime")
.contains("2017-10-18T14:11:01.840+08:00");
}
private void insertData() {
Cache record = new Cache();
record.setID(CommonUtils.getUUID());
record.setCacheKey("cachekey1");
record.setLastModifyTime("2017-10-18T14:11:01.840+08:00");
cacheMapper.insert(record);
}
}
...@@ -53,48 +53,53 @@ ...@@ -53,48 +53,53 @@
<!--<columnOverride column="is_red_invoice" javaType="java.lang.Boolean"/>--> <!--<columnOverride column="is_red_invoice" javaType="java.lang.Boolean"/>-->
<!--</table>--> <!--</table>-->
<table tableName="input_invoice_additional" domainObjectName="InputInvoiceAdditional"> <!--<table tableName="input_invoice_additional" domainObjectName="InputInvoiceAdditional">-->
<property name="ignoreQualifiersAtRuntime" value="true"/> <!--<property name="ignoreQualifiersAtRuntime" value="true"/>-->
<columnOverride column="type" javaType="java.lang.Integer"/> <!--<columnOverride column="type" javaType="java.lang.Integer"/>-->
</table> <!--</table>-->
<table tableName="input_invoice_file" domainObjectName="InputInvoiceFile"> <!--<table tableName="input_invoice_file" domainObjectName="InputInvoiceFile">-->
<property name="ignoreQualifiersAtRuntime" value="true"/> <!--<property name="ignoreQualifiersAtRuntime" value="true"/>-->
</table> <!--</table>-->
<table tableName="input_invoice_item" domainObjectName="InputInvoiceItem"> <!--<table tableName="input_invoice_item" domainObjectName="InputInvoiceItem">-->
<property name="ignoreQualifiersAtRuntime" value="true"/> <!--<property name="ignoreQualifiersAtRuntime" value="true"/>-->
</table> <!--</table>-->
<table tableName="input_invoice_item_original" domainObjectName="InputInvoiceItemOriginal"> <!--<table tableName="input_invoice_item_original" domainObjectName="InputInvoiceItemOriginal">-->
<property name="ignoreQualifiersAtRuntime" value="true"/> <!--<property name="ignoreQualifiersAtRuntime" value="true"/>-->
</table> <!--</table>-->
<table tableName="input_invoice_not_received" domainObjectName="InputInvoiceNotReceived"> <!--<table tableName="input_invoice_not_received" domainObjectName="InputInvoiceNotReceived">-->
<property name="ignoreQualifiersAtRuntime" value="true"/> <!--<property name="ignoreQualifiersAtRuntime" value="true"/>-->
<columnOverride column="invoice_type" javaType="java.lang.Integer"/> <!--<columnOverride column="invoice_type" javaType="java.lang.Integer"/>-->
<columnOverride column="upload_type" javaType="java.lang.Integer"/> <!--<columnOverride column="upload_type" javaType="java.lang.Integer"/>-->
<columnOverride column="invoice_entity_type" javaType="java.lang.Integer"/> <!--<columnOverride column="invoice_entity_type" javaType="java.lang.Integer"/>-->
<columnOverride column="invoice_source_type" javaType="java.lang.Integer"/> <!--<columnOverride column="invoice_source_type" javaType="java.lang.Integer"/>-->
<columnOverride column="status" javaType="java.lang.Integer"/> <!--<columnOverride column="status" javaType="java.lang.Integer"/>-->
<columnOverride column="deductible" javaType="java.lang.Boolean"/> <!--<columnOverride column="deductible" javaType="java.lang.Boolean"/>-->
<columnOverride column="has_down_file" javaType="java.lang.Boolean"/> <!--<columnOverride column="has_down_file" javaType="java.lang.Boolean"/>-->
<columnOverride column="verify_type" javaType="java.lang.Integer"/> <!--<columnOverride column="verify_type" javaType="java.lang.Integer"/>-->
<columnOverride column="deductible_result" javaType="java.lang.Integer"/> <!--<columnOverride column="deductible_result" javaType="java.lang.Integer"/>-->
</table> <!--</table>-->
<!--<table tableName="input_invoice_original" domainObjectName="InputInvoiceOriginal">-->
<!--<property name="ignoreQualifiersAtRuntime" value="true"/>-->
<!--<columnOverride column="invoice_type" javaType="java.lang.Integer"/>-->
<!--<columnOverride column="upload_type" javaType="java.lang.Integer"/>-->
<!--<columnOverride column="invoice_entity_type" javaType="java.lang.Integer"/>-->
<!--<columnOverride column="invoice_source_type" javaType="java.lang.Integer"/>-->
<!--<columnOverride column="status" javaType="java.lang.Integer"/>-->
<!--<columnOverride column="deductible" javaType="java.lang.Boolean"/>-->
<!--<columnOverride column="has_down_file" javaType="java.lang.Boolean"/>-->
<!--<columnOverride column="verify_type" javaType="java.lang.Integer"/>-->
<!--<columnOverride column="deductible_result" javaType="java.lang.Integer"/>-->
<!--<columnOverride column="is_red_invoice" javaType="java.lang.Boolean"/>-->
<!--</table>-->
<table tableName="input_invoice_original" domainObjectName="InputInvoiceOriginal"> <table tableName="api_cache" domainObjectName="ApiCache">
<property name="ignoreQualifiersAtRuntime" value="true"/> <property name="ignoreQualifiersAtRuntime" value="true"/>
<columnOverride column="invoice_type" javaType="java.lang.Integer"/> <columnOverride column="source_type" javaType="java.lang.Integer"/>
<columnOverride column="upload_type" javaType="java.lang.Integer"/>
<columnOverride column="invoice_entity_type" javaType="java.lang.Integer"/>
<columnOverride column="invoice_source_type" javaType="java.lang.Integer"/>
<columnOverride column="status" javaType="java.lang.Integer"/>
<columnOverride column="deductible" javaType="java.lang.Boolean"/>
<columnOverride column="has_down_file" javaType="java.lang.Boolean"/>
<columnOverride column="verify_type" javaType="java.lang.Integer"/>
<columnOverride column="deductible_result" javaType="java.lang.Integer"/>
<columnOverride column="is_red_invoice" javaType="java.lang.Boolean"/>
</table> </table>
</context> </context>
......
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