77import org .jfrog .artifactory .client .model .LocalRepository ;
88import org .testng .annotations .Test ;
99
10+ import java .io .IOException ;
1011import java .io .InputStream ;
1112import java .util .HashMap ;
1213import java .util .List ;
@@ -127,41 +128,55 @@ public void testSetItemPropertiesOnNonExistingDirectory() throws Exception {
127128 //this test move content of directory "x" to another repo into directory "abc", than both repo's will be removed after finish
128129 @ Test
129130 public void testMoveDirectory () throws Exception {
130- prepareRepositoriesForMovingAndCoping ();
131- ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_FROM ).folder ("x" );
132- ItemHandle newItemHandle = itemHandle .move (NEW_LOCAL_TO , "abc" );
133- checkTheEqualityOfFolders (newItemHandle );
134- deleteAllRelatedRepos ();
131+ try {
132+ prepareRepositoriesForMovingAndCoping ();
133+ ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_FROM ).folder ("x" );
134+ String path = "abc" ;
135+ checkTheEqualityOfFolders (itemHandle .move (NEW_LOCAL_TO , path ), NEW_LOCAL_TO , path );
136+ } finally {
137+ deleteAllRelatedRepos ();
138+ }
135139 }
136140
137141 //this test copy content of directory "x" to another repo into directory "abc", than both repo's will be removed after finish
138142 @ Test
139143 public void testCopyDirectory () throws Exception {
140- prepareRepositoriesForMovingAndCoping ();
141- ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_FROM ).folder ("x" );
142- ItemHandle newItemHandle = itemHandle .copy (NEW_LOCAL_TO , "abc" );
143- checkTheEqualityOfFolders (newItemHandle );
144- deleteAllRelatedRepos ();
144+ try {
145+ prepareRepositoriesForMovingAndCoping ();
146+ ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_FROM ).folder ("x" );
147+ String path = "abc" ;
148+ checkTheEqualityOfFolders (itemHandle .copy (NEW_LOCAL_TO , path ), NEW_LOCAL_TO , path );
149+ } finally {
150+ deleteAllRelatedRepos ();
151+ }
145152 }
146153
147154 //this test move file "z" to the root of another repo, than both repo's will be removed after finish
148155 @ Test
149156 public void testMoveFile () throws Exception {
150- prepareRepositoriesForMovingAndCoping ();
151- ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_FROM ).file ("x/y/z" );
152- ItemHandle newItemHandle = itemHandle .move (NEW_LOCAL_TO , "x/y/z" );
153- checkTheEqualityOfFiles (newItemHandle );
154- deleteAllRelatedRepos ();
157+ try {
158+ prepareRepositoriesForMovingAndCoping ();
159+ String path = "x/y/z" ;
160+ ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_FROM ).file (path );
161+ ItemHandle newItemHandle = itemHandle .move (NEW_LOCAL_TO , path );
162+ checkTheEqualityOfFiles (newItemHandle , NEW_LOCAL_TO , path );
163+ } finally {
164+ deleteAllRelatedRepos ();
165+ }
155166 }
156167
157168 //this test copy file "z" to the root of another repo, than both repo's will be removed after finish
158169 @ Test
159170 public void testCopyFile () throws Exception {
160- prepareRepositoriesForMovingAndCoping ();
161- ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_FROM ).file ("x/y/z" );
162- ItemHandle newItemHandle = itemHandle .copy (NEW_LOCAL_TO , "x/y/z" );
163- checkTheEqualityOfFiles (newItemHandle );
164- deleteAllRelatedRepos ();
171+ try {
172+ prepareRepositoriesForMovingAndCoping ();
173+ String path = "x/y/z" ;
174+ ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_FROM ).file (path );
175+ ItemHandle newItemHandle = itemHandle .copy (NEW_LOCAL_TO , path );
176+ checkTheEqualityOfFiles (newItemHandle , NEW_LOCAL_TO , path );
177+ } finally {
178+ deleteAllRelatedRepos ();
179+ }
165180 }
166181
167182 @ Test
@@ -171,9 +186,10 @@ public void testExceptionOnMovingFile() throws Exception {
171186 try {
172187 itemHandle .move (NEW_LOCAL_TO , "x/y/z" );
173188 } catch (CopyMoveException e ) {
174- assertEquals (curl ("api/move/" + NEW_LOCAL_FROM + "/a/a?to=x/y/z" , "POST" ).contains (e .getCopyMoveResultReport ().getMessages ().get (0 ).getMessage ()), true );
189+ assertTrue (curl ("api/move/" + NEW_LOCAL_FROM + "/a/a?to=x/y/z" , "POST" ).contains (e .getCopyMoveResultReport ().getMessages ().get (0 ).getMessage ()));
190+ } finally {
191+ deleteAllRelatedRepos ();
175192 }
176- deleteAllRelatedRepos ();
177193 }
178194
179195 @ Test
@@ -183,23 +199,24 @@ public void testExceptionOnCopingFile() throws Exception {
183199 try {
184200 itemHandle .copy (NEW_LOCAL_TO , "x/y/z" );
185201 } catch (CopyMoveException e ) {
186- assertEquals (curl ("api/copy/" + NEW_LOCAL_FROM + "/a/a?to=x/y/z" , "POST" ).contains (e .getCopyMoveResultReport ().getMessages ().get (0 ).getMessage ()), true );
202+ assertTrue (curl ("api/copy/" + NEW_LOCAL_FROM + "/a/a?to=x/y/z" , "POST" ).contains (e .getCopyMoveResultReport ().getMessages ().get (0 ).getMessage ()));
203+ } finally {
204+ deleteAllRelatedRepos ();
187205 }
188- deleteAllRelatedRepos ();
189206 }
190207
191- private void checkTheEqualityOfFolders (ItemHandle newItemHandle ) {
192- ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_TO ).folder ("abc" );
193- assertEquals (itemHandle .info (). equals (newItemHandle .info ()), true );
208+ private void checkTheEqualityOfFolders (ItemHandle newItemHandle , String expectedRepo , String expectedPath ) {
209+ ItemHandle itemHandle = artifactory .repository (expectedRepo ).folder (expectedPath );
210+ assertEquals (itemHandle .info (), (newItemHandle .info ()));
194211 }
195212
196- private void checkTheEqualityOfFiles (ItemHandle newItemHandle ) {
197- ItemHandle itemHandle = artifactory .repository (NEW_LOCAL_TO ).file ("x/y/z" );
198- assertEquals (itemHandle .info (). equals (newItemHandle .info ()), true );
213+ private void checkTheEqualityOfFiles (ItemHandle newItemHandle , String expectedRepo , String expectedPath ) {
214+ ItemHandle itemHandle = artifactory .repository (expectedRepo ).file (expectedPath );
215+ assertEquals (itemHandle .info (), (newItemHandle .info ()));
199216 }
200217
201218
202- private void prepareRepositoriesForMovingAndCoping () {
219+ private void prepareRepositoriesForMovingAndCoping () throws IOException {
203220 deleteAllRelatedRepos ();
204221 setupLocalRepo (NEW_LOCAL_FROM );
205222 setupLocalRepo (NEW_LOCAL_TO );
@@ -208,18 +225,8 @@ private void prepareRepositoriesForMovingAndCoping() {
208225 artifactory .repository (NEW_LOCAL_FROM ).upload ("x/y/z" , content ).doUpload ();
209226 }
210227
211- private void deleteAllRelatedRepos () {
228+ private void deleteAllRelatedRepos () throws IOException {
212229 deleteRepoIfExists (NEW_LOCAL_FROM );
213230 deleteRepoIfExists (NEW_LOCAL_TO );
214231 }
215-
216- private void deleteRepoIfExists (String repoName ) {
217- try {
218- artifactory .repository (repoName ).delete ();
219- } catch (Exception e ) {
220- if (!e .getMessage ().equals ("Not Found" )) { //if repo wasn't found - that's ok. It means testCreate didn't run.
221- throw e ;
222- }
223- }
224- }
225232}
0 commit comments