|
1 | 1 | package org.jfrog.artifactory.client; |
2 | 2 |
|
3 | 3 | import groovyx.net.http.HttpResponseException; |
| 4 | +import org.jfrog.artifactory.client.impl.CopyMoveException; |
4 | 5 | import org.jfrog.artifactory.client.model.File; |
5 | 6 | import org.jfrog.artifactory.client.model.Folder; |
6 | 7 | import org.jfrog.artifactory.client.model.LocalRepository; |
@@ -123,32 +124,95 @@ public void testSetItemPropertiesOnNonExistingDirectory() throws Exception { |
123 | 124 | assertTrue(folder.getPropertyValues("v1").contains("b2")); |
124 | 125 | } |
125 | 126 |
|
| 127 | + //this test move content of directory "x" to another repo into directory "abc", than both repo's will be removed after finish |
126 | 128 | @Test |
127 | | - public void testMoveItem() throws Exception { |
| 129 | + public void testMoveDirectory() throws Exception { |
128 | 130 | prepareRepositoriesForMovingAndCoping(); |
129 | | - ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).file("x"); |
130 | | - ItemHandle newItemHandle = itemHandle.move(NEW_LOCAL_TO, "x"); |
131 | | - assertNotNull(newItemHandle); |
| 131 | + ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).folder("x"); |
| 132 | + ItemHandle newItemHandle = itemHandle.move(NEW_LOCAL_TO, "abc"); |
| 133 | + checkTheEqualityOfFolders(newItemHandle); |
| 134 | + deleteAllRelatedRepos(); |
132 | 135 | } |
133 | 136 |
|
| 137 | + //this test copy content of directory "x" to another repo into directory "abc", than both repo's will be removed after finish |
134 | 138 | @Test |
135 | | - public void testCopyItem() throws Exception { |
| 139 | + public void testCopyDirectory() throws Exception { |
136 | 140 | prepareRepositoriesForMovingAndCoping(); |
137 | | - ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).file("x"); |
138 | | - ItemHandle newItemHandle = itemHandle.copy(NEW_LOCAL_TO, "x"); |
139 | | - assertNotNull(newItemHandle); |
| 141 | + ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).folder("x"); |
| 142 | + ItemHandle newItemHandle = itemHandle.copy(NEW_LOCAL_TO, "abc"); |
| 143 | + checkTheEqualityOfFolders(newItemHandle); |
| 144 | + deleteAllRelatedRepos(); |
140 | 145 | } |
141 | 146 |
|
| 147 | + //this test move file "z" to the root of another repo, than both repo's will be removed after finish |
| 148 | + @Test |
| 149 | + 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(); |
| 155 | + } |
| 156 | + |
| 157 | + //this test copy file "z" to the root of another repo, than both repo's will be removed after finish |
| 158 | + @Test |
| 159 | + 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(); |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + public void testExceptionOnMovingFile() throws Exception { |
| 169 | + prepareRepositoriesForMovingAndCoping(); |
| 170 | + ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).file("a/a"); |
| 171 | + try { |
| 172 | + itemHandle.move(NEW_LOCAL_TO, "x/y/z"); |
| 173 | + } 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); |
| 175 | + } |
| 176 | + deleteAllRelatedRepos(); |
| 177 | + } |
| 178 | + |
| 179 | + @Test |
| 180 | + public void testExceptionOnCopingFile() throws Exception { |
| 181 | + prepareRepositoriesForMovingAndCoping(); |
| 182 | + ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).file("a/a"); |
| 183 | + try { |
| 184 | + itemHandle.copy(NEW_LOCAL_TO, "x/y/z"); |
| 185 | + } 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); |
| 187 | + } |
| 188 | + deleteAllRelatedRepos(); |
| 189 | + } |
| 190 | + |
| 191 | + private void checkTheEqualityOfFolders(ItemHandle newItemHandle) { |
| 192 | + ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_TO).folder("abc"); |
| 193 | + assertEquals(itemHandle.info().equals(newItemHandle.info()), true); |
| 194 | + } |
| 195 | + |
| 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); |
| 199 | + } |
| 200 | + |
| 201 | + |
142 | 202 | private void prepareRepositoriesForMovingAndCoping() { |
143 | | - deleteRepoIfExists(NEW_LOCAL_FROM); |
144 | | - deleteRepoIfExists(NEW_LOCAL_TO); |
| 203 | + deleteAllRelatedRepos(); |
145 | 204 | setupLocalRepo(NEW_LOCAL_FROM); |
146 | 205 | setupLocalRepo(NEW_LOCAL_TO); |
147 | 206 | InputStream content = this.getClass().getResourceAsStream("/sample.txt"); |
148 | 207 | assertNotNull(content); |
149 | 208 | artifactory.repository(NEW_LOCAL_FROM).upload("x/y/z", content).doUpload(); |
150 | 209 | } |
151 | 210 |
|
| 211 | + private void deleteAllRelatedRepos() { |
| 212 | + deleteRepoIfExists(NEW_LOCAL_FROM); |
| 213 | + deleteRepoIfExists(NEW_LOCAL_TO); |
| 214 | + } |
| 215 | + |
152 | 216 | private void deleteRepoIfExists(String repoName) { |
153 | 217 | try { |
154 | 218 | artifactory.repository(repoName).delete(); |
|
0 commit comments