Results 1 to 6 of 6
  1. #1
    javajee is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default Need Help In JUnit

    Java Code:
    import java.util.Calendar;
    
    import javax.xml.rpc.handler.MessageContext;
    import javax.xml.rpc.handler.soap.SOAPMessageContext;
    import javax.xml.soap.SOAPElement;
    import javax.xml.soap.SOAPException;
    
    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;
    
    import com.abc.al.exception.BaseRequestException;
    import com.abc.al.integration.request.RequestConstants;
    import com.abc.al.types.request.ServiceControlHeaderParams;
    import com.abc.al.utils.LoggingUtil;
    import com.abc.al.utils.NPUtility;
    import com.abc.al.utils.RequestSystemPropertyReader;
    
    
    public class NCBSOAPHandler extends BSHandler {
    	private static final Logger LOGGER = Logger.getLogger(NCBSOAPHandler.class);
    	private String userName;
    	private String password;
    	private ServiceControlHeaderParams serviceControlHeader;
    	
    	/**
    	 * Default Constructor
    	 */
    	public NCBSOAPHandler() throws BaseRequestException {
    		super();
    		setUserName((String) RequestSystemPropertyReader
    				.getRequestSystemPropertyReaderInstance()
    				.getRequestSystemProperty(RequestConstants.NP_CALLBACK_SERVICE_USERNAME));
    
    		setPassword((String) RequestSystemPropertyReader
    				.getRequestSystemPropertyReaderInstance()
    				.getRequestSystemProperty(RequestConstants.NP_CALLBACK_SERVICE_PASSWORD));
    		
    		setServiceControlHeader(createServiceControlHeaderParams());
    	}
    	
    	
    	public NCBSOAPHandler(String userName, String password,ServiceControlHeaderParams serviceControlHeader)throws BaseRequestException {
    		super();
    
    		if (userName == null || password == null) {
    			setUserName((String) RequestSystemPropertyReader.getRequestSystemPropertyReaderInstance().getRequestSystemProperty(RequestConstants.IG_USERNAME));
    			setPassword((String) RequestSystemPropertyReader.getRequestSystemPropertyReaderInstance().getRequestSystemProperty(RequestConstants.IG_PASSWORD));
    		}
    		this.serviceControlHeader = serviceControlHeader;
    	}
    	
    	/**
    	 * Override method to handle requests .
    	 */
    	@Override
    	public boolean handleRequest(MessageContext context) {
    		boolean isRequestHadled = false;
    		try {
    			SOAPMessageContext soapMsgCtx = (SOAPMessageContext) context;
    			SOAPElement usernameToken = SOAPHeaderUtils.buildSecurityHeader(getUserName(), getPassword());
    
    			//Setting the current time stamp in service control header.
    			getServiceControlHeader().setSentTimeStamp(dateFormat.format(Calendar.getInstance().getTime()));
    			
    			SOAPElement serviceControl = SOAPHeaderUtils.buildServiceControlHeader(getServiceControlHeader());
    			
    			soapMsgCtx.getMessage().getSOAPHeader().addChildElement(usernameToken);
    			soapMsgCtx.getMessage().getSOAPHeader().addChildElement(serviceControl);
    			super.writeSOAPMessage(soapMsgCtx);
    			isRequestHadled = true;
    		} catch (SOAPException e) {
    			LoggingUtil.writeLogMessage("SOAPException occured while adding Service Contorl to SOAP header",LOGGER, Level.ERROR, e);
    		} catch (Exception e) {
    			LoggingUtil	.writeLogMessage("Exception occured while adding Service Contorl to SOAP header",LOGGER, Level.ERROR, e);
    		}
    		return isRequestHadled;
    	}
    	
    	
    	/**
    	 * @return the userName
    	 */
    	public String getUserName() {
    		return userName;
    	}
    	/**
    	 * @param userName the userName to set
    	 */
    	public void setUserName(String userName) {
    		this.userName = userName;
    	}
    	/**
    	 * @return the password
    	 */
    	public String getPassword() {
    		return password;
    	}
    	/**
    	 * @param password the password to set
    	 */
    	public void setPassword(String password) {
    		this.password = password;
    	}
    	/**
    	 * @return the serviceControlHeader
    	 */
    	public ServiceControlHeaderParams getServiceControlHeader() {
    		return serviceControlHeader;
    	}
    
    
    	/**
    	 * @param sClHeader the serviceControlHeader to set
    	 */
    	public void setSCHeader(
    			SCHeaderParams serviceControlHeader) {
    		this.serviceControlHeader = serviceControlHeader;
    	}
    
    	protected ServiceControlHeaderParams createServiceControlHeaderParams()throws BaseRequestException {
    		ServiceControlHeaderParams params = new ServiceControlHeaderParams();
    		
    		// Channel ID
    		params.setChannelID((String) RequestSystemPropertyReader
    				.getRequestSystemPropertyReaderInstance().getRequestSystemProperty(
    						RequestConstants.NOTFN_CALLBACK_CHANNEL_ID));
    		
    		String countryCode = NPUtility.getInstance().getCountryCodeFromPropertyFile();
    		
    		String langCode = NPUtility.getInstance().getLanguageCodeFromPropertyFile();
    		
    		params.setLanguageCode(langCode + "-" + countryCode);
    		params.setLanguageCodeType("Subscriber");
    					
    		// Environment
    		params.setProjectName((String) RequestSystemPropertyReader
    				.getRequestSystemPropertyReaderInstance().getRequestSystemProperty(
    						RequestConstants.NOTFN_CALLBACK_ENVIRONMENT));
    		
    		params.setSentTimeStamp(dateFormat.format(Calendar.getInstance().getTime()));
    		
    		return params;
    	}
    
    
    }
    Last edited by JosAH; 08-09-2011 at 06:01 PM. Reason: added [code] ... [/code] tags

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

  3. #3
    javajee is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by j2me64 View Post
    and your question is?
    I do not hav access to Database and I was supposed to use some easyMock/expectedMock..which i hav no idea to begin.
    i need to write testcases for all the 10 methods in it. what would be the input values for "username and Password" here. also when i return a value
    assertEquals(username,instance.getusername()); what will be the value at username falls.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default

    EasyMock.
    There's documentation there and everything.

  5. #5
    javajee is offline Member
    Join Date
    Aug 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    EasyMock.
    There's documentation there and everything.
    unable to access it. says error on page. Could you direct me to correct link

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

    Default

    That is the correct link, at least it works for me.
    You could always google you know.

Similar Threads

  1. Could any help me in JUNIT
    By acmohan in forum New To Java
    Replies: 29
    Last Post: 07-31-2011, 06:35 AM
  2. JUnit
    By cka in forum Eclipse
    Replies: 3
    Last Post: 07-27-2010, 04:14 PM
  3. JUnit testing
    By hedonist in forum Advanced Java
    Replies: 4
    Last Post: 10-04-2009, 12:06 PM
  4. Replies: 1
    Last Post: 08-03-2009, 05:31 PM
  5. Junit
    By Azndaddy in forum New To Java
    Replies: 6
    Last Post: 06-15-2008, 06:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •