assertEquals(original, repo.getDefaultBaseUrl());
}
@Ignore
public void testUpdateRepoUrlController() throws Exception {
RepositoryInfo repo = ambariMetaInfo.getRepository(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
RepositoryRequest request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
request.setBaseUrl("http://hortonworks.com");
Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>();
requests.add(request);
// test bad url
try {
controller.updateRespositories(requests);
fail ("Expected exception on invalid url");
} catch (Exception e) {
}
// test bad url, but allow to set anyway
request.setVerifyBaseUrl(false);
controller.updateRespositories(requests);
Assert.assertEquals(request.getBaseUrl(), repo.getBaseUrl());
// reset repo
requests.clear();
request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
request.setBaseUrl(repo.getDefaultBaseUrl());
requests.add(request);
controller.updateRespositories(requests);
Assert.assertEquals(repo.getBaseUrl(), repo.getDefaultBaseUrl());
String baseUrl = repo.getDefaultBaseUrl();
if (!baseUrl.endsWith("/"))
baseUrl += "/";
// variation #1: url with trailing slash, suffix preceding slash
backingProperties.setProperty(Configuration.REPO_SUFFIX_KEY, "/repodata/repomd.xml");
Assert.assertTrue(baseUrl.endsWith("/") && configuration.getRepoValidationSuffixes()[0].startsWith("/"));
request.setBaseUrl(baseUrl);
controller.updateRespositories(requests);
Assert.assertEquals(baseUrl, repo.getBaseUrl());
// variation #2: url with trailing slash, suffix no preceding slash
backingProperties.setProperty(Configuration.REPO_SUFFIX_KEY, "repodata/repomd.xml");
Assert.assertTrue(baseUrl.endsWith("/") && !configuration.getRepoValidationSuffixes()[0].startsWith("/"));
request.setBaseUrl(baseUrl);
controller.updateRespositories(requests);
Assert.assertEquals(baseUrl, repo.getBaseUrl());
baseUrl = baseUrl.substring(0, baseUrl.length()-1);
// variation #3: url with no trailing slash, suffix no prededing slash
Assert.assertTrue(!baseUrl.endsWith("/") && !configuration.getRepoValidationSuffixes()[0].startsWith("/"));
request.setBaseUrl(baseUrl);
controller.updateRespositories(requests);
Assert.assertEquals(baseUrl, repo.getBaseUrl());
// variation #4: url with no trailing slash, suffix preceding slash
backingProperties.setProperty(Configuration.REPO_SUFFIX_KEY, "/repodata/repomd.xml");
Assert.assertTrue(!baseUrl.endsWith("/") && configuration.getRepoValidationSuffixes()[0].startsWith("/"));
request.setBaseUrl(baseUrl);
controller.updateRespositories(requests);
Assert.assertEquals(baseUrl, repo.getBaseUrl());
// variation #5: multiple suffix tests
backingProperties.setProperty(Configuration.REPO_SUFFIX_KEY, "/foo/bar.xml,/repodata/repomd.xml");
Assert.assertTrue(configuration.getRepoValidationSuffixes().length > 1);
request.setBaseUrl(baseUrl);
controller.updateRespositories(requests);
Assert.assertEquals(baseUrl, repo.getBaseUrl());
}