UpdateStatusServlet.java

1
package com.popx.presentazione;
2
3
import com.popx.modello.OrdineBean;
4
import com.popx.persistenza.OrdineDAO;
5
import com.popx.persistenza.OrdineDAOImpl;
6
7
import javax.servlet.ServletException;
8
import javax.servlet.annotation.WebServlet;
9
import javax.servlet.http.*;
10
import java.io.IOException;
11
import java.util.logging.Level;
12
import java.util.logging.Logger;
13
14
@WebServlet("/UpdateOrderStatus")
15
public class UpdateStatusServlet extends HttpServlet {
16
17
    private final OrdineDAO ordineDAO;
18
    private static final Logger LOGGER = Logger.getLogger(UpdateStatusServlet.class.getName());
19
20
    // �� production
21
    public UpdateStatusServlet() {
22
        this.ordineDAO = new OrdineDAOImpl();
23
    }
24
25
    // �� test
26
    public UpdateStatusServlet(OrdineDAO ordineDAO) {
27
        this.ordineDAO = ordineDAO;
28
    }
29
30
    @Override
31
    public void doGet(HttpServletRequest request, HttpServletResponse response)
32
            throws ServletException, IOException {
33
34 1 1. doGet : removed call to javax/servlet/http/HttpServletResponse::setContentType → SURVIVED
        response.setContentType("application/json");
35
36
        String idParam = request.getParameter("id");
37
        String newStatus = request.getParameter("status");
38
39 2 1. doGet : negated conditional → KILLED
2. doGet : negated conditional → KILLED
        if (idParam == null || newStatus == null) {
40 1 1. doGet : removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
41 1 1. doGet : removed call to java/io/PrintWriter::write → SURVIVED
            response.getWriter().write("{\"success\": false}");
42
            return;
43
        }
44
45
        int orderId;
46
        try {
47
            orderId = Integer.parseInt(idParam);
48
        } catch (NumberFormatException e) {
49 1 1. doGet : removed call to javax/servlet/http/HttpServletResponse::setStatus → NO_COVERAGE
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
50 1 1. doGet : removed call to java/io/PrintWriter::write → NO_COVERAGE
            response.getWriter().write("{\"success\": false}");
51
            return;
52
        }
53
54
        try {
55
            OrdineBean ordine = ordineDAO.getOrdineById(orderId);
56 1 1. doGet : negated conditional → KILLED
            if (ordine == null) {
57 1 1. doGet : removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED
                response.setStatus(HttpServletResponse.SC_NOT_FOUND);
58 1 1. doGet : removed call to java/io/PrintWriter::write → SURVIVED
                response.getWriter().write("{\"success\": false}");
59
                return;
60
            }
61
62 1 1. doGet : removed call to com/popx/modello/OrdineBean::setStatus → SURVIVED
            ordine.setStatus(newStatus);
63
            boolean success = ordineDAO.updateStatus(ordine);
64
65 1 1. doGet : removed call to java/io/PrintWriter::write → KILLED
            response.getWriter().write("{\"success\": " + success + "}");
66
67
        } catch (Exception e) {
68
            LOGGER.log(Level.SEVERE, "Error updating order status in UpdateStatusServlet", e);
69 1 1. doGet : removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
70 1 1. doGet : removed call to java/io/PrintWriter::write → SURVIVED
            response.getWriter().write("{\"success\": false}");
71
        }
72
    }
73
}

Mutations

34

1.1
Location : doGet
Killed by : none
removed call to javax/servlet/http/HttpServletResponse::setContentType → SURVIVED

39

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.UpdateStatusServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.UpdateStatusServletTest]/[method:updateStatus_exception_returns500()]
negated conditional → KILLED

2.2
Location : doGet
Killed by : com.popx.integration.presentazione.UpdateStatusServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.UpdateStatusServletTest]/[method:updateStatus_exception_returns500()]
negated conditional → KILLED

40

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.UpdateStatusServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.UpdateStatusServletTest]/[method:updateStatus_missingParams_returns400()]
removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED

41

1.1
Location : doGet
Killed by : none
removed call to java/io/PrintWriter::write → SURVIVED

49

1.1
Location : doGet
Killed by : none
removed call to javax/servlet/http/HttpServletResponse::setStatus → NO_COVERAGE

50

1.1
Location : doGet
Killed by : none
removed call to java/io/PrintWriter::write → NO_COVERAGE

56

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.UpdateStatusServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.UpdateStatusServletTest]/[method:updateStatus_orderNotFound_returns404()]
negated conditional → KILLED

57

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.UpdateStatusServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.UpdateStatusServletTest]/[method:updateStatus_orderNotFound_returns404()]
removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED

58

1.1
Location : doGet
Killed by : none
removed call to java/io/PrintWriter::write → SURVIVED

62

1.1
Location : doGet
Killed by : none
removed call to com/popx/modello/OrdineBean::setStatus → SURVIVED

65

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.UpdateStatusServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.UpdateStatusServletTest]/[method:updateStatus_success()]
removed call to java/io/PrintWriter::write → KILLED

69

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.UpdateStatusServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.UpdateStatusServletTest]/[method:updateStatus_exception_returns500()]
removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED

70

1.1
Location : doGet
Killed by : none
removed call to java/io/PrintWriter::write → SURVIVED

Active mutators

Tests examined


Report generated by PIT 1.15.2