Produced by Araxis Merge on 3/8/2018 10:14:54 AM Eastern Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | PRE_PPS-N_v3.0.1.zip\PS_PPS_srv\src\test\java\gov\va\med\pharmacy\peps\external\common\utility\test | TransferFileIT.java | Fri Jan 12 15:43:38 2018 UTC |
2 | PRE_PPS-N_v3.0.1.zip\PS_PPS_srv\src\test\java\gov\va\med\pharmacy\peps\external\common\utility\test | TransferFileIT.java | Wed Mar 7 18:58:03 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 406 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | package go v.va.med.p harmacy.pe ps.externa l.common.u tility.tes t; | |
2 | ||
3 | import sta tic org.ha mcrest.Cor eMatchers. equalTo; | |
4 | import sta tic org.ju nit.Assert .assertTha t; | |
5 | ||
6 | import jav a.io.File; | |
7 | ||
8 | import org .apache.co mmons.io.F ileUtils; | |
9 | import org .apache.co mmons.vfs2 .FileObjec t; | |
10 | import org .apache.co mmons.vfs2 .FileSyste mException ; | |
11 | import org .apache.co mmons.vfs2 .impl.Stan dardFileSy stemManage r; | |
12 | import org .apache.lo gging.log4 j.LogManag er; | |
13 | import org .apache.lo gging.log4 j.Logger; | |
14 | import org .junit.Tes t; | |
15 | ||
16 | import gov .va.med.ph armacy.pep s.service. common.uti lity.FileI nfo; | |
17 | import gov .va.med.ph armacy.pep s.service. common.uti lity.Trans ferFile; | |
18 | import jun it.framewo rk.TestCas e; | |
19 | /** | |
20 | * The Cla ss Transfe rFileIT. | |
21 | */ | |
22 | public cla ss Transfe rFileIT ex tends Test Case { | |
23 | ||
24 | /** Th e Constant LOG. */ | |
25 | privat e static f inal Logge r LOG = Lo gManager.g etLogger(T ransferFil eIT.class) ; | |
26 | ||
27 | /** | |
28 | * Tes t local fi le to remo te file tr ansfer and also getS izeFor. | |
29 | * @th rows Excep tion | |
30 | */ | |
31 | @Test | |
32 | public final voi d testLoca lToRemote( ) throws E xception { | |
33 | Fi le tempFil e = null; | |
34 | Fi leInfo fil eInfo = nu ll; | |
35 | tr y{ | |
36 | tempFile = File.crea teTempFile ("LocalToR emote", ". txt"); | |
37 | String ran domText = "Some text here"; | |
38 | FileUtils. writeStrin gToFile(te mpFile, ra ndomText); | |
39 | ||
40 | fileInfo = createFil eInfo(temp File.getNa me(), "pen ding"); | |
41 | ||
42 | String inp utFileDire ctory = te mpFile.get ParentFile ().getAbso lutePath() + File.se parator; | |
43 | ||
44 | boolean fi leTransmit ted = Tran sferFile.m oveTo(inpu tFileDirec tory, file Info); | |
45 | assertThat (TransferF ile.getSiz eFor(fileI nfo), equa lTo(String .valueOf(r andomText. length())) ); | |
46 | LOG.info(f ileTransmi tted); | |
47 | assertTrue (fileTrans mitted); | |
48 | } | |
49 | fi nally{ | |
50 | // cleanup test file s | |
51 | try{ | |
52 | if (temp File!= nul l){ | |
53 | tempFi le.delete( ); | |
54 | } | |
55 | } | |
56 | finally{ | |
57 | deleteRe moteTestFi le(fileInf o); | |
58 | } | |
59 | } | |
60 | } | |
61 | ||
62 | /** | |
63 | * Tes t local fi le to remo te file tr ansfer and also getS izeFor. | |
64 | * @th rows Excep tion | |
65 | */ | |
66 | @Test | |
67 | public final voi d testLoca lToRemoteW henLocalDo esNotExist () throws Exception { | |
68 | Fi le tempFil e = null; | |
69 | Fi leInfo fil eInfo = nu ll; | |
70 | tr y{ | |
71 | tempFile = File.crea teTempFile ("LocalToR emote", ". txt"); | |
72 | String ran domText = "Some text here"; | |
73 | FileUtils. writeStrin gToFile(te mpFile, ra ndomText); | |
74 | ||
75 | fileInfo = createFil eInfo(temp File.getNa me(), "pen ding"); | |
76 | ||
77 | String inp utFileDire ctory = te mpFile.get ParentFile ().getAbso lutePath() + "/inval idgarbage" ; | |
78 | ||
79 | boolean fi leTransmit ted = Tran sferFile.m oveTo(inpu tFileDirec tory, file Info); | |
80 | assertFals e(fileTran smitted); | |
81 | } | |
82 | fi nally{ | |
83 | // cleanup test file s | |
84 | try{ | |
85 | if (temp File!= nul l){ | |
86 | tempFi le.delete( ); | |
87 | } | |
88 | } | |
89 | finally{ | |
90 | deleteRe moteTestFi le(fileInf o); | |
91 | } | |
92 | } | |
93 | } | |
94 | ||
95 | /** | |
96 | * Tes t remote f ile to rem ote file t ransfer. | |
97 | * @th rows Excep tion | |
98 | */ | |
99 | @Test | |
100 | public final voi d testRemo teToRemote () throws Exception { | |
101 | St ring fileN ame = "Rem oteToRemot e.txt"; | |
102 | Fi leInfo fil eInfoPendi ng = creat eFileInfo( fileName, "pending") ; | |
103 | // create th e initial file to be used duri ng the mov e | |
104 | Fi leObject t estFile = createRemo teTestFile (fileInfoP ending); | |
105 | LO G.info(tes tFile.getN ame()); | |
106 | Fi leInfo fil eInfoAppro ved = crea teFileInfo (fileName, "approved "); | |
107 | ||
108 | bo olean file Transmitte d = Transf erFile.mov eTo(fileIn foPending, fileInfoA pproved); | |
109 | ||
110 | // cleanup t est file | |
111 | de leteRemote TestFile(f ileInfoApp roved); | |
112 | as sertTrue(f ileTransmi tted); | |
113 | } | |
114 | ||
115 | /** | |
116 | * Cre ates a Fil eInfo obje ct when gi ven fileNa me and fol der of the file. | |
117 | * | |
118 | * @pa ram fileNa me | |
119 | * th e file nam e | |
120 | * @pa ram folder | |
121 | * th e folder | |
122 | * @re turn the f ile info | |
123 | * @th rows Excep tion if th e password is not en tered for the SFTP s erver | |
124 | */ | |
125 | privat e FileInfo createFil eInfo(Stri ng fileNam e, String folder) th rows Excep tion { | |
126 | Fi leInfo fil eInfo = ne w FileInfo (); | |
127 | ||
128 | fileInfo.s etHostName (" DNS URL ");//FQDN | |
129 | fi leInfo.set Port("22") ; | |
130 | fi leInfo.set UserName(" presftp"); //usernam e | |
131 | fi leInfo.set Authorizat ion("Im@g! N3"); //fi ll in pwd here | |
132 | if (fileInfo .getAuthor ization(). equals("") ){ | |
133 | throw new Exception( "You must fill in th e SFTP ser ver passwo rd in crea teFileInfo (). See th e Develope r KEEPASS file."); | |
134 | } | |
135 | ||
136 | fi leInfo.set DirectoryP ath("/home /presftp/p ps-n/dev/l ocalhost/" + folder + "/"); // an existin g folder f or the tes t | |
137 | fi leInfo.set FileName(f ileName); | |
138 | ||
139 | re turn fileI nfo; | |
140 | } | |
141 | ||
142 | /** | |
143 | * Cre ates the r emote test file. | |
144 | * | |
145 | * @pa ram fileIn fo | |
146 | * th e file inf o | |
147 | * @re turn the f ile object | |
148 | */ | |
149 | public final Fil eObject cr eateRemote TestFile(F ileInfo fi leInfo) { | |
150 | ||
151 | St andardFile SystemMana ger remote Fsm = new StandardFi leSystemMa nager(); | |
152 | Fi leObject r emoteFile = null; | |
153 | tr y { | |
154 | ||
155 | remoteFs m.init(); | |
156 | if (file Info != nu ll) { | |
157 | remo teFile = r emoteFsm.r esolveFile (fileInfo. getEncoded FilePath() , Transfer File.creat eFileSyste mOptions() ); | |
158 | remo teFile.cre ateFile(); | |
159 | } | |
160 | ||
161 | } catch (Fil eSystemExc eption e) { | |
162 | LOG.erro r("Excepti on creatin g test fil e", e); | |
163 | ||
164 | } finally { | |
165 | if (remo teFsm != n ull) { | |
166 | remo teFsm.clos e(); | |
167 | } | |
168 | } | |
169 | re turn remot eFile; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Del ete remote test file for clean up of test s. | |
174 | * | |
175 | * @pa ram fileIn fo | |
176 | * th e file inf o | |
177 | * @re turn the f ile object | |
178 | */ | |
179 | public final Fil eObject de leteRemote TestFile(F ileInfo fi leInfo) { | |
180 | ||
181 | St andardFile SystemMana ger remote Fsm = new StandardFi leSystemMa nager(); | |
182 | Fi leObject r emoteFile = null; | |
183 | tr y { | |
184 | ||
185 | remoteFs m.init(); | |
186 | if (file Info != nu ll) { | |
187 | remo teFile = | |
188 | remote Fsm.resolv eFile(file Info.getEn codedURIDi rectory() + File.sep arator + f ileInfo.ge tFileName( ), | |
189 | Transfer File.creat eFileSyste mOptions() ); | |
190 | remo teFile.del ete(); | |
191 | } | |
192 | ||
193 | } catch (Fil eSystemExc eption e) { | |
194 | LOG.erro r("Excepti on deletin g remote t est file " ); | |
195 | ||
196 | } finally { | |
197 | if (remo teFsm != n ull) { | |
198 | remo teFsm.clos e(); | |
199 | } | |
200 | } | |
201 | re turn remot eFile; | |
202 | } | |
203 | ||
204 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.