scala-academy / castalia

API stub server
Other
8 stars 3 forks source link

As a stubserver user I want to be able to programatically define the behavior of a stub #10

Closed jordi133 closed 8 years ago

jordi133 commented 8 years ago

background: given that the stubserver is started and configured to use a stub called "programmedstub" and that a stub config file with name "programmedstub.json" is on the classpath and "programmedstub.json" contains a property "endpoint" equal to "programmedstub"

given that "programmedstub.json" contains a property "behaviorSource" equal to "ProgrammedStub.class" and "ProgrammedStub.class" is on the classpath when I do a HTTP GET to .../castalia/stubs/programmedstub/ then the logic programmed in ProgrammedStub.scala should be used for creating the response

rezolya commented 8 years ago

can you add an example of ProgrammedStub.scala?

rezolya commented 8 years ago

do we need to compile the file ourselves, or do we get a jar?

rezolya commented 8 years ago

does the ProgrammedStub.scala contain Main object? does it take any parameters? how do we know which method to execute?

rezolya commented 8 years ago

Is the program supposed to return a json content or send the reply to the requester already?

jordi133 commented 8 years ago

Let's assume that there is a .class file (for example ProgrammedStub.class) available on the classpath of castalia and that the stub config contains "source" = "ProgrammedStub"

jeanmarc commented 8 years ago

There should be a trait that mixes in a function process(httpRequest: HttpRequest): StubResponse (or a RequestMatch, which will be enriched with the httpRequest.