/** * Search for file by name in a specific repository, return the location of file */ private static List<RepoPath> searchFile(Artifactory artifactory, String repoName, String fileToSearch) { if (artifactory == null || StringUtils.isEmpty(repoName) || StringUtils.isEmpty(fileToSearch)){ throw new IllegalArgumentException("Arguments passed to serachFile are not valid"); } return artifactory.searches() .repositories(repoName) .artifactsByName(fileToSearch) .doSearch(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testQuickSearchWithoutSearchTerm() throws IOException { artifactory.searches().doSearch(); }
@Test public void testArtifactsCreatedSinceSearch() throws IOException { long startTime = System.currentTimeMillis() - 86400000L; List<RepoPath> results = artifactory.searches().artifactsCreatedSince(startTime).doSearch(); assertFalse(results.isEmpty()); }
@Test public void testArtifactsCreatedInDateRangeSearch() throws IOException { long now = System.currentTimeMillis() + 60000L; long startTime = now - 86400000L; List<RepoPath> results = artifactory.searches().artifactsCreatedInDateRange(startTime, now).doSearch(); assertFalse(results.isEmpty()); } }
@Test public void testSearchByPropertyMapNotationWithMulipleValue() throws IOException { Map<String, List<String>> property = new HashMap<>(); property.put(colorsProp, asList("black", "white", "pink")); property.put(buildProp, asList("29")); List<RepoPath> list = artifactory.searches().itemsByProperty().properties(property).doSearch(); assertTrue(list.isEmpty()); }
@Test public void testSearchByPropertyWithMapNotation() throws IOException { Map<String, Boolean> properties = new HashMap<>(); properties.put(releasedProp, true); List<RepoPath> results = artifactory.searches().itemsByProperty().properties(properties).doSearch(); assertEquals(results.size(), 1); assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar")); }
@Test public void testSearchByPropertyWithWildCards() throws IOException { List<RepoPath> results = artifactory.searches().itemsByProperty().property(colorsProp, "r*?").doSearch(); assertEquals(results.size(), 1); assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar")); }
@Test public void testSearchByProperty() throws IOException { List<RepoPath> results = artifactory.searches().itemsByProperty().property(colorsProp, "red").doSearch(); assertEquals(results.size(), 1); assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar")); }
@Test public void testSearchByPropertyWithMulipleValue() throws IOException { List<RepoPath> list = artifactory.searches().itemsByProperty().property(colorsProp, "red", "green", "blue").doSearch(); assertTrue(list.isEmpty()); }
@Test public void testSearchByPropertyWithoutValue() throws IOException { List<RepoPath> results = artifactory.searches().itemsByProperty().property(releasedProp).property(buildProp, 28).doSearch(); assertEquals(results.size(), 1); assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar")); }
@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")); }
@Test public void testLimitlessQuickSearch() throws IOException { List<RepoPath> results = artifactory.searches().artifactsByName("junit").doSearch(); assertEquals(results.size(), countMatches(curl("api/search/artifact?name=junit"), "{") - 1); }
@Test public void testSearchByGavc() throws IOException { List<RepoPath> results = artifactory.searches().artifactsByGavc() .groupId("com.example") .artifactId(artifactId) .version("1.0.0") .classifier("zip") .doSearch(); assertEquals(results.size(), 1); assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar")); }
@Test public void testSearchByPropertyAndWrongRepoFilter() throws IOException { List<RepoPath> list = artifactory.searches().repositories(getJCenterRepoName()).itemsByProperty().property(releasedProp, true).doSearch(); assertTrue(list.isEmpty()); }
@Test public void testSearchByGavcAndRepository() throws IOException { List<RepoPath> results = artifactory.searches().artifactsByGavc() .groupId("com.example") .artifactId(artifactId) .version("1.0.0") .classifier("zip") .repositories(localRepository.getKey()) .doSearch(); assertEquals(results.size(), 1); assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar")); }
@Test public void testLatestVersionSearch() throws IOException { String results = artifactory.searches().artifactsLatestVersion() .groupId("junit") .artifactId("junit") .repositories(getJCenterRepoName()) .doRawSearch(); assertEquals(results, "4.13-beta-1"); }
@Test public void testQuickSearchWithRightSingleLimit() throws IOException { List<RepoPath> results = artifactory.searches().artifactsByName("junit").repositories(getJcenterCacheName()).doSearch(); assertEquals(results.size(), countMatches(curl("api/search/artifact?name=junit&repos=" + getJcenterCacheName()), "{") - 1); }
@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); }