List of usage examples for org.apache.http.client.fluent Request Put
public static Request Put(final String uri)
From source file:com.softinstigate.restheart.integrationtest.PatchCollectionIT.java
@Test public void testPatchCollection() throws Exception { try {/*w ww.j a v a 2s . c o m*/ Response resp; // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); // try to patch without body resp = adminExecutor.execute(Request.Patch(collectionTmpUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check patch tmp doc without etag", resp, HttpStatus.SC_NOT_ACCEPTABLE); // try to patch without etag resp = adminExecutor.execute(Request.Patch(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check patch tmp doc without etag", resp, HttpStatus.SC_CONFLICT); // try to patch with wrong etag resp = adminExecutor.execute(Request.Patch(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, "pippoetag")); check("check patch tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED); resp = adminExecutor.execute(Request.Get(collectionTmpUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); JsonObject content = JsonObject.readFrom(resp.returnContent().asString()); String etag = content.get("_etag").asString(); // try to patch with correct etag resp = adminExecutor.execute(Request.Patch(collectionTmpUri).bodyString("{b:2}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, etag)); check("check patch tmp doc with correct etag", resp, HttpStatus.SC_OK); resp = adminExecutor.execute(Request.Get(collectionTmpUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); content = JsonObject.readFrom(resp.returnContent().asString()); assertNotNull("check patched content", content.get("a")); assertNotNull("check patched content", content.get("b")); assertTrue("check patched content", content.get("a").asInt() == 1 && content.get("b").asInt() == 2); etag = content.get("_etag").asString(); // try to patch reserved field name resp = adminExecutor.execute(Request.Patch(collectionTmpUri).bodyString("{_embedded:\"a\"}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, etag)); content = JsonObject.readFrom(resp.returnContent().asString()); assertNotNull("check patched content", content.get("_embedded").asObject().get("rh:warnings").asArray()); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:org.restheart.test.integration.PostCollectionIT.java
@Test public void testPostCollection() throws Exception { try {//from w w w . j a va 2s . c om Response resp; // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); resp = adminExecutor.execute(Request.Post(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check post coll1", resp, HttpStatus.SC_CREATED); // *** POST tmpcoll resp = adminExecutor.execute(Request.Post(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); HttpResponse httpResp = check("check post coll1 again", resp, HttpStatus.SC_CREATED); Header[] headers = httpResp.getHeaders(Headers.LOCATION_STRING); assertNotNull("check loocation header", headers); assertTrue("check loocation header", headers.length > 0); Header locationH = headers[0]; String location = locationH.getValue(); URI createdDocUri = URI.create(location); resp = adminExecutor.execute(Request.Get(createdDocUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); JsonObject content = JsonObject.readFrom(resp.returnContent().asString()); assertNotNull("check created doc content", content.get("_id")); assertNotNull("check created doc content", content.get("_etag")); assertNotNull("check created doc content", content.get("a")); assertTrue("check created doc content", content.get("a").asInt() == 1); String _id = content.get("_id").asObject().get("$oid").asString(); String _etag = content.get("_etag").asObject().get("$oid").asString(); // try to post with _id without etag resp = adminExecutor.execute( Request.Post(collectionTmpUri).bodyString("{_id:{\"$oid\":\"" + _id + "\"}, a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check post created doc without etag", resp, HttpStatus.SC_CONFLICT); // try to post with wrong etag resp = adminExecutor.execute( Request.Post(collectionTmpUri).bodyString("{_id:{\"$oid\":\"" + _id + "\"}, a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, "pippoetag")); check("check put created doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED); // try to post with correct etag resp = adminExecutor.execute( Request.Post(collectionTmpUri).bodyString("{_id:{\"$oid\":\"" + _id + "\"}, a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, _etag)); check("check post created doc with correct etag", resp, HttpStatus.SC_OK); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:com.softinstigate.restheart.integrationtest.PutIndexIT.java
@Test public void testPutDocument() throws Exception { try {/*from ww w .j a v a 2s . com*/ Response resp; // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); // *** PUT wrong index //resp = adminExecutor.execute(Request.Put(indexTmpUri).bodyString("{a:1}", halCT).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); //check("check put wrong index", resp, HttpStatus.SC_NOT_ACCEPTABLE); // try to put without etag resp = adminExecutor.execute( Request.Put(indexTmpUri).bodyString("{ keys: {a:1,b:2}, ops: { name: \"ciao\"} }", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put correct index", resp, HttpStatus.SC_CREATED); resp = adminExecutor.execute(Request.Get(indexesTmpUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); HttpResponse httpResp = resp.returnResponse(); junit.framework.Assert.assertNotNull(httpResp); HttpEntity entity = httpResp.getEntity(); junit.framework.Assert.assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); junit.framework.Assert.assertNotNull(statusLine); junit.framework.Assert.assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); junit.framework.Assert.assertNotNull("content type not null", entity.getContentType()); junit.framework.Assert.assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue()); String content = EntityUtils.toString(entity); junit.framework.Assert.assertNotNull("", content); JsonObject json = null; try { json = JsonObject.readFrom(content); } catch (Throwable t) { junit.framework.Assert.fail("parsing received json"); } junit.framework.Assert.assertNotNull("check json not null", json); junit.framework.Assert.assertNotNull("check not null _returned property", json.get("_returned")); junit.framework.Assert.assertNotNull("check not null _size property", json.get("_size")); junit.framework.Assert.assertEquals("check _size value to be 5", 5, json.get("_size").asInt()); junit.framework.Assert.assertEquals("check _returned value to be 5", 5, json.get("_returned").asInt()); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:com.softinstigate.restheart.integrationtest.PostCollectionIT.java
@Test public void testPostCollection() throws Exception { try {//from ww w. jav a2 s.co m Response resp; // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); resp = adminExecutor.execute(Request.Post(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check post coll1", resp, HttpStatus.SC_CREATED); // *** POST tmpcoll resp = adminExecutor.execute(Request.Post(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); HttpResponse httpResp = check("check post coll1 again", resp, HttpStatus.SC_CREATED); Header[] headers = httpResp.getHeaders(Headers.LOCATION_STRING); assertNotNull("check loocation header", headers); assertTrue("check loocation header", headers.length > 0); Header locationH = headers[0]; String location = locationH.getValue(); URI createdDocUri = URI.create(location); resp = adminExecutor.execute(Request.Get(createdDocUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); JsonObject content = JsonObject.readFrom(resp.returnContent().asString()); assertNotNull("check created doc content", content.get("_id")); assertNotNull("check created doc content", content.get("_etag")); assertNotNull("check created doc content", content.get("a")); assertTrue("check created doc content", content.get("a").asInt() == 1); String _id = content.get("_id").asString(); String _etag = content.get("_etag").asString(); // try to post with _id without etag resp = adminExecutor .execute(Request.Post(collectionTmpUri).bodyString("{_id:\"" + _id + "\", a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check post created doc without etag", resp, HttpStatus.SC_CONFLICT); // try to post with wrong etag resp = adminExecutor .execute(Request.Post(collectionTmpUri).bodyString("{_id:\"" + _id + "\", a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, "pippoetag")); check("check put created doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED); // try to post with correct etag resp = adminExecutor .execute(Request.Post(collectionTmpUri).bodyString("{_id:\"" + _id + "\", a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, _etag)); check("check post created doc with correct etag", resp, HttpStatus.SC_OK); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:org.restheart.test.integration.PutIndexIT.java
@Test public void testPutDocument() throws Exception { try {//from ww w . ja v a2 s. co m Response resp; // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); // *** PUT wrong index //resp = adminExecutor.execute(Request.Put(indexTmpUri).bodyString("{a:1}", halCT).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); //check("check put wrong index", resp, HttpStatus.SC_NOT_ACCEPTABLE); // try to put without etag resp = adminExecutor.execute( Request.Put(indexTmpUri).bodyString("{ keys: {a:1,b:2}, ops: { name: \"ciao\"} }", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put correct index", resp, HttpStatus.SC_CREATED); resp = adminExecutor.execute(Request.Get(indexesTmpUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp); HttpEntity entity = httpResp.getEntity(); assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); assertNotNull("content type not null", entity.getContentType()); assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue()); String content = EntityUtils.toString(entity); assertNotNull("", content); JsonObject json = null; try { json = JsonObject.readFrom(content); } catch (Throwable t) { fail("parsing received json"); } assertNotNull("check json not null", json); assertNotNull("check not null _returned property", json.get("_returned")); assertNotNull("check not null _size property", json.get("_size")); assertEquals("check _size value to be 4", 4, json.get("_size").asInt()); assertEquals("check _returned value to be 4", 4, json.get("_returned").asInt()); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:org.debux.webmotion.server.tools.RequestBuilder.java
/** * @return a put request */ public Request Put() throws URISyntaxException { return Request.Put(this.build()); }
From source file:org.restheart.test.integration.DocIdTypeIT.java
@Test public void testPostCollectionInt() throws Exception { try {// w w w . j a v a 2 s. com Response resp; // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); URI collectionTmpUriInt = buildURI("/" + dbTmpName + "/" + collectionTmpName, new NameValuePair[] { new BasicNameValuePair(DOC_ID_TYPE_KEY, DOC_ID_TYPE.NUMBER.name()) }); // *** POST tmpcoll resp = adminExecutor.execute(Request.Post(collectionTmpUriInt).bodyString("{_id:100, a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); HttpResponse httpResp = check("check post coll1 again", resp, HttpStatus.SC_CREATED); Header[] headers = httpResp.getHeaders(Headers.LOCATION_STRING); assertNotNull("check loocation header", headers); assertTrue("check loocation header", headers.length > 0); Header locationH = headers[0]; String location = locationH.getValue(); //assertTrue("check location header value", location.endsWith("/100?id_type=NUMBER")); URI createdDocUri = URI.create(location); resp = adminExecutor.execute(Request.Get(createdDocUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); JsonObject content = JsonObject.readFrom(resp.returnContent().asString()); assertTrue("check created doc content", content.get("_id").asInt() == 100); assertNotNull("check created doc content", content.get("_etag")); assertNotNull("check created doc content", content.get("a")); assertTrue("check created doc content", content.get("a").asInt() == 1); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:org.restheart.test.integration.JsonPathConditionsCheckerIT.java
@Before public void createDBandCollection() throws Exception { Response resp;//from ww w. ja v a2 s. co m // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put mytmpdb", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll final String METADATA = getResourceFile("metadata/jsonpath-users.json"); resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString(METADATA, halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put mytmpdb.tmpcoll", resp, HttpStatus.SC_CREATED); }
From source file:org.mule.listener.HttpListenerMethodRoutingTestCase.java
@Test public void notAllowedCustomMethodReturns404() throws Exception { final String url = String.format("http://localhost:%s/%s", listenPort2.getNumber(), path.getValue()); final Response response = Request.Put(url).connectTimeout(1000).execute(); final HttpResponse httpResponse = response.returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode(), is(404)); }
From source file:com.jaspersoft.studio.server.utils.HttpUtils.java
public static Request put(String url, ServerProfile sp) throws HttpException, IOException { System.out.println(url);/*from ww w . ja va2s .c o m*/ return HttpUtils.setRequest(Request.Put(url), sp); }