use of org.apache.http.client.methods.HttpDelete in project indy by Commonjava.
the class IndyClientHttp method delete.
public void delete(final String path, final int... responseCodes) throws IndyClientException {
connect();
HttpDelete delete = null;
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
try {
client = newClient();
delete = newDelete(buildUrl(baseUrl, path));
response = client.execute(delete, newContext());
final StatusLine sl = response.getStatusLine();
if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
throw new IndyClientException(sl.getStatusCode(), "Error deleting: %s.\n%s", path, new IndyResponseErrorDetails(response));
}
} catch (final IOException e) {
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
cleanupResources(delete, response, client);
}
}
use of org.apache.http.client.methods.HttpDelete in project stanbol by apache.
the class SessionTest method testCRUD.
@Test
public void testCRUD() throws Exception {
RequestExecutor request;
// The needed Web resources to GET from.
executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", KRFormat.TURTLE)).assertStatus(200);
log.info("Request: " + SESSION_URI + " ... DONE");
String tempScopeUri = SESSION_URI + "/" + getClass().getCanonicalName() + "-" + System.currentTimeMillis();
// Scope should not be there
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(404);
log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
// Create scope
executor.execute(builder.buildOtherRequest(new HttpPut(builder.buildUrl(tempScopeUri))));
log.info("PUT Request: " + tempScopeUri + " ... DONE");
// Scope should be there now
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(200).assertContentContains(tempScopeUri);
log.info("Request: " + tempScopeUri + " ... DONE");
// TODO the U of CRUD
// Delete scope
executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl(tempScopeUri))));
log.info("DELETE Request: " + tempScopeUri + " ... DONE");
// Scope should not be there
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(404);
log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
}
use of org.apache.http.client.methods.HttpDelete in project stanbol by apache.
the class ScopeTest method testCRUD.
@Test
public void testCRUD() throws Exception {
RequestExecutor request;
// The needed Web resources to GET from.
executor.execute(builder.buildGetRequest(BASE_SCOPES_URI).withHeader("Accept", KRFormat.TURTLE)).assertStatus(200);
log.info("Request: " + BASE_SCOPES_URI + " ... DONE");
String tempScopeUri = BASE_SCOPES_URI + "/" + getClass().getCanonicalName() + "-" + System.currentTimeMillis();
// Scope should not be there
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(404);
log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
// Create scope
executor.execute(builder.buildOtherRequest(new HttpPut(builder.buildUrl(tempScopeUri))));
log.info("PUT Request: " + tempScopeUri + " ... DONE");
// Scope should be there now
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(200).assertContentContains(tempScopeUri);
log.info("Request: " + tempScopeUri + " ... DONE");
// TODO the U of CRUD
// Delete scope
executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl(tempScopeUri))));
log.info("DELETE Request: " + tempScopeUri + " ... DONE");
// Scope should not be there
request = executor.execute(builder.buildGetRequest(tempScopeUri).withHeader("Accept", KRFormat.TURTLE));
request.assertStatus(404);
log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
}
use of org.apache.http.client.methods.HttpDelete in project stanbol by apache.
the class EntityhubTest method testEntityDelete.
private void testEntityDelete() throws IOException {
String stanbolProjectUri = "http://stanbol.apache.org";
Request request = builder.buildOtherRequest(new HttpDelete(builder.buildUrl("/entityhub/entity", "id", stanbolProjectUri)));
RequestExecutor re = executor.execute(request);
re.assertStatus(200);
}
use of org.apache.http.client.methods.HttpDelete in project stanbol by apache.
the class EntityhubTest method testQueries.
@Test
public void testQueries() throws IOException, JSONException {
//first load the data for the rquery test
URL url = EntityhubTest.class.getClassLoader().getResource("apache-project-doap-files.zip");
Assert.assertNotNull(url);
File f;
try {
f = new File(url.toURI());
} catch (URISyntaxException e) {
f = new File(url.getPath());
}
Assert.assertNotNull(f.isFile());
ZipFile archive = new ZipFile(f);
try {
for (Enumeration<? extends ZipEntry> e = archive.entries(); e.hasMoreElements(); ) {
ZipEntry entry = e.nextElement();
log.debug(" - uploading {} to entityhub", entry);
RequestExecutor re = executor.execute(buildImportRdfData(archive.getInputStream(entry), RDF_XML, false, null));
//assert that the entity was created (or already existed)
//some projects seams to have more than a single doap file
int status = re.getResponse().getStatusLine().getStatusCode();
Assert.assertTrue("Unable to add '" + entry.getName() + "'! Status:" + re.getResponse().getStatusLine(), status == 200 || status == 304);
}
} finally {
archive.close();
}
testFindNameQuery();
testFindWildcards();
testFindLimitAndOffsetQuery();
testFieldQueryTextConstraints();
//finally delete all added entity
RequestExecutor re = executor.execute(builder.buildOtherRequest(new HttpDelete(builder.buildUrl("/entityhub/entity", "id", "*"))));
re.assertStatus(200);
}
Aggregations