|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package wvlet.airframe.http |
| 15 | + |
| 16 | +import wvlet.airspec.AirSpec |
| 17 | + |
| 18 | +class HttpRequestTest extends AirSpec { |
| 19 | + |
| 20 | + test("accept application/msgpack") { |
| 21 | + val r = Http.POST("/").withAcceptMsgPack |
| 22 | + r.acceptsMsgPack shouldBe true |
| 23 | + r.acceptsJson shouldBe false |
| 24 | + } |
| 25 | + |
| 26 | + test("accept application/x-msgpack") { |
| 27 | + val r = Http.POST("/").withAccept("application/x-msgpack") |
| 28 | + r.acceptsMsgPack shouldBe true |
| 29 | + r.acceptsJson shouldBe false |
| 30 | + } |
| 31 | + |
| 32 | + test("accept application/json;encoding=utf-8") { |
| 33 | + val r = Http.POST("/").withAcceptJson |
| 34 | + r.acceptsJson shouldBe true |
| 35 | + r.acceptsMsgPack shouldBe false |
| 36 | + } |
| 37 | + |
| 38 | + test("accept application/json") { |
| 39 | + val r = Http.POST("/").withAccept("application/json") |
| 40 | + r.acceptsJson shouldBe true |
| 41 | + r.acceptsMsgPack shouldBe false |
| 42 | + } |
| 43 | + |
| 44 | + test("content-type application/msgpack") { |
| 45 | + val r = Http.POST("/").withContentTypeMsgPack |
| 46 | + r.isContentTypeMsgPack shouldBe true |
| 47 | + r.isContentTypeJson shouldBe false |
| 48 | + } |
| 49 | + |
| 50 | + test("content-type application/x-msgpack") { |
| 51 | + val r = Http.POST("/").withContentType("application/x-msgpack") |
| 52 | + r.isContentTypeMsgPack shouldBe true |
| 53 | + r.isContentTypeJson shouldBe false |
| 54 | + } |
| 55 | + |
| 56 | + test("content-type application/json;encoding=utf-8") { |
| 57 | + val r = Http.POST("/").withContentTypeJson |
| 58 | + r.isContentTypeJson shouldBe true |
| 59 | + r.isContentTypeMsgPack shouldBe false |
| 60 | + } |
| 61 | + |
| 62 | + test("content-type application/json") { |
| 63 | + val r = Http.POST("/").withContentType("application/json") |
| 64 | + r.isContentTypeJson shouldBe true |
| 65 | + r.isContentTypeMsgPack shouldBe false |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments