diff --git a/src/test/java/com/gzzn/omms/msgexchangeapi/dao/CoutmsgDaoTest.java b/src/test/java/com/gzzn/omms/msgexchangeapi/dao/CoutmsgDaoTest.java new file mode 100644 index 00000000..0a487899 --- /dev/null +++ b/src/test/java/com/gzzn/omms/msgexchangeapi/dao/CoutmsgDaoTest.java @@ -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); + } +} diff --git a/src/test/java/com/gzzn/omms/msgexchangeapi/service/CmoutmsgServiceImplTest.java b/src/test/java/com/gzzn/omms/msgexchangeapi/service/CmoutmsgServiceImplTest.java index 17ce3ce6..557d1757 100644 --- a/src/test/java/com/gzzn/omms/msgexchangeapi/service/CmoutmsgServiceImplTest.java +++ b/src/test/java/com/gzzn/omms/msgexchangeapi/service/CmoutmsgServiceImplTest.java @@ -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() + { + + } } diff --git a/src/test/java/com/gzzn/omms/msgexchangeapi/service/ExchangeServiceImplTest.java b/src/test/java/com/gzzn/omms/msgexchangeapi/service/ExchangeServiceImplTest.java index f6197f70..964095a8 100644 --- a/src/test/java/com/gzzn/omms/msgexchangeapi/service/ExchangeServiceImplTest.java +++ b/src/test/java/com/gzzn/omms/msgexchangeapi/service/ExchangeServiceImplTest.java @@ -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 { "\r\n" + "\r\n" + ""; - 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 } diff --git a/src/test/java/com/gzzn/omms/msgexchangeapi/tools/ToolTest.java b/src/test/java/com/gzzn/omms/msgexchangeapi/tools/ToolTest.java index ce739079..ee8caa82 100644 --- a/src/test/java/com/gzzn/omms/msgexchangeapi/tools/ToolTest.java +++ b/src/test/java/com/gzzn/omms/msgexchangeapi/tools/ToolTest.java @@ -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 lsCmin = (List) cminmsgDao.findAll(); - //提取某个航班的信息 - List 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(); + } } diff --git a/src/test/java/com/gzzn/omms/msgexchangeapi/tools/XmlToPojoTest.java b/src/test/java/com/gzzn/omms/msgexchangeapi/tools/XmlToPojoTest.java index 5979c9ea..aaca60e6 100644 --- a/src/test/java/com/gzzn/omms/msgexchangeapi/tools/XmlToPojoTest.java +++ b/src/test/java/com/gzzn/omms/msgexchangeapi/tools/XmlToPojoTest.java @@ -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)); }