This server is a stub for testing RestApi integration.
...
<repositories>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>
...
<dependency>
<groupId>ru.svnik.tests</groupId>
<artifactId>fake-rest-server</artifactId>
<version>0.0.13</version>
<type>pom</type>
</dependency>
...
compile 'ru.svnik.tests:fake-rest-server:0.0.13'
Also you can build the lid by yourself.
gradle lib ## with all dependencies
gradle jar ## only fake server
Take lib in ./build/libs
use in your code
val app = FakeServer(port : Int = 7000, pathToFileContainsResource: String = "/resource.json").server()
//your test code
app.stop()
FakeServer app = FakeServer(int port, String pathToFileContainsResource).server();
//your test code
app.stop();
import ru.svnik.tests.elements.FakeRestServer;
public class JunitAnnotationTest {
@Rule
public FakeRestServerRule rule = new FakeRestServerRule();
@Test
@FakeRestServer(port = 7000,resourceFile = "/resource.json")
public void name() throws InterruptedException {
sleep(300);
}
}
import ru.svnik.tests.junit5.FakeRestServer;
public class JunitAnnotationTest {
@Test
@FakeRestServer(port = 7000,resourceFile = "/resource.json")
public void name() throws InterruptedException {
sleep(300);
}
}
import ru.svnik.tests.elements.FakeRestServer;
@Listeners(FakeRestServerListener.class)
public class TestNGAnnotationTest {
@Test
@FakeRestServer(port = 7000,resourceFile = "/resource.json")
public void name() throws InterruptedException {
sleep(300);
}
}
Required resources is resource.json and error.json. error.json file of the standard response on error. resource.json contains all information about the server resources.
[
{
"resource": "/api/hello/",
"code": 200,
},
{
"resource": "/api/robots/",
"code": 200,
"path": "/robots.json",
"method": ["get"],
"path_to_error": "/empty.json",
"error_code": 200,
"required_field":{
"info.old_info.info[1].name": "server"
},
"required_headers": {
"token": "123456789"
},
"required_queries": {
"last_name": ["Rodriguez", "Anna"]
}
}
]
resource and path required fields in resource.json.
If you want to use the server as a stand-alone application, use the app profile.
gradle app
java -Dport=80 -Dresourcefile="/resource.json" -jar fake-rest-server-app-version-hash.jar
Unfortunately you have to change the files in the jar.