@ -6,7 +6,6 @@ import com.fr.invoke.Reflect;
import com.fr.json.JSON ;
import com.fr.json.JSONArray ;
import com.fr.json.JSONFactory ;
import com.fr.json.JSONObject ;
import com.fr.stable.ProductConstants ;
import com.fr.stable.StringUtils ;
import com.fr.third.org.apache.commons.io.FileUtils ;
@ -18,6 +17,7 @@ import org.junit.Test;
import org.junit.runner.RunWith ;
import org.powermock.api.easymock.PowerMock ;
import org.powermock.core.classloader.annotations.PrepareForTest ;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor ;
import org.powermock.modules.junit4.PowerMockRunner ;
import java.io.File ;
@ -34,6 +34,7 @@ import static org.junit.Assert.assertTrue;
* /
@RunWith ( PowerMockRunner . class )
@PrepareForTest ( { ProductConstants . class , MarketConfig . class , DesignerEnvManager . class } )
@SuppressStaticInitializationFor ( { "com.fr.jvm.assist.FineAssist" } )
public class TemplateInfoCollectorTest {
private String filePath ;
private String initialFileContent ;
@ -58,6 +59,7 @@ public class TemplateInfoCollectorTest {
EasyMock . expect ( mockProcessInfo . useParaPane ( ) ) . andReturn ( false ) . anyTimes ( ) ;
EasyMock . expect ( mockProcessInfo . getComponentsInfo ( ) ) . andReturn ( new JSONArray ( ) ) . anyTimes ( ) ;
EasyMock . expect ( mockProcessInfo . isTestTemplate ( ) ) . andReturn ( true ) . anyTimes ( ) ;
EasyMock . expect ( mockProcessInfo . getReuseCmpList ( ) ) . andReturn ( JSONArray . create ( ) . add ( "reuse-id-1" ) ) . anyTimes ( ) ;
EasyMock . replay ( mockProcessInfo ) ;
// 缓存 tpl.info
@ -99,10 +101,11 @@ public class TemplateInfoCollectorTest {
Map consumingMap = Reflect . on ( templateInfo ) . field ( "consumingMap" ) . get ( ) ;
Map processMap = Reflect . on ( templateInfo ) . field ( "processMap" ) . get ( ) ;
assertJsonStringEquals ( "{\"process\":\"\",\"float_count\":1,\"widget_count\":0," +
"\"cell_count\":13,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," +
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\"}" ,
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" +
"}" ,
JSONFactory . createJSON ( JSON . OBJECT , processMap ) . toString ( ) ) ;
Assert . assertEquals ( 71113 , consumingMap . get ( "uid" ) ) ;
@ -130,10 +133,11 @@ public class TemplateInfoCollectorTest {
Map processMap = Reflect . on ( templateInfo ) . field ( "processMap" ) . get ( ) ;
assertEquals ( templateID , templateInfo . getTemplateID ( ) ) ;
assertJsonStringEquals ( "{\"process\":\"\",\"float_count\":1,\"widget_count\":0," +
"\"cell_count\":13,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," +
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\"}" , JSONFactory . createJSON ( JSON . OBJECT , processMap ) . toString ( ) ) ;
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" +
"}" , JSONFactory . createJSON ( JSON . OBJECT , processMap ) . toString ( ) ) ;
Map < String , Object > consumingMap = Reflect . on ( templateInfo ) . field ( "consumingMap" ) . get ( ) ;
Assert . assertEquals ( 71113 , consumingMap . get ( "uid" ) ) ;
@ -151,18 +155,19 @@ public class TemplateInfoCollectorTest {
String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa" ;
String originID = "16a988ce-8529-42f5-b17c-2ee849355071" ;
int timeConsume = 200 ;
collector . collectInfo ( templateID , originID , mockProcessInfo , timeConsume ) ;
// 检查是否写入成功
Reflect . on ( collector ) . call ( "loadFromFile" ) ;
TemplateInfo templateInfo = getTemplateInfoByID ( templateID ) ;
Map processMap = Reflect . on ( templateInfo ) . field ( "processMap" ) . get ( ) ;
assertJsonStringEquals ( "{\"process\":\"\",\"float_count\":1,\"widget_count\":0,\"cell_count\":13," +
"\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," +
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\"}" , JSONFactory . createJSON ( JSON . OBJECT , processMap ) . toString ( ) ) ;
assertJsonStringEquals ( "{\"process\":\"\",\"float_count\":1,\"widget_count\":0," +
"\"cell_count\":13,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," +
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" +
"}" , JSONFactory . createJSON ( JSON . OBJECT , processMap ) . toString ( ) ) ;
Map < String , Object > consumingMap = Reflect . on ( templateInfo ) . field ( "consumingMap" ) . get ( ) ;
Assert . assertEquals ( 71113 , consumingMap . get ( "uid" ) ) ;
Assert . assertEquals ( "2020-05-07 17:25" , consumingMap . get ( "create_time" ) ) ;