Exchangepack, Pack DTO 및 테스트 반영

dev
Jonguk. Lim 6 months ago
parent 6a0c6fa51c
commit 058211770c

@ -3,10 +3,12 @@ package cokr.xit.adds.inf.mois.model;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude; 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.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.XmlValue;
import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@ -34,12 +36,15 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class ExchangepackDto { public class ExchangepackDto {
@XmlElement(required = true) @JacksonXmlProperty(localName = "header")
@JsonProperty(required = true)
protected Header header; protected Header header;
@JacksonXmlProperty(localName = "contents")
protected Contents contents; protected Contents contents;
@XmlAttribute(name = "filename", required = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
@JsonProperty(required = true)
protected String filename; protected String filename;
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
@ -47,33 +52,43 @@ public class ExchangepackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Header { public static class Header {
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Server server; protected Server server;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Sender sender; protected Sender sender;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Receiver receiver; protected Receiver receiver;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String sendersystemname; protected String sendersystemname;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Exchangetype exchangetype; protected Exchangetype exchangetype;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String doctype; protected String doctype;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String date; protected String date;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String administrativenum; protected String administrativenum;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String title; protected String title;
@JacksonXmlProperty
protected Addenda addenda; protected Addenda addenda;
} }
@ -82,10 +97,12 @@ public class ExchangepackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Server { public static class Server {
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String sendserverid; protected String sendserverid;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String receiveserverid; protected String receiveserverid;
} }
@ -94,16 +111,21 @@ public class ExchangepackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Sender { public static class Sender {
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Organ organ; protected Organ organ;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String sendkey; protected String sendkey;
@JacksonXmlProperty
protected String username; protected String username;
@JacksonXmlProperty
protected String userposition; protected String userposition;
@JacksonXmlProperty
protected String email; protected String email;
} }
@ -112,10 +134,12 @@ public class ExchangepackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Organ { public static class Organ {
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Orgname orgname; protected Orgname orgname;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Deptname deptname; protected Deptname deptname;
} }
@ -125,9 +149,11 @@ public class ExchangepackDto {
@Builder @Builder
public static class Orgname { public static class Orgname {
@XmlValue @XmlValue
@JacksonXmlText
protected String value; protected String value;
@XmlAttribute(name = "orgcode", required = true) @JacksonXmlProperty(localName = "orgcode", isAttribute = true)
@JsonProperty(required = true)
protected String orgcode; protected String orgcode;
} }
@ -137,9 +163,11 @@ public class ExchangepackDto {
@Builder @Builder
public static class Deptname { public static class Deptname {
@XmlValue @XmlValue
@JacksonXmlText
protected String value; protected String value;
@XmlAttribute(name = "deptcode", required = true) @JacksonXmlProperty(localName = "deptcode", isAttribute = true)
@JsonProperty(required = true)
protected String deptcode; protected String deptcode;
} }
@ -148,16 +176,21 @@ public class ExchangepackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Receiver { public static class Receiver {
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Organ organ; protected Organ organ;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String recvkey; protected String recvkey;
@JacksonXmlProperty
protected String username; protected String username;
@JacksonXmlProperty
protected String userposition; protected String userposition;
@JacksonXmlProperty
protected String email; protected String email;
} }
@ -166,9 +199,11 @@ public class ExchangepackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Exchangetype { public static class Exchangetype {
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String maintype; protected String maintype;
@JacksonXmlProperty
protected String subtype; protected String subtype;
} }
@ -177,6 +212,8 @@ public class ExchangepackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Addenda { public static class Addenda {
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "addendum")
protected List<Addendum> addendum; protected List<Addendum> addendum;
} }
@ -186,12 +223,15 @@ public class ExchangepackDto {
@Builder @Builder
public static class Addendum { public static class Addendum {
@XmlValue @XmlValue
@JacksonXmlText
protected String value; protected String value;
@XmlAttribute(name = "Name", required = true) @JacksonXmlProperty(localName = "Name", isAttribute = true)
@JsonProperty(required = true)
protected String name; protected String name;
@XmlAttribute(name = "comment", required = true) @JacksonXmlProperty(localName = "comment", isAttribute = true)
@JsonProperty(required = true)
protected String comment; protected String comment;
} }
@ -200,6 +240,8 @@ public class ExchangepackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Contents { public static class Contents {
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "content")
protected List<Content> content; protected List<Content> content;
} }
@ -209,29 +251,32 @@ public class ExchangepackDto {
@Builder @Builder
public static class Content { public static class Content {
@XmlValue @XmlValue
@JacksonXmlText
protected String value; protected String value;
@XmlAttribute(name = "content-role", required = true) @JacksonXmlProperty(localName = "content-role", isAttribute = true)
@JsonProperty(required = true)
protected String contentRole; protected String contentRole;
@XmlAttribute(name = "sub-role") @JacksonXmlProperty(localName = "sub-role", isAttribute = true)
@Builder.Default @Builder.Default
protected String subRole = "content"; protected String subRole = "content";
@XmlAttribute(name = "content-transfer-encoding") @JacksonXmlProperty(localName = "content-transfer-encoding", isAttribute = true)
@Builder.Default @Builder.Default
protected String contentTransferEncoding = "base64"; protected String contentTransferEncoding = "base64";
@XmlAttribute(name = "filename", required = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
@JsonProperty(required = true)
protected String filename; protected String filename;
@XmlAttribute(name = "content-type") @JacksonXmlProperty(localName = "content-type", isAttribute = true)
protected String contentType; protected String contentType;
@XmlAttribute(name = "charset") @JacksonXmlProperty(localName = "charset", isAttribute = true)
protected String charset; protected String charset;
@XmlAttribute(name = "attachorder") @JacksonXmlProperty(localName = "attachorder", isAttribute = true)
protected String attachorder; protected String attachorder;
/** /**
@ -240,7 +285,7 @@ public class ExchangepackDto {
* modifiable | modified | non * modifiable | modified | non
* </pre> * </pre>
*/ */
@XmlAttribute(name = "modify") @JacksonXmlProperty(localName = "modify", isAttribute = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@Builder.Default @Builder.Default
protected String modify = "non"; protected String modify = "non";

@ -4,10 +4,12 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude; 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.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.XmlValue;
import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@ -35,13 +37,16 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public class PackDto { public class PackDto {
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Header header; protected Header header;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Contents contents; protected Contents contents;
@XmlAttribute(name = "filename", required = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
@JsonProperty(required = true)
protected String filename; protected String filename;
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
@ -49,34 +54,43 @@ public class PackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Header { public static class Header {
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected Type type; protected Type type;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String date; protected String date;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String sender; protected String sender;
@XmlElement(required = true) @JacksonXmlProperty
@JsonProperty(required = true)
protected String receiver; protected String receiver;
@XmlElement(name = "sender_userid", required = true) @JacksonXmlProperty(localName = "sender_userid")
@JsonProperty(required = true)
protected String senderUserid; protected String senderUserid;
@XmlElement(name = "receiver_userid", required = true) @JacksonXmlProperty(localName = "receiver_userid")
@JsonProperty(required = true)
protected String receiverUserid; protected String receiverUserid;
@XmlElement(name = "sender_email") @JacksonXmlProperty(localName = "sender_email")
protected String senderEmail; protected String senderEmail;
@XmlElement(name = "sender_orgname", required = true) @JacksonXmlProperty(localName = "sender_orgname")
@JsonProperty(required = true)
protected String senderOrgname; protected String senderOrgname;
@XmlElement(name = "sender_systemname", required = true) @JacksonXmlProperty(localName = "sender_systemname")
@JsonProperty(required = true)
protected String senderSystemname; protected String senderSystemname;
@XmlElement(name = "administrative_num", required = true) @JacksonXmlProperty(localName = "administrative_num")
@JsonProperty(required = true)
protected String administrativeNum; protected String administrativeNum;
} }
@ -91,7 +105,8 @@ public class PackDto {
* send|fail|arrive|receive|invalid|submit|return|approval * send|fail|arrive|receive|invalid|submit|return|approval
*</pre> *</pre>
*/ */
@XmlAttribute(name = "doc-type", required = true) @JacksonXmlProperty(localName = "doc-type", isAttribute = true)
@JsonProperty(required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class) @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
protected String docType; protected String docType;
} }
@ -101,6 +116,8 @@ public class PackDto {
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
public static class Contents { public static class Contents {
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "content")
protected List<Content> content; protected List<Content> content;
public List<Content> getContent() { public List<Content> getContent() {
@ -117,21 +134,24 @@ public class PackDto {
@Builder @Builder
public static class Content { public static class Content {
@XmlValue @XmlValue
@JacksonXmlText
protected String value; protected String value;
@XmlAttribute(name = "content-role", required = true) @JacksonXmlProperty(localName = "content-role", isAttribute = true)
@JsonProperty(required = true)
protected String contentRole; protected String contentRole;
@XmlAttribute(name = "content-transfer-encoding") @JacksonXmlProperty(localName = "content-transfer-encoding", isAttribute = true)
protected String contentTransferEncoding = "base64"; protected String contentTransferEncoding = "base64";
@XmlAttribute(name = "filename", required = true) @JacksonXmlProperty(localName = "filename", isAttribute = true)
@JsonProperty(required = true)
protected String filename; protected String filename;
@XmlAttribute(name = "content-type") @JacksonXmlProperty(localName = "content-type", isAttribute = true)
protected String contentType; protected String contentType;
@XmlAttribute(name = "charset") @JacksonXmlProperty(localName = "charset", isAttribute = true)
protected String charset; protected String charset;
} }
} }

@ -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;
/**
* <pre>
* description :
*
* packageName : cokr.xit.adds.inf.mois.model
* fileName : ExchangeDtoTest
* author : limju
* date : 2024-03-14
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024-03-14 limju
*
* </pre>
*/
@Slf4j
@ExtendWith(SpringExtension.class)
public class ExchangepackDtoTest {
String exchangeXml = """
<?xml version='1.1' encoding='UTF-8'?>
<exchangepack filename="filename">
<header>
<server>
<sendserverid>ADM131000040</sendserverid>
<receiveserverid>hongkildong</receiveserverid>
</server>
<sender>
<organ>
<orgname orgcode="hongkildong">orgname-value</orgname>
<deptname deptcode="deptcode">deptname-value</deptname>
</organ>
<sendkey>sendkey</sendkey>
<username>username</username>
</sender>
<receiver>
<organ>
<orgname orgcode="hongkildong">orgname-value</orgname>
<deptname deptcode="deptcode">deptname-value</deptname>
</organ>
</receiver>
<sendersystemname>sendersystemname</sendersystemname>
<doctype>doctype</doctype>
<date>date</date>
<administrativenum>administrativenum</administrativenum>
<title>title</title>
</header>
<contents>
<content content-role="contentRole" sub-role="content" content-transfer-encoding="base64" content-type="constentType" charset="utf8" modify="modified">content-value</content>
</contents>
</exchangepack>
""";
@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<ExchangepackDto>() {});
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 = """
<!DOCTYPE EXCHANGE SYSTEM "exchange.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;
}
}

@ -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;
/**
* <pre>
* description :
*
* packageName : cokr.xit.adds.inf.mois.model
* fileName : ExchangeDtoTest
* author : limju
* date : 2024-03-14
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024-03-14 limju
*
* </pre>
*/
@Slf4j
@ExtendWith(SpringExtension.class)
public class PackDtoTest {
String packXml = """
<?xml version='1.1' encoding='UTF-8'?>
<pack filename="filename">
<header>
<type doc-type="docType"/>
<date>2024-03-14</date>
<sender>sender</sender>
<receiver>receiver</receiver>
<sender_userid>senderUserid</sender_userid>
<receiver_userid>receiverUserid</receiver_userid>
<sender_email>senderEmail</sender_email>
<sender_orgname>senderOrgname</sender_orgname>
<sender_systemname>senderSystemname</sender_systemname>
<administrative_num>administrativeNum</administrative_num>
</header>
<contents>
<content content-role="contentRole" content-type="constentType" charset="utf8">content-value</content>
</contents>
</pack>
""";
@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<PackDto>() {});
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 = """
<!DOCTYPE EXCHANGE SYSTEM "exchange.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;
}
}

@ -1,138 +1,138 @@
package cokr.xit.adds.inf.nims.model; // package cokr.xit.adds.inf.nims.model;
//
import static org.junit.jupiter.api.Assertions.*; // import static org.junit.jupiter.api.Assertions.*;
//
import java.io.FileWriter; // import java.io.FileWriter;
import java.io.IOException; // import java.io.IOException;
import java.nio.file.Files; // import java.nio.file.Files;
import java.nio.file.Path; // import java.nio.file.Path;
import java.nio.file.Paths; // import java.nio.file.Paths;
import java.util.List; // import java.util.List;
//
import org.apache.commons.lang3.StringUtils; // import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.DisplayName; // import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; // import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; // import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension; // import org.springframework.test.context.junit.jupiter.SpringExtension;
//
import com.fasterxml.jackson.databind.SerializationFeature; // import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; // import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper; // import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; // import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
//
import lombok.extern.slf4j.Slf4j; // import lombok.extern.slf4j.Slf4j;
//
/** // /**
* <pre> // * <pre>
* description : // * description :
* // *
* packageName : cokr.xit.adds.inf.nims.model // * packageName : cokr.xit.adds.inf.nims.model
* fileName : AarDtoTest // * fileName : AarDtoTest
* author : limju // * author : limju
* date : 2024-03-26 // * date : 2024-03-26
* ====================================================================== // * ======================================================================
* // * 변경일 변경자 변경 내용
* ---------------------------------------------------------------------- // * ----------------------------------------------------------------------
* 2024-03-26 limju // * 2024-03-26 limju 최초 생성
* // *
* </pre> // * </pre>
*/ // */
@Slf4j // @Slf4j
@ExtendWith(SpringExtension.class) // @ExtendWith(SpringExtension.class)
public class AarDtoTest { // public class AarDtoTest {
//
@DisplayName("마약류폐기연계 xml read 테스트") // @DisplayName("마약류폐기연계 xml read 테스트")
@Test // @Test
public void aarXmlReadTest() throws IOException { // public void aarXmlReadTest() throws IOException {
String fileName = "/src/test/resources/test_data/123456789AAR20240326120248_0001.XML"; // String fileName = "/src/test/resources/test_data/123456789AAR20240326120248_0001.XML";
//
JacksonXmlModule jacksonXmlModule = new JacksonXmlModule(); // JacksonXmlModule jacksonXmlModule = new JacksonXmlModule();
jacksonXmlModule.setDefaultUseWrapper(false); // jacksonXmlModule.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(jacksonXmlModule); // XmlMapper xmlMapper = new XmlMapper(jacksonXmlModule);
xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); // xmlMapper.enable(SerializationFeature.INDENT_OUTPUT);
//
Path cur = Paths.get(""); //현재 디렉토리 정보 '상대 경로' 형태로 담긴 인스턴스 생성 // Path cur = Paths.get(""); //현재 디렉토리 정보 '상대 경로' 형태로 담긴 인스턴스 생성
String cdir; // String cdir;
//
if(cur.isAbsolute()) //절대 경로 일 경우. // if(cur.isAbsolute()) //절대 경로 일 경우.
cdir=cur.toString(); // cdir=cur.toString();
else // else
cdir = cur.toAbsolutePath().toString(); // cdir = cur.toAbsolutePath().toString();
//
Path path = Paths.get(cdir, fileName); // Path path = Paths.get(cdir, fileName);
Aar dto // Aar dto
= xmlMapper.readValue(Files.readString(path), Aar.class); // = xmlMapper.readValue(Files.readString(path), Aar.class);
//
assertNotNull(dto); // assertNotNull(dto);
//
xmlMapper.writeValue(System.out, dto); // xmlMapper.writeValue(System.out, dto);
} // }
//
@DisplayName("마약류폐기연계 xml write 테스트") // @DisplayName("마약류폐기연계 xml write 테스트")
@Test // @Test
public void aarXmlWriteTest() throws IOException { // public void aarXmlWriteTest() throws IOException {
Aar dto = getAar(); // Aar dto = getAar();
//
XmlMapper mapper = new XmlMapper(); // XmlMapper mapper = new XmlMapper();
mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); // mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
mapper.enable(SerializationFeature.INDENT_OUTPUT); // mapper.enable(SerializationFeature.INDENT_OUTPUT);
//
String xmlString = mapper.writeValueAsString(dto); // String xmlString = mapper.writeValueAsString(dto);
xmlString = xmlString.replaceFirst("nims\">", "nims\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); // xmlString = xmlString.replaceFirst("nims\">", "nims\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
xmlString = xmlString.replaceFirst(" xmlns=\"\"", StringUtils.EMPTY); // xmlString = xmlString.replaceFirst(" xmlns=\"\"", StringUtils.EMPTY);
System.out.println(xmlString); // System.out.println(xmlString);
//
// FIXME: 파일명 생성 // // FIXME: 파일명 생성
// filename: BSSH_CD + RPT_SE_CD + YYYYMMDDHHMMSS + _ + 0001.XML // // filename: BSSH_CD + RPT_SE_CD + YYYYMMDDHHMMSS + _ + 0001.XML
try (FileWriter w = new FileWriter("aar_001.xml")) { // try (FileWriter w = new FileWriter("aar_001.xml")) {
w.write(xmlString); // w.write(xmlString);
w.flush(); // w.flush();
//
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
//
} // }
} // }
//
private static Aar getAar() { // private static Aar getAar() {
Aar.Line line = Aar.Line.builder() // Aar.Line line = Aar.Line.builder()
.usrRptIdNo("123456789") // .usrRptIdNo("123456789")
.usrRptLnIdNo("123456789") // .usrRptLnIdNo("123456789")
.storgeNo("123456789") // .storgeNo("123456789")
.mvmnTyCd("123456789") // .mvmnTyCd("123456789")
.prductCd("123456789") // .prductCd("123456789")
.build(); // .build();
Aar.Line line2 = Aar.Line.builder() // Aar.Line line2 = Aar.Line.builder()
.usrRptIdNo("123456789-1") // .usrRptIdNo("123456789-1")
.usrRptLnIdNo("123456789-1") // .usrRptLnIdNo("123456789-1")
.storgeNo("123456789-1") // .storgeNo("123456789-1")
.mvmnTyCd("123456789-1") // .mvmnTyCd("123456789-1")
.prductCd("123456789-1") // .prductCd("123456789-1")
.build(); // .build();
//
Aar.Lines lines = Aar.Lines.builder() // Aar.Lines lines = Aar.Lines.builder()
.line(List.of(line, line2)) // .line(List.of(line, line2))
.build(); // .build();
//
Aar.AtchFiles atchFiles = Aar.AtchFiles.builder() // Aar.AtchFiles atchFiles = Aar.AtchFiles.builder()
.atchFileNm(List.of("file-1.txt","file-2.txt")) // .atchFileNm(List.of("file-1.txt","file-2.txt"))
.build(); // .build();
//
Aar.Header header = Aar.Header.builder() // Aar.Header header = Aar.Header.builder()
.hdrDe("20240326") // .hdrDe("20240326")
.bsshCd("123456789") // .bsshCd("123456789")
.lines(lines) // .lines(lines)
.atchFileCo("2") // .atchFileCo("2")
.atchFiles(atchFiles) // .atchFiles(atchFiles)
.build(); // .build();
//
Aar.ReportSet reportSet = Aar.ReportSet.builder() // Aar.ReportSet reportSet = Aar.ReportSet.builder()
.header(List.of(header)) // .header(List.of(header))
.build(); // .build();
//
Aar dto = Aar.builder() // Aar dto = Aar.builder()
.reportSet(reportSet) // .reportSet(reportSet)
.build(); // .build();
return dto; // return dto;
} // }
} // }

Loading…
Cancel
Save