How to write the junit test code for the following controller code

//Controller Code

package com.payoda.springs;

import java.util.ArrayList;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class StartController {

    @RequestMapping(value = "/Volume", method = RequestMethod.GET)
    public ModelAndView Volume() {
        /*
         * List<String> country = new ArrayList<String>();
         * country.add("Number 1"); country.add("Number 2");
         * country.add("Number 3"); country.add("Number 4");
         * country.add("Number 5"); model.addAttribute("country", country);
         */
        System.out.println("country");
        return new ModelAndView("Volumetest", "command", new test());
    }

    @RequestMapping(value = "/sendto", method = RequestMethod.POST)
    public String addStudent(@ModelAttribute("command") test test,
            ModelMap model, BindingResult result) {

        Validatorset Valid = new Validatorset();
        Valid.validate(test, result);

        if (result.hasErrors())
            return "Volumetest";
        else
            model.addAttribute("name", test.getName());
        return "Volumereturn";

    }
}


//  Mock test code

package com.payoda.test;
import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;

import com.payoda.springs.StartController;
/*
 * 
 * Junit tests for Spring(Web level)
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(locations={"file:{/WEB-INF/newprog-servlet.xml},{/WEB-INF/application-context.xml}" })
@ContextConfiguration(locations={ "file:WEB-INF/newprog-servlet.xml"})
public class MockTest {

    private MockHttpServletRequest request;
    private MockHttpServletResponse response;
    private AnnotationMethodHandlerAdapter handlerAdapter;

    @Before
    public void setUp() throws Exception {
        this.request = new MockHttpServletRequest();
        this.response = new MockHttpServletResponse();
        handlerAdapter = new AnnotationMethodHandlerAdapter();
    }

    @Test
    public void testNewForm() throws Exception {
        request.setMethod("GET");
        request.setRequestURI("/Volume");
        final ModelAndView mav = handlerAdapter.handle(request, response,
                new StartController());
        Assert.assertEquals("user", mav.getViewName());
    }
}

//Could any1 pls explain the problem in my 'mock test code' becoz am getting the java.illegal.state: Failed to load application context...

//Awaiting for ur reply... urgent ...

View Answers









Related Tutorials/Questions & Answers:
How to write the junit test code for the following controller code
How to write the junit test code for the following controller code  //Controller Code package com.payoda.springs; import java.util.ArrayList... "Volumereturn"; } } // Mock test code package com.payoda.test
how to write code for this output?
how to write code for this output?   1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Advertisements
How to write jsp/servlet code to integrate LINKDIN?
How to write jsp/servlet code to integrate LINKDIN?  How integrate linkdin api's in java codding
How to write the code for date in swings - Struts
How to write the code for date in swings  Hi Friends, I want to code for display the calendar.......technologies use only swing and core java also how to display calendar like that popup window.....please write and send me
source code for the following question
source code for the following question  source code for the fuzzy c-means
How to write a session code - Java Beginners
How to write a session code   Once Again Thanks Deepak...Thanks for continuing responce I want using session in my project plz help me how to write a session code plz write a session code and post answer my personal id
Expain the following code ?
Expain the following code ?  please explain the following line of code clearly? <html:link href="user.do?parameter=create">Create User</html:link>
How to write a error.jsp code - Java Beginners
How to write a error.jsp code  Thanks once again I have a session code pls help me that how can i write a error.jsp page. why use error.jsp...let me know that hw can i write the error.jsp code. plz send me error.jsp code
Java code for following
Java code for following  Create a function that returns day difference between two dates (inclusive), without using any function provided by the platform or external library. The function must work for all dates in the range of 1
how to write a programm in C for included code below
how to write a programm in C for included code below  Here is my question 'how to write a program in C that runs your sql-xml application session. In the session, you can run SQL queries interactively. The query results
help to write java code
help to write java code  write a full code to produce a system... of assignment 1,assignment 2, midterms-test and lave work to get total marks... 2: text-field /10 midterm-test: text-field /20 lab work: text-field /20
help to write java code
help to write java code  write a full code to produce a system... of assignment 1,assignment 2, midterms-test and lave work to get total marks... assignment 2: text-field /10 midterm-test: text-field /20 lab work: text-field /20
write code in c#
write code in c#  sir I want to write a save and save as code in the c#(windosForm).Please help me
Write JQUERY Code
Write JQUERY Code  Hi, Iam swathi.I created the table in the below format.can u please write the jquery code of this table..and my requirement... please send me the code through jquery..? Thank you Swathi
Write JQUERY Code
Write JQUERY Code  Hi, Iam swathi.I created the table in the below format.can u please write the jquery code of this table..and my requirement... please send me the code through jquery..? Thank you Swathi
core java code for following program
core java code for following program  We are hosting the Olympic games. Write a program that will track all the details of this hosting... should generate the following reports a. A medal tally b. For a given country
How to update record to database? I have trouble with the following code
How to update record to database? I have trouble with the following code  I have written the update statement but it still not work to update the record,what is the missing of the following code ?I need help,thankyou <?php
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...  The ActionListeners here are not running concurrently... import java.io.*; import javax.swing.*; import java.awt.event.*; import
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...  The ActionListeners here are not running concurrently... import java.io.*; import javax.swing.*; import java.awt.event.*; import
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...  The ActionListeners here are not running concurrently... import java.io.*; import javax.swing.*; import java.awt.event.*; import
How to run ActionListenters in two different thread for the following code...
How to run ActionListenters in two different thread for the following code...  The ActionListeners here are not running concurrently... import java.io.*; import javax.swing.*; import java.awt.event.*; import
how to write weighted moving average code using 2d-array
how to write weighted moving average code using 2d-array  how to write weighted moving average code using 2d-array
Need the Following MobileApplication Related Code
Need the Following MobileApplication Related Code  Hi, I need java coding for the following requirements in Collections.. Mobile Subscriber name... can provide code in switch cases,I feel more happy. Please reply me ASAP.ADS
How to write Example code for CRUD application in hibernate annotation?
How to write Example code for CRUD application in hibernate annotation?  Learn Hibernate can be easy if anyone help me with the simple example code. How to write Example code for CRUD application in hibernate annotation? Share
How to write Example code for comparing Strings in iPhone SDK?
How to write Example code for comparing Strings in iPhone SDK?  I... to compare the two string. Following code can be used: if([str1 isEqualToString... object. How to compare NSString object with another NSSTring object? Thanks  
Can i write JavaScript code in AjaxResponse Code ?
Can i write JavaScript code in AjaxResponse Code ?  Hai Every Dynamic's We can't write JavaScript code in Ajax Response Code.Why because it takes only html,json,xml response.I tried a lot to create js form in ajax response.It
how to write function of copy from one to another location in this code
how to write function of copy from one to another location in this code  I need to write a code to copy a file from one location to another using browse button in it. i have written code for the browse button. please help me
how to write a code for oracle database connection in asp.net for validation.
how to write a code for oracle database connection in asp.net for validation.  <script language="javascript" type="text/javascript"> function fill() { //<%@ import Namespace="System.Data" %> //<%@ import
code
code    how to write this in java
ModuleNotFoundError: No module named 'write-about-code'
named 'write-about-code' How to remove the ModuleNotFoundError: No module...-code python with following command: pip install write-about-code After...ModuleNotFoundError: No module named 'write-about-code'  Hi, My
ModuleNotFoundError: No module named 'write-about-code'
named 'write-about-code' How to remove the ModuleNotFoundError: No module...-code python with following command: pip install write-about-code After...ModuleNotFoundError: No module named 'write-about-code'  Hi, My
doubt in the following code of java - Java Beginners
doubt in the following code of java  Hi frends, actually i want to display the following calculated matrix a[][] in the table format..... but the following program code is only helping when iam giving size of matrix as 3
how to code
how to code  how to create mysql coding in php
how to code this?
a toString() method that returns a String in the following form: Your total... at their choices. (Use your class method) Then following the menu, ask
how to code this?
in the following form: Your total for ENTEREE and DRINK is: ORDERCOST Example...) Then following the menu, ask the customer what entree they would like to order
code
code  < comp xlink:type="new" xlink:actuate="onload"/> how to write this in java
code
and give him Rs 300/- as education allowance for each children. Write a single line of code to print the amount he should be paid as allowance
code
code  write a program to encrypt and decrypt the cipher text "adfgvx"   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; import
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Please write code for this program in java and Explain it ? pl'sssssssss
Please write code for this program in java and Explain it ? pl'sssssssss ... that were ever alive at one time. Write a method to compute this, given the above array of 2n integers. Write one of the following methods: C/C++: int
code
code   hi I need help in creating a java code that reminds user on a particular date about their festival. i have no clue of how to do it.. am looking forward to seek help from you
code
code  After creating the server, the developer writes the following code to create the RMI client on the local machine: import java.rmi.*; public... : "+e); } } } However, when the preceding code is executed it results
Code
Code  code for connecting c lang to database
code
code  code for android sample program
code for this is
code for this is  a b c d c b a a b c c b a a b b a a a code
code
code  please provide code for custom tags.by using currdate tag we need to get current date?please give me code
write java code discount bookstore - Java Beginners
write java code discount bookstore  The question Cik Mat operates... balance to the customer   Hi Friend, Try the following code: import... with special discounts, while others are sold at normal price. Write a program which
code
the correct code for a program.The output of the program is listed below...: {Block 5} ADDRESS-3: {San Juan} POST CODE:{6745} ENTER CODE (XX TO stop) CODE:{FF1} QUANTITY:{2} CODE:{TR4} QUANTITY:{1} CODE:XX INVOICE FOR YOUR ORDER Harry
code
code  i have four textboxes.whenever i click on up,down,left or down arrows then the cursor move to another textbox based on the key pressed.i want code for this in javascript