Reputation: 1002
I am working with two components, say A and B. Java development takes place in component B. I managed to modify the relevant Java code, generated JAR using Maven, and deployed it to the run-time instance. All is good.
Component A will invoke classes and methods in B. One method, named say, processNode()
in B takes the input of type org.w3c.dom.Node
. The input is generated in the run-time instance in A. For example, the code in A will invoke the code in B as follows:
... This is the code of A
... display form
... accept input
... convert the input to an object of type org.w3c.dom.Node
... org.w3c.dom.Node inp = ....
B.Solution sol = new B.Solution();
sol.processNode(inp);
...
...
My objective is to build a unit test and hard-code the value of the variable inp
in the unit test to make the development cycle more efficient. This will help me avoid the cycle to code, build, copy the jar to the instance, restart the instance, start the application, provide the input, and check the log ... it is too long.
If I can somehow intercept the value of the input inp
in component B and save it in text format for example, then I can hard-code it in the unit test, and convert it to the type org.w3c.dom.Node
before invoking B.solution.processNode()
I can see the value of inp
in the logs generated by the component A
as follows:
<?xml version="1.0" encoding="UTF-8"?>
<TskDta>
<fileNamePath>\path\to\file\filename.json</fileNamePath>
<fileData>{
"TranNumber": 12345,
"PropNumber": 12345,
"DateSigned": "2020-04-28T16:31:51.8937987Z",
"ValuatType": "002",
"BondAmt": 150000.0,
"TtlDNumber": "B2005-rexsd",
"PolNumber": "Policy123",
"MandOffName": "ManOffName123",
"AuthSigName": "Sig123",
"ConveName": "John123",
"CollatId": "Col351",
"AccNumber": "LoanAccontNumber123",
"Curr": " CurrencyType",
"TypOBond": "BondType",
"ProcGrp": "ProcessingGroup23",
"DeeOff": "6",
"BchUnt": "BrhUnit123"
}</fileData>
<archAlw>Y</archAlw>
<ArchFPath>path\to\arch\folder</ArchFPath>
<archiveFilePrefix>CollatLink</archiveFilePrefix>
<maxRet>3</maxRet>
<retryInter>2</retryInter>
<IBSerH>host.name.com</IBSerH>
<IBSerUName>UName</IBSerUName>
<IBSerP>asdcfre345</IBSerP>
<SSLOk>Y</SSLOk>
<httpConnectTimeout>1000</httpConnectTimeout>
<httpReadTimeout>2000</httpReadTimeout>
<endPointBaseURL>https://end.point.host</endPointBaseURL>
<authPartURL>/auht/part/url</authPartURL>
<busFuncPart>/func/part/url</busFuncPart>
<id_client>asdqwe</id_client>
<sec_client>dfsdfsdf</sec_client>
<grtype>cl_cred</grtype>
<scope>adasd</scope>
</TskDta>
I am guessing that I can convert the above XML into an object of type org.w3c.dom.Node
which I will base my research on.
I am checking if there is a better way, possibly serializing the variable inp
in B and saving it, hard-code the value in the unit test, and then deserializing it to convert it back to the original object type while running the unit test classes.
Is that possible?
Upvotes: 0
Views: 92
Reputation: 1
I guess you want to convert xml and entity classes to each other.
I see that your inp content contains json format. I can convert json files and entity classes to each other, which may help you.
Here is my code.
// Serialize the inp object into a json file
File save = new File("D:\\test0.json");
ObjectMapper mapper = new ObjectMapper();
Inp inp= new Inp();
inp.setName("sssss");
mapper.writeValue(save, sketch);
// Deserialize the json file into an inp object
Reader reader = new FileReader(save);
Inp inp1 = mapper.readValue(reader, Inp.class);
System.out.println(inp1);
Upvotes: 0