TopicObserver.com

Trond Pettersen on Web Development and Topic Maps

Category: Sun IdM

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 »

Replacing the Built-In DatePicker in Sun IdM 8.0

If you read my other post on creating custom view handlers in Sun IdM, you might have noticed my mixed feelings towards the system’s built-in interface.

I know its main task is not to look good, and that it is best at what it is supposed to be good at, but there really is no point in a system that no user would use – unless Sun wants other companies to take the market lead.

It is not only that it is hard to make proper customizations on the CSS layer due to the nested-tables-in-nested-tables-in…-nested-tables-we-do-not-know-how-to-properly-use-ids-or-classes-and-enjoy-the-font-tag-and-br-tags-for-space-HTML generated by code written by someone stuck in the 1990s, but also that a lot of the components look quite old fashion, so to speak.

Have a look at the built in date picker for instance:

Built-in Calendar Text Input Field - Old Fashioned Gray Button

Built in calendar - Pop up window with boring look

Lovely? No? Nor did our customer think.
Read the full post »

Custom Forms and View Handlers in Sun Identity Management 8.0

Sun IdM, XPress and myself

Lately I’ve been working in a project for a large corporation implementing an identity management solution based on Sun Identity Management 8.0.

As part of the project, we’re doing a lot of customization to the product. A lot of the customization is done because the built in components are in desperate need of adjustments — especially when it comes to the interface (the built in interfaces have probably never even been looked at by interaction designers or graphic designers), but we’re also adding to the existing functionality.

When customizing IdM, you soon realize that writing logic in XPress (Sun’s proprietary XML based programming language) is a painful process.

Although it is simple enough, XPress code is more tedious to write and maintain, and you also loose the benefits of tools such as good editor support and unit testing. Not to speak of the verboseness of XML, and writing an application in an XML-based language.

Nested <cond> tags, complex <rule>s (which could take 10s of lines in XPress compared to a few in Java), and too much logic in your <form>s or <field>s soon turn out to be a real mess. It’s just plain horrible.

I’m sure XPress was, or at least ought to, never have been meant for implementation of complex business logic, and that it might be better suited for simple customizations made by non-programmers. Still, from what I see on the WWW, "complex" logic (at least beyond doing string replacement, simple conditionals, etc.) is often placed in XPress forms and rules.

Unfortunately, there is only little documentation on IdM’s Java API available, though, and the JavaDocs are terrible. Further, the documentation that do exist, is, as is the case with many commercial products, of poor quality. Therefore, you might soon find yourself in XPress hell.

This is why I want to share some of my experiences doing customization to IdM in the Java layer — such as creating custom views, and integrating your Java code with XPress.
Read the full post »

  • RSS @twitter

  • Tags

  • Topics

  • Recent Comments

  • Topic Map Feeds