/** * Copyright (C) 2009-2010 Scalable Solutions AB */ package se.scalablesolutions.akka.spring import org.scalatest.Spec import org.scalatest.matchers.ShouldMatchers import org.scalatest.junit.JUnitRunner import org.junit.runner.RunWith import ScalaDom._ import se.scalablesolutions.akka.config.JavaConfig._ import org.w3c.dom.Element import org.springframework.beans.factory.support.BeanDefinitionBuilder /** * Test for SupervisionBeanDefinitionParser * @author michaelkober */ @RunWith(classOf[JUnitRunner]) class SupervisionBeanDefinitionParserTest extends Spec with ShouldMatchers { private class Parser extends SupervisionBeanDefinitionParser describe("A SupervisionBeanDefinitionParser") { val parser = new Parser() val builder = BeanDefinitionBuilder.genericBeanDefinition("foo.bar.Foo") it("should be able to parse active object configuration") { val props = parser.parseActiveObject(createActiveObjectElement); assert(props != null) assert(props.timeout == 1000) assert(props.target == "foo.bar.MyPojo") assert(props.transactional) } it("should parse the supervisor restart strategy") { parser.parseSupervisor(createSupervisorElement, builder); val strategy = builder.getBeanDefinition.getPropertyValues.getPropertyValue("restartStrategy").getValue.asInstanceOf[RestartStrategy] assert(strategy != null) assert(strategy.scheme match { case x:AllForOne => true case _ => false }) expect(3) { strategy.maxNrOfRetries } expect(1000) { strategy.withinTimeRange } } it("should parse the supervised active objects") { parser.parseSupervisor(createSupervisorElement, builder); val supervised = builder.getBeanDefinition.getPropertyValues.getPropertyValue("supervised").getValue.asInstanceOf[List[ActiveObjectProperties]] assert(supervised != null) expect(3) { supervised.length } val iterator = supervised.iterator expect("foo.bar.Foo") { iterator.next.target } expect("foo.bar.Bar") { iterator.next.target } expect("foo.bar.MyPojo") { iterator.next.target } } it("should throw IllegalArgumentException on missing mandatory attributes") { evaluating { parser.parseSupervisor(createSupervisorMissingAttribute, builder) } should produce [IllegalArgumentException] } it("should throw IllegalArgumentException on missing mandatory elements") { evaluating { parser.parseSupervisor(createSupervisorMissingElement, builder) } should produce [IllegalArgumentException] } } private def createActiveObjectElement : Element = { val xml = dom(xml).getDocumentElement } private def createSupervisorElement : Element = { val xml = java.io.IOException java.lang.NullPointerException dom(xml).getDocumentElement } private def createSupervisorMissingAttribute : Element = { val xml = java.io.IOException dom(xml).getDocumentElement } private def createSupervisorMissingElement : Element = { val xml = dom(xml).getDocumentElement } }