Search in sources :

Example 21 with IndyClientException

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();
    }
}
Also used : IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) HttpHead(org.apache.http.client.methods.HttpHead) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 22 with IndyClientException

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;
    }
}
Also used : StatusLine(org.apache.http.StatusLine) ZipInputStream(java.util.zip.ZipInputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResources(org.commonjava.indy.client.core.helper.HttpResources) HttpResponse(org.apache.http.HttpResponse) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IndyResponseErrorDetails(org.commonjava.indy.client.core.IndyResponseErrorDetails) IOException(java.io.IOException)

Example 23 with IndyClientException

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());
}
Also used : IndyRepoChangelogClientModule(org.commonjava.indy.changelog.client.IndyRepoChangelogClientModule) ChangeEvent(org.commonjava.auditquery.history.ChangeEvent) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 24 with IndyClientException

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());
    }
}
Also used : HttpResources(org.commonjava.indy.client.core.helper.HttpResources) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IOException(java.io.IOException) Logger(org.slf4j.Logger)

Example 25 with IndyClientException

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"));
}
Also used : ValidationRuleDTO(org.commonjava.indy.promote.model.ValidationRuleDTO) IndyClientException(org.commonjava.indy.client.core.IndyClientException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ValidationRuleSet(org.commonjava.indy.promote.model.ValidationRuleSet) Test(org.junit.Test)

Aggregations

IndyClientException (org.commonjava.indy.client.core.IndyClientException)31 Test (org.junit.Test)21 InputStream (java.io.InputStream)17 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)13 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)12 HostedRepository (org.commonjava.indy.model.core.HostedRepository)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 StoreKey (org.commonjava.indy.model.core.StoreKey)9 IOException (java.io.IOException)6 HttpResources (org.commonjava.indy.client.core.helper.HttpResources)5 HttpResponse (org.apache.http.HttpResponse)3 StatusLine (org.apache.http.StatusLine)3 AbstractIndyFunctionalTest (org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest)3 Logger (org.slf4j.Logger)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 CountingInputStream (org.apache.commons.io.input.CountingInputStream)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPost (org.apache.http.client.methods.HttpPost)2 IndyClientHttp (org.commonjava.indy.client.core.IndyClientHttp)2