use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class ContentBrowseHeadRequestTest method run.
@Test
public void run() {
final String changelog = "Create repo validation test structure";
try {
RemoteRepository mavenCentral = new RemoteRepository("maven", "m-central", REMOTE_MAVEN_CENTRAL_URL);
RemoteRepository npmCentral = new RemoteRepository("npm", "n-central", REMOTE_NPM_CENTRAL_URL);
client.stores().create(mavenCentral, changelog, RemoteRepository.class);
client.stores().create(npmCentral, changelog, RemoteRepository.class);
IndyClientHttp client = getHttp();
HttpHead httpMavenHeadReq = new HttpHead(REMOTE_MAVEN_CENTRAL);
HttpResources mavenResponse = client.execute(httpMavenHeadReq);
assertThat(200, is(mavenResponse.getStatusCode()));
HttpHead httpNpmHeadReq = new HttpHead(REMOTE_NPM_CENTRAL);
HttpResources npmResponse = client.execute(httpNpmHeadReq);
assertThat(200, is(npmResponse.getStatusCode()));
HttpHead httpMavenHeadSubReq = new HttpHead(REMOTE_MAVEN_TEST_SUB_URL);
HttpResources mavenSubResponse = client.execute(httpMavenHeadSubReq);
assertThat(200, is(mavenSubResponse.getStatusCode()));
HttpHead httpNpmHeadSubReq = new HttpHead(REMOTE_NPM_TEST_SUB_URL);
HttpResources npmSubResponse = client.execute(httpNpmHeadSubReq);
assertThat(200, is(npmSubResponse.getStatusCode()));
} catch (IndyClientException e) {
e.printStackTrace();
}
}
use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class IndyDiagnosticsClientModule method getDiagnosticBundle.
public ZipInputStream getDiagnosticBundle() throws IndyClientException {
HttpGet get = new HttpGet(buildUrl(getHttp().getBaseUrl(), "/diag/bundle"));
HttpResources resources = getHttp().getRaw(get);
HttpResponse response = null;
try {
response = resources.getResponse();
StatusLine sl = response.getStatusLine();
if (sl.getStatusCode() != 200) {
closeQuietly(resources);
throw new IndyClientException(sl.getStatusCode(), "Error retrieving diagnostic bundle: %s", new IndyResponseErrorDetails(response));
}
return new ZipInputStream(resources.getResponseStream());
} catch (IOException e) {
closeQuietly(resources);
throw new IndyClientException("Failed to read bundle stream from response: %s", e, new IndyResponseErrorDetails(response));
} catch (RuntimeException e) {
closeQuietly(resources);
throw e;
}
}
use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class RepoChangelogStoreDisableTest method test.
@Test
public void test() throws Exception {
HostedRepository repo = new HostedRepository(MAVEN_PKG_KEY, newName());
final StoreKey hostedKey = repo.getKey();
repo = client.stores().create(repo, name.getMethodName(), HostedRepository.class);
repo.setAllowReleases(!repo.isAllowReleases());
client.stores().update(repo, name.getMethodName());
repo.setReadonly(true);
client.stores().update(repo, name.getMethodName());
IndyRepoChangelogClientModule repoChangelogClientModule = client.module(IndyRepoChangelogClientModule.class);
List<ChangeEvent> logs = null;
try {
logs = repoChangelogClientModule.getByStoreKey(repo.getKey());
} catch (IndyClientException e) {
assertThat(e.getStatusCode(), equalTo(404));
}
assertNotNull(logs);
assertTrue(logs.isEmpty());
try {
repoChangelogClientModule.getAll();
} catch (IndyClientException e) {
assertThat(e.getStatusCode(), equalTo(404));
}
assertNotNull(logs);
assertTrue(logs.isEmpty());
}
use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class IndyContentClientModule method get.
public InputStream get(final StoreKey key, final String path) throws IndyClientException {
final HttpResources resources = http.getRaw(contentPath(key, path));
if (resources.getStatusCode() != 200) {
IOUtils.closeQuietly(resources);
if (resources.getStatusCode() == 404) {
return null;
}
throw new IndyClientException(resources.getStatusCode(), "Response returned status: %s.", resources.getStatusLine());
}
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Returning stream that should contain: {} bytes", resources.getResponse().getFirstHeader("Content-Length"));
try {
return resources.getResponseStream();
} catch (final IOException e) {
IOUtils.closeQuietly(resources);
throw new IndyClientException("Failed to open response content stream: %s", e, e.getMessage());
}
}
use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.
the class RuleAndRuleSetGetTest method run.
@Test
public void run() throws Exception {
getRuleScriptFiles().forEach((name, content) -> {
ValidationRuleDTO rule = null;
try {
rule = module.getRuleByName(name);
} catch (IndyClientException e) {
logger.error("Exception happened!", e);
}
assertNotNull(rule);
assertThat(rule.getName(), equalTo(name));
assertNotNull(rule.getSpec());
assertThat(rule.getSpec().length() > 0, equalTo(true));
});
getRuleSets().forEach((name, set) -> {
ValidationRuleSet ruleSet = null;
try {
ruleSet = module.getRuleSetByName(name);
} catch (IndyClientException e) {
logger.error("Exception happened!", e);
}
assertNotNull(ruleSet);
assertThat(ruleSet.getName(), containsString(name));
assertThat(ruleSet.getStoreKeyPattern(), equalTo(RULESET_TEST_STOREKEY));
});
ValidationRuleSet ruleSet = null;
try {
ruleSet = module.getRuleSetByStoreKey(StoreKey.fromString(RULESET_TEST_STOREKEY));
} catch (IndyClientException e) {
logger.error("Exception happened!", e);
}
assertNotNull(ruleSet);
assertThat(ruleSet.getName(), containsString(RULESET_TEST_NAME));
assertThat(ruleSet.getStoreKeyPattern(), equalTo(RULESET_TEST_STOREKEY));
List<String> ruleNames = module.getAllRules();
assertThat(ruleNames.size(), equalTo(2));
assertThat(ruleNames, CoreMatchers.hasItems(RULE1, RULE2));
List<String> ruleSetNames = module.getAllRuleSets();
assertThat(ruleSetNames.size(), equalTo(1));
assertThat(ruleSetNames.get(0), containsString("test"));
}
Aggregations