@@ -25,7 +24,6 @@
Title |
Author |
Price |
-
In Stock |
Add Book |
@@ -34,11 +32,8 @@
${ item.getTitle() } |
${ item.getAuthor() } |
|
-
10 |
Edit
Delete |
- <%--
Edit
- Delete | --%>
diff --git a/src/main/webapp/BookForm.jsp b/src/main/webapp/BookForm.jsp
index 353c2a51..c71ce22d 100644
--- a/src/main/webapp/BookForm.jsp
+++ b/src/main/webapp/BookForm.jsp
@@ -11,37 +11,19 @@
diff --git a/src/main/webapp/BookList.jsp b/src/main/webapp/BookList.jsp
index ad0950cb..ac40509a 100644
--- a/src/main/webapp/BookList.jsp
+++ b/src/main/webapp/BookList.jsp
@@ -14,7 +14,6 @@
@@ -25,16 +24,15 @@
Title |
Author |
Price |
-
|
-
+
+
diff --git a/src/main/webapp/ShoppingCart.jsp b/src/main/webapp/ShoppingCart.jsp
deleted file mode 100644
index fab13b4b..00000000
--- a/src/main/webapp/ShoppingCart.jsp
+++ /dev/null
@@ -1,45 +0,0 @@
-<%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
-<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
-<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
-
-
-
-
Book Store
-
-
-
-
-
-
-
-
-
-
- List of Books
-
- | Title |
- Author |
- Price |
- In Stock |
- Add Book |
-
-
-
-
- | ${ item.getTitle() } |
- ${ item.getAuthor() } |
- |
- 10 |
- Edit Delete |
-
-
-
-
-
-
-
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index dc5c5392..449850f0 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -8,23 +8,11 @@
Archetype Created Web Application
- LoginServlet
- LoginServlet
-
- com.pluralsight.LoginServlet
-
-
- LoginServlet
- /LoginServlet
-
-
-
- ControllerServlet
- com.pluralsight.ControllerServlet
+ ControllerServlet
+ com.pluralsight.ControllerServlet
-
- ControllerServlet
- /books/*
+ ControllerServlet
+ /books/*
diff --git a/src/test/java/com/pluralsight/module1/Module1_Task1_IT.java b/src/test/java/com/pluralsight/module1/Module1_Task1_IT.java
index 2be2c318..e1ed5583 100644
--- a/src/test/java/com/pluralsight/module1/Module1_Task1_IT.java
+++ b/src/test/java/com/pluralsight/module1/Module1_Task1_IT.java
@@ -1,4 +1,6 @@
-package com.pluralsight;
+package com.pluralsight.module1;
+
+import com.pluralsight.*;
import org.junit.After;
import org.junit.Before;
@@ -18,59 +20,59 @@ public class Module1_Task1_IT {
private String indexUrl;
private WebClient webClient;
- HtmlPage page;
+ HtmlPage page;
@Before
- public void setUp() throws IOException {
- indexUrl = "http://localhost:8080"; //System.getProperty("integration.base.url");
- webClient = new WebClient();
- // Open the admin page
- page = webClient.getPage(indexUrl + "/books/admin");
- }
- @After
- public void tearDown() {
- webClient.closeAllWindows();
- }
+ public void setUp() throws IOException {
+ indexUrl = "http://localhost:8080"; // System.getProperty("integration.base.url");
+ webClient = new WebClient();
+ // Open the admin page
+ page = webClient.getPage(indexUrl + "/books/admin");
+ }
+
+ @After
+ public void tearDown() {
+ webClient.closeAllWindows();
+ }
- // Verify the edit and delete hrefs, in BookAdmin.jsp contain the id
- @Test
- public void module1_task1() {
- url_contains_id("Delete");
- url_contains_id("Edit");
- }
+ // Verify the edit and delete hrefs, in BookAdmin.jsp contain the id
+ @Test
+ public void _task1() {
+ url_contains_id("Delete");
+ url_contains_id("Edit");
+ }
- public void url_contains_id(String textStr) {
- // First check if an anchor with text "Edit" exists
- HtmlAnchor anchor = null;
- try {
- anchor = page.getAnchorByText(textStr);
- }
- catch ( ElementNotFoundException e) {}
+ public void url_contains_id(String textStr) {
+ // First check if an anchor with text "Edit" exists
+ HtmlAnchor anchor = null;
+ try {
+ anchor = page.getAnchorByText(textStr);
+ } catch (ElementNotFoundException e) {
+ }
- assertNotNull("An anchor with the text " + textStr + " does not exist.", anchor);
+ assertNotNull("An anchor with the text " + textStr + " does not exist.", anchor);
- boolean found = findURLWithID(textStr.toLowerCase());
- assertTrue("The " + textStr + " anchor's href does not contain the id.", found);
- }
+ boolean found = findURLWithID(textStr.toLowerCase());
+ assertTrue("The " + textStr + " anchor's href does not contain the id.", found);
+ }
- private boolean findURLWithID(String urlStr) {
- String foundURL = "";
- try {
- for ( HtmlAnchor a : page.getAnchors()) {
- String href = a.getHrefAttribute();
- if (href.contains(urlStr)) {
- foundURL = a.getHrefAttribute().toString();
- break;
- }
- }
- }
- catch ( ElementNotFoundException e) {
- return false;
- }
- foundURL = foundURL.replaceAll("\\s+","");
- // Might have different id's in the database so remove them.
- foundURL = foundURL.replaceAll("[0-9]","");
- String testingURL = urlStr+"?id=";
- return foundURL.equals(testingURL);
- }
+ private boolean findURLWithID(String urlStr) {
+ String foundURL = "";
+ try {
+ for (HtmlAnchor a : page.getAnchors()) {
+ String href = a.getHrefAttribute();
+ if (href.contains(urlStr)) {
+ foundURL = a.getHrefAttribute().toString();
+ break;
+ }
+ }
+ } catch (ElementNotFoundException e) {
+ return false;
+ }
+ foundURL = foundURL.replaceAll("\\s+", "");
+ // Might have different id's in the database so remove them.
+ foundURL = foundURL.replaceAll("[0-9]", "");
+ String testingURL = urlStr + "?id=";
+ return foundURL.equals(testingURL);
+ }
}
diff --git a/src/test/java/com/pluralsight/module1/Module1_Task2_IT.java b/src/test/java/com/pluralsight/module1/Module1_Task2_IT.java
deleted file mode 100644
index 67f38d61..00000000
--- a/src/test/java/com/pluralsight/module1/Module1_Task2_IT.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.pluralsight;
-
-import static org.junit.Assert.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-
-import org.junit.BeforeClass;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import org.powermock.reflect.Whitebox;
-import java.lang.reflect.Method;
-
-import java.io.*;
-
-public class Module1_Task2_IT {
-
- private ControllerServlet controllerServlet;
-
- // @Before
- // public void setUp() throws Exception {
- // controllerServlet = new ControllerServlet();
- // }
-
- // Verify the deleteBook() method exists in ControllerServlet
- @Test
- public void module1_task2() throws Exception {
- Method method = null;
- try {
- method = Whitebox.getMethod(ControllerServlet.class,
- "deleteBook", HttpServletRequest.class, HttpServletResponse.class);
- } catch (Exception e) {}
-
- String errorMsg = "private void deleteBook() does not exist in ControllerServlet";
- assertNotNull(errorMsg, method);
- }
-}
diff --git a/src/test/java/com/pluralsight/module1/Module1_Task2_and_3_IT.java b/src/test/java/com/pluralsight/module1/Module1_Task2_and_3_IT.java
new file mode 100644
index 00000000..52498550
--- /dev/null
+++ b/src/test/java/com/pluralsight/module1/Module1_Task2_and_3_IT.java
@@ -0,0 +1,83 @@
+package com.pluralsight.module1;
+
+import com.pluralsight.*;
+
+import static org.junit.Assert.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+
+import org.junit.BeforeClass;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.exceptions.*;
+
+import org.powermock.reflect.Whitebox;
+import java.lang.reflect.Method;
+
+import java.io.*;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(ControllerServlet.class)
+public class Module1_Task2_and_3_IT {
+
+ private ControllerServlet controllerServlet;
+ private Method method = null;
+
+ @Before
+ public void setUp() throws Exception {
+ try {
+ method = Whitebox.getMethod(ControllerServlet.class, "deleteBook", HttpServletRequest.class,
+ HttpServletResponse.class);
+ } catch (Exception e) {
+ }
+ }
+
+ // Verify the deleteBook() method exists in ControllerServlet
+ @Test
+ public void _task2() throws Exception {
+ String errorMsg = "private void deleteBook() does not exist in ControllerServlet";
+ assertNotNull(errorMsg, method);
+ }
+
+ @Test
+ public void _task3() throws Exception {
+ String tempID = "0";
+ String errorMsg = "private void deleteBook() does not exist in ControllerServlet";
+ assertNotNull(errorMsg, method);
+
+ ControllerServlet controllerServlet = PowerMockito.spy(new ControllerServlet());
+ boolean called_deleteBook = false;
+ HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+
+ try {
+ Mockito.when(request.getPathInfo()).thenReturn("/delete");
+ // PowerMockito.doNothing().when(controllerServlet, "deleteBook", request,
+ // response);
+ Mockito.when(request.getParameter("id")).thenReturn(tempID);
+ } catch (MethodNotFoundException e) {
+ }
+
+ try {
+ controllerServlet.doGet(request, response);
+ try {
+ PowerMockito.verifyPrivate(controllerServlet).invoke("deleteBook", request, response);
+ called_deleteBook = true;
+ } catch (Throwable e) {
+ }
+ } catch (Exception e) {
+ }
+
+ errorMsg = "After action \"" + "/delete" + "\", did not call deleteBook().";
+ assertTrue(errorMsg, called_deleteBook);
+ }
+}
diff --git a/src/test/java/com/pluralsight/module1/Module1_Task3_IT.java b/src/test/java/com/pluralsight/module1/Module1_Task3_IT.java
deleted file mode 100644
index fd1217b1..00000000
--- a/src/test/java/com/pluralsight/module1/Module1_Task3_IT.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.pluralsight;
-
-import static org.junit.Assert.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-
-import org.junit.BeforeClass;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.exceptions.*;
-
-import java.io.*;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(ControllerServlet.class)
-public class Module1_Task3_IT extends Mockito{
- static String tempID = "0";
-
- // Verify the deleteBook() method exists in ControllerServlet
- // Since it's private need to verify the lines of code get called
- // through the /delete action in doGet()
- @Test
- public void module1_task3() throws Exception {
- ControllerServlet controllerServlet = PowerMockito.spy(new ControllerServlet());
- boolean called_deleteBook = false;
- HttpServletRequest request = mock(HttpServletRequest.class);
- HttpServletResponse response = mock(HttpServletResponse.class);
-
- try {
- when(request.getPathInfo()).thenReturn("/delete");
- //PowerMockito.doNothing().when(controllerServlet, "deleteBook", request, response);
- when(request.getParameter("id")).thenReturn(tempID);
- } catch (MethodNotFoundException e) {}
-
- // try {
- // controllerServlet.doGet(request, response);
- // try {
- // PowerMockito.verifyPrivate(controllerServlet)
- // .invoke("deleteBook", request, response);
- // called_deleteBook = true;
- // } catch (Throwable e) {}
- // } catch (Exception e) {}
-
- String errorMsg = "After action \"" + "/delete" +
- "\", did not call deleteBook().";
- assertTrue(errorMsg, called_deleteBook);
- }
-}
diff --git a/src/test/java/com/pluralsight/module1/Module1_Task4_IT.java b/src/test/java/com/pluralsight/module1/Module1_Task4_IT.java
index e07fb726..a4c7f9aa 100644
--- a/src/test/java/com/pluralsight/module1/Module1_Task4_IT.java
+++ b/src/test/java/com/pluralsight/module1/Module1_Task4_IT.java
@@ -1,4 +1,6 @@
-package com.pluralsight;
+package com.pluralsight.module1;
+
+import com.pluralsight.*;
import static org.junit.Assert.*;
import org.junit.Test;
@@ -8,18 +10,18 @@
public class Module1_Task4_IT {
- // Verify the deleteBook() method exists in BookDAO
- @Test
- public void module1_task4() throws Exception {
- Method method = null;
+ // Verify the deleteBook() method exists in BookDAO
+ @Test
+ public void _task4() throws Exception {
+ Method method = null;
- try {
- method = BookDAO.class.getMethod("deleteBook", int.class);
- } catch (NoSuchMethodException e) {
- //e.printStackTrace();
- }
+ try {
+ method = BookDAO.class.getMethod("deleteBook", int.class);
+ } catch (NoSuchMethodException e) {
+ // e.printStackTrace();
+ }
- String message = "The method deleteBook() doesn't exist in BookDAO.java.";
- assertNotNull(message, method);
- }
+ String message = "The method deleteBook() doesn't exist in BookDAO.java.";
+ assertNotNull(message, method);
+ }
}
diff --git a/src/test/java/com/pluralsight/module1/Module1_Task5_IT.java b/src/test/java/com/pluralsight/module1/Module1_Task5_IT.java
index 24d973ad..0488eec4 100644
--- a/src/test/java/com/pluralsight/module1/Module1_Task5_IT.java
+++ b/src/test/java/com/pluralsight/module1/Module1_Task5_IT.java
@@ -1,4 +1,6 @@
-package com.pluralsight;
+package com.pluralsight.module1;
+
+import com.pluralsight.*;
import static org.junit.Assert.*;
import java.sql.Connection;
@@ -17,44 +19,44 @@
import java.io.*;
-
@RunWith(PowerMockRunner.class)
-@PrepareForTest({DriverManager.class, PreparedStatement.class, BookDAO.class})
+@PrepareForTest({ DriverManager.class, PreparedStatement.class, BookDAO.class })
public class Module1_Task5_IT {
- // Verify the deleteBook() method exists in BookDAO
- @Test
- public void module1_task5() throws Exception {
- Method method = null;
- String sql = "DELETE FROM book WHERE id = ?";
- Connection mockConnection = Mockito.mock(Connection.class);
- PreparedStatement mockStatement = Mockito.mock(PreparedStatement.class);
- BookDAO bookDAO = new BookDAO(mockConnection);
- BookDAO spyBookDAO = Mockito.spy(bookDAO);
- boolean called_prepareStatement = false;
-
-
- Mockito.when(mockConnection.prepareStatement(sql)).thenReturn(mockStatement);
-
- try {
- method = BookDAO.class.getMethod("deleteBook", int.class);
- } catch (NoSuchMethodException e) {
- //e.printStackTrace();
- }
-
- String message = "The method deleteBook() doesn't exist in BookDAO.java.";
- assertNotNull(message, method);
-
- try {
- method.invoke(spyBookDAO, 0);
- } catch (Exception e) {}
-
- try {
- Mockito.verify(mockConnection,Mockito.atLeast(1)).prepareStatement(sql);
- called_prepareStatement = true;
- } catch (Throwable e) {}
-
- message = "The method deleteBook() doesn't call prepareStatement() correctly.";
- assertTrue(message, called_prepareStatement);
- }
+ // Verify the deleteBook() in BookDAO calls prepareStatement()
+ @Test
+ public void _task5() throws Exception {
+ Method method = null;
+ String sql = "DELETE FROM book WHERE id = ?";
+ Connection mockConnection = Mockito.mock(Connection.class);
+ PreparedStatement mockStatement = Mockito.mock(PreparedStatement.class);
+ BookDAO bookDAO = new BookDAO(mockConnection);
+ BookDAO spyBookDAO = Mockito.spy(bookDAO);
+ boolean called_prepareStatement = false;
+
+ Mockito.when(mockConnection.prepareStatement(sql)).thenReturn(mockStatement);
+
+ try {
+ method = BookDAO.class.getMethod("deleteBook", int.class);
+ } catch (NoSuchMethodException e) {
+ // e.printStackTrace();
+ }
+
+ String message = "The method deleteBook() doesn't exist in BookDAO.java.";
+ assertNotNull(message, method);
+
+ try {
+ method.invoke(spyBookDAO, 0);
+ } catch (Exception e) {
+ }
+
+ try {
+ Mockito.verify(mockConnection, Mockito.atLeast(1)).prepareStatement(sql);
+ called_prepareStatement = true;
+ } catch (Throwable e) {
+ }
+
+ message = "The method deleteBook() doesn't call prepareStatement() correctly.";
+ assertTrue(message, called_prepareStatement);
+ }
}
diff --git a/src/test/java/com/pluralsight/module1/Module1_Task6_IT.java b/src/test/java/com/pluralsight/module1/Module1_Task6_IT.java
index 488c858d..af24eb38 100644
--- a/src/test/java/com/pluralsight/module1/Module1_Task6_IT.java
+++ b/src/test/java/com/pluralsight/module1/Module1_Task6_IT.java
@@ -1,4 +1,6 @@
-package com.pluralsight;
+package com.pluralsight.module1;
+
+import com.pluralsight.*;
import static org.junit.Assert.*;
import java.sql.Connection;
@@ -17,56 +19,57 @@
import java.io.*;
-
@RunWith(PowerMockRunner.class)
-@PrepareForTest({DriverManager.class, PreparedStatement.class, BookDAO.class})
+@PrepareForTest({ DriverManager.class, PreparedStatement.class, BookDAO.class })
public class Module1_Task6_IT {
- // Verify the deleteBook() method exists in BookDAO
- @Test
- public void module1_task6() throws Exception {
- Method method = null;
- String sql = "DELETE FROM book WHERE id = ?";
- Connection spyConnection = Mockito.mock(Connection.class);
- PreparedStatement mockStatement = Mockito.mock(PreparedStatement.class);
- BookDAO bookDAO = new BookDAO(spyConnection);
- BookDAO spyBookDAO = Mockito.spy(bookDAO);
- boolean called_setInt = false;
- boolean called_execute = false;
- boolean called_prepareStatement = false;
- boolean called_close = false;
+ // Verify the deleteBook() method exists in BookDAO
+ @Test
+ public void _task6() throws Exception {
+ Method method = null;
+ String sql = "DELETE FROM book WHERE id = ?";
+ Connection spyConnection = Mockito.mock(Connection.class);
+ PreparedStatement mockStatement = Mockito.mock(PreparedStatement.class);
+ BookDAO bookDAO = new BookDAO(spyConnection);
+ BookDAO spyBookDAO = Mockito.spy(bookDAO);
+ boolean called_setInt = false;
+ boolean called_execute = false;
+ boolean called_prepareStatement = false;
+ boolean called_close = false;
- Mockito.when(spyConnection.prepareStatement(sql)).thenReturn(mockStatement);
+ Mockito.when(spyConnection.prepareStatement(sql)).thenReturn(mockStatement);
- try {
- method = BookDAO.class.getMethod("deleteBook", int.class);
- } catch (NoSuchMethodException e) {
- //e.printStackTrace();
- }
+ try {
+ method = BookDAO.class.getMethod("deleteBook", int.class);
+ } catch (NoSuchMethodException e) {
+ // e.printStackTrace();
+ }
- String message = "The method deleteBook() doesn't exist in BookDAO.java.";
- assertNotNull(message, method);
+ String message = "The method deleteBook() doesn't exist in BookDAO.java.";
+ assertNotNull(message, method);
- try {
- method.invoke(spyBookDAO, 0);
- } catch (Exception e) {}
+ try {
+ method.invoke(spyBookDAO, 0);
+ } catch (Exception e) {
+ }
- try {
- Mockito.verify(mockStatement, Mockito.atLeast(1)).setInt(Mockito.anyInt(), Mockito.anyInt());
- called_setInt = true;
- Mockito.verify(mockStatement, Mockito.atLeast(1)).executeUpdate();
- called_execute = true;
- Mockito.verify(mockStatement, Mockito.atLeast(1)).close();
- called_close = true;
- } catch (Throwable e) {}
+ try {
+ Mockito.verify(mockStatement, Mockito.atLeast(1)).setInt(Mockito.anyInt(), Mockito.anyInt());
+ called_setInt = true;
+ Mockito.verify(mockStatement, Mockito.atLeast(1)).executeUpdate();
+ called_execute = true;
+ Mockito.verify(mockStatement, Mockito.atLeast(1)).close();
+ called_close = true;
+ } catch (Throwable e) {
+ }
- message = "The method deleteBook() doesn't call setInt().";
- assertTrue(message, called_setInt);
+ message = "The method deleteBook() doesn't call setInt().";
+ assertTrue(message, called_setInt);
- message = "The method deleteBook() doesn't call executeUpdate().";
- assertTrue(message, called_execute);
+ message = "The method deleteBook() doesn't call executeUpdate().";
+ assertTrue(message, called_execute);
- message = "The method deleteBook() doesn't call PreparedStatement close().";
- assertTrue(message, called_close);
- }
+ message = "The method deleteBook() doesn't call PreparedStatement close().";
+ assertTrue(message, called_close);
+ }
}
diff --git a/src/test/java/com/pluralsight/module1/Module1_Task7_and_8_IT.java b/src/test/java/com/pluralsight/module1/Module1_Task7_and_8_IT.java
index 56c83fa4..e25a1cea 100644
--- a/src/test/java/com/pluralsight/module1/Module1_Task7_and_8_IT.java
+++ b/src/test/java/com/pluralsight/module1/Module1_Task7_and_8_IT.java
@@ -1,4 +1,6 @@
-package com.pluralsight;
+package com.pluralsight.module1;
+
+import com.pluralsight.*;
import static org.junit.Assert.*;
import javax.servlet.http.HttpServletRequest;
@@ -25,7 +27,7 @@
import java.lang.reflect.Method;
import java.io.*;
-public class Module1_Task7_and_8_IT extends Mockito{
+public class Module1_Task7_and_8_IT extends Mockito {
static StringWriter stringWriter = new StringWriter();
static String tempID = "0";
@@ -34,15 +36,15 @@ public class Module1_Task7_and_8_IT extends Mockito{
static boolean called_deleteBook = false;
static HttpServletRequest request = mock(HttpServletRequest.class);
static HttpServletResponse response = mock(HttpServletResponse.class);
- static Method deleteMethod = null;
- @Mock
- private BookDAO mockBookDAO;
+ static Method deleteMethod = null;
+ @Mock
+ private BookDAO mockBookDAO;
- @InjectMocks
- private ControllerServlet controllerServlet;
+ @InjectMocks
+ private ControllerServlet controllerServlet;
- @Before
- public void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
request = mock(HttpServletRequest.class);
@@ -52,55 +54,60 @@ public void setUp() throws Exception {
when(request.getParameter("id")).thenReturn(tempID);
try {
- deleteMethod = Whitebox.getMethod(ControllerServlet.class,
- "deleteBook", HttpServletRequest.class, HttpServletResponse.class);
- } catch (Exception e) {}
+ deleteMethod = Whitebox.getMethod(ControllerServlet.class, "deleteBook", HttpServletRequest.class,
+ HttpServletResponse.class);
+ } catch (Exception e) {
+ }
+
+ // String errorMsg = "private void deleteBook() does not exist in
+ // ControllerServlet";
+ // assertNotNull(errorMsg, deleteMethod);
+ if (deleteMethod != null) {
+ try {
+ controllerServlet.doGet(request, response);
+ } catch (Exception e) {
+ }
+ }
+ }
+ // Verify deleteBook() in ControllerServlet is complete
+ @Test
+ public void _task7() throws Exception {
String errorMsg = "private void deleteBook() does not exist in ControllerServlet";
assertNotNull(errorMsg, deleteMethod);
+ MockingDetails mockingDetails = Mockito.mockingDetails(mockBookDAO);
+
+ Collection
invocations = mockingDetails.getInvocations();
+
+ List methodsCalled = new ArrayList<>();
+ for (Invocation anInvocation : invocations) {
+ methodsCalled.add(anInvocation.getMethod().getName());
+ }
+ errorMsg = "The ControllerServlet deleteBook() method was not called.";
+ assertTrue(errorMsg, methodsCalled.contains("deleteBook"));
+
try {
- controllerServlet.doGet(request, response);
- } catch (Exception e) {}
- }
-
- // Verify deleteBook() in ControllerServlet is complete
- @Test
- public void module1_task7() throws Exception {
- String errorMsg = "private void deleteBook() does not exist in ControllerServlet";
- assertNotNull(errorMsg, deleteMethod);
-
- MockingDetails mockingDetails = Mockito.mockingDetails(mockBookDAO);
-
- Collection invocations = mockingDetails.getInvocations();
-
- List methodsCalled = new ArrayList<>();
- for (Invocation anInvocation : invocations) {
- methodsCalled.add(anInvocation.getMethod().getName());
- }
- assertTrue(methodsCalled.contains("deleteBook"));
-
- try {
- verify(request, atLeast(1)).getParameter("id");
- called_getParameter = true;
- } catch (Throwable e) {}
-
- errorMsg = "In ControllerServlet deleteBook()," +
- " did not call getParameter(\"id\").";
- assertTrue(errorMsg, called_getParameter);
- }
-
- @Test
- public void module1_task8() throws Exception {
- String errorMsg = "private void deleteBook() does not exist in ControllerServlet";
- assertNotNull(errorMsg, deleteMethod);
- try {
- verify(response, atLeast(1)).sendRedirect("list");
- called_sendRedirect = true;
- } catch (Throwable e) {}
+ verify(request, atLeast(1)).getParameter("id");
+ called_getParameter = true;
+ } catch (Throwable e) {
+ }
+
+ errorMsg = "In ControllerServlet deleteBook()," + " did not call getParameter(\"id\").";
+ assertTrue(errorMsg, called_getParameter);
+ }
- errorMsg = "In ControllerServlet deleteBook()," +
- " did not call sendRedirect(\"list\").";
- assertTrue(errorMsg, called_sendRedirect);
+ @Test
+ public void _task8() throws Exception {
+ String errorMsg = "private void deleteBook() does not exist in ControllerServlet";
+ assertNotNull(errorMsg, deleteMethod);
+ try {
+ verify(response, atLeast(1)).sendRedirect("list");
+ called_sendRedirect = true;
+ } catch (Throwable e) {
}
+
+ errorMsg = "In ControllerServlet deleteBook()," + " did not call sendRedirect(\"list\").";
+ assertTrue(errorMsg, called_sendRedirect);
+ }
}
diff --git a/src/test/java/com/pluralsight/module2/Module2_Task11_thru_14_IT.java b/src/test/java/com/pluralsight/module2/Module2_Task11_thru_14_IT.java
index 8d3c3206..9b5f1d7f 100644
--- a/src/test/java/com/pluralsight/module2/Module2_Task11_thru_14_IT.java
+++ b/src/test/java/com/pluralsight/module2/Module2_Task11_thru_14_IT.java
@@ -1,4 +1,6 @@
-package com.pluralsight;
+package com.pluralsight.module2;
+
+import com.pluralsight.*;
import org.junit.After;
import org.junit.Before;
@@ -22,113 +24,107 @@ public class Module2_Task11_thru_14_IT {
private String BOOK_FORM_NAME = "book_form";
private String indexUrl;
private WebClient webClient;
- HtmlPage firstPage = null;
+ HtmlPage firstPage = null;
HtmlPage nextPage = null;
HtmlForm form = null;
+ String formErrorMsg = "We can’t find a