Skip to content

Commit

Permalink
fix on the delete with foreign key constraint, changed response code …
Browse files Browse the repository at this point in the history
…of delete to 200, added integration test
  • Loading branch information
souravroy committed Jan 28, 2024
1 parent 1e0f28a commit c52c68d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


Expand All @@ -16,7 +15,7 @@ public class DeleteController {

private final DeleteService deleteService;

@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseStatus(HttpStatus.OK)
@DeleteMapping("/{tableName}")
public DeleteResponse delete(@PathVariable String tableName,
@RequestParam(name = "schemaName", required = false) String schemaName,
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/homihq/db2rest/rest/MySQLDeleteAllTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void delete_all_records_with_allow_safe_delete_false() throws Exception {
mockMvc.perform(delete("/country")
//.header("Content-Profile", "sakila")
.accept(APPLICATION_JSON))
.andExpect(status().isNoContent())
.andExpect(status().isOk())
.andExpect(jsonPath("$.rows", Matchers.equalTo(4)))
//.andDo(print())
.andDo(print())
.andDo(document("mysql-delete-a-director"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void delete_single_record() throws Exception {
.param("filter", "first_name==\"Alex\"")
// .header("Content-Profile", "sakila")
.accept(APPLICATION_JSON))
.andExpect(status().isNoContent())
.andExpect(status().isOk())
.andExpect(jsonPath("$.rows", Matchers.equalTo(1)))
//.andDo(print())
.andDo(print())
.andDo(document("mysql-delete-a-director"));
}

Expand All @@ -37,7 +37,7 @@ void delete_all_records_with_allow_safe_delete_true() throws Exception {
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.detail",
containsString("Invalid delete operation , safe set to true")))
//.andDo(print())
.andDo(print())
.andDo(document("mysql-delete-a-director"));
}

Expand Down Expand Up @@ -65,7 +65,7 @@ void foreign_key_constraint_violation() throws Exception {
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.detail",
containsString("Cannot delete or update a parent row: a foreign key constraint fails")))
//.andDo(print())
.andDo(print())
.andDo(document("mysql-delete-a-director"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ void delete_single_record() throws Exception {
mockMvc.perform(delete("/director")
.param("filter", "first_name==\"Alex\"")
.accept(APPLICATION_JSON))
.andExpect(status().isNoContent())
.andExpect(status().isOk())
.andExpect(jsonPath("$.rows", Matchers.equalTo(1)))
//.andDo(print())
.andDo(print())
.andDo(document("pg-delete-a-director"));
}

Expand All @@ -35,7 +35,7 @@ void delete_all_records_with_allow_safe_delete_true() throws Exception {
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.detail",
containsString("Invalid delete operation , safe set to true")))
//.andDo(print())
.andDo(print())
.andDo(document("pg-delete-a-director"));
}

Expand All @@ -59,9 +59,10 @@ void foreign_key_constraint_violation() throws Exception {
.param("filter", "name==\"English\"")
.accept(APPLICATION_JSON))
.andExpect(status().isBadRequest())
/*.andExpect(jsonPath("$.detail",
containsString("Cannot delete or update a parent row: a foreign key constraint fails")))*/
//.andDo(print())
.andExpect(jsonPath("$.detail",
containsString("ERROR: update or delete on table \"language\" violates foreign key " +
"constraint \"film_language_id_fkey\" on table \"film")))
.andDo(print())
.andDo(document("pg-delete-a-director"));
}
}
7 changes: 0 additions & 7 deletions src/test/resources/pg/postgres-sakila.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c52c68d

Please sign in to comment.