Search in sources :

Example 11 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class NPMReadonlyHostedDeleteMetadataTest method test.

@Test
public void test() throws Exception {
    // Prepare
    HostedRepository repo = new HostedRepository(NPM_PKG_KEY, repoName);
    repo = client.stores().create(repo, "adding npm hosted repo", HostedRepository.class);
    StoreKey storeKey = repo.getKey();
    client.content().store(storeKey, tarballPath, readTestResourceAsStream("helper-validator-identifier-7.10.4.tgz"));
    client.content().store(storeKey, packagePath, new ByteArrayInputStream(staleMeta.getBytes()));
    // Set readonly
    repo.setReadonly(true);
    client.stores().update(repo, "set read-only");
    // Create group G
    Group group = new Group(NPM_PKG_KEY, groupName, repo.getKey());
    client.stores().create(group, "adding npm group G", Group.class);
    // get from both A and G
    assertContent(repo, packagePath, staleMeta);
    assertContent(group, packagePath, staleMeta);
    // Extra case: delete non-metadata file is not allowed
    try {
        client.content().delete(storeKey, tarballPath);
    } catch (IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(ApplicationStatus.METHOD_NOT_ALLOWED.code()));
    }
    // Delete metadata from repo A
    IndyClientHttp http = client.module(IndyRawHttpModule.class).getHttp();
    http.deleteCache(client.content().contentPath(storeKey, packagePath) + "/package.json");
    assertExistence(repo, packagePath, false);
    assertExistence(group, packagePath, false);
    // Get metadata again
    try (InputStream is = client.content().get(storeKey, packagePath)) {
        // String actual = IOUtils.toString( is );
        // System.out.println( ">>>>\n" + actual );
        assertTarballUrl(is, "/api/content/npm/hosted/test/" + tarballPath);
    }
    try (InputStream is = client.content().get(group.getKey(), packagePath)) {
        // String actual = IOUtils.toString( is );
        // System.out.println( ">>>>\n" + actual );
        assertTarballUrl(is, "/api/content/npm/group/G/" + tarballPath);
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IndyClientHttp(org.commonjava.indy.client.core.IndyClientHttp) IndyRawHttpModule(org.commonjava.indy.client.core.module.IndyRawHttpModule) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 12 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class NPMRemoteDeleteFileTest method test.

@Test
public void test() throws Exception {
    final String content = "This is a test: " + System.nanoTime();
    InputStream stream = new ByteArrayInputStream(content.getBytes());
    final String path = "jquery";
    final String repoName = "test-remote";
    server.expect(server.formatUrl(repoName, path), 200, stream);
    RemoteRepository remoteRepository = new RemoteRepository(NPM_PKG_KEY, repoName, server.formatUrl(repoName));
    remoteRepository = client.stores().create(remoteRepository, "adding npm remote repo", RemoteRepository.class);
    StoreKey storeKey = remoteRepository.getKey();
    assertThat(client.content().exists(storeKey, path), equalTo(true));
    try {
        client.content().delete(storeKey, path);
    } catch (IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(ApplicationStatus.BAD_REQUEST.code()));
    }
    assertThat(client.content().exists(storeKey, path), equalTo(true));
    stream.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 13 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class NPMRemoteStoreFileTest method test.

@Test
public void test() throws Exception {
    final String content = "This is a test: " + System.nanoTime();
    InputStream stream = new ByteArrayInputStream(content.getBytes());
    final String path = "jquery";
    final String realPath = "jquery/package.json";
    final String repoName = "test-remote";
    RemoteRepository remoteRepository = new RemoteRepository(NPM_PKG_KEY, repoName, server.formatUrl(repoName));
    remoteRepository = client.stores().create(remoteRepository, "adding npm remote repo", RemoteRepository.class);
    StoreKey storeKey = remoteRepository.getKey();
    assertThat(client.content().exists(storeKey, path), equalTo(false));
    try {
        client.content().store(storeKey, path, stream);
    } catch (IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(ApplicationStatus.BAD_REQUEST.code()));
    }
    // for remote, list path of 'jquery/' will be stored
    assertThat(client.content().exists(storeKey, realPath), equalTo(false));
    stream.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

Example 14 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class CallableDelayedDownload method call.

public CallableDelayedDownload call() {
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName(getClass().getSimpleName() + ": " + oldName);
        Logger logger = LoggerFactory.getLogger(getClass());
        logger.info("Starting: {}", Thread.currentThread().getName());
        if (initialDelay > 0) {
            logger.info("Delaying: {}", initialDelay);
            try {
                Thread.sleep(initialDelay);
            } catch (final InterruptedException e) {
                return this;
            }
        }
        startTime = System.nanoTime();
        content = new ByteArrayOutputStream();
        logger.info("Trying: {}", Thread.currentThread().getName());
        try (InputStream in = client.content().get(key.getType(), key.getName(), path)) {
            if (in == null) {
                missing = true;
            } else {
                CountingInputStream cin = new CountingInputStream(in);
                IOUtils.copy(cin, content);
                logger.debug("Read: {} bytes", cin.getByteCount());
            }
        } catch (IndyClientException | IOException e) {
            e.printStackTrace();
            missing = true;
        }
        endTime = System.nanoTime();
        latch.countDown();
        logger.info("Stopping: {}", Thread.currentThread().getName());
        return this;
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : CountingInputStream(org.apache.commons.io.input.CountingInputStream) InputStream(java.io.InputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IndyClientException(org.commonjava.indy.client.core.IndyClientException) IOException(java.io.IOException) Logger(org.slf4j.Logger)

Example 15 with IndyClientException

use of org.commonjava.indy.client.core.IndyClientException in project indy by Commonjava.

the class RemoteRepoHeadErrorTest method run.

@Test
public void run() throws Exception {
    final String repo1 = "repo1";
    final String path = "org/foo/bar/maven-metadata.xml";
    server.registerException(server.formatUrl(repo1, path), "upstream error");
    RemoteRepository remote1 = new RemoteRepository(repo1, server.formatUrl(repo1));
    remote1.setMetadata(Location.CONNECTION_TIMEOUT_SECONDS, Integer.toString(1));
    remote1 = client.stores().create(remote1, "adding remote", RemoteRepository.class);
    try (InputStream is = client.content().get(remote, repo1, path)) {
    } catch (final IndyClientException e) {
        assertThat(e.getStatusCode(), equalTo(HttpStatus.SC_BAD_GATEWAY));
    }
}
Also used : InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyClientException(org.commonjava.indy.client.core.IndyClientException) Test(org.junit.Test) AbstractContentManagementTest(org.commonjava.indy.ftest.core.AbstractContentManagementTest)

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