public LocalRepositoryBuilder builderFrom(LocalRepository from) { return new LocalRepositoryBuilderImpl().repositorySettings(from.getRepositorySettings()) .blackedOut(from.isBlackedOut()).description(from.getDescription()).excludesPattern(from.getExcludesPattern()) .includesPattern(from.getIncludesPattern()).key(from.getKey()).notes(from.getNotes()).propertySets(from.getPropertySets()) .archiveBrowsingEnabled(from.isArchiveBrowsingEnabled()); }
@Test(dependsOnMethods = "testCreate") public void testGetLocal() throws Exception { Repository repository = artifactory.repository(localRepository.getKey()).get(); assertNotNull(repository); assertTrue(LocalRepository.class.isAssignableFrom(repository.getClass())); LocalRepository localRepo = (LocalRepository) repository; assertEquals(localRepo.getKey(), localRepository.getKey()); assertEquals(localRepo.getRclass().toString(), "local"); assertEquals(localRepo.getDescription(), "new local repository"); assertEquals(localRepo.getNotes(), ""); assertEquals(localRepo.getIncludesPattern(), "**/*"); assertEquals(localRepo.getExcludesPattern(), ""); assertFalse(localRepo.isBlackedOut()); List<String> propertySets = localRepo.getPropertySets(); assertEquals(propertySets.size(), 1); assertEquals(propertySets.get(0), ("artifactory")); assertEquals(localRepo.getRepoLayoutRef(), localRepository.getRepoLayoutRef()); }
@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 public void testUploadWithMavenGAVC() throws IOException { InputStream inputStream = this.getClass().getResourceAsStream("/sample.zip"); assertNotNull(inputStream); final String targetPath = "com/example/com.example.test/1.0.0/com.example.test-1.0.0-zip.jar"; File deployed = artifactory.repository(localRepository.getKey()).upload(targetPath, inputStream).doUpload(); assertNotNull(deployed); assertEquals(deployed.getRepo(), localRepository.getKey()); assertEquals(deployed.getPath(), "/" + targetPath); assertEquals(deployed.getCreatedBy(), username); // GroupId: com.example; ArtifactId: com.example.test; Version 1.0.0; Classifier: zip assertEquals(deployed.getDownloadUri(), url + localRepository.getKey() + "/" + targetPath); assertEquals(deployed.getSize(), 442); }
@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 public void testUploadWithSingleProperty() throws IOException { InputStream inputStream = this.getClass().getResourceAsStream("/sample.txt"); assertNotNull(inputStream); File deployed = artifactory.repository(localRepository.getKey()).upload(PATH, inputStream).withProperty("color", "blue") .withProperty("color", "red").doUpload(); assertNotNull(deployed); assertEquals(deployed.getRepo(), localRepository.getKey()); assertEquals(deployed.getPath(), "/" + PATH); assertEquals(deployed.getCreatedBy(), username); assertEquals(deployed.getDownloadUri(), url + localRepository.getKey() + "/" + PATH); assertTrue(deployed.getSize() == 3044 || deployed.getSize() == 3017); assertTrue(curlAndStrip("api/storage/" + localRepository.getKey() + "/" + PATH + "?properties").contains("\"color\":[\"red\"]")); }
@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 = "testCreate") public void testReplicationStatus() throws Exception { assertEquals(artifactory.repository(localRepository.getKey()).replicationStatus().getStatus(), "never_run"); }
@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 = "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 public void testQuickSearchWithWrongSingleLimit() throws IOException { List<RepoPath> list = artifactory.searches().artifactsByName("junit").repositories(localRepository.getKey()).doSearch(); assertTrue(list.isEmpty()); }
@Test public void testSearchByPropertyAndRepoFilter() throws IOException { List<RepoPath> results = artifactory.searches().itemsByProperty().property(releasedProp, true).repositories(localRepository.getKey()).doSearch(); assertEquals(results.size(), 1); assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar")); }
/** * This test requires a 'set_property' user plugin * * @throws IOException */ @Test public void testUploadWithSinglePropertyOnArbitraryLocationAndKeep() throws IOException { InputStream inputStream = this.getClass().getResourceAsStream("/sample.txt"); assertNotNull(inputStream); File deployed = artifactory.repository(localRepository.getKey()).upload(PATH, inputStream).withProperty("color", "red") .withProperty("target", "m", "keep").doUpload(); assertNotNull(deployed); assertEquals(deployed.getRepo(), localRepository.getKey()); assertEquals(deployed.getPath(), "/" + PATH); assertEquals(deployed.getCreatedBy(), username); assertEquals(deployed.getDownloadUri(), url + localRepository.getKey() + "/" + PATH); assertTrue(deployed.getSize() == 3044 || deployed.getSize() == 3017); assertTrue(curlAndStrip("api/storage/" + localRepository.getKey() + "/" + PATH + "?properties").contains("\"color\":[\"red\"]")); assertFalse(curlAndStrip("api/storage/" + localRepository.getKey() + "/" + PATH + "?properties").contains("\"target\":[\"m/a\"]")); }
@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(groups = "security") public void testEffectiveRepoPermissions() { Set<ItemPermission> itemPermissions = artifactory.repository(localRepository.getKey()).effectivePermissions(); assertItemPermissions(itemPermissions); }