Skip to content

Commit

Permalink
enhance cola mock
Browse files Browse the repository at this point in the history
  • Loading branch information
fulan.zjf committed Mar 12, 2019
1 parent 5f09791 commit 30554c7
Show file tree
Hide file tree
Showing 39 changed files with 629 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
import com.alibaba.cola.mock.model.ColaTestModel;

import org.junit.runner.Description;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.FactoryBean;

/**
* @author shawnzhan.zxy
* @date 2018/09/02
*/
public class ColaMockContext implements Serializable{
private static Logger logger = LoggerFactory.getLogger(ColaMockContext.class);

private Object testInstance;
private Description testMeta;
/** 整体监控列表,容器启动需要一次性将需要mock的类都通过cglib代理*/
Expand Down Expand Up @@ -111,6 +115,10 @@ public Map<Class, ColaTestModel> getColaTestModelMap() {
}

public void putColaTestModel(ColaTestModel colaTestModel) {
if(colaTestModel == null){
logger.error("No cola mock config is specified, which could be normal if you are not intend to do Recording");
return;
}
colaTestModelMap.put(colaTestModel.getTestClazz(), colaTestModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</encoder>
</appender>

<root level="DEBUG">
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="APPLICATION" />
</root>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.alibaba.craftsman;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.annotation.ExcludeCompare;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.MetricsServiceI;
import com.alibaba.craftsman.dto.CodeReviewMetricAddCmd;
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -17,14 +22,14 @@
* @author Frank Zhang
* @date 2019-03-04 11:23 AM
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class CodeReviewMetricAddCmdExeTest {
@RunWith(ColaTestRunner.class)
@ColaMockConfig(mocks={MetricTunnel.class})
public class CodeReviewMetricAddCmdExeTest extends MockTestBase {
@Autowired
private MetricsServiceI metricsService;

@Test
@ExcludeCompare(fields = {"id","userId"})
public void testSuccess(){
CodeReviewMetricAddCmd codeReviewMetricAddCmd = prepareCodeReviewMetricAddCmd("CodeReviewMetricAddCmdExeTest_098873");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@


import com.alibaba.cola.dto.Response;
import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.MetricsServiceI;
import com.alibaba.craftsman.dto.MetricDeleteCmd;
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -12,10 +16,9 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class MetricDeleteCmdExeTest {
@RunWith(ColaTestRunner.class)
@ColaMockConfig(mocks={MetricTunnel.class})
public class MetricDeleteCmdExeTest extends MockTestBase {

@Autowired
private MetricsServiceI metricsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@
import java.util.List;

/**
* MetricTunnelTest
* This is Tunnel Test, no need to mock, and no regression needed as well
*
* @author Frank Zhang
* @date 2019-02-27 2:33 PM
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class MetricTunnelTest {

@Autowired
private MetricTunnel metricTunnel;

@Test
public void testCRUD(){
String userId = "MetricTunnelTest" + Math.random();
MetricDO metricDO = new MetricDO();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.alibaba.craftsman;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.annotation.ExcludeCompare;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.MetricsServiceI;
import com.alibaba.craftsman.dto.MiscMetricAddCmd;
import com.alibaba.craftsman.dto.clientobject.MiscMetricCO;
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,14 +23,14 @@
* @author Frank Zhang
* @date 2019-03-04 1:47 PM
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class MiscMetricAddCmdExeTest {
@RunWith(ColaTestRunner.class)
@ColaMockConfig(mocks={MetricTunnel.class})
public class MiscMetricAddCmdExeTest extends MockTestBase {
@Autowired
private MetricsServiceI metricsService;

@Test
@ExcludeCompare(fields = {"id","userId"})
public void testSuccess(){
MiscMetricAddCmd miscMetricAddCmd = new MiscMetricAddCmd();
MiscMetricCO miscMetricCO = new MiscMetricCO();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.alibaba.craftsman;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.annotation.ExcludeCompare;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.MetricsServiceI;
import com.alibaba.craftsman.dto.PaperMetricAddCmd;
import com.alibaba.craftsman.dto.clientobject.PaperMetricCO;
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,14 +23,14 @@
* @author Frank Zhang
* @date 2019-03-03 11:46 AM
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class PaperMetricAddCmdExeTest {
@RunWith(ColaTestRunner.class)
@ColaMockConfig(mocks={MetricTunnel.class})
public class PaperMetricAddCmdExeTest extends MockTestBase {
@Autowired
private MetricsServiceI metricsService;

@Test
@ExcludeCompare(fields = {"id","userId"})
public void testPaperMetricAddSuccess(){
PaperMetricAddCmd paperMetricAddCmd = new PaperMetricAddCmd();
PaperMetricCO paperMetricCO = new PaperMetricCO();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.alibaba.craftsman;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.annotation.ExcludeCompare;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.MetricsServiceI;
import com.alibaba.craftsman.dto.PatentMetricAddCmd;
import com.alibaba.craftsman.dto.clientobject.PatentMetricCO;
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,14 +23,14 @@
* @author Frank Zhang
* @date 2019-03-03 11:57 AM
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class PatentMetricAddCmdExeTest {
@RunWith(ColaTestRunner.class)
@ColaMockConfig(mocks={MetricTunnel.class})
public class PatentMetricAddCmdExeTest extends MockTestBase {
@Autowired
private MetricsServiceI metricsService;

@Test
@ExcludeCompare(fields = {"id","userId"})
public void testPatentMetricAddSuccess(){
PatentMetricAddCmd patentMetricAddCmd = new PatentMetricAddCmd();
patentMetricAddCmd.setOperater("jack ma");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.alibaba.craftsman;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.annotation.ExcludeCompare;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.MetricsServiceI;
import com.alibaba.craftsman.dto.RefactoringMetricAddCmd;
import com.alibaba.craftsman.dto.clientobject.RefactoringMetricCO;
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,15 +23,15 @@
* @author Frank Zhang
* @date 2019-03-04 1:59 PM
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class RefactoringMetricAddCmdExeTest {
@RunWith(ColaTestRunner.class)
@ColaMockConfig(mocks={MetricTunnel.class})
public class RefactoringMetricAddCmdExeTest extends MockTestBase {

@Autowired
private MetricsServiceI metricsService;

@Test
@ExcludeCompare(fields = {"id","userId"})
public void testSuccess(){
RefactoringMetricAddCmd refactoringMetricAddCmd = new RefactoringMetricAddCmd();
RefactoringMetricCO refactoringMetricCO = new RefactoringMetricCO();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package com.alibaba.craftsman;


import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.MetricsServiceI;
import com.alibaba.craftsman.api.UserProfileServiceI;
import com.alibaba.craftsman.dto.ATAMetricAddCmd;
import com.alibaba.craftsman.dto.CodeReviewMetricAddCmd;
import com.alibaba.craftsman.dto.UserProfileAddCmd;
import com.alibaba.craftsman.dto.clientobject.UserProfileCO;
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;

@RunWith(ColaTestRunner.class)
@ColaMockConfig(mocks={MetricTunnel.class})
//@RunWith(ColaTestRunner.class)
//@ColaMockConfig(mocks={MetricTunnel.class, UserProfileTunnel.class})
public class ScoreRecalculateTest extends MockTestBase {
private String userId;

Expand All @@ -31,7 +26,7 @@ public void init(){
userId = "ScoreRecalculateTest" + System.currentTimeMillis();
}

@Test
//@Test
public void testDevSuccess(){
UserProfileAddCmd userProfileAddCmd = UserProfileCmdExeTest.prepareCommand(userId, UserProfileCO.DEV_ROLE);
userProfileService.addUserProfile(userProfileAddCmd);
Expand All @@ -42,7 +37,7 @@ public void testDevSuccess(){
metricsService.addATAMetric(ataMetricAddCmd);
}

@Test
//@Test
public void testQASuccess(){
UserProfileAddCmd userProfileAddCmd = UserProfileCmdExeTest.prepareCommand(userId, UserProfileCO.QA_ROLE);
userProfileService.addUserProfile(userProfileAddCmd);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.alibaba.craftsman;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.annotation.ExcludeCompare;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.MetricsServiceI;
import com.alibaba.craftsman.dto.SharingMetricAddCmd;
import com.alibaba.craftsman.dto.clientobject.SharingMetricCO;
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,14 +23,14 @@
* @author Frank Zhang
* @date 2019-03-02 5:08 PM
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class SharingMetricAddCmdExeTest {
@RunWith(ColaTestRunner.class)
@ColaMockConfig(mocks={MetricTunnel.class})
public class SharingMetricAddCmdExeTest extends MockTestBase {
@Autowired
private MetricsServiceI metricsService;

@Test
@ExcludeCompare(fields = {"id","userId"})
public void testSharingMetricAddSuccess(){
SharingMetricAddCmd sharingMetricAddCmd = new SharingMetricAddCmd();
SharingMetricCO sharingMetricCO = new SharingMetricCO();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.mock.annotation.ColaMockConfig;
import com.alibaba.cola.mock.annotation.ExcludeCompare;
import com.alibaba.cola.mock.runner.ColaTestRunner;
import com.alibaba.craftsman.api.UserProfileServiceI;
import com.alibaba.craftsman.dto.RefreshScoreCmd;
Expand All @@ -12,6 +13,7 @@
import com.alibaba.craftsman.mock.MockTestBase;
import com.alibaba.craftsman.tunnel.database.MetricTunnel;
import com.alibaba.craftsman.tunnel.database.UserProfileTunnel;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -35,14 +37,17 @@ public class UserProfileCmdExeTest extends MockTestBase {
@Autowired
private UserProfileServiceI userProfileService;

@Autowired
private UserProfileTunnel userProfileTunnel;

private String userId;

public static final String TEST_USER_NAME = "Frank";
public static final String TEST_DEP = "ICBU";

@Before
public void init(){
userId = "UserProfileCmdExeTest" + System.currentTimeMillis();
userId = "UserProfileCmdExeTest1000";
}

public static UserProfileAddCmd prepareCommand(String userId, String role){
Expand Down Expand Up @@ -101,4 +106,9 @@ public void testSuccessUpdate(){
Assert.assertEquals(100, result.getTechContributionScore(), 0.01);
Assert.assertEquals(TEST_DEP, result.getDep());
}

@After
public void cleanup(){
userProfileTunnel.delete(userId);
}
}
Loading

0 comments on commit 30554c7

Please sign in to comment.