TopicObserver.com

Trond Pettersen on Web Development and Topic Maps

Tag: junit

Unit Testing Sun IdM XPress Rules with jUnit

Now that you know how to Execute XPress rules from Java I hope that the link to unit testing your XPress code (or perhaps mess?) is clear, and I would of course advise you to do so for every rule you write.

In order to test your XPress rules with jUnit, you can write normal unit tests that utilizes our XpressUtil.executeRule method. In addition, we have to use IdM’s SessionFactory to create a session to work with.

Here’s an example:

package com.mycorp.xpress;

import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import com.mycorp.util.XpressUtil;
import com.waveset.session.Session;
import com.waveset.session.SessionFactory;
import com.waveset.util.EncryptedData;
import com.waveset.util.WavesetException;

public class UserRuleLibraryTest {

	private Session session = null;

	private static final String username = "Configurator";
	private static final String password = "configurator";
        private static final String userAttributeRule = "MyCorp-UserRuleLibrary:getUserAttribute";

        @Before
	public void initializeSession() throws WavesetException {
		// You can of course move this somewhere else
		// ... and move away from hard coded usr/passwd.
		EncryptedData encPassword = new EncryptedData(password);
		session = SessionFactory.getSession(username, encPassword);
	}

	@Test
	public void getUserAttributeRuleReturnsCorrectValueForName() throws WavesetException {
		Object ruleResult = XpressUtil.executeRule( session, userAttributeRule, makeUserAttributeArgs() );
		assertEquals("Received unexpected fullname from rule", "Bushy George", ruleResult);
	}

        private Map<String, Object> makeUserAttributeArgs() {
                Map<String, Object> args = new HashMap<String, Object>();
		args.put("context", getSession());
		args.put("accountId", "georgeb");
		args.put("attrName", "fullname");
                return args;
        }

}

One thing to remember is that in order to run this test, you have to pass in the waveset.home to be used. If you are like me — and use eclipse, you can set this under e.g. “Run Configurations” → “VM arguments”. Here’s a copy of what arguments I use for most of my jUnit tests:

-Xms128m
-Xmx512m
-Dwaveset.home="C:\\code\\mycorp\\idm\\image\\idm"

Next up: Unit testing Sun IdM web pages.

Executing Sun IdM XPress Rules from Java

Although I don’t want this to turn into an IdM blog, I want to share at least a couple of more posts on using Sun IdM.

The reason is mainly that when I first started developing on Sun IdM last summer, I couldn’t find much information on the web. At the same time, I was, and is, not very happy with the (java)docs. I also assume that as the SOX and similar acts are getting widespread and gain impact, there will be more and more people in the same situation as myself and Holly.

So if you’re a Java or web- turning IdM developer, then hopefully this post can save some of your hair from certain death. If not, please bare with me :)

Read the full post »

  • RSS @twitter

    • Could not connect to Twitter
  • Tags

  • Topics

  • Recent Comments

  • Topic Map Feeds