1
0
mirror of synced 2025-12-23 18:48:00 +08:00

重构企业号代码

This commit is contained in:
Binary Wang
2017-06-24 22:45:49 +08:00
parent a90628c3b8
commit 6b1b7f1a81
26 changed files with 706 additions and 271 deletions

View File

@@ -6,6 +6,8 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage;
import java.io.IOException;
import java.io.InputStream;
@@ -25,10 +27,10 @@ public class ApiTestModule implements Module {
.getSystemResourceAsStream("test-config.xml")) {
WxXmlCpInMemoryConfigStorage config = fromXml(
WxXmlCpInMemoryConfigStorage.class, is1);
WxCpServiceImpl wxService = new WxCpServiceImpl();
WxCpService wxService = new WxCpServiceImpl();
wxService.setWxCpConfigStorage(config);
binder.bind(WxCpServiceImpl.class).toInstance(wxService);
binder.bind(WxCpService.class).toInstance(wxService);
binder.bind(WxCpConfigStorage.class).toInstance(config);
} catch (IOException e) {
e.printStackTrace();

View File

@@ -3,6 +3,7 @@ package me.chanjar.weixin.cp.api;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import org.apache.commons.lang3.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Guice;

View File

@@ -3,6 +3,9 @@ package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.StandardSessionManager;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.message.WxCpMessageHandler;
import me.chanjar.weixin.cp.message.WxCpMessageMatcher;
import me.chanjar.weixin.cp.message.WxCpMessageRouter;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.testng.Assert;

View File

@@ -4,6 +4,7 @@ import com.google.inject.Inject;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpTag;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

View File

@@ -1,76 +0,0 @@
package me.chanjar.weixin.cp.api;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.List;
import static org.testng.Assert.assertNotEquals;
/**
* 测试用户接口
*
* @author Daniel Qian
*/
@Test(groups = "userAPI")
@Guice(modules = ApiTestModule.class)
public class WxCpUserAPITest {
@Inject
protected WxCpServiceImpl wxCpService;
public void testUserCreate() throws WxErrorException {
WxCpUser user = new WxCpUser();
user.setUserId("some.woman");
user.setName("Some Woman");
user.setDepartIds(new Integer[]{9, 8});
user.setEmail("none@none.com");
user.setGender("");
user.setMobile("13560084979");
user.setPosition("woman");
user.setTelephone("3300393");
user.addExtAttr("爱好", "table");
this.wxCpService.userCreate(user);
}
@Test(dependsOnMethods = "testUserCreate")
public void testUserUpdate() throws WxErrorException {
WxCpUser user = new WxCpUser();
user.setUserId("some.woman");
user.setName("Some Woman");
user.addExtAttr("爱好", "table2");
this.wxCpService.userUpdate(user);
}
@Test(dependsOnMethods = "testUserUpdate")
public void testUserGet() throws WxErrorException {
WxCpUser user = this.wxCpService.userGet("some.woman");
Assert.assertNotNull(user);
}
@Test(dependsOnMethods = "testUserGet")
public void testDepartGetUsers() throws WxErrorException {
List<WxCpUser> users = this.wxCpService.departGetUsers(1, true, 0);
assertNotEquals(users.size(), 0);
}
@Test(dependsOnMethods = "testDepartGetUsers")
public void testUserDelete() throws WxErrorException {
this.wxCpService.userDelete("some.woman");
}
public void testUserList() throws WxErrorException {
List<WxCpUser> users = this.wxCpService.userList(1, true, 0);
assertNotEquals(users.size(), 0);
for (WxCpUser user : users) {
System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE));
}
}
}

View File

@@ -0,0 +1,66 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.List;
import static org.testng.Assert.*;
/**
* <pre>
* Created by BinaryWang on 2017/6/24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Guice(modules = ApiTestModule.class)
public class WxCpDepartmentServiceImplTest {
@Inject
private WxCpService wxCpService;
private WxCpDepart depart;
@Test
public void testCreate() throws Exception {
WxCpDepart cpDepart = new WxCpDepart();
cpDepart.setName("子部门" + System.currentTimeMillis());
cpDepart.setParentId(1);
cpDepart.setOrder(1);
Integer departId = this.wxCpService.getDepartmentService().create(cpDepart);
System.out.println(departId);
}
@Test
public void testListAll() throws Exception {
System.out.println("=================获取部门");
List<WxCpDepart> departList = this.wxCpService.getDepartmentService().listAll();
assertNotNull(departList);
assertTrue(departList.size() > 0);
for (WxCpDepart g : departList) {
this.depart = g;
System.out.println(this.depart.getId() + ":" + this.depart.getName());
assertNotNull(g.getName());
}
}
@Test(dependsOnMethods = {"testListAll", "testCreate"})
public void testUpdate() throws Exception {
System.out.println("=================更新部门");
this.depart.setName("子部门改名" + System.currentTimeMillis());
this.wxCpService.getDepartmentService().update(this.depart);
}
@Test(dependsOnMethods = "testUpdate")
public void testDelete() throws Exception {
System.out.println("=================删除部门");
System.out.println(this.depart.getId() + ":" + this.depart.getName());
this.wxCpService.getDepartmentService().delete(this.depart.getId());
}
}

View File

@@ -0,0 +1,86 @@
package me.chanjar.weixin.cp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.List;
import static org.testng.Assert.*;
/**
* <pre>
* Created by BinaryWang on 2017/6/24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Guice(modules = ApiTestModule.class)
public class WxCpUserServiceImplTest {
@Inject
private WxCpService wxCpService;
@Test
public void testAuthenticate() throws Exception {
}
@Test
public void testCreate() throws Exception {
WxCpUser user = new WxCpUser();
user.setUserId("some.woman");
user.setName("Some Woman");
user.setDepartIds(new Integer[]{9, 8});
user.setEmail("none@none.com");
user.setGender("");
user.setMobile("13560084979");
user.setPosition("woman");
user.setTelephone("3300393");
user.addExtAttr("爱好", "table");
this.wxCpService.getUserService().create(user);
}
@Test(dependsOnMethods = "testCreate")
public void testUpdate() throws Exception {
WxCpUser user = new WxCpUser();
user.setUserId("some.woman");
user.setName("Some Woman");
user.addExtAttr("爱好", "table2");
this.wxCpService.getUserService().update(user);
}
@Test
public void testDelete() throws Exception {
this.wxCpService.getUserService().delete("some.woman");
}
@Test(dependsOnMethods = "testUpdate")
public void testGetById() throws Exception {
WxCpUser user = this.wxCpService.getUserService().getById("some.woman");
assertNotNull(user);
}
@Test
public void testListByDepartment() throws Exception {
List<WxCpUser> users = this.wxCpService.getUserService().listByDepartment(1, true, 0);
assertNotEquals(users.size(), 0);
for (WxCpUser user : users) {
System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE));
}
}
@Test
public void testListSimpleByDepartment() throws Exception {
List<WxCpUser> users = this.wxCpService.getUserService().listSimpleByDepartment(1, true, 0);
assertNotEquals(users.size(), 0);
for (WxCpUser user : users) {
System.out.println(ToStringBuilder.reflectionToString(user, ToStringStyle.MULTI_LINE_STYLE));
}
}
}

View File

@@ -3,7 +3,7 @@ package me.chanjar.weixin.cp.demo;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.cp.api.WxCpInMemoryConfigStorage;
import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage;
import java.io.InputStream;

View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.cp.demo;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.api.WxCpMessageHandler;
import me.chanjar.weixin.cp.api.WxCpMessageRouter;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.message.WxCpMessageHandler;
import me.chanjar.weixin.cp.message.WxCpMessageRouter;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;

View File

@@ -1,7 +1,7 @@
package me.chanjar.weixin.cp.demo;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.api.WxCpMessageRouter;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.message.WxCpMessageRouter;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;