cancel
Showing results for 
Search instead for 
Did you mean: 

EJB function unit test

0 Kudos

Hi everyone,

I have simple problem I am struggling with. I developed EJB function and deployed it on Java AS. So before using this as mapping function in SAP BPM process i would like to test it.

First, i found the simplest way, but it doesn't work for me:

Second way would be to write unit test in NWDS, but still i don't know how to initialize DataObject and InvocationContext to call the invokeSdo method.

I didn't say what function does, but it isn't important for my problem - let's assume that function receives one string parameter and returns the same.

I would be grateful if someone can point me to right solution, either using EJB Explorer or writing unit test in NWDS.

0 Kudos

I made one more EJB just to see how testing in EJB Explorer works. This new EJB has two methods for currency conversion (EUR->USD and USD->EUR) and it doesn't implement any other interfaces, except local.

CurrencyConverterBean.java code:

package com.sap.tutorial.javaee;

import java.math.BigDecimal;
import javax.ejb.Stateless;

/**
 * Session Bean implementation class CurrencyConverterBean
 */
@Stateless
public class CurrencyConverterBean implements CurrencyConverterBeanLocal {

    private BigDecimal dollarRate = new BigDecimal("1.2");
    private BigDecimal euroRate = new BigDecimal("0.83");	
	
    /**
     * Default constructor. 
     */
    public CurrencyConverterBean() 
    {
        // TODO Auto-generated constructor stub
    }
    
    public BigDecimal dollarToEuro(BigDecimal dollars) 
    {
        BigDecimal result = dollars.multiply(euroRate);
        return result.setScale(2, BigDecimal.ROUND_UP);
    }


    public BigDecimal euroToDollar(BigDecimal euros) 
    {
        BigDecimal result = euros.multiply(dollarRate);
        return result.setScale(2, BigDecimal.ROUND_UP);
    }
}

CurrencyConverterBeanLocal.java code:

package com.sap.tutorial.javaee;

import javax.ejb.Local;
import java.math.BigDecimal;

@Local
public interface CurrencyConverterBeanLocal 
{
	public BigDecimal dollarToEuro (BigDecimal dollars);

	public BigDecimal euroToDollar (BigDecimal euros);
}

After I deployed it I successfully tested it in EJB Explorer:

Conclusion for my primary question:

EJB Explorer knows how to work with "primitive" types as parameters such as String, Int, BigDecimal (...), but it doesn't know how to work with parameters of type commonj.sdo.DataObject and com.sap.glx.mapping.execution.api.invoker.SdoInvoker.InvocationContext.

So the only option to unit test the EJB function left is to write unit test within NWDS. Does anyone have code example for this?

Accepted Solutions (0)

Answers (0)