@Test public void run() throws Exception { final String repo1 = "repo1"; final String repo2 = "repo2"; final String path = "org/foo/bar/maven-metadata.xml"; /* @formatter:off */ final String repo1Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<metadata>\n" + " <groupId>org.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <versioning>\n" + " <latest>1.0</latest>\n" + " <release>1.0</release>\n" + " <versions>\n" + " <version>1.0</version>\n" + " </versions>\n" + " <lastUpdated>20150722164334</lastUpdated>\n" + " </versioning>\n" + "</metadata>\n"; /* @formatter:on */ server.expect(server.formatUrl(repo1, path), 200, repo1Content); server.registerException(server.formatUrl(repo2, path), "Server error"); RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1)); remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class); RemoteRepository remote2 = new RemoteRepository(repo2, server.formatUrl(repo2)); remote2.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1)); remote2 = client.stores().create(remote2, "adding remote", RemoteRepository.class); Group g = new Group("test", remote1.getKey(), remote2.getKey()); g = client.stores().create(g, "adding group", Group.class); System.out.printf( "\n\nGroup constituents are:\n %s\n\n", StringUtils.join(g.getConstituents(), "\n ")); final InputStream stream = client.content().get(group, g.getName(), path); assertThat(stream, notNullValue()); final String metadata = IOUtils.toString(stream); assertThat(metadata, equalTo(repo1Content)); stream.close(); }
private ArtifactStore getRequestStore(PromoteRequest promoteRequest, String baseUrl) throws PromotionValidationException { final ArtifactStore store; final Logger logger = LoggerFactory.getLogger(getClass()); if (needTempRepo(promoteRequest)) { logger.info( "Promotion temporary repo is needed for {}, points to {} ", promoteRequest.getSource(), baseUrl); final PathsPromoteRequest pathsReq = (PathsPromoteRequest) promoteRequest; String tempName = PROMOTE_REPO_PREFIX + "tmp_" + pathsReq.getSource().getName() + new SimpleDateFormat("yyyyMMdd.hhmmss.SSSZ").format(new Date()); final RemoteRepository tempRemote = new RemoteRepository(tempName, baseUrl); tempRemote.setPathMaskPatterns(pathsReq.getPaths()); store = tempRemote; try { storeDataMgr.storeArtifactStore( tempRemote, new ChangeSummary(ChangeSummary.SYSTEM_USER, "create temp remote repository")); } catch (IndyDataException e) { throw new PromotionValidationException( "Can not store the temp remote repository correctly", e); } } else { logger.info("Promotion temporary repo is not needed for {} ", promoteRequest.getSource()); try { store = storeDataMgr.getArtifactStore(promoteRequest.getSource()); } catch (IndyDataException e) { throw new PromotionValidationException( "Failed to retrieve source ArtifactStore: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage()); } } return store; }