tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmar...@apache.org
Subject svn commit: r412475 - in /incubator/tuscany/sandbox/jboynes/sca/core2/src: main/java/org/apache/tuscany/core/component/ main/java/org/apache/tuscany/core/component/event/ main/java/org/apache/tuscany/core/component/scope/ test/java/org/apache/tuscany/c...
Date Wed, 07 Jun 2006 18:18:26 GMT
Author: jmarino
Date: Wed Jun  7 11:18:25 2006
New Revision: 412475

URL: http://svn.apache.org/viewvc?rev=412475&view=rev
Log:
improve test coverage in core

Added:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/CompositeComponentTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/event/
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
  (with props)
Modified:
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStart.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStop.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java?rev=412475&r1=412474&r2=412475&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
Wed Jun  7 11:18:25 2006
@@ -16,7 +16,7 @@
 
     private static final Object REMOTE_CONTEXT = new Object();
 
-    // @TODO design a proper propagation strategy for creating new threads
+    // TODO implement propagation strategy for creating new threads
     /*
      * a map ( associated with the current thread) of scope identifiers keyed on the event
context id type. the scope identifier
      * may be a {@link ScopeIdentifier} or an opaque id

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStart.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStart.java?rev=412475&r1=412474&r2=412475&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStart.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStart.java
Wed Jun  7 11:18:25 2006
@@ -15,11 +15,11 @@
      * Creates a module stop event
      *
      * @param source the source of the event
-     * @param ctx    the composite component associated the module being stopped
+     * @param component    the composite component associated the module being stopped
      */
-    public CompositeStart(Object source, CompositeComponent ctx) {
+    public CompositeStart(Object source, CompositeComponent component) {
         super(source);
-        component = ctx;
+        this.component = component;
     }
 
     public CompositeComponent getComposite() {

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStop.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStop.java?rev=412475&r1=412474&r2=412475&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStop.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/event/CompositeStop.java
Wed Jun  7 11:18:25 2006
@@ -15,11 +15,11 @@
      * Creates a module stop event
      *
      * @param source the source of the event
-     * @param ctx    the composite component associated the module being stopped
+     * @param component    the composite component associated the module being stopped
      */
-    public CompositeStop(Object source, CompositeComponent ctx) {
+    public CompositeStop(Object source, CompositeComponent component) {
         super(source);
-        component = ctx;
+        this.component = component;
     }
 
     public CompositeComponent getComposite() {

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java?rev=412475&r1=412474&r2=412475&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java
Wed Jun  7 11:18:25 2006
@@ -106,7 +106,7 @@
         }
     }
 
-    protected WorkContext getEventContext() {
+    protected WorkContext getWorkContext() {
         return workContext;
     }
 

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.java?rev=412475&r1=412474&r2=412475&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.java
Wed Jun  7 11:18:25 2006
@@ -32,7 +32,6 @@
 
     public StatelessScopeContainer(WorkContext workContext) {
         super("Stateless scope", workContext);
-        assert(workContext != null): "Work context was null";
     }
 
     public Scope getScope() {

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/CompositeComponentTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/CompositeComponentTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/CompositeComponentTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/CompositeComponentTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,15 @@
+package org.apache.tuscany.core.component;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentTestCase extends TestCase {
+
+    public void testSetUri() throws Exception {
+        CompositeComponentImpl<?> component = new CompositeComponentImpl("foo", null,
null, null);
+        component.setURI("foo/bar");
+        assertEquals("foo/bar", component.getURI());
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/CompositeComponentTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/CompositeComponentTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,54 @@
+package org.apache.tuscany.core.component.event;
+
+import org.jmock.MockObjectTestCase;
+import org.jmock.Mock;
+import org.apache.tuscany.spi.component.CompositeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EventTestCase extends MockObjectTestCase {
+
+    private CompositeComponent component;
+
+    public void testCompositeStart() {
+        CompositeStart event = new CompositeStart(this,component);
+        assertEquals(component,event.getComposite());
+    }
+
+    public void testCompositeStop() {
+        CompositeStop event = new CompositeStop(this,component);
+        assertEquals(component,event.getComposite());
+    }
+
+    public void testHttpSessionStart() {
+        Object id = new Object();
+        HttpSessionEvent event = new HttpSessionStart(this,id);
+        assertEquals(this,event.getSource());
+        assertEquals(id,event.getId());
+    }
+
+    public void testHttpSessionEnd() {
+        Object id = new Object();
+        HttpSessionEvent event = new HttpSessionEnd(this,id);
+        assertEquals(this,event.getSource());
+        assertEquals(id,event.getId());
+    }
+
+    public void testRequestStart() {
+        RequestStart event = new RequestStart(this);
+        assertEquals(this,event.getSource());
+    }
+
+    public void testReequestEnd() {
+        RequestEnd event = new RequestEnd(this);
+        assertEquals(this,event.getSource());
+    }
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        Mock mock = mock(CompositeComponent.class);
+        component = (CompositeComponent)mock.proxy();
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,120 @@
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.EventFilter;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.event.TrueFilter;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractScopeContainerTestCase extends MockObjectTestCase {
+
+    public void testSetWorkContext(){
+        TestContainer container = new TestContainer("foo");
+        WorkContext ctx = new WorkContextImpl();
+        container.setWorkContext(ctx);
+        assertEquals(ctx,container.getWorkContext());
+
+    }
+    public void testFireListener() {
+        TestContainer container = new TestContainer("foo");
+        Mock mock = mock(RuntimeEventListener.class);
+        Event event = new TestEvent();
+        mock.expects(once()).method("onEvent").with(eq(event));
+        RuntimeEventListener listener = (RuntimeEventListener) mock.proxy();
+        container.addListener(listener);
+        container.publish(event);
+    }
+
+    public void testRemoveListener() {
+        TestContainer container = new TestContainer("foo");
+        Mock mock = mock(RuntimeEventListener.class);
+        Event event = new TestEvent();
+        mock.expects(never()).method("onEvent").with(eq(event));
+        RuntimeEventListener listener = (RuntimeEventListener) mock.proxy();
+        container.addListener(listener);
+        container.removeListener(listener);
+        container.publish(event);
+    }
+
+    public void testFalseFilterListener() {
+        TestContainer container = new TestContainer("foo");
+        Mock mock = mock(RuntimeEventListener.class);
+        Event event = new TestEvent();
+        mock.expects(never()).method("onEvent").with(eq(event));
+        RuntimeEventListener listener = (RuntimeEventListener) mock.proxy();
+        container.addListener(new FalseFilter(), listener);
+        container.publish(event);
+    }
+
+    public void testTrueFilterListener() {
+        TestContainer container = new TestContainer("foo");
+        Mock mock = mock(RuntimeEventListener.class);
+        Event event = new TestEvent();
+        mock.expects(once()).method("onEvent").with(eq(event));
+        RuntimeEventListener listener = (RuntimeEventListener) mock.proxy();
+        container.addListener(new TrueFilter(), listener);
+        container.publish(event);
+    }
+
+    public void testToString() {
+        TestContainer container = new TestContainer("foo");
+        assertNotNull(container.toString());
+    }
+
+    public void testGetName() {
+        TestContainer container = new TestContainer("foo");
+        assertEquals("foo", container.getName());
+    }
+
+
+
+    private class TestContainer extends AbstractScopeContainer {
+
+        public TestContainer(String name) {
+            super(name,null);
+        }
+
+        protected InstanceWrapper getInstanceWrapper(AtomicComponent component) {
+            return null;
+        }
+
+        public Scope getScope() {
+            return null;
+        }
+
+        public void register(AtomicComponent component) {
+
+        }
+
+        public void onEvent(Event event) {
+
+        }
+
+        public WorkContext getWorkContext(){
+            return super.getWorkContext();
+        }
+    }
+
+    private class TestEvent implements Event {
+        public Object getSource() {
+            return null;
+        }
+    }
+
+    private class FalseFilter implements EventFilter {
+
+        public boolean match(Event event) {
+            return false;
+        }
+    }
+
+
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,58 @@
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.Lifecycle;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+import org.jmock.core.Invocation;
+import org.jmock.core.Stub;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InstanceWrapperTestCase extends MockObjectTestCase {
+
+
+
+    public void testExceptionInit() throws Exception {
+        AtomicComponent component = getComponent();
+        InstanceWrapper wrapper = new InstanceWrapperImpl(component, new Object());
+        try {
+            wrapper.start();
+            fail();
+        } catch (SomeException e) {
+            // expected
+        }
+        assertEquals(Lifecycle.ERROR,wrapper.getLifecycleState());
+    }
+
+    public void testNonStart() throws Exception {
+        Mock mock = mock(AtomicComponent.class);
+        AtomicComponent comp = (AtomicComponent) mock.proxy();  // class-level one has an
expects
+        InstanceWrapper wrapper = new InstanceWrapperImpl(comp, new Object());
+        try {
+            wrapper.getInstance();
+            fail();
+        } catch (IllegalStateException e) {
+            // expected
+        }
+    }
+
+    private AtomicComponent getComponent() throws Exception {
+        // do not use setUp() since we do not need this in all testcases
+        Mock mock = mock(AtomicComponent.class);
+        mock.expects(once()).method("init").will(new Stub() {
+            public Object invoke(Invocation invocation) throws Throwable {
+                throw new SomeException();
+            }
+
+            public StringBuffer describeTo(StringBuffer stringBuffer) {
+                return stringBuffer.append("bad init");
+            }
+        });
+       return (AtomicComponent) mock.proxy();
+    }
+
+    private class SomeException extends RuntimeException {
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,13 @@
+package org.apache.tuscany.core.component.scope;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ModuleScopeObjectFactoryTestCase extends TestCase {
+
+    public void testCreation() {
+        assertNotNull(new ModuleScopeObjectFactory().getInstance());
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ModuleScopeObjectFactoryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java?rev=412475&r1=412474&r2=412475&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java
Wed Jun  7 11:18:25 2006
@@ -1,18 +1,19 @@
 package org.apache.tuscany.core.component.scope;
 
-import junit.framework.TestCase;
 import org.apache.tuscany.core.component.WorkContextImpl;
 import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeNotFoundException;
 import org.apache.tuscany.spi.component.ScopeRegistry;
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.model.Scope;
+import org.jmock.MockObjectTestCase;
 
 /**
  * Verifies retrieval of standard scope contexts from the default scope registry
  *
  * @version $$Rev$$ $$Date$$
  */
-public class ScopeRegistryTestCase extends TestCase {
+public class ScopeRegistryTestCase extends MockObjectTestCase {
     public void testScopeContextCreation() throws Exception {
         WorkContext workContext = new WorkContextImpl();
         ScopeRegistry scopeRegistry = new ScopeRegistryImpl(workContext);
@@ -26,4 +27,43 @@
         assertSame(session, scopeRegistry.getScopeContainer(Scope.SESSION));
         assertNotSame(request, session);
     }
+
+    public void testDeregisterFactory() throws Exception {
+        WorkContext workContext = new WorkContextImpl();
+        ScopeRegistry scopeRegistry = new ScopeRegistryImpl(workContext);
+        RequestScopeObjectFactory factory = new RequestScopeObjectFactory();
+        scopeRegistry.registerFactory(Scope.REQUEST, factory);
+        scopeRegistry.deregisterFactory(Scope.REQUEST);
+        try {
+            scopeRegistry.getScopeContainer(Scope.REQUEST);
+            fail();
+        } catch (ScopeNotFoundException e) {
+            // expected
+        }
+    }
+
+    public void testScopeNotRegistered() throws Exception {
+        WorkContext workContext = new WorkContextImpl();
+        ScopeRegistry scopeRegistry = new ScopeRegistryImpl(workContext);
+        try {
+            scopeRegistry.getScopeContainer(Scope.REQUEST);
+            fail();
+        } catch (ScopeNotFoundException e) {
+            // expected
+        }
+        try {
+            scopeRegistry.getScopeContainer(Scope.SESSION);
+            fail();
+        } catch (ScopeNotFoundException e) {
+            // expected
+        }
+        try {
+            scopeRegistry.getScopeContainer(Scope.STATELESS);
+            fail();
+        } catch (ScopeNotFoundException e) {
+            // expected
+        }
+    }
+
+
 }

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,30 @@
+package org.apache.tuscany.core.component.scope;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StatelessScopeContainerTestCase extends TestCase {
+
+    public void testBadStopWithoutStart() throws Exception {
+        StatelessScopeContainer container = new StatelessScopeContainer();
+        try {
+            container.stop();
+            fail();
+        } catch (IllegalStateException e) {
+            //expected
+        }
+    }
+
+    public void testBadDoubleStart() throws Exception {
+        StatelessScopeContainer container = new StatelessScopeContainer();
+        try {
+            container.start();
+            container.start();
+            fail();
+        } catch (IllegalStateException e) {
+            //expected
+        }
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,13 @@
+package org.apache.tuscany.core.component.scope;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StatelessScopeObjectFactoryTestCase extends TestCase {
+
+    public void testCreation() {
+        assertNotNull(new StatelessScopeObjectFactory().getInstance());
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,76 @@
+package org.apache.tuscany.core.component.scope;
+
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WorkContextTestCase extends MockObjectTestCase {
+
+    public void testRemoteComponent() throws Exception {
+        WorkContext ctx = new WorkContextImpl();
+        Mock mock = mock(CompositeComponent.class);
+        CompositeComponent component = (CompositeComponent) mock.proxy();
+        Mock mock2 = mock(CompositeComponent.class);
+        CompositeComponent component2 = (CompositeComponent) mock2.proxy();
+        ctx.setRemoteComponent(component);
+        assertEquals(component, ctx.getRemoteComponent());
+        ctx.setRemoteComponent(component2);
+        assertEquals(component2, ctx.getRemoteComponent());
+    }
+
+    public void testNonSetRemoteComponent() throws Exception {
+        WorkContext ctx = new WorkContextImpl();
+        assertNull(ctx.getRemoteComponent());
+    }
+
+    public void testIndentifier() throws Exception {
+        WorkContext ctx = new WorkContextImpl();
+        Object id = new Object();
+        ctx.setIdentifier(this,id);
+        assertEquals(id,ctx.getIdentifier(this));
+    }
+
+    public void testClearIndentifier() throws Exception {
+        WorkContext ctx = new WorkContextImpl();
+        Object id = new Object();
+        ctx.setIdentifier(this,id);
+        ctx.clearIdentifier(this);
+        assertNull(ctx.getIdentifier(this));
+    }
+
+    public void testClearIndentifiers() throws Exception {
+        WorkContext ctx = new WorkContextImpl();
+        Object id = new Object();
+        Object id2 = new Object();
+        ctx.setIdentifier(id,id);
+        ctx.setIdentifier(id2,id2);
+        ctx.clearIdentifiers();
+        assertNull(ctx.getIdentifier(id));
+        assertNull(ctx.getIdentifier(id2));
+    }
+
+    public void testClearNonExistentIndentifier() throws Exception {
+        WorkContext ctx = new WorkContextImpl();
+        ctx.clearIdentifier(this);
+    }
+
+    public void testNullIndentifier() throws Exception {
+        WorkContext ctx = new WorkContextImpl();
+        Object id = new Object();
+        ctx.setIdentifier(this,id);
+        ctx.clearIdentifier(null);
+        assertEquals(id,ctx.getIdentifier(this));
+    }
+
+    public void testNoIndentifier() throws Exception {
+        WorkContext ctx = new WorkContextImpl();
+        assertNull(ctx.getIdentifier(this));
+    }
+
+
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,33 @@
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.Field;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FieldInjectorTestCase extends TestCase {
+
+    private Field privateField;
+
+    public void testIllegalAccess() throws Exception {
+        FieldInjector<Foo> injector = new FieldInjector<Foo>(privateField, new
SingletonObjectFactory<String>("foo"));
+        try {
+            injector.inject(new Foo());
+            fail();
+        } catch (AssertionError e) {
+            //expected
+        }
+    }
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        privateField = Foo.class.getDeclaredField("hidden");
+    }
+
+    private class Foo {
+        private String hidden;
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,42 @@
+package org.apache.tuscany.core.injection;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+import org.jmock.core.Invocation;
+import org.jmock.core.Stub;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JNDIObjectFactoryTestCase extends MockObjectTestCase {
+
+    public void testGetInstance() throws Exception {
+        Mock mock = mock(Context.class);
+        mock.expects(once()).method("lookup").with(eq("foo")).will(returnValue(new Foo()));
+        Context ctx = (Context) mock.proxy();
+        JNDIObjectFactory<Foo> factory = new JNDIObjectFactory<Foo>(ctx, "foo");
+        assertTrue(factory.getInstance() instanceof Foo); // must do an instanceof b/c of
type erasure
+    }
+
+    public void testGetInstanceError() throws Exception {
+        Mock mock = mock(Context.class);
+        mock.expects(once()).method("lookup").with(eq("foo")).will(throwException(new NamingException()));
+        Context ctx = (Context) mock.proxy();
+        JNDIObjectFactory<Foo> factory = new JNDIObjectFactory<Foo>(ctx, "foo");
+        try {
+            factory.getInstance();
+            fail();
+        } catch (ObjectCreationException e) {
+            //expected
+        }
+    }
+
+
+    private class Foo {
+
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,55 @@
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.Method;
+
+import org.jmock.MockObjectTestCase;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.ObjectCreationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MethodEventInvokerTestCase extends MockObjectTestCase {
+    private Method privateMethod;
+    private Method exceptionMethod;
+
+    public void testIllegalAccess() throws Exception {
+        MethodEventInvoker<MethodEventInvokerTestCase.Foo> injector = new MethodEventInvoker<Foo>(privateMethod);
+        try {
+            injector.invokeEvent(new Foo());
+            fail();
+        } catch (AssertionError e) {
+            // expected
+        }
+    }
+
+    public void testException() throws Exception {
+        MethodEventInvoker<MethodEventInvokerTestCase.Foo> injector = new MethodEventInvoker<Foo>(exceptionMethod);
+        try {
+            injector.invokeEvent(new Foo());
+            fail();
+        } catch (RuntimeException e) {
+            // expected
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        privateMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("hidden");
+        exceptionMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("exception");
+
+    }
+
+    private class Foo {
+
+        public void foo() {
+        }
+
+        private void hidden(){}
+
+        public void exception(){
+            throw new RuntimeException();
+        }
+
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,70 @@
+package org.apache.tuscany.core.injection;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.jmock.MockObjectTestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MethodInjectorTestCase extends MockObjectTestCase {
+    private Method fooMethod;
+    private Method privateMethod;
+    private Method exceptionMethod;
+
+    public void testIllegalArgument() throws Exception {
+        ObjectFactory<Object> factory = new SingletonObjectFactory<Object>(new
Object());
+        MethodInjector<Foo> injector = new MethodInjector<Foo>(fooMethod, factory);
+        try {
+            injector.inject(new Foo());
+            fail();
+        } catch (ObjectCreationException e) {
+            // expected
+        }
+    }
+
+    public void testIllegalAccess() throws Exception {
+        ObjectFactory<Object> factory = new SingletonObjectFactory<Object>("foo");
+        MethodInjector<Foo> injector = new MethodInjector<Foo>(privateMethod,
factory);
+        try {
+            injector.inject(new Foo());
+            fail();
+        } catch (AssertionError e) {
+            // expected
+        }
+    }
+
+    public void testException() throws Exception {
+        ObjectFactory<Object> factory = new SingletonObjectFactory<Object>("foo");
+        MethodInjector<Foo> injector = new MethodInjector<Foo>(exceptionMethod,
factory);
+        try {
+            injector.inject(new Foo());
+            fail();
+        } catch (RuntimeException e) {
+            // expected
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        fooMethod = Foo.class.getMethod("foo", String.class);
+        privateMethod = Foo.class.getDeclaredMethod("hidden", String.class);
+        exceptionMethod = Foo.class.getDeclaredMethod("exception", String.class);
+
+    }
+
+    private class Foo {
+
+        public void foo(String bar) {
+        }
+
+        private void hidden(String bar){}
+
+        public void exception(String bar){
+            throw new RuntimeException();
+        }
+
+    }
+}
\ No newline at end of file

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java?rev=412475&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
Wed Jun  7 11:18:25 2006
@@ -0,0 +1,15 @@
+package org.apache.tuscany.core.injection;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SingletonObjectFactoryTestCase extends TestCase {
+
+    public void testSingleton() throws Exception{
+        Object o = new Object();
+        SingletonObjectFactory<Object> factory = new SingletonObjectFactory<Object>(o);
+        assertEquals(o,factory.getInstance());
+    }
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/core2/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message