/** * This method receives the uploaded file source and destination, performs the upload to artifactory */ private static File uploadFile(Artifactory artifactory, String repo, String destPath, String fileNameToUpload) throws IOException { if (StringUtils.isEmpty(repo) || StringUtils.isEmpty(destPath) || StringUtils.isEmpty(fileNameToUpload) || artifactory == null){ throw new IllegalArgumentException("Arguments passed to createArtifactory are not valid"); } Path path = Paths.get(fileNameToUpload); Files.write(path, Collections.singleton("This is an example line"), Charset.forName("UTF-8")); java.io.File file = new java.io.File(fileNameToUpload); return artifactory.repository(repo).upload(destPath, file).doUpload(); }
LOGGER.info("Aritifactory client created successfully with uri {}", client.getUri()); FileAttribute<Set<PosixFilePermission>> perms = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-xr-x")); InputStream response = client.repository(repoName).download(metadataStr).doDownload(); LOGGER.info("download complete"); Files.copy(response, tempFilePath, StandardCopyOption.REPLACE_EXISTING);
/** * 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; }
/** * We have not ability to create certificate through java client. * @TODOs Remove `(enabled = false)`. Create certificate with name "clientTlsCertificate". */ @Test(enabled = false) public void testClientTlsCertificate() throws Exception { String clientTlsCertificate = "clientTlsCertificate"; RemoteRepository changedRepository = artifactory.repositories().builders().builderFrom(remoteRepository) .description("create remote repo with clientTlsCertificate") .clientTlsCertificate(clientTlsCertificate) .build(); artifactory.repositories().create(1, changedRepository); RemoteRepository repository = (RemoteRepository) artifactory.repository(changedRepository.getKey()).get(); assertNotNull(repository); assertEquals(repository.getClientTlsCertificate(), clientTlsCertificate); }
/** * 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(); }
artifactory = ArtifactoryClientBuilder.create().setUrl("http://myhost.com/clienttests").build(); assertEquals("http://myhost.com", artifactory.getUri()); assertEquals("clienttests", artifactory.getContextName()); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("clienttests", artifactory.getContextName()); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("clienttests", artifactory.getContextName()); assertEquals("http://myhost.com", artifactory.getUri()); assertEquals("", artifactory.getContextName()); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("", artifactory.getContextName()); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("", artifactory.getContextName()); assertEquals("http://abc.com:80", artifactory.getUri()); assertEquals("ab/artifactory/webapp/webapp", artifactory.getContextName()); .build(); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("", artifactory.getContextName()); assertEquals("testAgent", artifactory.getUserAgent());
@Test(enabled = false) public void testPluginsList() { Map<PluginType, List<Plugin>> plugins = artifactory.plugins().list(); assertEquals(plugins.size(), 1); assertTrue(plugins.containsKey(executions)); List<Plugin> executionPlugins = plugins.get(executions); verifyExecutionPlugins(executionPlugins); }
public InputStream doDownload() throws IOException { String params = parseParams(props, "=") + parseParams(mandatoryProps, "+="); if (params.length() > 0) { params = ";" + params; } String uri = String.format("/%s/%s%s", repo, path, params); return artifactory.getInputStream(uri); }
@AfterClass public void clean() { deleteRepoIfExists(localRepository.getKey()); deleteRepoIfExists(getJCenterRepoName()); artifactory.close(); }
/** * Tests whether the builder sets the bypassHead request correctly (true) */ @Test public void testRemoteRepoBypassHead() throws Exception { RemoteRepository changedRepository = artifactory.repositories().builders().builderFrom(remoteRepository) .key("testRemoteRepoBypassHead") .description("create remote repo with bypassHead=true") .bypassHeadRequests(true) .build(); artifactory.repositories().create(1, changedRepository); RemoteRepository repository = (RemoteRepository) artifactory.repository(changedRepository.getKey()).get(); assertNotNull(repository); assertEquals(repository.isBypassHeadRequests(), true); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testQuickSearchWithoutSearchTerm() throws IOException { artifactory.searches().doSearch(); }
@Test public void urlsTest() throws IOException { Artifactory artifactory; ArtifactoryClientBuilder artifactoryClientBuilder = ArtifactoryClientBuilder.create(); artifactory = artifactoryClientBuilder.setUrl("http://myhost.com/clienttests").setUsername("").setPassword("").build(); assertEquals("http://myhost.com", artifactory.getUri()); assertEquals("clienttests", artifactory.getContextName()); artifactory = artifactoryClientBuilder.setUrl("http://myhost.com:80/clienttests").setUsername("").setPassword("").build(); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("clienttests", artifactory.getContextName()); artifactory = artifactoryClientBuilder.setUrl("http://myhost.com:80/clienttests/").setUsername("").setPassword("").build(); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("clienttests", artifactory.getContextName()); artifactory = artifactoryClientBuilder.setUrl("http://myhost.com").setUsername("").setPassword("").build(); assertEquals("http://myhost.com", artifactory.getUri()); assertEquals("", artifactory.getContextName()); artifactory = artifactoryClientBuilder.setUrl("http://myhost.com:80").setUsername("").setPassword("").build(); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("", artifactory.getContextName()); artifactory = artifactoryClientBuilder.setUrl("http://myhost.com:80/").setUsername("").setPassword("").build(); assertEquals("http://myhost.com:80", artifactory.getUri()); assertEquals("", artifactory.getContextName()); artifactory = artifactoryClientBuilder.setUrl("http://abc.com:80/ab/artifactory/webapp/webapp").setUsername("").setPassword("").build(); assertEquals("http://abc.com:80", artifactory.getUri()); assertEquals("ab/artifactory/webapp/webapp", artifactory.getContextName()); artifactory = artifactoryClientBuilder.setUrl("http://myhost.com:80/").setUsername("").setPassword("").setUserAgent("testAgent").build(); assertEquals(artifactory.getUri(), "http://myhost.com:80"); assertEquals("", artifactory.getContextName()); assertEquals("testAgent", artifactory.getUserAgent()); }
@Test(enabled = false) public void testPluginsListByType() { List<Plugin> list = artifactory.plugins().list(executions); verifyExecutionPlugins(list); }
/** * Download the required file from artifactory */ private static java.io.File downloadFile(Artifactory artifactory, String repo, String filePath, String fileDownloadToLocation) throws Exception { if (artifactory == null || StringUtils.isEmpty(repo) || StringUtils.isEmpty(filePath)){ throw new IllegalArgumentException("Arguments passed to downloadFile are not valid"); } InputStream inputStream = artifactory.repository(repo) .download(filePath) .doDownload(); java.io.File targetFile = new java.io.File(fileDownloadToLocation); FileUtils.copyInputStreamToFile(inputStream, targetFile); return targetFile; }
/** * Tests whether the builder sets the bypassHead request correctly (false) */ @Test public void testRemoteRepoNotBypassHead() throws Exception { RemoteRepository changedRepository = artifactory.repositories().builders().builderFrom(remoteRepository) .description("create remote repo with bypassHead=false") .key("testRemoteRepoNotBypassHead") .bypassHeadRequests(false) .build(); artifactory.repositories().create(1, changedRepository); RemoteRepository repository = (RemoteRepository) artifactory.repository(changedRepository.getKey()).get(); assertNotNull(repository); assertEquals(repository.isBypassHeadRequests(), false); }
@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(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(enabled = false) public void testExecutePlugin(){ //TODO change to assert default params instead of null once RTFACT-5867 is fixed verifyExecutionResult(artifactory.plugins().execute(PLUGIN_NAME).sync(), null); String variable = "test"; verifyExecutionResult(artifactory.plugins().execute(PLUGIN_NAME).withParameter("whom", variable).sync(), "["+variable+"]"); }
@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()); }
deleteRepoIfExists(localRepositoryKey); deleteRepoIfExists(getJCenterRepoName()); localRepository = artifactory.repositories().builders().localRepositoryBuilder() .key(localRepositoryKey) .description("new local repository") .build(); if (!artifactory.repository(localRepository.getKey()).exists()) { artifactory.repositories().create(1, localRepository); if (!artifactory.repository(jcenterRepoName).exists()) { Repository jcenter = artifactory.repositories().builders().remoteRepositoryBuilder() .key(jcenterRepoName) .url(JCENTER_URL) .repositorySettings(new MavenRepositorySettingsImpl()) .build(); artifactory.repositories().create(1, jcenter);