diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangepackDto.java b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangepackDto.java index d0c3e94..28ab7af 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/ExchangepackDto.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/ExchangepackDto.java @@ -3,10 +3,12 @@ package cokr.xit.adds.inf.mois.model; import java.util.List; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; -import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlValue; import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; @@ -34,12 +36,15 @@ import lombok.NoArgsConstructor; @AllArgsConstructor @Builder public class ExchangepackDto { - @XmlElement(required = true) + @JacksonXmlProperty(localName = "header") + @JsonProperty(required = true) protected Header header; + @JacksonXmlProperty(localName = "contents") protected Contents contents; - @XmlAttribute(name = "filename", required = true) + @JacksonXmlProperty(localName = "filename", isAttribute = true) + @JsonProperty(required = true) protected String filename; @JsonInclude(JsonInclude.Include.NON_EMPTY) @@ -47,33 +52,43 @@ public class ExchangepackDto { @AllArgsConstructor @Builder public static class Header { - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Server server; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Sender sender; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Receiver receiver; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String sendersystemname; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Exchangetype exchangetype; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String doctype; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String date; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String administrativenum; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String title; + @JacksonXmlProperty protected Addenda addenda; } @@ -82,10 +97,12 @@ public class ExchangepackDto { @AllArgsConstructor @Builder public static class Server { - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String sendserverid; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String receiveserverid; } @@ -94,16 +111,21 @@ public class ExchangepackDto { @AllArgsConstructor @Builder public static class Sender { - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Organ organ; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String sendkey; + @JacksonXmlProperty protected String username; + @JacksonXmlProperty protected String userposition; + @JacksonXmlProperty protected String email; } @@ -112,10 +134,12 @@ public class ExchangepackDto { @AllArgsConstructor @Builder public static class Organ { - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Orgname orgname; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Deptname deptname; } @@ -125,9 +149,11 @@ public class ExchangepackDto { @Builder public static class Orgname { @XmlValue + @JacksonXmlText protected String value; - @XmlAttribute(name = "orgcode", required = true) + @JacksonXmlProperty(localName = "orgcode", isAttribute = true) + @JsonProperty(required = true) protected String orgcode; } @@ -137,9 +163,11 @@ public class ExchangepackDto { @Builder public static class Deptname { @XmlValue + @JacksonXmlText protected String value; - @XmlAttribute(name = "deptcode", required = true) + @JacksonXmlProperty(localName = "deptcode", isAttribute = true) + @JsonProperty(required = true) protected String deptcode; } @@ -148,16 +176,21 @@ public class ExchangepackDto { @AllArgsConstructor @Builder public static class Receiver { - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Organ organ; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String recvkey; + @JacksonXmlProperty protected String username; + @JacksonXmlProperty protected String userposition; + @JacksonXmlProperty protected String email; } @@ -166,9 +199,11 @@ public class ExchangepackDto { @AllArgsConstructor @Builder public static class Exchangetype { - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String maintype; + @JacksonXmlProperty protected String subtype; } @@ -177,6 +212,8 @@ public class ExchangepackDto { @AllArgsConstructor @Builder public static class Addenda { + @JacksonXmlElementWrapper(useWrapping = false) + @JacksonXmlProperty(localName = "addendum") protected List addendum; } @@ -186,12 +223,15 @@ public class ExchangepackDto { @Builder public static class Addendum { @XmlValue + @JacksonXmlText protected String value; - @XmlAttribute(name = "Name", required = true) + @JacksonXmlProperty(localName = "Name", isAttribute = true) + @JsonProperty(required = true) protected String name; - @XmlAttribute(name = "comment", required = true) + @JacksonXmlProperty(localName = "comment", isAttribute = true) + @JsonProperty(required = true) protected String comment; } @@ -200,6 +240,8 @@ public class ExchangepackDto { @AllArgsConstructor @Builder public static class Contents { + @JacksonXmlElementWrapper(useWrapping = false) + @JacksonXmlProperty(localName = "content") protected List content; } @@ -209,29 +251,32 @@ public class ExchangepackDto { @Builder public static class Content { @XmlValue + @JacksonXmlText protected String value; - @XmlAttribute(name = "content-role", required = true) + @JacksonXmlProperty(localName = "content-role", isAttribute = true) + @JsonProperty(required = true) protected String contentRole; - @XmlAttribute(name = "sub-role") + @JacksonXmlProperty(localName = "sub-role", isAttribute = true) @Builder.Default protected String subRole = "content"; - @XmlAttribute(name = "content-transfer-encoding") + @JacksonXmlProperty(localName = "content-transfer-encoding", isAttribute = true) @Builder.Default protected String contentTransferEncoding = "base64"; - @XmlAttribute(name = "filename", required = true) + @JacksonXmlProperty(localName = "filename", isAttribute = true) + @JsonProperty(required = true) protected String filename; - @XmlAttribute(name = "content-type") + @JacksonXmlProperty(localName = "content-type", isAttribute = true) protected String contentType; - @XmlAttribute(name = "charset") + @JacksonXmlProperty(localName = "charset", isAttribute = true) protected String charset; - @XmlAttribute(name = "attachorder") + @JacksonXmlProperty(localName = "attachorder", isAttribute = true) protected String attachorder; /** @@ -240,7 +285,7 @@ public class ExchangepackDto { * modifiable | modified | non * */ - @XmlAttribute(name = "modify") + @JacksonXmlProperty(localName = "modify", isAttribute = true) @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @Builder.Default protected String modify = "non"; diff --git a/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java b/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java index 7870728..99d7481 100644 --- a/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java +++ b/src/main/java/cokr/xit/adds/inf/mois/model/PackDto.java @@ -4,10 +4,12 @@ import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText; -import jakarta.xml.bind.annotation.XmlAttribute; -import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlValue; import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; @@ -35,13 +37,16 @@ import lombok.NoArgsConstructor; @AllArgsConstructor @Builder public class PackDto { - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Header header; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Contents contents; - @XmlAttribute(name = "filename", required = true) + @JacksonXmlProperty(localName = "filename", isAttribute = true) + @JsonProperty(required = true) protected String filename; @JsonInclude(JsonInclude.Include.NON_EMPTY) @@ -49,34 +54,43 @@ public class PackDto { @AllArgsConstructor @Builder public static class Header { - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected Type type; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String date; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String sender; - @XmlElement(required = true) + @JacksonXmlProperty + @JsonProperty(required = true) protected String receiver; - @XmlElement(name = "sender_userid", required = true) + @JacksonXmlProperty(localName = "sender_userid") + @JsonProperty(required = true) protected String senderUserid; - @XmlElement(name = "receiver_userid", required = true) + @JacksonXmlProperty(localName = "receiver_userid") + @JsonProperty(required = true) protected String receiverUserid; - @XmlElement(name = "sender_email") + @JacksonXmlProperty(localName = "sender_email") protected String senderEmail; - @XmlElement(name = "sender_orgname", required = true) + @JacksonXmlProperty(localName = "sender_orgname") + @JsonProperty(required = true) protected String senderOrgname; - @XmlElement(name = "sender_systemname", required = true) + @JacksonXmlProperty(localName = "sender_systemname") + @JsonProperty(required = true) protected String senderSystemname; - @XmlElement(name = "administrative_num", required = true) + @JacksonXmlProperty(localName = "administrative_num") + @JsonProperty(required = true) protected String administrativeNum; } @@ -91,7 +105,8 @@ public class PackDto { * send|fail|arrive|receive|invalid|submit|return|approval * */ - @XmlAttribute(name = "doc-type", required = true) + @JacksonXmlProperty(localName = "doc-type", isAttribute = true) + @JsonProperty(required = true) @XmlJavaTypeAdapter(CollapsedStringAdapter.class) protected String docType; } @@ -101,6 +116,8 @@ public class PackDto { @AllArgsConstructor @Builder public static class Contents { + @JacksonXmlElementWrapper(useWrapping = false) + @JacksonXmlProperty(localName = "content") protected List content; public List getContent() { @@ -117,21 +134,24 @@ public class PackDto { @Builder public static class Content { @XmlValue + @JacksonXmlText protected String value; - @XmlAttribute(name = "content-role", required = true) + @JacksonXmlProperty(localName = "content-role", isAttribute = true) + @JsonProperty(required = true) protected String contentRole; - @XmlAttribute(name = "content-transfer-encoding") + @JacksonXmlProperty(localName = "content-transfer-encoding", isAttribute = true) protected String contentTransferEncoding = "base64"; - @XmlAttribute(name = "filename", required = true) + @JacksonXmlProperty(localName = "filename", isAttribute = true) + @JsonProperty(required = true) protected String filename; - @XmlAttribute(name = "content-type") + @JacksonXmlProperty(localName = "content-type", isAttribute = true) protected String contentType; - @XmlAttribute(name = "charset") + @JacksonXmlProperty(localName = "charset", isAttribute = true) protected String charset; } } diff --git a/src/test/java/cokr/xit/adds/inf/mois/model/ExchangepackDtoTest.java b/src/test/java/cokr/xit/adds/inf/mois/model/ExchangepackDtoTest.java new file mode 100644 index 0000000..e5e6ae0 --- /dev/null +++ b/src/test/java/cokr/xit/adds/inf/mois/model/ExchangepackDtoTest.java @@ -0,0 +1,188 @@ +package cokr.xit.adds.inf.mois.model; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; + +import javax.xml.stream.XMLOutputFactory; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; + +import cokr.xit.foundation.data.XML; +import lombok.extern.slf4j.Slf4j; + +/** + *
+ * description :
+ *
+ * packageName : cokr.xit.adds.inf.mois.model
+ * fileName    : ExchangeDtoTest
+ * author      : limju
+ * date        : 2024-03-14
+ * ======================================================================
+ * 변경일         변경자        변경 내용
+ * ----------------------------------------------------------------------
+ * 2024-03-14    limju       최초 생성
+ *
+ * 
+ */ +@Slf4j +@ExtendWith(SpringExtension.class) +public class ExchangepackDtoTest { + String exchangeXml = """ + + +
+ + ADM131000040 + hongkildong + + + + orgname-value + deptname-value + + sendkey + username + + + + orgname-value + deptname-value + + + sendersystemname + doctype + date + administrativenum + title +
+ + content-value + +
+ """; + + @DisplayName("전자결재 exchangepack xml read 테스트") + @Test + public void exchangepackXmlReadTest() throws IOException { + // JacksonXmlModule jacksonXmlModule = new JacksonXmlModule(); + // jacksonXmlModule.setDefaultUseWrapper(false); + // //ObjectMapper xmlMapper = new XmlMapper(jacksonXmlModule); + // XmlMapper xmlMapper = new XmlMapper(jacksonXmlModule); + // xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); + // + // ExchangepackDto dto + // = xmlMapper.readValue(exchangeXml, ExchangepackDto.class); + // + // assertNotNull(dto); + // + // xmlMapper.writeValue(System.out, dto); + + XML xml = new XML(); + ExchangepackDto dto = xml.parse(exchangeXml, new TypeReference() {}); + log.info("dto: {}", dto); + xml.write(System.out, dto, true); + } + + @DisplayName("전자결재 exchangepack xml write 테스트") + @Test + public void exchangepackXmlWriteTest() throws IOException { + ExchangepackDto dto = getExchangepackDto(); + + JacksonXmlModule module = new JacksonXmlModule(); + module.setDefaultUseWrapper(true); + XmlMapper mapper = new XmlMapper(module); + + XMLOutputFactory factory = mapper.getFactory().getXMLOutputFactory(); + + String dtd = """ + + """; + // FIXME: 파일명 생성 + try (FileOutputStream fos = new FileOutputStream("exchangepack.xml");) { + XML xml = new XML(); + xml.write(fos, dto, true); + fos.flush(); + + }catch (Exception e) { + e.printStackTrace(); + } + } + + private static ExchangepackDto getExchangepackDto() { + ExchangepackDto.Server server = ExchangepackDto.Server.builder() + .sendserverid("ADM131000040") + .receiveserverid("hongkildong") + .build(); + + + + + ExchangepackDto.Orgname orgname = ExchangepackDto.Orgname.builder() + //.orgid("ADM131000040") + .orgcode("hongkildong") + .value("orgname-value") + .build(); + ExchangepackDto.Deptname deptname = ExchangepackDto.Deptname.builder() + //.orgid("ADM131000040") + .deptcode("deptcode") + .value("deptname-value") + .build(); + + ExchangepackDto.Organ organ = ExchangepackDto.Organ.builder() + .orgname(orgname) + .deptname(deptname) + .build(); + + + ExchangepackDto.Sender sender = ExchangepackDto.Sender.builder() + .organ(organ) + .sendkey("sendkey") + .username("username") + .build(); + + ExchangepackDto.Receiver receiver = ExchangepackDto.Receiver.builder() + .organ(organ) + .build(); + + ExchangepackDto.Header header = ExchangepackDto.Header.builder() + .server(server) + .sender(sender) + .receiver(receiver) + .sendersystemname("sendersystemname") + .exchangetype(null) + .doctype("doctype") + .date("date") + .administrativenum("administrativenum") + .title("title") + //.addenda(null) + .build(); + + ExchangepackDto.Content content = ExchangepackDto.Content.builder() + .contentRole("contentRole") + .contentType("constentType") + .charset("utf8") + .modify("modified") + .value("content-value") + .build(); + + ExchangepackDto exchangepackDto = ExchangepackDto.builder() + .header(header) + .contents(ExchangepackDto.Contents.builder() + .content(List.of(content)) + .build()) + .filename("filename") + .build(); + + + return exchangepackDto; + } +} diff --git a/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java b/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java new file mode 100644 index 0000000..14e3616 --- /dev/null +++ b/src/test/java/cokr/xit/adds/inf/mois/model/PackDtoTest.java @@ -0,0 +1,142 @@ +package cokr.xit.adds.inf.mois.model; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; + +import javax.xml.stream.XMLOutputFactory; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; + +import cokr.xit.foundation.data.XML; +import lombok.extern.slf4j.Slf4j; + +/** + *
+ * description :
+ *
+ * packageName : cokr.xit.adds.inf.mois.model
+ * fileName    : ExchangeDtoTest
+ * author      : limju
+ * date        : 2024-03-14
+ * ======================================================================
+ * 변경일         변경자        변경 내용
+ * ----------------------------------------------------------------------
+ * 2024-03-14    limju       최초 생성
+ *
+ * 
+ */ +@Slf4j +@ExtendWith(SpringExtension.class) +public class PackDtoTest { + String packXml = """ + + +
+ + 2024-03-14 + sender + receiver + senderUserid + receiverUserid + senderEmail + senderOrgname + senderSystemname + administrativeNum +
+ + content-value + +
+ """; + + @DisplayName("전자결재 pack xml read 테스트") + @Test + public void packXmlReadTest() throws IOException { + // JacksonXmlModule jacksonXmlModule = new JacksonXmlModule(); + // jacksonXmlModule.setDefaultUseWrapper(false); + // //ObjectMapper xmlMapper = new XmlMapper(jacksonXmlModule); + // XmlMapper xmlMapper = new XmlMapper(jacksonXmlModule); + // xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); + // + // PackDto dto + // = xmlMapper.readValue(packXml, PackDto.class); + // + // assertNotNull(dto); + // + // xmlMapper.writeValue(System.out, dto); + + XML xml = new XML(); + PackDto dto = xml.parse(packXml, new TypeReference() {}); + log.info("dto: {}", dto); + xml.write(System.out, dto, true); + } + + @DisplayName("전자결재 pack xml write 테스트") + @Test + public void packXmlWriteTest() throws IOException { + PackDto dto = getPackDto(); + + JacksonXmlModule module = new JacksonXmlModule(); + module.setDefaultUseWrapper(true); + XmlMapper mapper = new XmlMapper(module); + + XMLOutputFactory factory = mapper.getFactory().getXMLOutputFactory(); + + String dtd = """ + + """; + // FIXME: 파일명 생성 + try (FileOutputStream fos = new FileOutputStream("pack.xml");) { + XML xml = new XML(); + xml.write(fos, dto, true); + fos.flush(); + + }catch (Exception e) { + e.printStackTrace(); + } + } + + private static PackDto getPackDto() { + + PackDto.Header header = PackDto.Header.builder() + .type(PackDto.Type.builder() + .docType("docType") + .build()) + .date("2024-03-14") + .sender("sender") + .receiver("receiver") + .senderUserid("senderUserid") + .receiverUserid("receiverUserid") + .senderEmail("senderEmail") + .senderOrgname("senderOrgname") + .senderSystemname("senderSystemname") + .administrativeNum("administrativeNum") + .build(); + + PackDto.Content content = PackDto.Content.builder() + .contentRole("contentRole") + .contentType("constentType") + .charset("utf8") + .value("content-value") + .build(); + + PackDto packDto = PackDto.builder() + .header(header) + .contents(PackDto.Contents.builder() + .content(List.of(content)) + .build()) + .filename("filename") + .build(); + + + return packDto; + } +} diff --git a/src/test/java/cokr/xit/adds/inf/nims/model/AarDtoTest.java b/src/test/java/cokr/xit/adds/inf/nims/model/AarDtoTest.java index 5893c0d..cb0a244 100644 --- a/src/test/java/cokr/xit/adds/inf/nims/model/AarDtoTest.java +++ b/src/test/java/cokr/xit/adds/inf/nims/model/AarDtoTest.java @@ -1,138 +1,138 @@ -package cokr.xit.adds.inf.nims.model; - -import static org.junit.jupiter.api.Assertions.*; - -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; - -import lombok.extern.slf4j.Slf4j; - -/** - *
- * description :
- *
- * packageName : cokr.xit.adds.inf.nims.model
- * fileName    : AarDtoTest
- * author      : limju
- * date        : 2024-03-26
- * ======================================================================
- * 변경일         변경자        변경 내용
- * ----------------------------------------------------------------------
- * 2024-03-26    limju       최초 생성
- *
- * 
- */ -@Slf4j -@ExtendWith(SpringExtension.class) -public class AarDtoTest { - - @DisplayName("마약류폐기연계 xml read 테스트") - @Test - public void aarXmlReadTest() throws IOException { - String fileName = "/src/test/resources/test_data/123456789AAR20240326120248_0001.XML"; - - JacksonXmlModule jacksonXmlModule = new JacksonXmlModule(); - jacksonXmlModule.setDefaultUseWrapper(false); - XmlMapper xmlMapper = new XmlMapper(jacksonXmlModule); - xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); - - Path cur = Paths.get(""); //현재 디렉토리 정보 '상대 경로' 형태로 담긴 인스턴스 생성 - String cdir; - - if(cur.isAbsolute()) //절대 경로 일 경우. - cdir=cur.toString(); - else - cdir = cur.toAbsolutePath().toString(); - - Path path = Paths.get(cdir, fileName); - Aar dto - = xmlMapper.readValue(Files.readString(path), Aar.class); - - assertNotNull(dto); - - xmlMapper.writeValue(System.out, dto); - } - - @DisplayName("마약류폐기연계 xml write 테스트") - @Test - public void aarXmlWriteTest() throws IOException { - Aar dto = getAar(); - - XmlMapper mapper = new XmlMapper(); - mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); - mapper.enable(SerializationFeature.INDENT_OUTPUT); - - String xmlString = mapper.writeValueAsString(dto); - xmlString = xmlString.replaceFirst("nims\">", "nims\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); - xmlString = xmlString.replaceFirst(" xmlns=\"\"", StringUtils.EMPTY); - System.out.println(xmlString); - - // FIXME: 파일명 생성 - // filename: BSSH_CD + RPT_SE_CD + YYYYMMDDHHMMSS + _ + 0001.XML - try (FileWriter w = new FileWriter("aar_001.xml")) { - w.write(xmlString); - w.flush(); - - } catch (IOException e) { - e.printStackTrace(); - - } - } - - private static Aar getAar() { - Aar.Line line = Aar.Line.builder() - .usrRptIdNo("123456789") - .usrRptLnIdNo("123456789") - .storgeNo("123456789") - .mvmnTyCd("123456789") - .prductCd("123456789") - .build(); - Aar.Line line2 = Aar.Line.builder() - .usrRptIdNo("123456789-1") - .usrRptLnIdNo("123456789-1") - .storgeNo("123456789-1") - .mvmnTyCd("123456789-1") - .prductCd("123456789-1") - .build(); - - Aar.Lines lines = Aar.Lines.builder() - .line(List.of(line, line2)) - .build(); - - Aar.AtchFiles atchFiles = Aar.AtchFiles.builder() - .atchFileNm(List.of("file-1.txt","file-2.txt")) - .build(); - - Aar.Header header = Aar.Header.builder() - .hdrDe("20240326") - .bsshCd("123456789") - .lines(lines) - .atchFileCo("2") - .atchFiles(atchFiles) - .build(); - - Aar.ReportSet reportSet = Aar.ReportSet.builder() - .header(List.of(header)) - .build(); - - Aar dto = Aar.builder() - .reportSet(reportSet) - .build(); - return dto; - } -} +// package cokr.xit.adds.inf.nims.model; +// +// import static org.junit.jupiter.api.Assertions.*; +// +// import java.io.FileWriter; +// import java.io.IOException; +// import java.nio.file.Files; +// import java.nio.file.Path; +// import java.nio.file.Paths; +// import java.util.List; +// +// import org.apache.commons.lang3.StringUtils; +// import org.junit.jupiter.api.DisplayName; +// import org.junit.jupiter.api.Test; +// import org.junit.jupiter.api.extension.ExtendWith; +// import org.springframework.test.context.junit.jupiter.SpringExtension; +// +// import com.fasterxml.jackson.databind.SerializationFeature; +// import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; +// import com.fasterxml.jackson.dataformat.xml.XmlMapper; +// import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; +// +// import lombok.extern.slf4j.Slf4j; +// +// /** +// *
+//  * description :
+//  *
+//  * packageName : cokr.xit.adds.inf.nims.model
+//  * fileName    : AarDtoTest
+//  * author      : limju
+//  * date        : 2024-03-26
+//  * ======================================================================
+//  * 변경일         변경자        변경 내용
+//  * ----------------------------------------------------------------------
+//  * 2024-03-26    limju       최초 생성
+//  *
+//  * 
+// */ +// @Slf4j +// @ExtendWith(SpringExtension.class) +// public class AarDtoTest { +// +// @DisplayName("마약류폐기연계 xml read 테스트") +// @Test +// public void aarXmlReadTest() throws IOException { +// String fileName = "/src/test/resources/test_data/123456789AAR20240326120248_0001.XML"; +// +// JacksonXmlModule jacksonXmlModule = new JacksonXmlModule(); +// jacksonXmlModule.setDefaultUseWrapper(false); +// XmlMapper xmlMapper = new XmlMapper(jacksonXmlModule); +// xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); +// +// Path cur = Paths.get(""); //현재 디렉토리 정보 '상대 경로' 형태로 담긴 인스턴스 생성 +// String cdir; +// +// if(cur.isAbsolute()) //절대 경로 일 경우. +// cdir=cur.toString(); +// else +// cdir = cur.toAbsolutePath().toString(); +// +// Path path = Paths.get(cdir, fileName); +// Aar dto +// = xmlMapper.readValue(Files.readString(path), Aar.class); +// +// assertNotNull(dto); +// +// xmlMapper.writeValue(System.out, dto); +// } +// +// @DisplayName("마약류폐기연계 xml write 테스트") +// @Test +// public void aarXmlWriteTest() throws IOException { +// Aar dto = getAar(); +// +// XmlMapper mapper = new XmlMapper(); +// mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); +// mapper.enable(SerializationFeature.INDENT_OUTPUT); +// +// String xmlString = mapper.writeValueAsString(dto); +// xmlString = xmlString.replaceFirst("nims\">", "nims\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); +// xmlString = xmlString.replaceFirst(" xmlns=\"\"", StringUtils.EMPTY); +// System.out.println(xmlString); +// +// // FIXME: 파일명 생성 +// // filename: BSSH_CD + RPT_SE_CD + YYYYMMDDHHMMSS + _ + 0001.XML +// try (FileWriter w = new FileWriter("aar_001.xml")) { +// w.write(xmlString); +// w.flush(); +// +// } catch (IOException e) { +// e.printStackTrace(); +// +// } +// } +// +// private static Aar getAar() { +// Aar.Line line = Aar.Line.builder() +// .usrRptIdNo("123456789") +// .usrRptLnIdNo("123456789") +// .storgeNo("123456789") +// .mvmnTyCd("123456789") +// .prductCd("123456789") +// .build(); +// Aar.Line line2 = Aar.Line.builder() +// .usrRptIdNo("123456789-1") +// .usrRptLnIdNo("123456789-1") +// .storgeNo("123456789-1") +// .mvmnTyCd("123456789-1") +// .prductCd("123456789-1") +// .build(); +// +// Aar.Lines lines = Aar.Lines.builder() +// .line(List.of(line, line2)) +// .build(); +// +// Aar.AtchFiles atchFiles = Aar.AtchFiles.builder() +// .atchFileNm(List.of("file-1.txt","file-2.txt")) +// .build(); +// +// Aar.Header header = Aar.Header.builder() +// .hdrDe("20240326") +// .bsshCd("123456789") +// .lines(lines) +// .atchFileCo("2") +// .atchFiles(atchFiles) +// .build(); +// +// Aar.ReportSet reportSet = Aar.ReportSet.builder() +// .header(List.of(header)) +// .build(); +// +// Aar dto = Aar.builder() +// .reportSet(reportSet) +// .build(); +// return dto; +// } +// }