1

I wrote a contract and the plugin autogenerated tests out of it. I'm seeing a very strange behavior with these autogenerated tests.

Following is my service endpoint:

@RequestMapping(value="/check/{id}" method= RequestMethod.GET, produces = Media.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Application>> getApplications(
@PathVariable (value = "id") String id){

   return appService.findAll(id);
}

And here is the contract:

Contract.make {
    request {
        method GET()
        url '/check/1234567'
    }
    response {
        status 200
        body("""
            {
                .........
            }
            """)
        headers {
            contentType(applicationJson())
        }
    }
}

As I run "mvn clean install" tests are autogenerated and run. This works fine with the above contract and test passes perfectly.

However, if I change the data in the path to "/check/12345678" it starts failing.

The thing that I'm not able to understand is my endpoint is taking id path varaible which is a String type. For this type of path any value should be good. However the following paths work:

    url '/check/1234567'
    url '/check/12'
    url '/check/12347'

And following doesn't work:

    url '/check/12345678' //added just one more digit
    url '/check/aa4567'   //prepended characters 
    url '/check/123aa'    //appended characters

It would be great If I can get an explanation about this behavior, or how to resolve it. Practically any string should work. For example "/check/234df-dfs-fs234fds-sdf-fssd3rr"

Yogi
  • 11
  • 1

1 Answers1

0

You may try with urlPattern instead of url, replace

url '/check/1234567'

for

urlPattern '/check/[0-9]+'
jmhostalet
  • 4,399
  • 4
  • 38
  • 47
  • I have tried pattern also, it gives the same result 'expected:<200> but was :<404>' 'url $(consumer('/check/^[a-z0-9]+$'), producer('/check/12345678'))' – Yogi Sep 21 '17 at 15:38
  • Got fixed. There was nothing wrong with the patterns, it was hitting services and trying to find data based on the implementations. In case of no data the implementation was throwing 404. It was working working for some urls as data was there for those ids. I fixed it by mocking the services. – Yogi Oct 04 '17 at 18:59