Testing a piece of code written in Java Spring

I am having a spring application which renders home page of a website and perform many other operations. I integrated a new function in it. which uses autowiring of variables.
As the code is still in progress i want to test my code by deploying the application.

Although i have tested my code as a standalone code by making separate classes in java.
But now i have integrated into the codebase which uses autowiring and some other things.

How do i call this function after deploying it from tomcat.
Following is the .java file. And i need to call the render function. So that i can check the value of  following calls :
                  parsedResponse = JsonKeyMapService.modifyJsonDataKeyMap(result,dataKeyMap);

package com.yatra.product.fresco.renderer.module.subModuleRenderer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yatra.platform.commons.VelocityHelper;
import com.yatra.product.fresco.cache.MasterDataCache;
import com.yatra.product.fresco.model.Module;
import com.yatra.product.fresco.service.JsonKeyMapService;
import com.yatra.product.fresco.template.TemplateInfoKeeper;
import com.yatra.product.fresco.model.Theme;

public class ServiceRenderer implements SubRenderer {

	@Autowired VelocityHelper velocityHelper;
	@Autowired MasterDataCache masterDataCache;
	public String render(Module module) {
		// TODO Auto-generated method stub
		String dataHandler = module.getDataHandler();
		String dataKeyMap = module.getdataKeyMap();
		String result;
		String parsedResponse = null;
		try {
			result = JsonKeyMapService.getDataHandlerServiceResponse(dataHandler);
			parsedResponse = JsonKeyMapService.modifyJsonDataKeyMap(result,dataKeyMap);
			Map<String,Object> jsonMap = new ObjectMapper().readValue("{\"root\":" + parsedResponse + "}", Map.class);
			List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
			Map<String,Object>  map = new HashMap<String, Object>();
			map.put("moduleData", list);
			Theme theme = masterDataCache.getTheme(TemplateInfoKeeper.getThemeId());
			String output = velocityHelper.velocityConvertor("velocity/"+theme.getDirectory()+"/"+module.getViewName()+".jsp", map);
			return output;
		} catch (IOException e) {
			// TODO Auto-generated catch block
		} catch (ParseException e) {
			// TODO Auto-generated catch block
		return "var viewservice1 = "+parsedResponse;


Open in new window

Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
I'm not sure I understand the problem. Can't you just create a simple test page where the controller for that page calls your render method? If not, you might need to elaborate on what you are trying to do.
Rohit BajajAuthor Commented:
Can be done using Junit.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rohit BajajAuthor Commented:
I got this from one of my friend. That testing spring code with autowired variables can be done by writing a Junit test case
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.