UCSBArticlesController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBArticles;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBArticlesRepository;
6
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import lombok.extern.slf4j.Slf4j;
11
12
import com.fasterxml.jackson.core.JsonProcessingException;
13
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.format.annotation.DateTimeFormat;
16
import org.springframework.security.access.prepost.PreAuthorize;
17
import org.springframework.web.bind.annotation.DeleteMapping;
18
import org.springframework.web.bind.annotation.GetMapping;
19
import org.springframework.web.bind.annotation.PostMapping;
20
import org.springframework.web.bind.annotation.PutMapping;
21
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RestController;
25
26
import javax.validation.Valid;
27
28
import java.time.LocalDateTime;
29
30
@Tag(name = "UCSBArticles")
31
@RequestMapping("/api/ucsbarticles")
32
@RestController
33
@Slf4j
34
public class UCSBArticlesController extends ApiController {
35
36
    @Autowired
37
    UCSBArticlesRepository ucsbArticlesRepository;
38
39
    @Operation(summary= "List all ucsb articles")
40
    @PreAuthorize("hasRole('ROLE_USER')")
41
    @GetMapping("/all")
42
    public Iterable<UCSBArticles> allUCSBArticles() {
43
        Iterable<UCSBArticles> articles = ucsbArticlesRepository.findAll();
44 1 1. allUCSBArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::allUCSBArticles → KILLED
        return articles;
45
    }
46
47
    @Operation(summary= "Create a new article")
48
    @PreAuthorize("hasRole('ROLE_ADMIN')")
49
    @PostMapping("/post")
50
    public UCSBArticles postUCSBArticles(
51
            @Parameter(name="title") @RequestParam String title,
52
            @Parameter(name="url") @RequestParam String url,
53
            @Parameter(name="explanation") @RequestParam String explanation,
54
            @Parameter(name="email") @RequestParam String email,
55
            @Parameter(name="dateAdded", description = "in iso format, e.g. YYYY-mm-dd see https://en.wikipedia.org/wiki/ISO_8601") @RequestParam("dateAdded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateAdded)
56
            throws JsonProcessingException {
57
58
        // For an explanation of @ArticlesTimeFormat(iso = ArticlesTimeFormat.ISO.DATE_TIME)
59
        // See: https://www.baeldung.com/spring-date-parameters
60
61
        //log.info("localArticlesTime={}", dateAdded);
62
63
        UCSBArticles ucsbArticles = new UCSBArticles();
64 1 1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setTitle → KILLED
        ucsbArticles.setTitle(title);
65 1 1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setUrl → KILLED
        ucsbArticles.setUrl(url);
66 1 1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setExplanation → KILLED
        ucsbArticles.setExplanation(explanation);
67 1 1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setEmail → KILLED
        ucsbArticles.setEmail(email);
68 1 1. postUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setDateAdded → KILLED
        ucsbArticles.setDateAdded(dateAdded);
69
70
        UCSBArticles savedUcsbArticles = ucsbArticlesRepository.save(ucsbArticles);
71
72 1 1. postUCSBArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::postUCSBArticles → KILLED
        return savedUcsbArticles;
73
    }
74
75
    @Operation(summary= "Get a single article")
76
    @PreAuthorize("hasRole('ROLE_USER')")
77
    @GetMapping("")
78
    public UCSBArticles getById(
79
            @Parameter(name="id") @RequestParam Long id) {
80
        UCSBArticles ucsbArticles = ucsbArticlesRepository.findById(id)
81 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBArticles.class, id));
82
83 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::getById → KILLED
        return ucsbArticles;
84
    }
85
86
    @Operation(summary= "Delete a UCSBArticles")
87
    @PreAuthorize("hasRole('ROLE_ADMIN')")
88
    @DeleteMapping("")
89
    public Object deleteUCSBArticles(
90
            @Parameter(name="id") @RequestParam Long id) {
91
        UCSBArticles ucsbArticles = ucsbArticlesRepository.findById(id)
92 1 1. lambda$deleteUCSBArticles$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$deleteUCSBArticles$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBArticles.class, id));
93
94 1 1. deleteUCSBArticles : removed call to edu/ucsb/cs156/example/repositories/UCSBArticlesRepository::delete → KILLED
        ucsbArticlesRepository.delete(ucsbArticles);
95 1 1. deleteUCSBArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::deleteUCSBArticles → KILLED
        return genericMessage("UCSBArticles with id %s deleted".formatted(id));
96
    }
97
98
    @Operation(summary= "Update a single article")
99
    @PreAuthorize("hasRole('ROLE_ADMIN')")
100
    @PutMapping("")
101
    public UCSBArticles updateUCSBArticles(
102
            @Parameter(name="id") @RequestParam Long id,
103
            @RequestBody @Valid UCSBArticles incoming) {
104
105
        UCSBArticles ucsbArticles = ucsbArticlesRepository.findById(id)
106 1 1. lambda$updateUCSBArticles$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$updateUCSBArticles$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBArticles.class, id));
107
108 1 1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setTitle → KILLED
        ucsbArticles.setTitle(incoming.getTitle());
109 1 1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setUrl → KILLED
        ucsbArticles.setUrl(incoming.getUrl());
110 1 1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setExplanation → KILLED
        ucsbArticles.setExplanation(incoming.getExplanation());
111 1 1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setEmail → KILLED
        ucsbArticles.setEmail(incoming.getEmail());
112 1 1. updateUCSBArticles : removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setDateAdded → KILLED
        ucsbArticles.setDateAdded(incoming.getDateAdded());
113
114
        ucsbArticlesRepository.save(ucsbArticles);
115
116 1 1. updateUCSBArticles : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::updateUCSBArticles → KILLED
        return ucsbArticles;
117
    }
118
}

Mutations

44

1.1
Location : allUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:logged_in_user_can_get_all_ucsbarticles()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::allUCSBArticles → KILLED

64

1.1
Location : postUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setTitle → KILLED

65

1.1
Location : postUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setUrl → KILLED

66

1.1
Location : postUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setExplanation → KILLED

67

1.1
Location : postUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setEmail → KILLED

68

1.1
Location : postUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setDateAdded → KILLED

72

1.1
Location : postUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:an_admin_user_can_post_a_new_ucsbarticles()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::postUCSBArticles → KILLED

81

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$getById$0 → KILLED

83

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::getById → KILLED

92

1.1
Location : lambda$deleteUCSBArticles$1
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_tries_to_delete_non_existant_ucsbarticles_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$deleteUCSBArticles$1 → KILLED

94

1.1
Location : deleteUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_can_delete_a_articles()]
removed call to edu/ucsb/cs156/example/repositories/UCSBArticlesRepository::delete → KILLED

95

1.1
Location : deleteUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_can_delete_a_articles()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::deleteUCSBArticles → KILLED

106

1.1
Location : lambda$updateUCSBArticles$2
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_cannot_edit_ucsbarticles_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::lambda$updateUCSBArticles$2 → KILLED

108

1.1
Location : updateUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_can_edit_an_existing_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setTitle → KILLED

109

1.1
Location : updateUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_can_edit_an_existing_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setUrl → KILLED

110

1.1
Location : updateUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_can_edit_an_existing_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setExplanation → KILLED

111

1.1
Location : updateUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_can_edit_an_existing_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setEmail → KILLED

112

1.1
Location : updateUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_can_edit_an_existing_ucsbarticles()]
removed call to edu/ucsb/cs156/example/entities/UCSBArticles::setDateAdded → KILLED

116

1.1
Location : updateUCSBArticles
Killed by : edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBArticlesControllerTests]/[method:admin_can_edit_an_existing_ucsbarticles()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBArticlesController::updateUCSBArticles → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3