@Test public void testListRemotes() throws Exception { List<LightweightRepository> remoteRepositories = artifactory.repositories().list(REMOTE); assertNotNull(remoteRepositories); String expected = curlAndStrip("api/repositories/?type=remote"); assertEquals(remoteRepositories.size(), countMatches(expected, "{")); LightweightRepository repo = remoteRepositories.get(0); assertNotNull(repo); assertTrue(LightweightRepository.class.isAssignableFrom(repo.getClass())); assertTrue(expected.substring(9).startsWith(repo.getKey())); assertEquals(repo.getType().toString(), "remote"); assertFalse(repo.getUrl().startsWith(url)); }
/** * This method checks whether repository with supplied name exists or not, and creates new if required. */ private static String createNewRepository(Artifactory artifactory, String repoName) { if (artifactory == null || StringUtils.isEmpty(repoName)){ throw new IllegalArgumentException("Arguments passed to createNewRepository are not valid"); } List<LightweightRepository> repoList = artifactory.repositories().list(LOCAL); Set<String> repoNamesList = repoList.stream() .map(LightweightRepository::getKey) .collect(Collectors.toSet()); String creationResult = null; if ( repoNamesList != null && !(repoNamesList.contains(repoName)) ){ GenericRepositorySettingsImpl settings = new GenericRepositorySettingsImpl(); Repository repository = artifactory.repositories() .builders() .localRepositoryBuilder() .key(repoName) .description("new example local repository") .repositorySettings(settings) .build(); creationResult = artifactory.repositories().create(1, repository); } return creationResult; }
@Test(dependsOnMethods = "testCreate")// to be sure number of repos match public void testListLocals() throws Exception { List<LightweightRepository> localRepositories = artifactory.repositories().list(LOCAL); String expected = curl("api/repositories?type=local"); assertEquals(localRepositories.size(), countMatches(expected, "{")); for (LightweightRepository localRepository : localRepositories) { assertTrue(localRepository.getUrl().startsWith(url)); assertEquals(localRepository.getType().toString(), "local"); } }
@Test public void testListVirtuals() throws Exception { List<LightweightRepository> virtualRepositories = artifactory.repositories().list(VIRTUAL); assertEquals(virtualRepositories.size(), countMatches(curl("api/repositories?type=virtual"), "{")); for (LightweightRepository virtualRepository : virtualRepositories) { assertTrue(virtualRepository.getUrl().startsWith(url)); assertEquals(virtualRepository.getType().toString(), "virtual"); } }