├── logo.png ├── .gitignore ├── .travis.yml ├── .rultor.yml ├── LICENSE.txt ├── settings.xml.asc └── src ├── main └── java │ └── hr │ └── com │ └── vgv │ └── verano │ └── http │ ├── package-info.java │ ├── mock │ ├── package-info.java │ ├── MatchingCriteria.java │ ├── BodyMatch.java │ ├── PathMatch.java │ ├── Answer.java │ ├── MethodMatch.java │ ├── RequestUriMatch.java │ ├── HeaderMatch.java │ ├── FormParamMatch.java │ ├── QueryParamMatch.java │ ├── GetMatch.java │ ├── PutMatch.java │ ├── PostMatch.java │ ├── DeleteMatch.java │ └── MultiMatching.java │ ├── wire │ ├── package-info.java │ ├── apache │ │ ├── package-info.java │ │ ├── ApacheContext.java │ │ ├── ApacheClient.java │ │ ├── ApacheHeaders.java │ │ ├── SslTrusted.java │ │ └── Proxy.java │ └── VerificationWire.java │ ├── parts │ ├── package-info.java │ ├── body │ │ ├── package-info.java │ │ ├── XmlBody.java │ │ └── HtmlBody.java │ ├── headers │ │ ├── package-info.java │ │ ├── Accept.java │ │ ├── ContentType.java │ │ ├── Authorization.java │ │ └── BasicAuth.java │ └── Method.java │ ├── request │ ├── package-info.java │ ├── Get.java │ ├── Put.java │ ├── Post.java │ └── Delete.java │ ├── response │ ├── package-info.java │ ├── FailWith.java │ └── ReasonPhrase.java │ ├── Verification.java │ ├── XmlSource.java │ ├── HtmlSource.java │ ├── JsonSource.java │ ├── Wire.java │ ├── DictOf.java │ ├── JoinedDict.java │ ├── KvpOf.java │ └── Kvp.java └── test └── java └── hr └── com └── vgv └── verano └── http ├── package-info.java ├── wire ├── package-info.java ├── apache │ ├── package-info.java │ ├── SslTrustedTest.java │ └── ProxyTest.java ├── VerificationWireTest.java └── ExpandedWireTest.java ├── parts ├── package-info.java ├── body │ ├── package-info.java │ ├── Dto.java │ ├── DtoBodyTest.java │ ├── DtoBodyOfTest.java │ ├── XmlBodyOfTest.java │ ├── HtmlBodyOfTest.java │ ├── HtmlBodyTest.java │ ├── XmlBodyTest.java │ └── JsonBodyTest.java ├── headers │ ├── package-info.java │ ├── AcceptTest.java │ ├── CookieTest.java │ ├── BasicAuthTest.java │ ├── ContentTypeTest.java │ ├── AuthorizationTest.java │ └── CookieOfTest.java ├── BodyTest.java ├── MethodTest.java ├── HeaderTest.java ├── QueryParamTest.java ├── RequestUriTest.java ├── QueryParamsTest.java ├── MethodOfTest.java ├── FormParamsOfTest.java ├── QueryParamsOfTest.java ├── QueryParamOfTest.java ├── HeaderOfTest.java ├── FormParamOfTest.java ├── PathTest.java ├── RequestUriOfTest.java ├── BodyOfTest.java ├── FormParamsTest.java └── HeadersTest.java ├── mock ├── package-info.java ├── BodyMatchTest.java ├── PathMatchTest.java ├── RequestUriMatchTest.java ├── HeaderMatchTest.java ├── FormParamMatchTest.java ├── QueryParamMatchTest.java ├── GetMatchTest.java └── PutMatchTest.java ├── request ├── package-info.java └── RequestTest.java └── response ├── package-info.java ├── StatusTest.java ├── ReasonPhraseTest.java ├── StatusOfTest.java └── ReasonPhraseOfTest.java /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vatavuk/verano-http/HEAD/logo.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea 3 | *.iml 4 | /bin 5 | .settings/ 6 | .classpath 7 | .project 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | jdk: 4 | - oraclejdk8 5 | script: 6 | - set -e 7 | - mvn clean install -Pqulice --errors --batch-mode 8 | after_success: 9 | - bash <(curl -s https://codecov.io/bash) 10 | -------------------------------------------------------------------------------- /.rultor.yml: -------------------------------------------------------------------------------- 1 | decrypt: 2 | settings.xml: "repo/settings.xml.asc" 3 | pubring.gpg: "repo/pubring.gpg.asc" 4 | secring.gpg: "repo/secring.gpg.asc" 5 | release: 6 | script: | 7 | mvn versions:set "-DnewVersion=${tag}" 8 | git commit -am "${tag}" 9 | mvn clean deploy -Psonatype -Pqulice -Pexcel-io --settings /home/r/settings.xml 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Vedran Grgo Vatavuk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /settings.xml.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP MESSAGE----- 2 | Version: GnuPG v1 3 | 4 | hQEMA5qETcGag5w6AQgAh2CnxGhH/PnIAKKGgwiy6MHh5gdLPLSBCMQdvGyEdtV9 5 | wegni0Fl/sQZqqY7urDl6Gdbs/WALDzXULvdJWI2+DpDW7GszLZujmR8i4nFGzHW 6 | 2a2mXbPgLwG4+9xEptiWBelMNsPsRpRmxKiv2Dul+o2L/35J2clyU/LmarQ0WLU8 7 | dZhO8wOjFdrZB0wGsZNwZCqEDMIgwRqMi6OujqLcWbBVXeWErSoI9Qgsj5+rwmxH 8 | LretOTOHhDOIkECPKSF2XcFcvGTiqpYcNym6w0eFH7C9cbGs+MbQLwmKEN64rl3P 9 | wHR7X1+MSMd8tU2qTIoF21iwI1HSbwg8iRKphHySMtLBDwGVTWNCH/gB6sQ9JAJi 10 | N/dd+bpWiPD9MFZer5ikOKkJs/iRtn0uiMahyg+DHLoe+LCy+6n1H42XvuvbIROW 11 | JcDY/6eE3t0hYXduyAmsJYvIdBaB2qUe8zPue0qrPCf4oe/oJPZ/YIFWAKZAheIW 12 | kzXiis4tsQ0OSJhrRC1YlcZA3/Pym64Z4TqM1t/yoQpTaTC7kZfSTVsarR1Se7KY 13 | HJTiFC7mxX3MVTXQ2mui45hOJ87ZuVz3gT9oFbl7s9XZgzolc40dj4zeKpWclFYN 14 | Ze3e8fr0OLC7prptlKR8W7fJJp9ioa6wJjzvUA6D8qABv4JY+nRYT49VrS/p9NsM 15 | RN0riuM46rvK7zBb6B0lDEN2ZkrViNGyu2g0M2xnbdlj/IgVtb2SxaetN29/LpKZ 16 | ESSFHimuSiE4pgPEH4s9uxGhRXVryDTSMdDwcRRm39mzW36JUfqT4RMVmGMuZ6+X 17 | hvhHR2DedXCI4PNCtpXTtY9WIzBxGyRUwea4Fh/y9rQ/aS0dtCkqzoXzNVg2wrcK 18 | Dt2TRQnPNGaNW0pqsgWuEaslQsCgLe0tMrDINB98UohGtJecIvholxh0L8IPZ00e 19 | Fl+Dok2zEwunj93VvPoBU64= 20 | =vTtL 21 | -----END PGP MESSAGE----- 22 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http client. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Mock. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.mock; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/wire/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Wire. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.wire; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Verano-http tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/wire/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Wire tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.wire; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http parts. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.parts; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/request/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http request. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.request; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/response/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http response. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.response; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http parts tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.parts; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/body/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http bodies. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.parts.body; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/headers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Headers. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.parts.headers; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/wire/apache/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Apache wire. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.wire.apache; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Verano-http mock tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.mock; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/request/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http request tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.request; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http body tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.parts.body; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/wire/apache/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Wire apache tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.wire.apache; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/headers/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Http body tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.parts.headers; 30 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/response/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Verano-http response tests. 27 | * @since 0.1 28 | */ 29 | package hr.com.vgv.verano.http.response; 30 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/Verification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | /** 27 | * Dictionary verification. 28 | * @since 1.0 29 | */ 30 | public interface Verification { 31 | /** 32 | * Verify dictionary. 33 | * @param dict Dictionary 34 | */ 35 | void verify(Dict dict); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/XmlSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | import com.jcabi.xml.XML; 27 | 28 | /** 29 | * Xml source. 30 | * @since 1.0 31 | */ 32 | public interface XmlSource { 33 | 34 | /** 35 | * Return xml representation of the source. 36 | * @return Xml Xml 37 | */ 38 | XML xml(); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/HtmlSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | import org.jsoup.nodes.Element; 27 | 28 | /** 29 | * Html source. 30 | * @since 1.0 31 | */ 32 | public interface HtmlSource { 33 | /** 34 | * Return source as an html element. 35 | * @return Html Html 36 | */ 37 | Element htmlElement(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/JsonSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | import javax.json.JsonStructure; 27 | 28 | /** 29 | * Json source. 30 | * @since 1.0 31 | */ 32 | public interface JsonSource { 33 | /** 34 | * Return json representation of the source. 35 | * @return Json Json 36 | */ 37 | JsonStructure json(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/Wire.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | import java.io.IOException; 27 | 28 | /** 29 | * Wire for executing requests. 30 | * @since 1.0 31 | */ 32 | public interface Wire { 33 | /** 34 | * Send request. 35 | * @param request Request 36 | * @return Dict Dictionary 37 | * @throws IOException If fails 38 | */ 39 | Dict send(Dict request) throws IOException; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/headers/Accept.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.parts.Header; 27 | 28 | /** 29 | * Accept header. 30 | * @since 1.0 31 | */ 32 | public class Accept extends Header { 33 | /** 34 | * Ctor. 35 | * @param value Header 36 | */ 37 | public Accept(final String value) { 38 | super("Accept", value); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/headers/ContentType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.parts.Header; 27 | 28 | /** 29 | * Content-Type header. 30 | * @since 1.0 31 | */ 32 | public class ContentType extends Header { 33 | /** 34 | * Ctor. 35 | * @param value Header 36 | */ 37 | public ContentType(final String value) { 38 | super("Content-Type", value); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/headers/Authorization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.parts.Header; 27 | 28 | /** 29 | * Authorization header. 30 | * @since 1.0 31 | */ 32 | public class Authorization extends Header { 33 | /** 34 | * Ctor. 35 | * @param value Header 36 | */ 37 | public Authorization(final String value) { 38 | super("Authorization", value); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/MatchingCriteria.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import java.util.Collection; 28 | 29 | /** 30 | * Matching criteria. 31 | * @since 1.0 32 | */ 33 | public interface MatchingCriteria { 34 | 35 | /** 36 | * Apply matching criteria to a dictionary. 37 | * @param dict Dictionary 38 | * @return Errors Errors 39 | */ 40 | Collection apply(Dict dict); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/wire/apache/ApacheContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire.apache; 25 | 26 | import org.apache.http.impl.client.HttpClientBuilder; 27 | 28 | /** 29 | * Context to be attached to apache http client. 30 | * @since 1.0 31 | */ 32 | public interface ApacheContext { 33 | /** 34 | * Apply additional context to http client builder. 35 | * @param builder Builder 36 | * @return HttpClientBuilder Builder 37 | */ 38 | HttpClientBuilder apply(HttpClientBuilder builder); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/BodyMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.parts.Body; 28 | import org.hamcrest.Matcher; 29 | 30 | /** 31 | * Body matching. 32 | * @since 1.0 33 | */ 34 | public class BodyMatch extends HamcrestMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param matcher Matcher 39 | */ 40 | public BodyMatch(final Matcher matcher) { 41 | super((Dict req) -> new Body.Of(req).asString(), matcher); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/PathMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.parts.Path; 28 | import org.hamcrest.Matcher; 29 | 30 | /** 31 | * Path matching. 32 | * @since 1.0 33 | */ 34 | public class PathMatch extends HamcrestMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param matcher Matcher 39 | */ 40 | public PathMatch(final Matcher matcher) { 41 | super((Dict req) -> new Path.Of(req).asString(), matcher); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/Answer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | 28 | /** 29 | * Answer to a request. 30 | * @since 1.0 31 | */ 32 | public interface Answer { 33 | 34 | /** 35 | * Check if answer is applicable for specified request. 36 | * @param request Request 37 | * @return Boolean Boolean 38 | */ 39 | boolean applicable(Dict request); 40 | 41 | /** 42 | * Return response as an answer. 43 | * @return Dict Response 44 | */ 45 | Dict response(); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/MethodMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.parts.Method; 28 | import org.hamcrest.BaseMatcher; 29 | 30 | /** 31 | * Method matching. 32 | * @since 1.0 33 | */ 34 | public class MethodMatch extends HamcrestMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param matcher Matcher 39 | */ 40 | public MethodMatch(final BaseMatcher matcher) { 41 | super((Dict req) -> new Method.Of(req).asString(), matcher); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/RequestUriMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.parts.RequestUri; 28 | import org.hamcrest.Matcher; 29 | 30 | /** 31 | * Request uri matching. 32 | * @since 1.0 33 | */ 34 | public class RequestUriMatch extends HamcrestMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param matcher Matcher 39 | */ 40 | public RequestUriMatch(final Matcher matcher) { 41 | super((Dict req) -> new RequestUri.Of(req).asString(), matcher); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/response/FailWith.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.response; 25 | 26 | import org.cactoos.Text; 27 | 28 | /** 29 | * Fail message. 30 | * @since 1.0 31 | */ 32 | public class FailWith implements Text { 33 | /** 34 | * Message text. 35 | */ 36 | private final String text; 37 | 38 | /** 39 | * Ctor. 40 | * @param text Text message 41 | */ 42 | public FailWith(final String text) { 43 | this.text = text; 44 | } 45 | 46 | @Override 47 | public final String asString() { 48 | return this.text; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/HeaderMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.parts.Header; 28 | import org.hamcrest.Matcher; 29 | 30 | /** 31 | * Header matching. 32 | * @since 1.0 33 | */ 34 | public class HeaderMatch extends HamcrestMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param key Parameter key 39 | * @param matcher Matcher 40 | */ 41 | public HeaderMatch(final String key, final Matcher matcher) { 42 | super((Dict req) -> new Header.Of(key, req).asString(), matcher); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/Dto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | /** 27 | * Dto class. 28 | * @since 1.0 29 | */ 30 | public final class Dto { 31 | 32 | /** 33 | * Property. 34 | */ 35 | private String property; 36 | 37 | /** 38 | * Property getter. 39 | * @return Property Property 40 | */ 41 | public String getProperty() { 42 | return this.property; 43 | } 44 | 45 | /** 46 | * Property setter. 47 | * @param prop Property 48 | */ 49 | public void setProperty(final String prop) { 50 | this.property = prop; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/FormParamMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.parts.FormParam; 28 | import org.hamcrest.Matcher; 29 | 30 | /** 31 | * Form parameter matching. 32 | * @since 1.0 33 | */ 34 | public class FormParamMatch extends HamcrestMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param key Parameter key 39 | * @param matcher Matcher 40 | */ 41 | public FormParamMatch(final String key, final Matcher matcher) { 42 | super((Dict req) -> new FormParam.Of(key, req).asString(), matcher); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/QueryParamMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.parts.QueryParam; 28 | import org.hamcrest.Matcher; 29 | 30 | /** 31 | * Query parameter matching. 32 | * @since 1.0 33 | */ 34 | public class QueryParamMatch extends HamcrestMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param key Parameter key 39 | * @param matcher Matcher 40 | */ 41 | public QueryParamMatch(final String key, final Matcher matcher) { 42 | super((Dict req) -> new QueryParam.Of(key, req).asString(), matcher); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/wire/apache/ApacheClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire.apache; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import java.io.IOException; 28 | import org.apache.http.client.methods.CloseableHttpResponse; 29 | 30 | /** 31 | * Apache http client. 32 | * @since 1.0 33 | */ 34 | public interface ApacheClient { 35 | 36 | /** 37 | * Executes HTTP request using the given dictionary request data. 38 | * @param request Http Request 39 | * @return HttpResponse Http Response 40 | * @throws IOException If fails 41 | */ 42 | CloseableHttpResponse execute(Dict request) throws IOException; 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/BodyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link Body}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class BodyTest { 37 | 38 | @Test 39 | public void appliesBodyToRequest() { 40 | final String body = "hello"; 41 | MatcherAssert.assertThat( 42 | new Body(body.getBytes()).apply(new HashDict()).get("body"), 43 | new IsEqual<>(body) 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/MethodTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link Method}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class MethodTest { 37 | 38 | @Test 39 | public void appliesMethodToRequest() { 40 | final String method = "GET"; 41 | MatcherAssert.assertThat( 42 | new Method(method).apply(new HashDict()).get("method"), 43 | new IsEqual<>(method) 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/response/StatusTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.response; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link Status}. 33 | * @since 1.0 34 | * @checkstyle MagicNumberCheck (500 lines) 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class StatusTest { 38 | 39 | @Test 40 | public void appliesStatusToResponse() { 41 | MatcherAssert.assertThat( 42 | new Status(200).apply(new HashDict()).get("status"), 43 | new IsEqual<>("200") 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/HeaderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link Header}. 33 | * @since 1.0 34 | */ 35 | public final class HeaderTest { 36 | 37 | @Test 38 | public void addsHeaderToRequest() { 39 | final String value = "text/html"; 40 | MatcherAssert.assertThat( 41 | new Header("content-type", value) 42 | .apply(new HashDict()) 43 | .get("h.Content-Type"), 44 | new IsEqual<>(value) 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/QueryParamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link QueryParam}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class QueryParamTest { 37 | 38 | @Test 39 | public void appliesQueryParamToRequest() { 40 | final String value = "value"; 41 | MatcherAssert.assertThat( 42 | new QueryParam("key", value).apply(new HashDict()).get("q.key"), 43 | new IsEqual<>(value) 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/RequestUriTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link RequestUri}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class RequestUriTest { 37 | 38 | @Test 39 | public void appliesRequestUriToRequest() { 40 | final String uri = "www.example.com"; 41 | MatcherAssert.assertThat( 42 | new RequestUri(uri) 43 | .apply(new HashDict()).get("uri"), 44 | new IsEqual<>(uri) 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/response/ReasonPhraseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.response; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link ReasonPhrase}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class ReasonPhraseTest { 37 | 38 | @Test 39 | public void appliesReasonPhraseToResponse() { 40 | final String reason = "some reason"; 41 | MatcherAssert.assertThat( 42 | new ReasonPhrase(reason).apply(new HashDict()).get("reason"), 43 | new IsEqual<>(reason) 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/DtoBodyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link DtoBody}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class DtoBodyTest { 37 | 38 | @Test 39 | public void appliesDtoBodyToRequest() { 40 | final Dto dto = new Dto(); 41 | dto.setProperty("prop"); 42 | MatcherAssert.assertThat( 43 | new DtoBody(dto).apply(new HashDict()).get("body"), 44 | new IsEqual<>("{\"property\":\"prop\"}") 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/QueryParamsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link QueryParams}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class QueryParamsTest { 37 | 38 | @Test 39 | public void appliesQueryParamsToRequest() { 40 | final String value = "value"; 41 | MatcherAssert.assertThat( 42 | new QueryParams(new QueryParam("key", value)) 43 | .apply(new HashDict()).get("q.key"), 44 | new IsEqual<>(value) 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/headers/AcceptTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link Accept}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class AcceptTest { 37 | 38 | @Test 39 | public void addsAcceptHeaderToRequest() { 40 | final String value = "text/html"; 41 | MatcherAssert.assertThat( 42 | new Accept(value) 43 | .apply(new HashDict()) 44 | .get("h.Accept"), 45 | new IsEqual<>(value) 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/headers/CookieTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link Cookie}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class CookieTest { 37 | 38 | @Test 39 | public void addsContentTypeHeaderToRequest() { 40 | final String value = "text/html"; 41 | MatcherAssert.assertThat( 42 | new Cookie(value) 43 | .apply(new HashDict()) 44 | .get("h.Cookie"), 45 | new IsEqual<>(value) 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/GetMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import org.cactoos.iterable.IterableOf; 27 | import org.cactoos.iterable.Joined; 28 | import org.hamcrest.core.IsEqual; 29 | 30 | /** 31 | * Get request matching. 32 | * @since 1.0 33 | */ 34 | public class GetMatch extends MultiMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param matches Matches 39 | */ 40 | public GetMatch(final MatchingCriteria... matches) { 41 | this(new IterableOf<>(matches)); 42 | } 43 | 44 | /** 45 | * Ctor. 46 | * @param matches Matches 47 | */ 48 | public GetMatch(final Iterable matches) { 49 | super(new Joined<>(new MethodMatch(new IsEqual<>("GET")), matches)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/PutMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import org.cactoos.iterable.IterableOf; 27 | import org.cactoos.iterable.Joined; 28 | import org.hamcrest.core.IsEqual; 29 | 30 | /** 31 | * Put request matching. 32 | * @since 1.0 33 | */ 34 | public class PutMatch extends MultiMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param matches Matches 39 | */ 40 | public PutMatch(final MatchingCriteria... matches) { 41 | this(new IterableOf<>(matches)); 42 | } 43 | 44 | /** 45 | * Ctor. 46 | * @param matches Matches 47 | */ 48 | public PutMatch(final Iterable matches) { 49 | super(new Joined<>(new MethodMatch(new IsEqual<>("PUT")), matches)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/headers/BasicAuthTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link BasicAuth}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class BasicAuthTest { 37 | 38 | @Test 39 | public void addsBasicAuthHeaderToRequest() { 40 | MatcherAssert.assertThat( 41 | new BasicAuth("username", "password") 42 | .apply(new HashDict()) 43 | .get("h.Authorization"), 44 | new IsEqual<>("Basic dXNlcm5hbWU6cGFzc3dvcmQ=") 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/PostMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import org.cactoos.iterable.IterableOf; 27 | import org.cactoos.iterable.Joined; 28 | import org.hamcrest.core.IsEqual; 29 | 30 | /** 31 | * Post request matching. 32 | * @since 1.0 33 | */ 34 | public class PostMatch extends MultiMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param matches Matches 39 | */ 40 | public PostMatch(final MatchingCriteria... matches) { 41 | this(new IterableOf<>(matches)); 42 | } 43 | 44 | /** 45 | * Ctor. 46 | * @param matches Matches 47 | */ 48 | public PostMatch(final Iterable matches) { 49 | super(new Joined<>(new MethodMatch(new IsEqual<>("POST")), matches)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/headers/ContentTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link Accept}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class ContentTypeTest { 37 | 38 | @Test 39 | public void addsContentTypeHeaderToRequest() { 40 | final String value = "text/html"; 41 | MatcherAssert.assertThat( 42 | new ContentType(value) 43 | .apply(new HashDict()) 44 | .get("h.Content-Type"), 45 | new IsEqual<>(value) 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/DeleteMatch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import org.cactoos.iterable.IterableOf; 27 | import org.cactoos.iterable.Joined; 28 | import org.hamcrest.core.IsEqual; 29 | 30 | /** 31 | * Delete request matching. 32 | * @since 1.0 33 | */ 34 | public class DeleteMatch extends MultiMatching { 35 | 36 | /** 37 | * Ctor. 38 | * @param matches Matches 39 | */ 40 | public DeleteMatch(final MatchingCriteria... matches) { 41 | this(new IterableOf<>(matches)); 42 | } 43 | 44 | /** 45 | * Ctor. 46 | * @param matches Matches 47 | */ 48 | public DeleteMatch(final Iterable matches) { 49 | super(new Joined<>(new MethodMatch(new IsEqual<>("DELETE")), matches)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/headers/AuthorizationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.core.IsEqual; 29 | import org.junit.Test; 30 | 31 | /** 32 | * Test case for {@link Authorization}. 33 | * @since 1.0 34 | * @checkstyle JavadocMethodCheck (500 lines) 35 | */ 36 | public final class AuthorizationTest { 37 | 38 | @Test 39 | public void addsAuthorizationHeaderToRequest() { 40 | final String value = "basic"; 41 | MatcherAssert.assertThat( 42 | new Authorization(value) 43 | .apply(new HashDict()) 44 | .get("h.Authorization"), 45 | new IsEqual<>(value) 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/DictOf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | import org.cactoos.iterable.IterableOf; 27 | 28 | /** 29 | * Dictionary made of dictionary inputs. 30 | * @since 1.0 31 | */ 32 | public class DictOf extends Dict.Envelope { 33 | /** 34 | * Ctor. 35 | * @param inputs Inputs 36 | */ 37 | public DictOf(final DictInput... inputs) { 38 | this(new IterableOf<>(inputs)); 39 | } 40 | 41 | /** 42 | * Ctor. 43 | * @param inputs Inputs 44 | */ 45 | public DictOf(final Iterable inputs) { 46 | super(() -> { 47 | Dict dict = new HashDict(); 48 | for (final DictInput input : inputs) { 49 | dict = input.apply(dict); 50 | } 51 | return dict; 52 | }); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/MethodOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link Method.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class MethodOfTest { 38 | 39 | @Test 40 | public void extractsMethodFromDict() { 41 | final String method = "GET"; 42 | MatcherAssert.assertThat( 43 | new Method.Of( 44 | new HashDict( 45 | new KvpOf("method", method), new KvpOf("unknown", "") 46 | ) 47 | ).asString(), 48 | new IsEqual<>(method) 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/response/StatusOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.response; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link Status.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | * @checkstyle MagicNumberCheck (500 lines) 37 | */ 38 | public final class StatusOfTest { 39 | 40 | @Test 41 | public void extractsReasonPhraseFromDict() { 42 | MatcherAssert.assertThat( 43 | new Status.Of( 44 | new HashDict( 45 | new KvpOf("status", "200"), new KvpOf("unknown", "") 46 | ) 47 | ).intValue(), 48 | new IsEqual<>(200) 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/FormParamsOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link FormParams.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class FormParamsOfTest { 38 | @Test 39 | public void buildsFormParamsInput() { 40 | MatcherAssert.assertThat( 41 | new FormParams.Of( 42 | new HashDict( 43 | new KvpOf("f.name", "John"), 44 | new KvpOf("f.surname", "Smith") 45 | ) 46 | ).asString(), 47 | new IsEqual<>("name=John&surname=Smith") 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/QueryParamsOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link QueryParams.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class QueryParamsOfTest { 38 | @Test 39 | public void buildQueryParamsInput() { 40 | MatcherAssert.assertThat( 41 | new QueryParams.Of( 42 | new HashDict( 43 | new KvpOf("q.name", "John"), 44 | new KvpOf("q.surname", "Smith") 45 | ) 46 | ).asString(), 47 | new IsEqual<>("?name=John&surname=Smith") 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/DtoBodyOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link DtoBody.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class DtoBodyOfTest { 38 | 39 | @Test 40 | public void extractsBodyFromDict() { 41 | MatcherAssert.assertThat( 42 | new DtoBody.Of( 43 | new HashDict( 44 | new KvpOf("body", "{\"property\":\"prop\"}"), 45 | new KvpOf("unknown", "") 46 | ) 47 | ).as(Dto.class).getProperty(), 48 | new IsEqual<>("prop") 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/XmlBodyOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsNot; 30 | import org.hamcrest.core.IsNull; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Test case for {@link XmlBody.Of}. 35 | * @since 1.0 36 | * @checkstyle JavadocMethodCheck (500 lines) 37 | */ 38 | public final class XmlBodyOfTest { 39 | 40 | @Test 41 | public void extractsJsonObjectFromDict() { 42 | MatcherAssert.assertThat( 43 | new XmlBody.Of( 44 | new HashDict( 45 | new KvpOf("body", ""), 46 | new KvpOf("unknown", "") 47 | ) 48 | ).xml(), 49 | new IsNot<>(new IsNull<>()) 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/wire/VerificationWireTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.HashDict; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link VerificationWire}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | * @checkstyle WhitespaceAroundCheck (500 lines) 37 | */ 38 | public final class VerificationWireTest { 39 | 40 | @Test 41 | public void successfulRequest() throws Exception { 42 | final Dict origin = new HashDict(); 43 | MatcherAssert.assertThat( 44 | new VerificationWire( 45 | in -> origin, 46 | dict -> {} 47 | ).send(new HashDict()), 48 | new IsEqual<>(origin) 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/JoinedDict.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | import org.cactoos.iterable.Joined; 27 | 28 | /** 29 | * Joined dictionary. 30 | * @since 1.0 31 | */ 32 | public class JoinedDict extends Dict.Envelope { 33 | /** 34 | * Ctor. 35 | * @param kvp Key-value pair 36 | * @param dict Dictionary 37 | */ 38 | public JoinedDict(final Kvp kvp, final Dict dict) { 39 | this(new HashDict(kvp), dict); 40 | } 41 | 42 | /** 43 | * Ctor. 44 | * @param input Input 45 | * @param dict Dictionary 46 | */ 47 | public JoinedDict(final DictInput input, final Dict dict) { 48 | this(new DictOf(input), dict); 49 | } 50 | 51 | /** 52 | * Ctor. 53 | * @param dicts Dictionaries 54 | */ 55 | public JoinedDict(final Dict... dicts) { 56 | super(() -> new HashDict(new Joined<>(dicts))); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/QueryParamOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link QueryParam.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class QueryParamOfTest { 38 | 39 | @Test 40 | public void extractsQueryParamFromDict() { 41 | final String value = "value"; 42 | MatcherAssert.assertThat( 43 | new QueryParam.Of( 44 | "key", 45 | new HashDict( 46 | new KvpOf("q.key", value), new KvpOf("unknown", "") 47 | ) 48 | ).asString(), 49 | new IsEqual<>(value) 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/response/ReasonPhraseOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.response; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link ReasonPhrase.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class ReasonPhraseOfTest { 39 | 40 | @Test 41 | public void extractsReasonPhraseFromDict() { 42 | MatcherAssert.assertThat( 43 | new ReasonPhrase.Of( 44 | new HashDict( 45 | new KvpOf("reason", "test"), new KvpOf("unknown", "") 46 | ) 47 | ).asString(), 48 | new IsEqual<>("test") 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/HeaderOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link Header.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class HeaderOfTest { 38 | 39 | @Test 40 | public void extractsHeaderFromDict() { 41 | final String name = "John"; 42 | MatcherAssert.assertThat( 43 | new Header.Of( 44 | "name", 45 | new HashDict( 46 | new KvpOf("h.Name", name), 47 | new KvpOf("surname", "Smith") 48 | ) 49 | ).asString(), 50 | new IsEqual<>(name) 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/HtmlBodyOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsNot; 30 | import org.hamcrest.core.IsNull; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Test case for {@link HtmlBody}. 35 | * @since 1.0 36 | * @checkstyle JavadocMethodCheck (500 lines) 37 | */ 38 | public final class HtmlBodyOfTest { 39 | 40 | @Test 41 | public void extractsHtmlBodyFromDict() { 42 | MatcherAssert.assertThat( 43 | new HtmlBody.Of( 44 | new HashDict( 45 | new KvpOf("body", ""), 46 | new KvpOf("unknown", "") 47 | ) 48 | ).html().html(), 49 | new IsNot<>(new IsNull<>()) 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/FormParamOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link FormParam.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class FormParamOfTest { 38 | 39 | @Test 40 | public void extractsFormParamFromDict() { 41 | final String name = "John"; 42 | MatcherAssert.assertThat( 43 | new FormParam.Of( 44 | "name", 45 | new HashDict( 46 | new KvpOf("f.name", name), 47 | new KvpOf("f.surname", "Smith") 48 | ) 49 | ).asString(), 50 | new IsEqual<>(name) 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/wire/apache/SslTrustedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire.apache; 25 | 26 | import org.apache.http.impl.client.HttpClientBuilder; 27 | import org.apache.http.impl.client.HttpClients; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.hamcrest.core.IsNot; 31 | import org.hamcrest.core.IsNull; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link Proxy}. 36 | * @since 1.0 37 | * @checkstyle JavadocMethodCheck (500 lines) 38 | */ 39 | public final class SslTrustedTest { 40 | 41 | @Test 42 | public void appendsSslTrustedToClient() { 43 | final HttpClientBuilder builder = HttpClients.custom(); 44 | MatcherAssert.assertThat( 45 | new SslTrusted().apply(builder), 46 | new IsEqual<>(builder) 47 | ); 48 | MatcherAssert.assertThat( 49 | builder.build(), 50 | new IsNot<>(new IsNull<>()) 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/mock/MultiMatching.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import java.util.ArrayList; 28 | import java.util.Collection; 29 | import java.util.List; 30 | 31 | /** 32 | * Multiple matching criteria. 33 | * @since 1.0 34 | */ 35 | public class MultiMatching implements MatchingCriteria { 36 | 37 | /** 38 | * Matches. 39 | */ 40 | private final Iterable matches; 41 | 42 | /** 43 | * Ctor. 44 | * @param matches Matches 45 | */ 46 | public MultiMatching(final Iterable matches) { 47 | this.matches = matches; 48 | } 49 | 50 | @Override 51 | public final Collection apply(final Dict dict) { 52 | final List result = new ArrayList<>(0); 53 | for (final MatchingCriteria criteria: this.matches) { 54 | result.addAll(criteria.apply(dict)); 55 | } 56 | return result; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/KvpOf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | import java.util.Map; 27 | import org.cactoos.map.MapEntry; 28 | 29 | /** 30 | * Key-value pair made of a string pair. 31 | * @since 1.0 32 | */ 33 | public class KvpOf implements Kvp { 34 | 35 | /** 36 | * Map entry. 37 | */ 38 | private final Map.Entry entry; 39 | 40 | /** 41 | * Ctor. 42 | * @param key Key 43 | * @param value Value 44 | */ 45 | public KvpOf(final String key, final String value) { 46 | this(new MapEntry<>(key, value)); 47 | } 48 | 49 | /** 50 | * Ctor. 51 | * @param entry Map entry 52 | */ 53 | public KvpOf(final Map.Entry entry) { 54 | this.entry = entry; 55 | } 56 | 57 | @Override 58 | public final String key() { 59 | return this.entry.getKey(); 60 | } 61 | 62 | @Override 63 | public final String value() { 64 | return this.entry.getValue(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/BodyMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link BodyMatch}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class BodyMatchTest { 38 | 39 | @Test 40 | public void matchesBody() { 41 | final String body = "some body"; 42 | MatcherAssert.assertThat( 43 | new BodyMatch(new IsEqual<>(body)) 44 | .apply(new HashDict(new KvpOf("body", body))).isEmpty(), 45 | new IsEqual<>(true) 46 | ); 47 | } 48 | 49 | @Test 50 | public void bodyMismatch() { 51 | MatcherAssert.assertThat( 52 | new BodyMatch(new IsEqual<>("text")).apply(new HashDict()).size(), 53 | new IsEqual<>(1) 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/PathMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link PathMatch}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | public final class PathMatchTest { 38 | 39 | @Test 40 | public void matchesPath() { 41 | final String path = "some path"; 42 | MatcherAssert.assertThat( 43 | new PathMatch(new IsEqual<>(path)) 44 | .apply(new HashDict(new KvpOf("path", path))).isEmpty(), 45 | new IsEqual<>(true) 46 | ); 47 | } 48 | 49 | @Test 50 | public void pathMismatch() { 51 | MatcherAssert.assertThat( 52 | new PathMatch(new IsEqual<>("text")).apply(new HashDict()).size(), 53 | new IsEqual<>(1) 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/wire/apache/ProxyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire.apache; 25 | 26 | import org.apache.http.impl.client.HttpClientBuilder; 27 | import org.apache.http.impl.client.HttpClients; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.hamcrest.core.IsNot; 31 | import org.hamcrest.core.IsNull; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link Proxy}. 36 | * @since 1.0 37 | * @checkstyle JavadocMethodCheck (500 lines) 38 | * @checkstyle MagicNumberCheck (500 lines) 39 | */ 40 | public final class ProxyTest { 41 | 42 | @Test 43 | public void appendsProxyToClient() { 44 | final HttpClientBuilder builder = HttpClients.custom(); 45 | MatcherAssert.assertThat( 46 | new Proxy("localhost", 8080).apply(builder), 47 | new IsEqual<>(builder) 48 | ); 49 | MatcherAssert.assertThat( 50 | builder.build(), 51 | new IsNot<>(new IsNull<>()) 52 | ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/wire/apache/ApacheHeaders.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire.apache; 25 | 26 | import hr.com.vgv.verano.http.DictInput; 27 | import hr.com.vgv.verano.http.JoinedDict; 28 | import hr.com.vgv.verano.http.parts.Headers; 29 | import org.apache.http.Header; 30 | import org.cactoos.iterable.Mapped; 31 | 32 | /** 33 | * Apache headers. 34 | * @since 1.0 35 | */ 36 | public class ApacheHeaders extends DictInput.Envelope { 37 | /** 38 | * Ctor. 39 | * @param headers Headers 40 | */ 41 | public ApacheHeaders(final Header... headers) { 42 | super( 43 | dict -> new JoinedDict( 44 | dict, 45 | new Headers( 46 | new Mapped<>( 47 | header -> new hr.com.vgv.verano.http.parts.Header( 48 | header.getName(), header.getValue() 49 | ), 50 | headers 51 | ) 52 | ).apply(dict) 53 | ) 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/Kvp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http; 25 | 26 | /** 27 | * Key-value pair. 28 | * @since 1.0 29 | */ 30 | public interface Kvp { 31 | 32 | /** 33 | * Key. 34 | * @return Key 35 | */ 36 | String key(); 37 | 38 | /** 39 | * Value. 40 | * @return Value 41 | */ 42 | String value(); 43 | 44 | /** 45 | * Simple implementation of {@link Kvp} used to simplify Kvp decorators. 46 | */ 47 | class Envelope implements Kvp { 48 | 49 | /** 50 | * Original key-value pair. 51 | */ 52 | private final Kvp origin; 53 | 54 | /** 55 | * Ctor. 56 | * @param origin Origin 57 | */ 58 | public Envelope(final Kvp origin) { 59 | this.origin = origin; 60 | } 61 | 62 | @Override 63 | public final String key() { 64 | return this.origin.key(); 65 | } 66 | 67 | @Override 68 | public final String value() { 69 | return this.origin.value(); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/HtmlBodyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import org.hamcrest.MatcherAssert; 28 | import org.hamcrest.Matchers; 29 | import org.jsoup.Jsoup; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link HtmlBody}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class HtmlBodyTest { 39 | 40 | @Test 41 | public void appliesHtmlElementToRequest() { 42 | MatcherAssert.assertThat( 43 | new HtmlBody(Jsoup.parse("")) 44 | .apply(new HashDict()).get("body"), 45 | Matchers.containsString("html") 46 | ); 47 | } 48 | 49 | @Test 50 | public void appliesHtmlSourceToRequest() { 51 | MatcherAssert.assertThat( 52 | new HtmlBody(() -> Jsoup.parse("")) 53 | .apply(new HashDict()).get("body"), 54 | Matchers.containsString("html") 55 | ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/XmlBodyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import com.jcabi.xml.XMLDocument; 27 | import hr.com.vgv.verano.http.HashDict; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link XmlBody}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class XmlBodyTest { 39 | 40 | @Test 41 | public void appliesJXmlBodyToRequest() { 42 | MatcherAssert.assertThat( 43 | new XmlBody(new XMLDocument("")) 44 | .apply(new HashDict()).get("body"), 45 | Matchers.containsString("test") 46 | ); 47 | } 48 | 49 | @Test 50 | public void appliesJXmlSourceToRequest() { 51 | MatcherAssert.assertThat( 52 | new XmlBody(() -> new XMLDocument("")) 53 | .apply(new HashDict()).get("body"), 54 | Matchers.containsString("test") 55 | ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/RequestUriMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link RequestUriMatch}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class RequestUriMatchTest { 39 | 40 | @Test 41 | public void matchesBody() { 42 | final String uri = "some uri"; 43 | MatcherAssert.assertThat( 44 | new RequestUriMatch(new IsEqual<>(uri)) 45 | .apply(new HashDict(new KvpOf("uri", uri))).isEmpty(), 46 | new IsEqual<>(true) 47 | ); 48 | } 49 | 50 | @Test 51 | public void bodyMismatch() { 52 | MatcherAssert.assertThat( 53 | new RequestUriMatch(new IsEqual<>("text")) 54 | .apply(new HashDict()).size(), 55 | new IsEqual<>(1) 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/wire/VerificationWire.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.Verification; 28 | import hr.com.vgv.verano.http.Wire; 29 | import java.io.IOException; 30 | 31 | /** 32 | * Wire with additional assertion on response. 33 | * @since 1.0 34 | */ 35 | public class VerificationWire implements Wire { 36 | /** 37 | * Original wire. 38 | */ 39 | private final Wire origin; 40 | 41 | /** 42 | * Assertion. 43 | */ 44 | private final Verification verification; 45 | 46 | /** 47 | * Ctor. 48 | * @param origin Origin 49 | * @param verification Assertion 50 | */ 51 | public VerificationWire( 52 | final Wire origin, final Verification verification 53 | ) { 54 | this.origin = origin; 55 | this.verification = verification; 56 | } 57 | 58 | @Override 59 | public final Dict send(final Dict request) throws IOException { 60 | final Dict response = this.origin.send(request); 61 | this.verification.verify(response); 62 | return response; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/HeaderMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link HeaderMatch}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class HeaderMatchTest { 39 | 40 | @Test 41 | public void matchesQueryParam() { 42 | final String value = "some value"; 43 | MatcherAssert.assertThat( 44 | new HeaderMatch("key", new IsEqual<>(value)) 45 | .apply(new HashDict(new KvpOf("h.Key", value))).isEmpty(), 46 | new IsEqual<>(true) 47 | ); 48 | } 49 | 50 | @Test 51 | public void queryParamMismatch() { 52 | MatcherAssert.assertThat( 53 | new HeaderMatch("key", new IsEqual<>("text")) 54 | .apply(new HashDict(new KvpOf("h.Key", ""))).size(), 55 | new IsEqual<>(1) 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/body/JsonBodyTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import javax.json.Json; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link JsonBody}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class JsonBodyTest { 39 | 40 | @Test 41 | public void appliesJsonBodyToRequest() { 42 | MatcherAssert.assertThat( 43 | new JsonBody(Json.createObjectBuilder().add("key", "val").build()) 44 | .apply(new HashDict()).get("body"), 45 | Matchers.containsString("key") 46 | ); 47 | } 48 | 49 | @Test 50 | public void appliesJsonSourceToRequest() { 51 | MatcherAssert.assertThat( 52 | new JsonBody( 53 | () -> Json.createObjectBuilder().add("key", "val").build() 54 | ).apply(new HashDict()).get("body"), 55 | Matchers.containsString("key") 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/FormParamMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link FormParamMatch}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class FormParamMatchTest { 39 | 40 | @Test 41 | public void matchesFormParam() { 42 | final String value = "some value"; 43 | MatcherAssert.assertThat( 44 | new FormParamMatch("key", new IsEqual<>(value)) 45 | .apply(new HashDict(new KvpOf("f.key", value))).isEmpty(), 46 | new IsEqual<>(true) 47 | ); 48 | } 49 | 50 | @Test 51 | public void formParamMismatch() { 52 | MatcherAssert.assertThat( 53 | new FormParamMatch("key", new IsEqual<>("text")) 54 | .apply(new HashDict(new KvpOf("f.key", ""))).size(), 55 | new IsEqual<>(1) 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/QueryParamMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link QueryParamMatch}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class QueryParamMatchTest { 39 | 40 | @Test 41 | public void matchesQueryParam() { 42 | final String value = "some value"; 43 | MatcherAssert.assertThat( 44 | new QueryParamMatch("key", new IsEqual<>(value)) 45 | .apply(new HashDict(new KvpOf("q.key", value))).isEmpty(), 46 | new IsEqual<>(true) 47 | ); 48 | } 49 | 50 | @Test 51 | public void queryParamMismatch() { 52 | MatcherAssert.assertThat( 53 | new QueryParamMatch("key", new IsEqual<>("text")) 54 | .apply(new HashDict(new KvpOf("q.key", ""))).size(), 55 | new IsEqual<>(1) 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/wire/apache/SslTrusted.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire.apache; 25 | 26 | import javax.net.ssl.SSLContext; 27 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; 28 | import org.apache.http.impl.client.HttpClientBuilder; 29 | import org.apache.http.ssl.SSLContextBuilder; 30 | import org.apache.http.ssl.SSLContexts; 31 | 32 | /** 33 | * Trust all ssl certificates. 34 | * @since 1.0 35 | */ 36 | @SuppressWarnings("PMD.AvoidCatchingGenericException") 37 | public class SslTrusted implements ApacheContext { 38 | @Override 39 | public final HttpClientBuilder apply(final HttpClientBuilder builder) { 40 | final SSLContext context; 41 | try { 42 | final SSLContextBuilder ssl = SSLContexts.custom(); 43 | ssl.loadTrustMaterial((chain, type) -> true); 44 | context = ssl.build(); 45 | //@checkstyle IllegalCatchCheck (1 lines) 46 | } catch (final Exception exp) { 47 | throw new IllegalStateException(exp); 48 | } 49 | return builder.setSSLSocketFactory( 50 | new SSLConnectionSocketFactory(context, (ctx, session) -> true) 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/headers/BasicAuth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import javax.xml.bind.DatatypeConverter; 27 | import org.cactoos.scalar.UncheckedScalar; 28 | 29 | /** 30 | * Basic authorization header. 31 | * @since 1.0 32 | */ 33 | public class BasicAuth extends Authorization { 34 | 35 | /** 36 | * Ctor. 37 | * @param username Username 38 | * @param password Password 39 | */ 40 | public BasicAuth(final String username, final String password) { 41 | super(BasicAuth.encode(username, password)); 42 | } 43 | 44 | /** 45 | * Encode credentials to base64. 46 | * @param username Username 47 | * @param password Password 48 | * @return String Credentials as base64. 49 | */ 50 | private static String encode( 51 | final String username, final String password 52 | ) { 53 | return new UncheckedScalar<>( 54 | () -> String.format( 55 | "Basic %s", 56 | DatatypeConverter.printBase64Binary( 57 | String.format("%s:%s", username, password).getBytes("UTF-8") 58 | ) 59 | ) 60 | ).value(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/PathTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.HashDict; 28 | import hr.com.vgv.verano.http.KvpOf; 29 | import org.cactoos.collection.CollectionOf; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.core.IsEqual; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link Path}. 36 | * @since 1.0 37 | * @checkstyle JavadocMethodCheck (500 lines) 38 | * @checkstyle MagicNumberCheck (500 lines) 39 | */ 40 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 41 | public final class PathTest { 42 | 43 | @Test 44 | public void concatenatesPath() { 45 | final Dict dict = new Path("/items") 46 | .apply( 47 | new HashDict( 48 | new KvpOf("aaa", "test"), 49 | new KvpOf("path", "localhost") 50 | ) 51 | ); 52 | MatcherAssert.assertThat( 53 | new CollectionOf<>(dict).size(), 54 | new IsEqual<>(3) 55 | ); 56 | MatcherAssert.assertThat( 57 | dict.get("path"), 58 | new IsEqual<>("localhost/items") 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/Method.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.DictInput; 28 | import hr.com.vgv.verano.http.KvpOf; 29 | import org.cactoos.Text; 30 | 31 | /** 32 | * Http method. 33 | * @since 1.0 34 | */ 35 | public class Method extends DictInput.Envelope { 36 | /** 37 | * Method key in dictionary. 38 | */ 39 | private static final String KEY = "method"; 40 | 41 | /** 42 | * Ctor. 43 | * @param method Http method 44 | */ 45 | public Method(final String method) { 46 | super(new KvpOf(Method.KEY, method)); 47 | } 48 | 49 | /** 50 | * Method from response. 51 | */ 52 | public static class Of implements Text { 53 | 54 | /** 55 | * Response. 56 | */ 57 | private final Dict response; 58 | 59 | /** 60 | * Ctor. 61 | * @param response Response 62 | */ 63 | public Of(final Dict response) { 64 | this.response = response; 65 | } 66 | 67 | @Override 68 | public final String asString() { 69 | return this.response.get(Method.KEY, "GET"); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/request/Get.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.request; 25 | 26 | import hr.com.vgv.verano.http.DictInput; 27 | import org.cactoos.iterable.IterableOf; 28 | 29 | /** 30 | * Http GET request. 31 | * @since 1.0 32 | */ 33 | public class Get extends Request { 34 | /** 35 | * Ctor. 36 | * @param inputs Inputs 37 | */ 38 | public Get(final DictInput... inputs) { 39 | this(new IterableOf<>(inputs)); 40 | } 41 | 42 | /** 43 | * Ctor. 44 | * @param inputs Inputs 45 | */ 46 | public Get(final Iterable inputs) { 47 | this("", inputs); 48 | } 49 | 50 | /** 51 | * Ctor. 52 | * @param uri Uri 53 | */ 54 | public Get(final String uri) { 55 | this(uri, new IterableOf<>()); 56 | } 57 | 58 | /** 59 | * Ctor. 60 | * @param uri Uri 61 | * @param inputs Inputs 62 | */ 63 | public Get(final String uri, final DictInput... inputs) { 64 | this(uri, new IterableOf<>(inputs)); 65 | } 66 | 67 | /** 68 | * Ctor. 69 | * @param uri Uri 70 | * @param inputs Inputs 71 | */ 72 | public Get(final String uri, final Iterable inputs) { 73 | super(uri, "GET", inputs); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/request/Put.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.request; 25 | 26 | import hr.com.vgv.verano.http.DictInput; 27 | import org.cactoos.iterable.IterableOf; 28 | 29 | /** 30 | * Http PUT request. 31 | * @since 1.0 32 | */ 33 | public class Put extends Request { 34 | /** 35 | * Ctor. 36 | * @param inputs Inputs 37 | */ 38 | public Put(final DictInput... inputs) { 39 | this(new IterableOf<>(inputs)); 40 | } 41 | 42 | /** 43 | * Ctor. 44 | * @param inputs Inputs 45 | */ 46 | public Put(final Iterable inputs) { 47 | this("", inputs); 48 | } 49 | 50 | /** 51 | * Ctor. 52 | * @param uri Uri 53 | */ 54 | public Put(final String uri) { 55 | this(uri, new IterableOf<>()); 56 | } 57 | 58 | /** 59 | * Ctor. 60 | * @param uri Uri 61 | * @param inputs Inputs 62 | */ 63 | public Put(final String uri, final DictInput... inputs) { 64 | this(uri, new IterableOf<>(inputs)); 65 | } 66 | 67 | /** 68 | * Ctor. 69 | * @param uri Uri 70 | * @param inputs Inputs 71 | */ 72 | public Put(final String uri, final Iterable inputs) { 73 | super(uri, "PUT", inputs); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/RequestUriOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import java.net.URI; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.core.IsEqual; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Test case for {@link RequestUri.Of}. 35 | * @since 1.0 36 | * @checkstyle JavadocMethodCheck (500 lines) 37 | */ 38 | public final class RequestUriOfTest { 39 | @Test 40 | public void extractsUriFromDict() { 41 | final String base = "http://localhost:8080"; 42 | final String path = "/example"; 43 | MatcherAssert.assertThat( 44 | new RequestUri.Of( 45 | new HashDict( 46 | new KvpOf("uri", base), 47 | new KvpOf("path", path), 48 | new KvpOf("q.first", "10"), 49 | new KvpOf("q.second", "someStr") 50 | ) 51 | ).uri().toString(), 52 | new IsEqual<>( 53 | String.format( 54 | "%s?first=10&second=someStr", 55 | URI.create(base + path).toString() 56 | ) 57 | ) 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/request/Post.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.request; 25 | 26 | import hr.com.vgv.verano.http.DictInput; 27 | import org.cactoos.iterable.IterableOf; 28 | 29 | /** 30 | * Http POST request. 31 | * @since 1.0 32 | */ 33 | public class Post extends Request { 34 | /** 35 | * Ctor. 36 | * @param inputs Inputs 37 | */ 38 | public Post(final DictInput... inputs) { 39 | this(new IterableOf<>(inputs)); 40 | } 41 | 42 | /** 43 | * Ctor. 44 | * @param inputs Inputs 45 | */ 46 | public Post(final Iterable inputs) { 47 | this("", inputs); 48 | } 49 | 50 | /** 51 | * Ctor. 52 | * @param uri Uri 53 | */ 54 | public Post(final String uri) { 55 | this(uri, new IterableOf<>()); 56 | } 57 | 58 | /** 59 | * Ctor. 60 | * @param uri Uri 61 | * @param inputs Inputs 62 | */ 63 | public Post(final String uri, final DictInput... inputs) { 64 | this(uri, new IterableOf<>(inputs)); 65 | } 66 | 67 | /** 68 | * Ctor. 69 | * @param uri Uri 70 | * @param inputs Inputs 71 | */ 72 | public Post(final String uri, final Iterable inputs) { 73 | super(uri, "POST", inputs); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/BodyOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link Body.Of}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class BodyOfTest { 39 | 40 | @Test 41 | public void extractsBodyFromDict() { 42 | MatcherAssert.assertThat( 43 | new Body.Of( 44 | new HashDict( 45 | new KvpOf("body", "test"), new KvpOf("unknown", "") 46 | ) 47 | ).asString(), 48 | new IsEqual<>("test") 49 | ); 50 | } 51 | 52 | @Test 53 | public void extractsBodyFromDictWithFormParams() { 54 | MatcherAssert.assertThat( 55 | new Body.Of( 56 | new HashDict( 57 | new KvpOf("f.param1", "test1"), 58 | new KvpOf("f.param2", "test2") 59 | ) 60 | ).asString(), 61 | new IsEqual<>("param1=test1¶m2=test2") 62 | ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/request/Delete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.request; 25 | 26 | import hr.com.vgv.verano.http.DictInput; 27 | import org.cactoos.iterable.IterableOf; 28 | 29 | /** 30 | * Http DELETE request. 31 | * @since 1.0 32 | */ 33 | public class Delete extends Request { 34 | /** 35 | * Ctor. 36 | * @param inputs Inputs 37 | */ 38 | public Delete(final DictInput... inputs) { 39 | this(new IterableOf<>(inputs)); 40 | } 41 | 42 | /** 43 | * Ctor. 44 | * @param inputs Inputs 45 | */ 46 | public Delete(final Iterable inputs) { 47 | this("", inputs); 48 | } 49 | 50 | /** 51 | * Ctor. 52 | * @param uri Uri 53 | */ 54 | public Delete(final String uri) { 55 | this(uri, new IterableOf<>()); 56 | } 57 | 58 | /** 59 | * Ctor. 60 | * @param uri Uri 61 | * @param inputs Inputs 62 | */ 63 | public Delete(final String uri, final DictInput... inputs) { 64 | this(uri, new IterableOf<>(inputs)); 65 | } 66 | 67 | /** 68 | * Ctor. 69 | * @param uri Uri 70 | * @param inputs Inputs 71 | */ 72 | public Delete(final String uri, final Iterable inputs) { 73 | super(uri, "DELETE", inputs); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/response/ReasonPhrase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.response; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.DictInput; 28 | import hr.com.vgv.verano.http.KvpOf; 29 | import org.cactoos.Text; 30 | 31 | /** 32 | * Http reason phrase. 33 | * @since 1.0 34 | */ 35 | public class ReasonPhrase extends DictInput.Envelope { 36 | 37 | /** 38 | * Reason phrase key in dictionary. 39 | */ 40 | private static final String KEY = "reason"; 41 | 42 | /** 43 | * Ctor. 44 | * @param reason Reason phrase 45 | */ 46 | public ReasonPhrase(final String reason) { 47 | super(new KvpOf(ReasonPhrase.KEY, reason)); 48 | } 49 | 50 | /** 51 | * Reason phrase from response. 52 | */ 53 | public static class Of implements Text { 54 | /** 55 | * Response. 56 | */ 57 | private final Dict response; 58 | 59 | /** 60 | * Ctor. 61 | * @param response Response 62 | */ 63 | public Of(final Dict response) { 64 | this.response = response; 65 | } 66 | 67 | @Override 68 | public final String asString() { 69 | return this.response.get(ReasonPhrase.KEY, ""); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/request/RequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.request; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.parts.headers.ContentType; 28 | import org.cactoos.collection.CollectionOf; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.core.IsEqual; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Test case for {@link Request}. 35 | * @since 1.0 36 | * @checkstyle JavadocMethodCheck (500 lines) 37 | * @checkstyle MagicNumberCheck (500 lines) 38 | */ 39 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 40 | public final class RequestTest { 41 | 42 | @Test 43 | public void buildsRequest() { 44 | final Dict dict = new Request("GET", new ContentType("text/html")); 45 | MatcherAssert.assertThat( 46 | new CollectionOf<>(dict).size(), 47 | new IsEqual<>(3) 48 | ); 49 | MatcherAssert.assertThat( 50 | dict.get("method"), 51 | new IsEqual<>("GET") 52 | ); 53 | MatcherAssert.assertThat( 54 | dict.get("path").isEmpty(), 55 | new IsEqual<>(true) 56 | ); 57 | MatcherAssert.assertThat( 58 | dict.get("h.Content-Type"), 59 | new IsEqual<>("text/html") 60 | ); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/wire/ExpandedWireTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.HashDict; 28 | import hr.com.vgv.verano.http.KvpOf; 29 | import hr.com.vgv.verano.http.parts.headers.ContentType; 30 | import org.cactoos.collection.CollectionOf; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.core.IsEqual; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link ExpandedWire}. 37 | * @since 1.0 38 | * @checkstyle JavadocMethodCheck (500 lines) 39 | */ 40 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 41 | public final class ExpandedWireTest { 42 | 43 | @Test 44 | public void expandWireWithAdditionalData() throws Exception { 45 | final Dict response = new ExpandedWire( 46 | req -> req, new ContentType("application/json") 47 | ).send(new HashDict(new KvpOf("foo", "bar"))); 48 | MatcherAssert.assertThat( 49 | new CollectionOf<>(response).size(), 50 | new IsEqual<>(2) 51 | ); 52 | MatcherAssert.assertThat( 53 | response.get("h.Content-Type"), 54 | new IsEqual<>("application/json") 55 | ); 56 | MatcherAssert.assertThat( 57 | response.get("foo"), 58 | new IsEqual<>("bar") 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/FormParamsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.HashDict; 28 | import hr.com.vgv.verano.http.KvpOf; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.core.IsEqual; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Test case for {@link FormParams}. 35 | * @since 1.0 36 | * @checkstyle JavadocMethodCheck (500 lines) 37 | */ 38 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 39 | public class FormParamsTest { 40 | @Test 41 | public void buildHeaderInput() { 42 | final Dict dict = 43 | new FormParams( 44 | new FormParam("name", "John"), 45 | new FormParam("surname", "Smith") 46 | ).apply( 47 | new HashDict( 48 | new KvpOf("foo", "bar"), 49 | new KvpOf("f.name", "unknown") 50 | ) 51 | ); 52 | MatcherAssert.assertThat( 53 | dict.get("f.name"), 54 | new IsEqual<>("John") 55 | ); 56 | MatcherAssert.assertThat( 57 | dict.get("f.surname"), 58 | new IsEqual<>("Smith") 59 | ); 60 | MatcherAssert.assertThat( 61 | dict.get("foo"), 62 | new IsEqual<>("bar") 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/body/XmlBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import com.jcabi.xml.XML; 27 | import com.jcabi.xml.XMLDocument; 28 | import hr.com.vgv.verano.http.Dict; 29 | import hr.com.vgv.verano.http.DictInput; 30 | import hr.com.vgv.verano.http.XmlSource; 31 | import hr.com.vgv.verano.http.parts.Body; 32 | 33 | /** 34 | * Http body as xml. 35 | * @since 1.0 36 | */ 37 | public class XmlBody extends DictInput.Envelope { 38 | 39 | /** 40 | * Ctor. 41 | * @param source Xml source 42 | */ 43 | public XmlBody(final XmlSource source) { 44 | super(() -> new Body(source.xml().toString())); 45 | } 46 | 47 | /** 48 | * Ctor. 49 | * @param xml Xml 50 | */ 51 | public XmlBody(final XML xml) { 52 | super(() -> new Body(xml.toString())); 53 | } 54 | 55 | /** 56 | * Xml body from response. 57 | */ 58 | public static class Of extends Body.Of { 59 | 60 | /** 61 | * Ctor. 62 | * @param response Response 63 | */ 64 | public Of(final Dict response) { 65 | super(response); 66 | } 67 | 68 | /** 69 | * Xml from response body. 70 | * @return Element Html 71 | */ 72 | public final XML xml() { 73 | return new XMLDocument(this.asString()); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/headers/CookieOfTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.headers; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link Cookie}. 34 | * @since 1.0 35 | */ 36 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 37 | public final class CookieOfTest { 38 | 39 | @Test 40 | public void extractsCookieFromDict() { 41 | MatcherAssert.assertThat( 42 | new Cookie.Of( 43 | "param1", 44 | new HashDict( 45 | new KvpOf("h.Set-Cookie", "param1=val1; param2=val2"), 46 | new KvpOf("unknown", "") 47 | ) 48 | ).asString(), 49 | new IsEqual<>("val1") 50 | ); 51 | } 52 | 53 | @Test(expected = IllegalStateException.class) 54 | public void cookieHeaderNotPresent() { 55 | new Cookie.Of( 56 | "param1", new HashDict(new KvpOf("unknown", "")) 57 | ).asString(); 58 | } 59 | 60 | @Test(expected = IllegalStateException.class) 61 | public void cookieNotFound() { 62 | new Cookie.Of( 63 | "param1", new HashDict(new KvpOf("h.Set-Cookie", "param2=val2")) 64 | ).asString(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/parts/body/HtmlBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts.body; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.DictInput; 28 | import hr.com.vgv.verano.http.HtmlSource; 29 | import hr.com.vgv.verano.http.parts.Body; 30 | import org.jsoup.Jsoup; 31 | import org.jsoup.nodes.Element; 32 | 33 | /** 34 | * Http body as html. 35 | * @since 1.0 36 | */ 37 | public class HtmlBody extends DictInput.Envelope { 38 | 39 | /** 40 | * Ctor. 41 | * @param source Html source 42 | */ 43 | public HtmlBody(final HtmlSource source) { 44 | super(() -> new Body(source.htmlElement().html())); 45 | } 46 | 47 | /** 48 | * Ctor. 49 | * @param html Html 50 | */ 51 | public HtmlBody(final Element html) { 52 | super(() -> new Body(html.html())); 53 | } 54 | 55 | /** 56 | * Html body from response. 57 | */ 58 | public static class Of extends Body.Of { 59 | 60 | /** 61 | * Ctor. 62 | * @param response Response 63 | */ 64 | public Of(final Dict response) { 65 | super(response); 66 | } 67 | 68 | /** 69 | * Jsoup html from response body. 70 | * @return Element Html 71 | */ 72 | public final Element html() { 73 | return Jsoup.parse(this.asString()); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/parts/HeadersTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.parts; 25 | 26 | import hr.com.vgv.verano.http.Dict; 27 | import hr.com.vgv.verano.http.HashDict; 28 | import hr.com.vgv.verano.http.KvpOf; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.core.IsEqual; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Test case for {@link Headers}. 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | * @since 1.0 37 | */ 38 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 39 | public final class HeadersTest { 40 | @Test 41 | public void buildHeaderInput() { 42 | final Dict dict = 43 | new Headers( 44 | new Header("Content-Type", "application/json"), 45 | new Header("Authorization", "Bearer 1234") 46 | ).apply( 47 | new HashDict( 48 | new KvpOf("foo", "bar"), 49 | new KvpOf("h.Content-Type", "unknown") 50 | ) 51 | ); 52 | MatcherAssert.assertThat( 53 | dict.get("h.Content-Type"), 54 | new IsEqual<>("application/json") 55 | ); 56 | MatcherAssert.assertThat( 57 | dict.get("h.Authorization"), 58 | new IsEqual<>("Bearer 1234") 59 | ); 60 | MatcherAssert.assertThat( 61 | dict.get("foo"), 62 | new IsEqual<>("bar") 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/hr/com/vgv/verano/http/wire/apache/Proxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.wire.apache; 25 | 26 | import org.apache.http.HttpHost; 27 | import org.apache.http.impl.client.HttpClientBuilder; 28 | import org.apache.http.impl.conn.DefaultProxyRoutePlanner; 29 | 30 | /** 31 | * Http proxy. 32 | * @since 1.0 33 | */ 34 | public class Proxy implements ApacheContext { 35 | 36 | /** 37 | * Scheme. 38 | */ 39 | private final String scheme; 40 | 41 | /** 42 | * Host. 43 | */ 44 | private final String host; 45 | 46 | /** 47 | * Port. 48 | */ 49 | private final int port; 50 | 51 | /** 52 | * Ctor. 53 | * @param host Host 54 | * @param port Port 55 | */ 56 | public Proxy(final String host, final int port) { 57 | this("http", host, port); 58 | } 59 | 60 | /** 61 | * Ctor. 62 | * @param scheme Scheme 63 | * @param host Host 64 | * @param port Port 65 | */ 66 | public Proxy(final String scheme, final String host, final int port) { 67 | this.scheme = scheme; 68 | this.host = host; 69 | this.port = port; 70 | } 71 | 72 | @Override 73 | public final HttpClientBuilder apply(final HttpClientBuilder builder) { 74 | return builder.setRoutePlanner( 75 | new DefaultProxyRoutePlanner( 76 | new HttpHost(this.host, this.port, this.scheme) 77 | ) 78 | ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/GetMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link GetMatch}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class GetMatchTest { 39 | 40 | @Test 41 | public void matchesGetMethod() { 42 | final String body = "some body"; 43 | MatcherAssert.assertThat( 44 | new GetMatch( 45 | new BodyMatch(new IsEqual<>(body)) 46 | ).apply( 47 | new HashDict( 48 | new KvpOf("body", body), 49 | new KvpOf("method", "GET") 50 | ) 51 | ).isEmpty(), 52 | new IsEqual<>(true) 53 | ); 54 | } 55 | 56 | @Test 57 | public void getMethodMismatch() { 58 | final String body = "some body"; 59 | MatcherAssert.assertThat( 60 | new GetMatch( 61 | new BodyMatch(new IsEqual<>(body)) 62 | ).apply( 63 | new HashDict( 64 | new KvpOf("body", "unknown"), 65 | new KvpOf("method", "PUT") 66 | ) 67 | ).size(), 68 | new IsEqual<>(2) 69 | ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/hr/com/vgv/verano/http/mock/PutMatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package hr.com.vgv.verano.http.mock; 25 | 26 | import hr.com.vgv.verano.http.HashDict; 27 | import hr.com.vgv.verano.http.KvpOf; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.core.IsEqual; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link PutMatch}. 34 | * @since 1.0 35 | * @checkstyle JavadocMethodCheck (500 lines) 36 | */ 37 | @SuppressWarnings("PMD.AvoidDuplicateLiterals") 38 | public final class PutMatchTest { 39 | 40 | @Test 41 | public void matchesPutMethod() { 42 | final String body = "some body"; 43 | MatcherAssert.assertThat( 44 | new PutMatch( 45 | new BodyMatch(new IsEqual<>(body)) 46 | ).apply( 47 | new HashDict( 48 | new KvpOf("body", body), 49 | new KvpOf("method", "PUT") 50 | ) 51 | ).isEmpty(), 52 | new IsEqual<>(true) 53 | ); 54 | } 55 | 56 | @Test 57 | public void putMethodMismatch() { 58 | final String body = "some body"; 59 | MatcherAssert.assertThat( 60 | new PutMatch( 61 | new BodyMatch(new IsEqual<>(body)) 62 | ).apply( 63 | new HashDict( 64 | new KvpOf("body", "unknown"), 65 | new KvpOf("method", "GET") 66 | ) 67 | ).size(), 68 | new IsEqual<>(2) 69 | ); 70 | } 71 | } 72 | --------------------------------------------------------------------------------