/** * 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 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 testLatestVersionSearch() throws IOException { String results = artifactory.searches().artifactsLatestVersion() .groupId("junit") .artifactId("junit") .repositories(getJCenterRepoName()) .doRawSearch(); assertEquals(results, "4.13-beta-1"); }
@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 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 testSearchByPropertyAndWrongRepoFilter() throws IOException { List<RepoPath> list = artifactory.searches().repositories(getJCenterRepoName()).itemsByProperty().property(releasedProp, true).doSearch(); assertTrue(list.isEmpty()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testQuickSearchWithoutSearchTerm() throws IOException { artifactory.searches().doSearch(); }
@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 testQuickSearchWithWrongSingleLimit() throws IOException { List<RepoPath> list = artifactory.searches().artifactsByName("junit").repositories(localRepository.getKey()).doSearch(); assertTrue(list.isEmpty()); }
@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); }