@Test(dependsOnMethods = "testCreate") public void testCreateDirectoryWithIllegalName() throws IOException { try { artifactory.repository(localRepository.getKey()).folder("myFolder?").create(); } catch (Exception e) { assertTrue(e instanceof HttpResponseException); assertTrue(((HttpResponseException)e).getStatusCode() == 500); } }
private void checkTheEqualityOfFolders(ItemHandle newItemHandle, String expectedRepo, String expectedPath) { ItemHandle itemHandle = artifactory.repository(expectedRepo).folder(expectedPath); assertEquals(itemHandle.info(), (Item)newItemHandle.info()); }
@Test(dependsOnMethods = "testCreate") public void testCreateDirectory() throws IOException { Folder folder = artifactory.repository(localRepository.getKey()).folder("myFolder").create(); assertEquals("/myFolder/", folder.getPath()); assertNotNull(folder.getCreated()); }
@Test(dependsOnMethods = "testUploadWithSingleProperty") public void testUploadExplodeArchive() throws IOException { artifactory.repository(localRepository.getKey()).upload("sample/sample.zip", this.getClass().getResourceAsStream("/sample.zip")) .doUploadAndExplode(); List<Item> items = ((FolderImpl) artifactory.repository(localRepository.getKey()).folder("sample").info()).getChildren(); assertEquals(items.get(0).getUri(), "/a.txt"); assertEquals(items.get(1).getUri(), "/b.txt"); assertEquals(items.get(2).getUri(), "/c.txt"); }
@Test public void testFolderInfo() throws IOException { // Get the folder to the cache artifactory.repository(getJCenterRepoName()).download("junit/junit/4.10/junit-4.10-sources.jar").doDownload(); Folder folder = artifactory.repository(getJcenterCacheName()).folder("junit").info(); assertNotNull(folder); assertTrue(folder.isFolder()); assertEquals(folder.getChildren().size(), 1); assertEquals(folder.getRepo(), getJcenterCacheName()); assertEquals(folder.getPath(), "/junit"); }
@Test public void testMoveDirectory() throws Exception { try { prepareRepositoriesForMovingAndCoping(); ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).folder("m"); String path = "abc"; checkTheEqualityOfFolders(itemHandle.move(NEW_LOCAL_TO, path), NEW_LOCAL_TO, path); } finally { deleteAllRelatedRepos(); } }
@Test public void testCopyDirectory() throws Exception { try { prepareRepositoriesForMovingAndCoping(); ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).folder("m"); String path = "abc"; checkTheEqualityOfFolders(itemHandle.copy(NEW_LOCAL_TO, path), NEW_LOCAL_TO, path); } finally { deleteAllRelatedRepos(); } }
@Test(dependsOnMethods = "testCreate") public void testCreateDirectoryWithoutPermissions() throws IOException { Artifactory anonymousArtifactory = ArtifactoryClientBuilder.create().setUrl(url).build(); try { anonymousArtifactory.repository(localRepository.getKey()).folder("myFolder").create(); } catch (HttpResponseException e) { assertTrue(e.getStatusCode() == HttpStatus.SC_UNAUTHORIZED); } }
@Test(groups = "items") public void testSetItemPropertiesOnNonExistingDirectory() throws Exception { ItemHandle folder = artifactory.repository(localRepository.getKey()).folder("x/y/z"); try { folder.info(); //should fail } catch (Exception e) { //noinspection ConstantConditions if (!(e instanceof HttpResponseException) || !(((HttpResponseException) e).getStatusCode() == 404 || ((HttpResponseException) e).getStatusCode() == 405)) { throw e; } } folder.properties().addProperty("v1", "b2").doSet(); Folder info = folder.info(); assertNotNull(info); assertTrue(info.isFolder()); assertTrue(folder.getPropertyValues("v1").contains("b2")); }