1010import static org .evomaster .client .java .controller .api .EMTestUtils .*;
1111import org .evomaster .client .java .controller .SutHandler ;
1212import static org .evomaster .client .java .controller .db .dsl .SqlDsl .sql ;
13+ import org .evomaster .client .java .controller .api .dto .database .operations .InsertionResultsDto ;
1314import org .evomaster .client .java .controller .api .dto .database .operations .InsertionDto ;
1415import java .util .List ;
1516import static org .hamcrest .Matchers .*;
1920import static org .evomaster .client .java .controller .contentMatchers .NumberMatcher .*;
2021import static org .evomaster .client .java .controller .contentMatchers .StringMatcher .*;
2122import static org .evomaster .client .java .controller .contentMatchers .SubStringMatcher .*;
23+ import static org .evomaster .client .java .controller .expect .ExpectationHandler .expectationHandler ;
24+ import org .evomaster .client .java .controller .expect .ExpectationHandler ;
25+ import io .restassured .path .json .JsonPath ;
26+ import java .util .Arrays ;
2227
2328
2429
2530
2631/**
27- * This file was automatically generated by EvoMaster on 2021-07-01T14:44:48.601869400+02 :00[Europe/Oslo]
32+ * This file was automatically generated by EvoMaster on 2021-12-03T15:45:26.280491100+01 :00[Europe/Oslo]
2833 * <br>
29- * The generated test suite contains 2 tests
34+ * The generated test suite contains 1 tests
3035 * <br>
31- * Covered targets: 10
36+ * Covered targets: 8
3237 * <br>
3338 * Used time: 0h 1m 0s
3439 * <br>
35- * Needed budget for current results: 29 %
40+ * Needed budget for current results: 1 %
3641 * <br>
3742 * This file contains one example of each category of fault. The test cases in this file are a subset of the set of test cases likely to indicate faults.
3843 */
@@ -41,6 +46,14 @@ public class EvoMaster_fault_representatives_Test {
4146
4247 private static final SutHandler controller = new org .example .EMDriver ();
4348 private static String baseUrlOfSut ;
49+ /** [ems] - expectations master switch - is the variable that activates/deactivates expectations individual test cases
50+ * by default, expectations are turned off. The variable needs to be set to [true] to enable expectations
51+ */
52+ private static boolean ems = false ;
53+ /**
54+ * rso - response structure oracle - checking that the response objects match the responses defined in the schema
55+ */
56+ private static boolean rso = false ;
4457
4558
4659 @ BeforeAll
@@ -72,36 +85,20 @@ public void initTest() {
7285
7386
7487 @ Test
75- public void test_0_with500 () throws Exception {
76- List <InsertionDto > insertions = sql ().insertInto ("ITEM" , 260L )
77- .d ("ID" , "1" )
78- .dtos ();
79- controller .execInsertionsIntoDatabase (insertions );
88+ public void test_0 () throws Exception {
89+ ExpectationHandler expectationHandler = expectationHandler ();
8090
8191 given ().accept ("*/*" )
8292 .contentType ("application/json" )
83- .body (" { " +
84- " \" cost\" : 641, " +
85- " \" name\" : \" o7vTiW9OQF8TyKO\" " +
86- " } " )
93+ .body (" {} " )
8794 .post (baseUrlOfSut + "/api/items" )
8895 .then ()
89- .statusCode (500 ) // org/example/RestApi_43_create
90- .assertThat ()
91- .contentType ("application/json" )
92- .body ("'status'" , numberMatches (500.0 ))
93- .body ("'error'" , containsString ("Internal Server Error" ))
94- .body ("'message'" , containsString ("" ))
95- .body ("'path'" , containsString ("/api/items" ));
96-
97- given ().accept ("*/*" )
98- .get (baseUrlOfSut + "/api/items/0" )
99- .then ()
100- .statusCode (404 )
96+ .statusCode (201 )
10197 .assertThat ()
10298 .body (isEmptyOrNullString ());
10399
104- given ().accept ("*/*" )
100+
101+ ValidatableResponse res_1 = given ().accept ("*/*" )
105102 .get (baseUrlOfSut + "/api/items" )
106103 .then ()
107104 .statusCode (200 )
@@ -112,52 +109,10 @@ public void test_0_with500() throws Exception {
112109 .body ("[0].'description'" , nullValue ())
113110 .body ("[0].'cost'" , nullValue ());
114111
115- given ().accept ("*/*" )
116- .get (baseUrlOfSut + "/api/items/-16776455" )
117- .then ()
118- .statusCode (404 )
119- .assertThat ()
120- .body (isEmptyOrNullString ());
121- }
122-
123-
124- @ Test
125- public void test_1 () throws Exception {
126- List <InsertionDto > insertions = sql ().insertInto ("ITEM" , 239L )
127- .d ("ID" , "4933" )
128- .and ().insertInto ("ITEM" , 238L )
129- .d ("ID" , "30" )
130- .and ().insertInto ("ITEM" , 237L )
131- .d ("ID" , "0" )
132- .dtos ();
133- controller .execInsertionsIntoDatabase (insertions );
134-
135- given ().accept ("*/*" )
136- .get (baseUrlOfSut + "/api/items" )
137- .then ()
138- .statusCode (200 )
139- .assertThat ()
140- .contentType ("application/json" )
141- .body ("size()" , equalTo (3 ))
142- .body ("[0].'name'" , nullValue ())
143- .body ("[0].'description'" , nullValue ())
144- .body ("[0].'cost'" , nullValue ())
145- .body ("[1].'name'" , nullValue ())
146- .body ("[1].'description'" , nullValue ())
147- .body ("[1].'cost'" , nullValue ())
148- .body ("[2].'name'" , nullValue ())
149- .body ("[2].'description'" , nullValue ())
150- .body ("[2].'cost'" , nullValue ());
151-
152- given ().accept ("*/*" )
153- .get (baseUrlOfSut + "/api/items/0" )
154- .then ()
155- .statusCode (200 )
156- .assertThat ()
157- .contentType ("application/json" )
158- .body ("'name'" , nullValue ())
159- .body ("'description'" , nullValue ())
160- .body ("'cost'" , nullValue ());
112+ expectationHandler .expect (ems )
113+ .that (rso , ((Map ) ((List ) res_1 .extract ().response ().jsonPath ().getJsonObject ("" )).get (0 )).keySet ().containsAll (Arrays .asList ("Iterable«Item»" )))
114+ .that (rso , Arrays .asList ()
115+ .containsAll (((Map ) ((List ) res_1 .extract ().response ().jsonPath ().getJsonObject ("" )).get (0 )).keySet ()));
161116 }
162117
163118
0 commit comments