/** * This method receives the uploaded file source and destination, performs the upload to artifactory */ private static File uploadFile(Artifactory artifactory, String repo, String destPath, String fileNameToUpload) throws IOException { if (StringUtils.isEmpty(repo) || StringUtils.isEmpty(destPath) || StringUtils.isEmpty(fileNameToUpload) || artifactory == null){ throw new IllegalArgumentException("Arguments passed to createArtifactory are not valid"); } Path path = Paths.get(fileNameToUpload); Files.write(path, Collections.singleton("This is an example line"), Charset.forName("UTF-8")); java.io.File file = new java.io.File(fileNameToUpload); return artifactory.repository(repo).upload(destPath, file).doUpload(); }
@Test(dependsOnMethods = "testCreate") public void testRepositoryExists() throws IOException { assertTrue(artifactory.repository(localRepository.getKey()).exists()); String notExistsRepoName = Long.toString(System.currentTimeMillis()); assertFalse(artifactory.repository(notExistsRepoName).exists()); }
@Test(dependsOnMethods = "testCreate") public void testRepositoryIsFolder() throws IOException { try { assertTrue(artifactory.repository(localRepository.getKey()).isFolder("myFolder")); } catch (Exception e) { assertTrue(e.getMessage().contains("Internal Server Error")); } }
@Test(groups = "security") public void testEffectiveItemPermissions() throws Exception { InputStream inputStream = this.getClass().getResourceAsStream("/sample.txt"); Assert.assertNotNull(inputStream); File deployed = artifactory.repository(localRepository.getKey()).upload(PATH, inputStream).doUpload(); Assert.assertNotNull(deployed); Set<ItemPermission> itemPermissions = artifactory.repository(localRepository.getKey()).file(PATH).effectivePermissions(); assertItemPermissions(itemPermissions); }
@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(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); } }
@Test(groups = "security") public void testEffectiveRepoPermissions() { Set<ItemPermission> itemPermissions = artifactory.repository(localRepository.getKey()).effectivePermissions(); assertItemPermissions(itemPermissions); }
@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 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(dependsOnMethods = "testUploadWithMultipleProperties") public void testDownloadWithMatchingNonMandatoryProperties() throws IOException { //property matches InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).withProperty("colors", "red") .doDownload(); assertEquals(textFrom(inputStream), textFrom(this.getClass().getResourceAsStream("/sample.txt"))); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties") public void testDownloadWithMatchingMandatoryProperties() throws IOException { // Property matches InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).withMandatoryProperty("colors", "red").doDownload(); assertEquals(textFrom(inputStream), textFrom(this.getClass().getResourceAsStream("/sample.txt"))); }
@Test(dependsOnMethods = "testUploadWithSingleProperty")//to spare all the checks public void testUploadWithMultipleProperties() throws IOException { artifactory.repository(localRepository.getKey()).upload(PATH, this.getClass().getResourceAsStream("/sample.txt")) .withProperty("colors", "red") .withProperty("build", 28) .withProperty("released", false).doUpload(); assertTrue(curlAndStrip("api/storage/" + localRepository.getKey() + "/" + PATH + "?properties").contains("{\"build\":[\"28\"],\"colors\":[\"red\"],\"released\":[\"false\"]}")); }
@Test(enabled = false, dependsOnMethods = "testUploadWithSingleProperty") public void testUploadWithMultiplePropertyValues() throws IOException { artifactory.repository(localRepository.getKey()).upload(PATH, this.getClass().getResourceAsStream("/sample.txt")) .withProperty("colors", "red", "green", "blue") .withProperty("build", 28) .withProperty("released", false).doUpload(); assertTrue(curl("api/storage/" + localRepository.getKey() + "/" + PATH + "?properties") .contains("{\"build\":[\"28\"],\"colors\":[\"red\",\"green\",\"blue\"],\"released\":[\"false\"]}")); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties", expectedExceptions = HttpResponseException.class) public void testDownloadWithWrongNonMandatoryProperties() throws IOException { //property doesn't match, will fail artifactory.repository(localRepository.getKey()).download(PATH).withProperty("colors", "black").doDownload(); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties", expectedExceptions = HttpResponseException.class) public void testDownloadWithWrongMandatoryProperties() throws IOException { // Property doesn't match, will fail artifactory.repository(localRepository.getKey()).download(PATH).withMandatoryProperty("colors", "black").doDownload(); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties") public void testDownloadWithMandatoryAndNonMandatoryProperties() throws IOException { InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).withProperty("released", false) .withProperty("foo", "bar").withMandatoryProperty("colors", "red").doDownload(); assertEquals(textFrom(inputStream), textFrom(this.getClass().getResourceAsStream("/sample.txt"))); } }
@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 testCopyFile() throws Exception { try { prepareRepositoriesForMovingAndCoping(); ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).file(PATH); ItemHandle newItemHandle = itemHandle.copy(NEW_LOCAL_TO, PATH); checkTheEqualityOfFiles(newItemHandle, NEW_LOCAL_TO, PATH); } finally { deleteAllRelatedRepos(); } }
@Test public void testMoveFile() throws Exception { try { prepareRepositoriesForMovingAndCoping(); ItemHandle itemHandle = artifactory.repository(NEW_LOCAL_FROM).file(PATH); ItemHandle newItemHandle = itemHandle.move(NEW_LOCAL_TO, PATH); checkTheEqualityOfFiles(newItemHandle, NEW_LOCAL_TO, PATH); } finally { deleteAllRelatedRepos(); } }
@Test(dependsOnMethods = "testFileInfo") public void testFileInfoWithSha256() throws Exception { String path = "junit/junit/4.10/junit-4.10-sources.jar"; calcSha256ForItem(getJcenterCacheName(), path); File file = artifactory.repository(getJcenterCacheName()).file(path).info(); assertNotNull(file); assertEquals(file.getDownloadUri(), url + getJcenterCacheName() + "/junit/junit/4.10/junit-4.10-sources.jar"); assertEquals(file.getChecksums().getMd5(), "8f17d4271b86478a2731deebdab8c846"); assertEquals(file.getChecksums().getSha1(), "6c98d6766e72d5575f96c9479d1c1d3b865c6e25"); assertEquals(file.getChecksums().getSha256(), "e3a4cb7ac3343265f5663b68857078ae68787450afc6e72dc6826962a1bf5212"); }