@Test
 public void getCanFindAfterInsert() throws SQLException {
   Controller expected = controller();
   controllerDao.insert(expected);
   Controller actual = controllerDao.getById(expected.getId());
   assertReflectionEquals(expected, actual);
 }
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out = response.getWriter();

    try {
      Long cellinkId = Long.parseLong(request.getParameter("cellinkId"));
      Long controllerId = Long.parseLong(request.getParameter("controllerId"));
      Long flockId = Long.parseLong(request.getParameter("flockId"));
      String amount = request.getParameter("amount");
      String name = request.getParameter("name");
      String price = request.getParameter("price");
      String total = request.getParameter("total");

      try {
        MedicineDao medicineDao = DbImplDecider.use(DaoType.MYSQL).getDao(MedicineDao.class);
        Medicine medicine = new Medicine();

        medicine.setFlockId(flockId);
        medicine.setAmount(Integer.parseInt(amount));
        medicine.setName(name);
        medicine.setPrice(Float.parseFloat(price));
        medicine.setTotal(Float.parseFloat(total));
        medicineDao.insert(medicine);
        logger.info("Medicine added successfully to the database");

        List<Medicine> medicines = medicineDao.getAllByFlockId(flockId);
        float totalMedicine = 0;

        for (Medicine m : medicines) {
          totalMedicine += m.getTotal();
        }

        FlockDao flockDao = DbImplDecider.use(DaoType.MYSQL).getDao(FlockDao.class);
        Flock flock = flockDao.getById(flockId);

        flock.setTotalMedic(totalMedicine);
        flockDao.updateFlockDetail(flock);

        ControllerDao controllerDao = DbImplDecider.use(DaoType.MYSQL).getDao(ControllerDao.class);
        Collection<Controller> controllers = controllerDao.getAllByCellink(cellinkId);

        for (Controller controller : controllers) {
          Collection<Flock> flocks = flockDao.getAllFlocksByController(controller.getId());
          controller.setFlocks(flocks);
        }

        request.setAttribute("controllers", controllers);
        request
            .getRequestDispatcher(
                "./rmctrl-add-medicine.jsp?celinkId="
                    + cellinkId
                    + "&controllerId="
                    + controllerId
                    + "&flockId="
                    + flockId)
            .forward(request, response);
      } catch (Exception ex) {
        logger.info("Error adding medicine", ex);
        request
            .getRequestDispatcher(
                "./rmctrl-add-medicine.jsp?celinkId="
                    + cellinkId
                    + "&controllerId="
                    + controllerId
                    + "&flockId="
                    + flockId)
            .forward(request, response);
      }
    } finally {
      out.close();
    }
  }