Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Magazine How to write the junit test code for the following controller code
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Hari Prasanth
How to write the junit test code for the following controller code
0 Answer(s)      2 years and 3 months ago
Posted in : Java Magazine


//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 ...


Advertisement
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
source code for the following question
source code for the following question  source code for the fuzzy c-means
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 jsp/servlet code to integrate LINKDIN?
How to write jsp/servlet code to integrate LINKDIN?  How integrate linkdin api's in java codding
Junit Test Suite
Junit Test Suite  Hi Sir I am a beginner to JUnit. I have created... these all with a Test Suite. Please mention code with your answer. Best regards   Hi friend Given below the code according to the test classes you
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
junit test case - Java Beginners
junit test case  how to use junit for testing email id format  Hi Friend, Please visit the following link: http://www.roseindia.net/junit/ Hope that it will be helpful for you. Thanks
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
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
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
Junit @Test annotation
Junit @Test annotation  What is the Application of @Test Annotation in JUnit ?   The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case : public class Example
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
test case - JUNIT
test case  Hi i am doing project on online reservation i want to know how to write the test case template for this online reservation
junit
junit  why we are going to junit?   Hi, Junit is unit testing framework to unit test Java applications. It is advisable to the java developers to write Unit test to test their code. Junit test is used to test
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
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
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
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
JUnit Training
can use to write unit tests to check that another code unit works as expected. JUnit helps us to code and test any time when you make any changes in your code... framework. You will learn how to set it up, write, aggregate and run tests in your
WRITE AND TEST
WRITE AND TEST   WRITE AND TEST PROGRAM TO ACCEPT A STRING? 1).WHICH STARTS WITH 'S' OR 's' 2).ENDS WITH "nd" 3) THE LENGTH OF THE STRING SHOULD BE 10 OR LESS
What is JUnit?
What is JUnit?  What is the use of JUnit? How to write program to test a Java application? Thanks   Hi, JUnit is unit testing tool in Java. You can use the JUnit to test your Java code. Read more at JUnit 4.3.1
Advertisements
 

 

 

DMCA.com