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);
}
}
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();
}
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();
}
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);
}
}
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));
}
}
Aggregations