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?
Rohit BajajConnect With a Mentor Author Commented:
Can be done using Junit.
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:
I got this from one of my friend. That testing spring code with autowired variables can be done by writing a Junit test case
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.