提交测试用例

This commit is contained in:
zhouxiunai
2019-01-08 14:57:23 +08:00
parent f4613f219e
commit a4844a783d
5 changed files with 171 additions and 48 deletions
@@ -0,0 +1,23 @@
package com.gzzn.omms.msgexchangeapi.dao;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class CoutmsgDaoTest {
@Autowired
private CmoutmsgDao cmoutmsgDao;
@Test
public void testFindByCminmsgsIdGreaterThanAndCminmsgsDateProcessedIsNull()
{
Integer maxId = cmoutmsgDao.findMaxId();
System.out.println("maxId:"+maxId);
}
}
@@ -1,5 +1,17 @@
package com.gzzn.omms.msgexchangeapi.service;
public class CmoutmsgServiceImplTest {
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class CmoutmsgServiceImplTest {
@Test
private void testSendSchdGetMsg()
{
}
}
@@ -3,6 +3,9 @@ package com.gzzn.omms.msgexchangeapi.service;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import org.junit.Test;
@@ -15,8 +18,15 @@ import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao;
import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGESUBTYPES;
import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGETYPES;
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
import com.gzzn.omms.msgexchangeapi.entity.msg.RQFD;
import com.gzzn.omms.msgexchangeapi.entity.msg.SUBSYSTEMS;
import com.gzzn.omms.msgexchangeapi.entity.msg.builder.METABuilder;
import com.gzzn.omms.msgexchangeapi.entity.msg.builder.MSGBuilder;
import com.gzzn.omms.msgexchangeapi.service.exchange.IExchangeService;
import com.gzzn.omms.msgexchangeapi.utils.DateTimeUtil;
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
@RunWith(SpringRunner.class)
@@ -50,7 +60,7 @@ public class ExchangeServiceImplTest {
"</PSDT>\r\n" +
"</FLOP>\r\n" +
"</MSG>";
String jsonString = exchangeService.xmlstrToJson(xmlString);
String jsonString = exchangeService.xmlMsgToJsonMsg(xmlString);
System.out.println(jsonString);
//assertThat(jsonPath("$.", matcher)).
@@ -88,7 +98,7 @@ public class ExchangeServiceImplTest {
{
String xml = cminmsgDao.findOne(300L).getCminmsgsClobMsg();
MSG dNLDMsg = exchangeService.xmlstrToObject(xml, MSG.class);
MSG dNLDMsg = exchangeService.xmlToMsg(xml);
String jsonString=JsonUtil.getString(dNLDMsg);
File file = new File("schd.json");
@@ -99,4 +109,40 @@ public class ExchangeServiceImplTest {
System.out.println(jsonString);
}
/**
* POJO 转xml字符串
*/
@Test
public void testObjectToXmlstr()
{
Long nowtime = System.currentTimeMillis();
MSG rqfdMsg = new MSGBuilder().
setMETA(
new METABuilder()
.setSNDR(SUBSYSTEMS.OSH5)
.setTYPE(MESSAGETYPES.RQFD)
.setSTYP(MESSAGESUBTYPES.NONE)
.setDTTM(new BigInteger(nowtime.toString()))
.build()
)
.build();
RQFD rqfd = new RQFD();
rqfd.setSTDB(getDateStr(new Date()));
rqfd.setSTDE(getDateStr(new Date()));
rqfdMsg.setRQFD(rqfd);
//打印xml结果
System.out.println(exchangeService.msgToXml(rqfdMsg));
}
private String getDateStr(Date date)
{
return DateTimeUtil.gtFormatStr(
date,
"ddMMMyyHHmm",
Locale.ENGLISH)
.toUpperCase();
}//end function
}
@@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,6 +21,8 @@ import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao;
import com.gzzn.omms.msgexchangeapi.entity.Cminmsg;
import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGESUBTYPES;
import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGETYPES;
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
import com.gzzn.omms.msgexchangeapi.service.exchange.IExchangeService;
@@ -48,7 +51,7 @@ public class ToolTest {
//每种类型提取一个
for(Cminmsg x : lsCmin)
{
MSG msg = exchangeService.xmlstrToObject(x.getCminmsgsClobMsg(),MSG.class);
MSG msg = exchangeService.xmlToMsg(x.getCminmsgsClobMsg());
mapCminmsg.putIfAbsent(msg.getMETA().getTYPE() + "_" + msg.getMETA().getSTYP(), x);
}
@@ -62,21 +65,13 @@ public class ToolTest {
* @throws JsonMappingException
* @throws IOException
*/
@Test
public void exportToXmlFiles() throws JsonParseException, JsonMappingException, IOException
{
List<Cminmsg> lsCmin = (List<Cminmsg>) cminmsgDao.findAll();
//提取某个航班的信息
List<Cminmsg> lsFlopTypeCmin = lsCmin.parallelStream()
.filter(node->{
MSG msg = exchangeService.xmlstrToObject(node.getCminmsgsClobMsg(), MSG.class);
return msg.getMETA().getTYPE().equals("FLOP");
})
.collect(Collectors.toList());
flopMsgToXmlFiles(lsFlopTypeCmin);
flopMsgToXmlFiles(lsCmin);
} //end function
@@ -89,7 +84,7 @@ public class ToolTest {
try {
for(Cminmsg x : lsCmin)
{
String json = exchangeService.xmlstrToJson(x.getCminmsgsClobMsg());
String json = exchangeService.xmlMsgToJsonMsg(x.getCminmsgsClobMsg());
MSG msg;
msg = JsonUtil.getObject(json,MSG.class);
@@ -114,7 +109,7 @@ public class ToolTest {
//
File f = new File(path.toString());
try (FileOutputStream fop = new FileOutputStream(f)) {
String jsonString = exchangeService.xmlstrToJson(x.getCminmsgsClobMsg());
String jsonString = exchangeService.xmlMsgToJsonMsg(x.getCminmsgsClobMsg());
jsonString = jsonString.replace("\"noNamespaceSchemaLocation\":\"unisysaodbsis.xsd\",", "");
byte[] contentInBytes = jsonString.getBytes("UTF-8");
@@ -145,36 +140,64 @@ public class ToolTest {
try {
for(Cminmsg x : lsCmin)
{
MSG msg = exchangeService.xmlstrToObject(x.getCminmsgsClobMsg(), MSG.class);
Map msgMap = exchangeService.xmlstrToObject(x.getCminmsgsClobMsg(), Map.class);
Map mapFlop = (Map)msgMap.get("FLOP");
String flid = String.valueOf(mapFlop.get("FLID"));
if(null == flid || flid.equalsIgnoreCase("null") || flid.equals("")) {
logger.warn("没有flid的消息:"+x.getCminmsgsClobMsg());
continue;
}
String type = "xml";
String path = getPathGroupByFlid(msg,type,flid);
//父目录是否存在
File fileDir = new File(path);
if(fileDir.getParentFile().exists() == false)
try {
MSG msg;
msg = exchangeService.xmlToMsg(x.getCminmsgsClobMsg());
String flid="unknown-flid";
if(msg.getMETA().getTYPE() == MESSAGETYPES.LDM && msg.getMETA().getSTYP() == MESSAGESUBTYPES.FLOP)
{
flid = msg.getLDM().getLDMR().get(0).getFLID().toString();
}
else if(msg.getMETA().getTYPE() == MESSAGETYPES.REGN && msg.getMETA().getSTYP() == MESSAGESUBTYPES.ADD)
{
continue;
}
else if(msg.getMETA().getTYPE() == MESSAGETYPES.RSTA && msg.getMETA().getSTYP() == MESSAGESUBTYPES.ADD)
{
continue;
}
else if(msg.getMETA().getTYPE() == MESSAGETYPES.SCHD && msg.getMETA().getSTYP() == MESSAGESUBTYPES.ADFT)
{
flid = msg.getSCHD().getFLTR().get(0).getFLID().toString();
}
else if(msg.getMETA().getTYPE() == MESSAGETYPES.SCHD && msg.getMETA().getSTYP() == MESSAGESUBTYPES.DNLD)
{
continue;
}
else if(msg.getMETA().getTYPE() == MESSAGETYPES.FLOP)
{
flid = msg.getFLOP().getFLID().toString();
}
else {
continue;
}
/*
String type = "xml";
String path = getPathGroupByMsgType(msg,type,flid);
//父目录是否存在
File fileDir = new File(path);
if(fileDir.getParentFile().exists() == false)
{
fileDir.getParentFile().mkdirs();
}
//
byte[] contentInBytes = x.getCminmsgsClobMsg().getBytes("UTF-8");
File f = new File(path.toString());
fop = new FileOutputStream(f);
fop.write(contentInBytes);
fop.flush();
fop.close();
*/
}
catch (Exception e)
{
fileDir.getParentFile().mkdirs();
logger.error("消息转换失败:"+x.getCminmsgsClobMsg());
}
//
byte[] contentInBytes = x.getCminmsgsClobMsg().getBytes("UTF-8");
File f = new File(path.toString());
fop = new FileOutputStream(f);
fop.write(contentInBytes);
fop.flush();
fop.close();
}//end for
}
catch (Exception e) {
@@ -215,6 +238,21 @@ public class ToolTest {
return path.toString();
}
private String getPathGroupByMsgType(MSG msg,String type,String flid)
{
String dir = type;
StringBuilder path = new StringBuilder();
path.append(dir);
path.append("/");
path.append(msg.getMETA().getTYPE());//Type
path.append("-"+msg.getMETA().getSTYP());//Subtype
path.append("/");
path.append(msg.getMETA().getDTTM());//dttm
path.append("-"+flid);
path.append("."+dir);
return path.toString();
}
}
@@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao;
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
import com.gzzn.omms.msgexchangeapi.service.exchange.IExchangeService;
@@ -34,11 +35,14 @@ public class XmlToPojoTest {
@Test
public void testXmlToPojo()
{
String xml = cminmsgDao.findOne(300L).getCminmsgsClobMsg();
String xml = cminmsgDao.findOne(847328L).getCminmsgsClobMsg();
Long start = System.currentTimeMillis();
//生成pojo类
Map map = exchangeService.xmlstrToObject(xml, Map.class);
MSG msg = exchangeService.xmlToMsg(xml);
System.out.println("转换耗时:" + (System.currentTimeMillis() - start));
}