22
33import de .kaleidox .workbench .model .jpa .representant .Customer ;
44import de .kaleidox .workbench .repo .CustomerRepository ;
5+ import org .junit .jupiter .api .MethodOrderer ;
56import org .junit .jupiter .api .Order ;
67import org .junit .jupiter .api .Test ;
8+ import org .junit .jupiter .api .TestMethodOrder ;
79import org .springframework .beans .factory .annotation .Autowired ;
810import org .springframework .boot .test .context .SpringBootTest ;
911import org .springframework .boot .test .web .client .TestRestTemplate ;
1315
1416import static org .junit .jupiter .api .Assertions .*;
1517
18+ @ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
1619@ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .DEFINED_PORT )
1720public class CustomerApiTest {
1821 public static final String FAARQUARDT_NAME = "Lord Faarquardt" ;
@@ -29,7 +32,20 @@ void contextLoads() {
2932 }
3033
3134 @ Test
32- @ Order (1 )
35+ @ Order (10 )
36+ void createCustomers () {
37+ for (var customer : List .of (FAARQUARDT_CASTLE , FAARQUARDT_HOUSE )) {
38+ var response = rest .postForEntity ("http://localhost:8080/api/customers" , customer , Void .class );
39+ assertEquals (201 , response .getStatusCode ().value (), "status code mismatch" );
40+
41+ var result = customers .findById (customer .key ());
42+ assertTrue (result .isPresent (), "customer not found" );
43+ assertEquals (customer , result .get ());
44+ }
45+ }
46+
47+ @ Test
48+ @ Order (11 )
3349 void fetchNames () {
3450 var response = rest .getForEntity ("http://localhost:8080/api/customers/names" , String [].class );
3551 assertTrue (response .getStatusCode ().is2xxSuccessful (), "request unsuccessful" );
@@ -41,7 +57,7 @@ void fetchNames() {
4157 }
4258
4359 @ Test
44- @ Order (2 )
60+ @ Order (12 )
4561 void fetchDepartments () {
4662 var response = rest .getForEntity ("http://localhost:8080/api/customers/%s/departments" .formatted (FAARQUARDT_NAME ),
4763 String [].class );
@@ -53,17 +69,4 @@ void fetchDepartments() {
5369 assertNotEquals (-1 , Arrays .binarySearch (data , "Castle" ), "department not found" );
5470 assertNotEquals (-1 , Arrays .binarySearch (data , "House" ), "department not found" );
5571 }
56-
57- @ Test
58- @ Order (10 )
59- void createCustomers () {
60- for (var customer : List .of (FAARQUARDT_CASTLE , FAARQUARDT_HOUSE )) {
61- var response = rest .postForEntity ("http://localhost:8080/api/customers" , customer , Void .class );
62- assertEquals (201 , response .getStatusCode ().value (), "status code mismatch" );
63-
64- var result = customers .findById (customer .key ());
65- assertTrue (result .isPresent (), "customer not found" );
66- assertEquals (customer , result .get ());
67- }
68- }
6972}
0 commit comments