@Test(groups = "repositoryBasics") public void testDelete() throws Exception { //all the assertions are taken care of in deleteRepoIfExists deleteRepoIfExists(localRepository.getKey()); }
@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(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(groups = "repositoryBasics", dependsOnMethods = "testDelete") public void testCreate() throws Exception { String result = artifactory.repositories().create(2, localRepository); assertTrue(result.startsWith("Successfully created repository")); assertTrue(curl(LIST_PATH).contains(localRepository.getKey())); result = artifactory.repositories().create(2, localRepository2); assertTrue(result.startsWith("Successfully created repository")); assertTrue(curl(LIST_PATH).contains(localRepository2.getKey())); result = artifactory.repositories().create(2, virtualRepository); assertTrue(result.startsWith("Successfully created repository")); assertTrue(curl(LIST_PATH).contains(virtualRepository.getKey())); }
@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(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(dependsOnMethods = "testUploadWithSingleProperty") public void testDownloadWithoutProperties() throws IOException { InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).doDownload(); String actual = textFrom(inputStream); assertEquals(actual, textFrom(this.getClass().getResourceAsStream("/sample.txt"))); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties") public void testDownloadWithNonExistingNonMandatoryProperties() throws IOException { //property doesn't exist InputStream inputStream = artifactory.repository(localRepository.getKey()).download(PATH).withProperty("foo", "bar").doDownload(); assertEquals(textFrom(inputStream), textFrom(this.getClass().getResourceAsStream("/sample.txt"))); }
@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 = "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 public void testQuickSearchWithMultipleLimits() throws IOException { List<RepoPath> results = artifactory.searches().artifactsByName("junit").repositories(localRepository.getKey(), getJcenterCacheName()) .doSearch(); assertEquals(results.size(), countMatches(curl("api/search/artifact?name=junit&repos=" + localRepository.getKey() + "," + getJcenterCacheName()), "{") - 1); }
@Test(dependsOnMethods = "testUploadWithMultipleProperties", expectedExceptions = IOException.class) public void testDownloadWithNonExistingMandatoryProperties() throws IOException { // Property doesn't exist, will fail artifactory.repository(localRepository.getKey()).download(PATH).withMandatoryProperty("foo", "bar").doDownload(); }
@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 = "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(dependsOnMethods = "testCreate") public void testUpdate() throws Exception { RepositorySettings genericRepo = new MavenRepositorySettingsImpl(); LocalRepository changedRepository = artifactory.repositories().builders().builderFrom(localRepository) .description("new_description") .repositorySettings(genericRepo) .build(); artifactory.repositories().update(changedRepository); assertTrue(curlAndStrip("api/repositories/" + localRepository.getKey()).contains("\"description\":\"new_description\"")); }