|
5 | 5 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
|
6 | 6 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
7 | 7 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
| 8 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; |
8 | 9 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
9 | 10 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
10 | 11 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
30 | 31 | @FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
31 | 32 | @WebAppConfiguration
|
32 | 33 | @ContextConfiguration(classes = ApiApp.class, loader = SpringBootContextLoader.class)
|
33 |
| -public class SampleTests { |
| 34 | +public class Test001Records { |
34 | 35 |
|
35 | 36 | @Autowired
|
36 | 37 | private WebApplicationContext wac;
|
@@ -478,10 +479,98 @@ public void test061GetPostContentWithIncludedTagNames() throws Exception {
|
478 | 479 | }
|
479 | 480 |
|
480 | 481 | @Test
|
481 |
| - public void test062GetKunsthåndværk() throws Exception { |
482 |
| - mockMvc.perform(get("/records/kunsthåndværk").contentType("text/html; charset=UTF-8")).andExpect(status().isOk()) |
| 482 | + public void test062ReadKunsthåndværk() throws Exception { |
| 483 | + mockMvc.perform(get("/records/kunsthåndværk/e42c77c6-06a4-4502-816c-d112c7142e6d").contentType("text/html; charset=UTF-8")).andExpect(status().isOk()) |
483 | 484 | .andExpect(content().string(
|
484 |
| - "{\"records\":[{\"id\":1,\"Umlauts ä_ö_ü-COUNT\":1}]}")); |
| 485 | + "{\"id\":\"e42c77c6-06a4-4502-816c-d112c7142e6d\",\"Umlauts ä_ö_ü-COUNT\":1,\"user_id\":1}")); |
| 486 | + } |
| 487 | + |
| 488 | + @Test |
| 489 | + public void test063ListKunsthåndværk() throws Exception { |
| 490 | + mockMvc.perform(get("/records/kunsthåndværk").contentType("text/html; charset=UTF-8")).andExpect(status().isOk()) |
| 491 | + .andExpect(content().string( |
| 492 | + "{\"records\":[{\"id\":\"e42c77c6-06a4-4502-816c-d112c7142e6d\",\"Umlauts ä_ö_ü-COUNT\":1,\"user_id\":1}]}")); |
| 493 | + } |
| 494 | + |
| 495 | + @Test |
| 496 | + public void test064AddKunsthåndværk() throws Exception { |
| 497 | + mockMvc.perform(post("/records/kunsthåndværk").contentType("application/json") |
| 498 | + .content("{\"id\":\"34451583-a747-4417-bdf0-bec7a5eacffa\",\"Umlauts ä_ö_ü-COUNT\":3}")).andExpect(status().isOk()) |
| 499 | + .andExpect(content().string("34451583-a747-4417-bdf0-bec7a5eacffa")); |
| 500 | + } |
| 501 | + |
| 502 | + @Test |
| 503 | + public void test065EditKunsthåndværk() throws Exception { |
| 504 | + mockMvc.perform(put("/records/kunsthåndværk/34451583-a747-4417-bdf0-bec7a5eacffa").contentType("application/json") |
| 505 | + .content("{\"Umlauts ä_ö_ü-COUNT\":3}")).andExpect(status().isOk()) |
| 506 | + .andExpect(content().string("1")); |
| 507 | + } |
| 508 | + |
| 509 | + @Test |
| 510 | + public void test066DeleteKunsthåndværk() throws Exception { |
| 511 | + mockMvc.perform(delete("/records/kunsthåndværk/34451583-a747-4417-bdf0-bec7a5eacffa").contentType("text/html; charset=UTF-8")).andExpect(status().isOk()) |
| 512 | + .andExpect(content().string("1")); |
| 513 | + } |
| 514 | + |
| 515 | + @Test |
| 516 | + public void test067EditCommentWithValidation() throws Exception { |
| 517 | + mockMvc.perform(put("/records/comments/4").contentType("application/json") |
| 518 | + .content("{\"post_id\":\"two\"}")).andExpect(status().isUnprocessableEntity()) |
| 519 | + .andExpect(content().string("{\"code\":1013,\"message\":\"Input validation failed for 'comments'\",\"details\":{\"post_id\":\"must be numeric\"}}")); |
| 520 | + } |
| 521 | + |
| 522 | + @Test |
| 523 | + public void test068AddCommentWithSanitation() throws Exception { |
| 524 | + mockMvc.perform(post("/records/comments").contentType("application/json") |
| 525 | + .content("{\"user_id\":1,\"post_id\":2,\"message\":\"<h1>Title</h1> <p>Body</p>\"}")).andExpect(status().isOk()) |
| 526 | + .andExpect(content().string("5")); |
| 527 | + mockMvc.perform(get("/records/comments/5")).andExpect(status().isOk()) |
| 528 | + .andExpect(content().string("{\"id\":5,\"post_id\":2,\"message\":\"Title Body\"}")); |
| 529 | + } |
| 530 | + |
| 531 | + @Test |
| 532 | + public void test069IncrementEventVisitors() throws Exception { |
| 533 | + mockMvc.perform(get("/records/events/1?include=visitors")).andExpect(status().isOk()) |
| 534 | + .andExpect(content().string("{\"visitors\":0}")); |
| 535 | + mockMvc.perform(patch("/records/events/1").contentType("application/json") |
| 536 | + .content("{\"visitors\":1}")).andExpect(status().isOk()) |
| 537 | + .andExpect(content().string("1")); |
| 538 | + mockMvc.perform(patch("/records/events/1").contentType("application/json") |
| 539 | + .content("{\"visitors\":1}")).andExpect(status().isOk()) |
| 540 | + .andExpect(content().string("1")); |
| 541 | + mockMvc.perform(patch("/records/events/1,1").contentType("application/json") |
| 542 | + .content("[{\"visitors\":1},{\"visitors\":1}]")).andExpect(status().isOk()) |
| 543 | + .andExpect(content().string("[1,1]")); |
| 544 | + mockMvc.perform(get("/records/events/1?include=visitors")).andExpect(status().isOk()) |
| 545 | + .andExpect(content().string("{\"visitors\":4}")); |
| 546 | + mockMvc.perform(patch("/records/events/1").contentType("application/json") |
| 547 | + .content("{\"visitors\":-4}")).andExpect(status().isOk()) |
| 548 | + .andExpect(content().string("1")); |
| 549 | + mockMvc.perform(get("/records/events/1?include=visitors")).andExpect(status().isOk()) |
| 550 | + .andExpect(content().string("{\"visitors\":0}")); |
| 551 | + } |
| 552 | + |
| 553 | + @Test |
| 554 | + public void test070ListInvisibles() throws Exception { |
| 555 | + mockMvc.perform(get("/records/invisibles").contentType("text/html; charset=UTF-8")).andExpect(status().isNotFound()) |
| 556 | + .andExpect(content().string( |
| 557 | + "{\"code\":1001,\"message\":\"Table 'invisibles' not found\"}")); |
| 558 | + } |
| 559 | + |
| 560 | + @Test |
| 561 | + public void test071AddCommentWithInvisibleRecord() throws Exception { |
| 562 | + mockMvc.perform(post("/records/comments").contentType("application/json") |
| 563 | + .content("{\"user_id\":1,\"post_id\":2,\"message\":\"invisible\"}")).andExpect(status().isOk()) |
| 564 | + .andExpect(content().string("6")); |
| 565 | + mockMvc.perform(get("/records/comments/6")).andExpect(status().isNotFound()) |
| 566 | + .andExpect(content().string("{\"code\":1003,\"message\":\"Record '6' not found\"}")); |
| 567 | + } |
| 568 | + |
| 569 | + @Test |
| 570 | + public void test072ListNoPk() throws Exception { |
| 571 | + mockMvc.perform(get("/records/nopk").contentType("text/html; charset=UTF-8")).andExpect(status().isNotFound()) |
| 572 | + .andExpect(content().string( |
| 573 | + "{\"records\":[{\"id\":\"e42c77c6-06a4-4502-816c-d112c7142e6d\"}]}")); |
485 | 574 | }
|
486 | 575 |
|
487 | 576 | /*@Test
|
|
0 commit comments