use of org.apache.http.Header in project gerrit by GerritCodeReview.
the class CorsIT method check.
private RestResponse check(String url, boolean accept, String origin) throws Exception {
Header hdr = new BasicHeader(ORIGIN, origin);
RestResponse r = adminRestSession.getWithHeader(url, hdr);
r.assertOK();
checkCors(r, accept, origin);
return r;
}
use of org.apache.http.Header in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method rebuildEntitiesCreatedByImpersonation.
@Test
public void rebuildEntitiesCreatedByImpersonation() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey();
PatchSet.Id psId = new PatchSet.Id(id, 1);
String prefix = "/changes/" + id + "/revisions/current/";
// For each of the entities that have a real user field, create one entity
// without impersonation and one with.
CommentInput ci = new CommentInput();
ci.path = Patch.COMMIT_MSG;
ci.side = Side.REVISION;
ci.line = 1;
ci.message = "comment without impersonation";
ReviewInput ri = new ReviewInput();
ri.label("Code-Review", -1);
ri.message = "message without impersonation";
ri.drafts = DraftHandling.KEEP;
ri.comments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
userRestSession.post(prefix + "review", ri).assertOK();
DraftInput di = new DraftInput();
di.path = Patch.COMMIT_MSG;
di.side = Side.REVISION;
di.line = 1;
di.message = "draft without impersonation";
userRestSession.put(prefix + "drafts", di).assertCreated();
allowRunAs();
try {
Header runAs = new BasicHeader("X-Gerrit-RunAs", user.id.toString());
ci.message = "comment with impersonation";
ri.message = "message with impersonation";
ri.label("Code-Review", 1);
adminRestSession.postWithHeader(prefix + "review", ri, runAs).assertOK();
di.message = "draft with impersonation";
adminRestSession.putWithHeader(prefix + "drafts", runAs, di).assertCreated();
} finally {
removeRunAs();
}
List<ChangeMessage> msgs = Ordering.natural().onResultOf(ChangeMessage::getWrittenOn).sortedCopy(db.changeMessages().byChange(id));
assertThat(msgs).hasSize(3);
assertThat(msgs.get(1).getMessage()).endsWith("message without impersonation");
assertThat(msgs.get(1).getAuthor()).isEqualTo(user.id);
assertThat(msgs.get(1).getRealAuthor()).isEqualTo(user.id);
assertThat(msgs.get(2).getMessage()).endsWith("message with impersonation");
assertThat(msgs.get(2).getAuthor()).isEqualTo(user.id);
assertThat(msgs.get(2).getRealAuthor()).isEqualTo(admin.id);
List<PatchSetApproval> psas = db.patchSetApprovals().byChange(id).toList();
assertThat(psas).hasSize(1);
assertThat(psas.get(0).getLabel()).isEqualTo("Code-Review");
assertThat(psas.get(0).getValue()).isEqualTo(1);
assertThat(psas.get(0).getAccountId()).isEqualTo(user.id);
assertThat(psas.get(0).getRealAccountId()).isEqualTo(admin.id);
Ordering<PatchLineComment> commentOrder = Ordering.natural().onResultOf(PatchLineComment::getWrittenOn);
List<PatchLineComment> drafts = commentOrder.sortedCopy(db.patchComments().draftByPatchSetAuthor(psId, user.id));
assertThat(drafts).hasSize(2);
assertThat(drafts.get(0).getMessage()).isEqualTo("draft without impersonation");
assertThat(drafts.get(0).getAuthor()).isEqualTo(user.id);
assertThat(drafts.get(0).getRealAuthor()).isEqualTo(user.id);
assertThat(drafts.get(1).getMessage()).isEqualTo("draft with impersonation");
assertThat(drafts.get(1).getAuthor()).isEqualTo(user.id);
assertThat(drafts.get(1).getRealAuthor()).isEqualTo(admin.id);
List<PatchLineComment> pub = commentOrder.sortedCopy(db.patchComments().publishedByPatchSet(psId));
assertThat(pub).hasSize(2);
assertThat(pub.get(0).getMessage()).isEqualTo("comment without impersonation");
assertThat(pub.get(0).getAuthor()).isEqualTo(user.id);
assertThat(pub.get(0).getRealAuthor()).isEqualTo(user.id);
assertThat(pub.get(1).getMessage()).isEqualTo("comment with impersonation");
assertThat(pub.get(1).getAuthor()).isEqualTo(user.id);
assertThat(pub.get(1).getRealAuthor()).isEqualTo(admin.id);
}
use of org.apache.http.Header in project lucene-solr by apache.
the class NoCacheHeaderTest method doCacheControl.
@Override
protected void doCacheControl(String method) throws Exception {
HttpRequestBase m = getSelectMethod(method);
HttpResponse response = getClient().execute(m);
checkResponseBody(method, response);
Header head = response.getFirstHeader("Cache-Control");
assertNull("We got a cache-control header in response", head);
head = response.getFirstHeader("Expires");
assertNull("We got an Expires header in response", head);
}
use of org.apache.http.Header in project lucene-solr by apache.
the class ResponseHeaderTest method testHttpResponse.
@Test
public void testHttpResponse() throws SolrServerException, IOException {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
HttpClient httpClient = client.getHttpClient();
URI uri = URI.create(client.getBaseURL() + "/withHeaders?q=*:*");
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = httpClient.execute(httpGet);
Header[] headers = response.getAllHeaders();
boolean containsWarningHeader = false;
for (Header header : headers) {
if ("Warning".equals(header.getName())) {
containsWarningHeader = true;
assertEquals("This is a test warning", header.getValue());
break;
}
}
assertTrue("Expected header not found", containsWarningHeader);
}
use of org.apache.http.Header in project lucene-solr by apache.
the class CacheHeaderTest method doLastModified.
@Override
protected void doLastModified(String method) throws Exception {
// We do a first request to get the last modified
// This must result in a 200 OK response
HttpRequestBase get = getSelectMethod(method);
HttpResponse response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Got no response code 200 in initial request", 200, response.getStatusLine().getStatusCode());
Header head = response.getFirstHeader("Last-Modified");
assertNotNull("We got no Last-Modified header", head);
Date lastModified = DateUtils.parseDate(head.getValue());
// If-Modified-Since tests
get = getSelectMethod(method);
get.addHeader("If-Modified-Since", DateUtils.formatDate(new Date()));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 304 NotModified response with current date", 304, response.getStatusLine().getStatusCode());
get = getSelectMethod(method);
get.addHeader("If-Modified-Since", DateUtils.formatDate(new Date(lastModified.getTime() - 10000)));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 200 OK response with If-Modified-Since in the past", 200, response.getStatusLine().getStatusCode());
// If-Unmodified-Since tests
get = getSelectMethod(method);
get.addHeader("If-Unmodified-Since", DateUtils.formatDate(new Date(lastModified.getTime() - 10000)));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 412 Precondition failed with If-Unmodified-Since in the past", 412, response.getStatusLine().getStatusCode());
get = getSelectMethod(method);
get.addHeader("If-Unmodified-Since", DateUtils.formatDate(new Date()));
response = getClient().execute(get);
checkResponseBody(method, response);
assertEquals("Expected 200 OK response with If-Unmodified-Since and current date", 200, response.getStatusLine().getStatusCode());
}
Aggregations