Giter VIP home page Giter VIP logo

httpmocker's People

Contributors

lsuski avatar speekha avatar stephanebg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

httpmocker's Issues

Record mode issue?

I am using the following builder setup to just to record some canned responses in a directory.

 MockResponseInterceptor.Builder()
            .parseScenariosWith(GsonMapper())
            .loadFileWith { context.assets.open(it) }
            .setInterceptorStatus(MockResponseInterceptor.Mode.RECORD)
            .saveScenariosIn(File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOWNLOADS).absolutePath))
.saveScenariosIn(File(Environment.getExternalStorageDirectory().path))
            .build()

I also tried File(Environment.getExternalStorageDirectory().path) without any luck

I cannot see any json respons saved or any logs indicating a issue.
Am I missing something?

Ability to mock request exception

In version 1.6 interceptor is caching all exceptions throwed during creating ResponseDescriptor and return default response (404, page not found).

try {
    provider.loadResponse(request)?.let { response ->
        executeMockResponse(response, request, provider)
    }
} catch (e: Throwable) {
    logger.error("Scenario file could not be loaded", e)
    null
}

There is no possibility to mock any communication exception now. It would be nice to have such option back.

Restore Dokka with multiplatform

Documentation generation and publication with Dokka has been temporarily removed in order to let KMM target build. Needs to be updated and reactivated.

Allow custom RequestDescriptor.match(request: Request) handler

I have 2 requests hitting the same endpoint that differ in several ways:

The first request has no params (since Retrofit strips out null param values):

"request": {
      "method": "GET",
      "headers": {},
      "params": {}
    }

The second request does have a param:

"request": {
      "method": "GET",
      "headers": {},
      "params": {
        "token": "eyJvYmplY3Rfc2VxIjo2NDUyNTd9"
      }
    }

The problem is that the matcher always matches the first request, since params.all { request.url().queryParameter(it.key) == it.value } short-circuits and always returns true for a request that has empty params list.

Adding params.size == request.url().querySize() check to the RequestDescriptor.match(request: Request) fixes the issue, but I'm not sure if that's the desired behavior in every case and/or for this library in general.

Add support for different JSON parrsing libs

Given the different parsing libraries available, developers might not want to include Jackson in their apps if they already use GSON or Moshi. The lib should be modular and allow to include the desired parser.

Support for multiplatform

HttpMocker is only available for JVM compatible platforms (JVM or Android). Other platforms, especially mobile ones like iOS, could benefit from a dedicated version for multiplatform applications.

JVM specific code will have to be isolated so a common project can be extracted and iOS specific implementations can be provided for iOS developers.

Requires support for a multiplatform http client first, like Ktor.

Replace mockito in tests

Mockito kotlin hasn't shown sign of support for quite a while. Replacing it with Mockk would be preferable.

Ability to execute the chain with a new request in Mixed mode.

Currently, the Interceptor used in my project appends some extra headers and tokens depending on certain conditions.
Screenshot 2020-04-19 at 2 58 31 PM

Now if I were to change my above function as
Screenshot 2020-04-19 at 2 59 39 PM

In mixed mode the api(which are not going to give the mock data) will never be able to run with "extra_header". CMIIW.

Body matcher fails due to regex matching

I have a static scenario with "record". When trying to match them with mode.ENABLED, I get an exception :

ERROR fr.speekha.httpmocker.scenario.StaticMockProvider - Scenario file could not be loaded
java.util.regex.PatternSyntaxException: Illegal repetition
{"data":{"username":"XXX","key":"XXX","project_code":"Explorers_Helidon"},"action":"get_information","group":"projects"}
	at java.util.regex.Pattern.error(Pattern.java:1969) ~[?:1.8.0_265]
	at java.util.regex.Pattern.closure(Pattern.java:3171) ~[?:1.8.0_265]
	at java.util.regex.Pattern.sequence(Pattern.java:2148) ~[?:1.8.0_265]
	at java.util.regex.Pattern.expr(Pattern.java:2010) ~[?:1.8.0_265]
	at java.util.regex.Pattern.compile(Pattern.java:1702) ~[?:1.8.0_265]
	at java.util.regex.Pattern.<init>(Pattern.java:1352) ~[?:1.8.0_265]
	at java.util.regex.Pattern.compile(Pattern.java:1028) ~[?:1.8.0_265]
	at kotlin.text.Regex.<init>(Regex.kt:89) ~[kotlin-stdlib-1.4.10.jar:1.4.10-release-411 (1.4.10)]
	at fr.speekha.httpmocker.io.OkHttpExtensionsKt.matchBody(OkHttpExtensions.kt:46) ~[mocker-1.2.0.jar:?]
	at fr.speekha.httpmocker.scenario.RequestMatcher.matchBody(RequestMatcher.kt:37) ~[mocker-1.2.0.jar:?]

To Reproduce

Create a static scenario with :

{
  "request" : {
    "method" : "POST",
    "headers" : { },
    "params" : { },
    "body" : "{\"data\":{\"username\":\"XXX\",\"key\":\"XXX\",\"project_code\":\"Explorers_Helidon\"},\"action\":\"get_information\",\"group\":\"projects\"}"
  },

Expected behavior
Of course the body section of a request is meant to be a regex, but a recorded scenario should be matched "out of the box" to minimize work for the developer.
I experimented a little and an easy solution would be to create the regex in OkHttpExtensions.kt:44 :
Regex(bodyPattern, RegexOption.LITERAL), but then normal regex would not work anymore :(

Desktop (please complete the following information):
httpmocker version 1.2.0
Kotlin version 1.4
Retrofit version 2.9.0
OkHttp version 4.8.1

Support for Ktor HTTP client

HttpMocker support should be extended to Ktor clients.

OkHttp specific parts need to be isolated in a common module. An okHttp specific module should gather the specific code and a new Ktor module should be created to implement its specificities

Ktor support could allow to design a multiplatform build in the future.

Add noop artifact for release builds

When HttpMocker is used for debuging purposes (mocking unavailable HTTP services), the interceptor should not be included in production code. One way to allow to remove Httpmocker code from production builds is to provide a No-op artifact which would preserve compilation but not include any of the HttpMocker code.

Automatic mocking

Based on existing data classes, and possibly on retrofit services, mock responses could be computed automatically :

  • at runtime through introspection/reflection
  • or at compile time by generating static scenarios.

Query parameters should support doubles

A URL can have multiple instances of a single query parameter. Storing them as a Map<String, String> is not valid. They should be stored as List<Pair<String, String>> like headers.

Possible race condition in DynamicMockProvider

Hi, I've encountered very rare situation in tests, when there are 2 requests sent simultaneously . I've digged into DynamicMockProvider and it looks like it uses LinkedHashMap which is not synchronized (according to https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html). I can't reproduce it easily but probably there is a bug in this line
body[request] = result.body.toByteArray() - if this executes at the same time for 2 requests then one of them could override another due to lack of synchronization in LinkedHashMap.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.