From a1fb6ff6a58424628df1a8d8d56ac489633dc6c4 Mon Sep 17 00:00:00 2001 From: Anand Date: Thu, 13 Sep 2012 11:01:15 -0700 Subject: [PATCH 1/5] Added log message. --- src/main/java/com/example/controller/PersonController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/controller/PersonController.java b/src/main/java/com/example/controller/PersonController.java index 82ee420..db1bb4a 100755 --- a/src/main/java/com/example/controller/PersonController.java +++ b/src/main/java/com/example/controller/PersonController.java @@ -11,6 +11,7 @@ import com.example.model.Person; import com.example.service.PersonService; +import java.util.List; import java.util.Map; @Controller @@ -23,8 +24,9 @@ public class PersonController { public String listPeople(Map map) { map.put("person", new Person()); - map.put("peopleList", personService.listPeople()); - + List personList = personService.listPeople(); + map.put("peopleList", personList); + System.out.println(" PeopleList.size()="+personList.size()); return "people"; } From 2edeb51eec015a7c2e87875a8d338a9b5dd46bb4 Mon Sep 17 00:00:00 2001 From: Anand Date: Thu, 13 Sep 2012 11:45:28 -0700 Subject: [PATCH 2/5] Added Testcase. --- pom.xml | 7 +++++ .../example/tests/PersonControllerTest.java | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/test/java/com/example/tests/PersonControllerTest.java diff --git a/pom.xml b/pom.xml index f0fbd3e..5259ac7 100755 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,13 @@ 7.0.22.3 provided + + + junit + junit + 4.10 + test + diff --git a/src/test/java/com/example/tests/PersonControllerTest.java b/src/test/java/com/example/tests/PersonControllerTest.java new file mode 100644 index 0000000..4a3df9a --- /dev/null +++ b/src/test/java/com/example/tests/PersonControllerTest.java @@ -0,0 +1,30 @@ +package com.example.tests; + +import junit.framework.TestCase; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.web.servlet.ModelAndView; + +import com.example.controller.PersonController; + + +import java.util.HashMap; +import java.util.Map; +import java.util.TimeZone; + +import static org.junit.Assert.assertEquals; + + +public class PersonControllerTest extends TestCase { + @Test + public void testListPersons() throws Exception { + /*Map reqMap = new HashMap(); + PersonController c= new PersonController(); + + String viewName = c.listPeople(reqMap); + */ + Assert.assertEquals(1, 1); + } + +} \ No newline at end of file From 82094ac0660c3b1c5058a8bd470b3571ab8f217b Mon Sep 17 00:00:00 2001 From: Anand Date: Thu, 13 Sep 2012 17:28:39 -0700 Subject: [PATCH 3/5] Added a real test method. --- pom.xml | 227 +++++++++--------- .../example/tests/PersonControllerTest.java | 27 ++- 2 files changed, 140 insertions(+), 114 deletions(-) diff --git a/pom.xml b/pom.xml index 5259ac7..60c5d2b 100755 --- a/pom.xml +++ b/pom.xml @@ -1,114 +1,125 @@ - 4.0.0 - com.example - spring-hibernate-template - war - 0.0.1-SNAPSHOT + 4.0.0 + com.example + spring-hibernate-template + war + 0.0.1-SNAPSHOT - - 3.1.1.RELEASE - UTF-8 - + + 3.1.1.RELEASE + UTF-8 + - - - javax.servlet - javax.servlet-api - 3.0.1 - provided - - - org.springframework - spring-webmvc - ${org.springframework.version} - - - org.springframework - spring-orm - ${org.springframework.version} - - - taglibs - standard - 1.1.2 - - - javax.servlet - jstl - 1.2 - - - org.hsqldb - hsqldb - 2.2.8 - - - postgresql - postgresql - 9.1-901-1.jdbc4 - - - commons-dbcp - commons-dbcp - 1.4 - - - org.hibernate - hibernate-entitymanager - 3.6.10.Final - - - com.github.jsimone - webapp-runner - 7.0.22.3 - provided - - - - junit - junit - 4.10 - test - - + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + org.springframework + spring-webmvc + ${org.springframework.version} + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.springframework + spring-test + ${org.springframework.version} + + + taglibs + standard + 1.1.2 + + + javax.servlet + jstl + 1.2 + + + org.hsqldb + hsqldb + 2.2.8 + + + postgresql + postgresql + 9.1-901-1.jdbc4 + + + commons-dbcp + commons-dbcp + 1.4 + + + org.hibernate + hibernate-entitymanager + 3.6.10.Final + + + com.github.jsimone + webapp-runner + 7.0.22.3 + provided + + + + junit + junit + 4.10 + test + + + org.mockito + mockito-core + 1.9.5-rc1 + test + + - - - - maven-compiler-plugin - - 1.6 - 1.6 - - - - maven-war-plugin - 2.2 - - - org.apache.maven.plugins - maven-dependency-plugin - 2.4 - - - package - - copy - - - - - com.github.jsimone - webapp-runner - 7.0.22.3 - webapp-runner.jar - - - - - - - - + + + + maven-compiler-plugin + + 1.6 + 1.6 + + + + maven-war-plugin + 2.2 + + + org.apache.maven.plugins + maven-dependency-plugin + 2.4 + + + package + + copy + + + + + com.github.jsimone + webapp-runner + 7.0.22.3 + webapp-runner.jar + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/example/tests/PersonControllerTest.java b/src/test/java/com/example/tests/PersonControllerTest.java index 4a3df9a..8cefe44 100644 --- a/src/test/java/com/example/tests/PersonControllerTest.java +++ b/src/test/java/com/example/tests/PersonControllerTest.java @@ -4,27 +4,42 @@ import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.servlet.ModelAndView; import com.example.controller.PersonController; +import com.example.model.Person; +import com.example.service.PersonService; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.TimeZone; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.*; +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "/applicationContext.xml" }) public class PersonControllerTest extends TestCase { - @Test + + @Autowired + PersonService personService; + + @Test public void testListPersons() throws Exception { - /*Map reqMap = new HashMap(); - PersonController c= new PersonController(); + Person p = new Person(); + p.setFirstName("Test"); + p.setLastName("Person"); + personService.addPerson(p); - String viewName = c.listPeople(reqMap); - */ - Assert.assertEquals(1, 1); + List persons = personService.listPeople(); + Assert.assertEquals(1, persons.size()); } } \ No newline at end of file From 47770e647b81ec97a69e002c98fb76ee98ae7c6d Mon Sep 17 00:00:00 2001 From: Anand Date: Thu, 13 Sep 2012 17:33:50 -0700 Subject: [PATCH 4/5] Reverted log message change. --- src/main/java/com/example/controller/PersonController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/example/controller/PersonController.java b/src/main/java/com/example/controller/PersonController.java index db1bb4a..091f930 100755 --- a/src/main/java/com/example/controller/PersonController.java +++ b/src/main/java/com/example/controller/PersonController.java @@ -24,9 +24,7 @@ public class PersonController { public String listPeople(Map map) { map.put("person", new Person()); - List personList = personService.listPeople(); - map.put("peopleList", personList); - System.out.println(" PeopleList.size()="+personList.size()); + map.put("peopleList", personService.listPeople()); return "people"; } From badd8c2bc4c73e47088dbbba0a991f75723b1385 Mon Sep 17 00:00:00 2001 From: Anand Date: Fri, 14 Sep 2012 06:56:38 -0700 Subject: [PATCH 5/5] Removed "mockito" from pom dependencies --- pom.xml | 6 ------ src/test/java/com/example/tests/PersonControllerTest.java | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 60c5d2b..9f8db63 100755 --- a/pom.xml +++ b/pom.xml @@ -76,12 +76,6 @@ 4.10 test - - org.mockito - mockito-core - 1.9.5-rc1 - test - diff --git a/src/test/java/com/example/tests/PersonControllerTest.java b/src/test/java/com/example/tests/PersonControllerTest.java index 8cefe44..0d2f6c0 100644 --- a/src/test/java/com/example/tests/PersonControllerTest.java +++ b/src/test/java/com/example/tests/PersonControllerTest.java @@ -21,7 +21,7 @@ import java.util.TimeZone; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/applicationContext.xml" })