-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathEx2_CreateTestConf.java
More file actions
49 lines (36 loc) · 2.03 KB
/
Ex2_CreateTestConf.java
File metadata and controls
49 lines (36 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package es.us.isa.restest.examples;
import es.us.isa.restest.configuration.TestConfigurationFilter;
import es.us.isa.restest.configuration.generators.DefaultTestConfigurationGenerator;
import es.us.isa.restest.specification.OpenAPISpecification;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
/**
* All RESTest test case generators requires an input test configuration file specifying the API operations to be tested,
* test data generators for each input parameter, authentication details, etc.
* This example shows how to generate a default test configuration file for an API given its OAS specification.
* See test cases for more examples.
*
* The resources for this example are located at src/main/resources/Examples/Ex2_CreateTestConf.
*
*/
public class Ex2_CreateTestConf {
public static final String SPEC_PATH = "src/main/resources/Examples/Ex2_CreateTestConf/spec_bigoven.yaml"; // Path to OAS specification file
public static final String CONF_PATH = "src/main/resources/Examples/Ex2_CreateTestConf/default_test_conf.yaml"; // Path to test configuration file
private static final Logger logger = LogManager.getLogger(Ex2_CreateTestConf.class.getName());
public static void main(String[] args) {
// Load specification file
OpenAPISpecification spec = new OpenAPISpecification(SPEC_PATH);
// Create filters to indicate which operations (paths and http methods) to include in the test configuration file.
List<TestConfigurationFilter> filters = new ArrayList<>();
TestConfigurationFilter filter = new TestConfigurationFilter();
filter.setPath("/recipes");
filter.addGetMethod();
filters.add(filter);
// Generate default test configuration file
DefaultTestConfigurationGenerator gen = new DefaultTestConfigurationGenerator(spec);
gen.generate(CONF_PATH, filters);
logger.info("Default test configuration file generated at " + CONF_PATH);
}
}