tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmar...@apache.org
Subject svn commit: r412677 - in /incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi: QualifiedNameTestCase.java extension/CompositeComponentExtensionTestCase.java
Date Thu, 08 Jun 2006 06:57:40 GMT
Author: jmarino
Date: Wed Jun  7 23:57:40 2006
New Revision: 412677

URL: http://svn.apache.org/viewvc?rev=412677&view=rev
Log:
more test coverage for spi

Added:
    incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
  (with props)
Modified:
    incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java

Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java?rev=412677&r1=412676&r2=412677&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java
Wed Jun  7 23:57:40 2006
@@ -29,11 +29,21 @@
 
     public void testInvalidName() throws Exception {
         try {
-            QualifiedName name = new QualifiedName("/Foo/Bar");
+            new QualifiedName("/Foo/Bar");
             fail("Invalid name exception not thrown");
         } catch (InvalidNameException e) {
 
         }
+    }
+
+    public void testQualifiedName() throws Exception {
+        QualifiedName name = new QualifiedName("Foo/Bar");
+        assertEquals("Foo/Bar", name.getQualifiedName());
+    }
+
+    public void testToString() throws Exception {
+        QualifiedName name = new QualifiedName("Foo/Bar");
+        assertEquals("Foo/Bar", name.toString());
     }
 
 }

Added: incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java?rev=412677&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
Wed Jun  7 23:57:40 2006
@@ -0,0 +1,224 @@
+package org.apache.tuscany.spi.extension;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentNotFoundException;
+import org.apache.tuscany.spi.component.DuplicateNameException;
+import org.apache.tuscany.spi.component.IllegalTargetException;
+import org.apache.tuscany.spi.component.InvalidComponentTypeException;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentExtensionTestCase extends MockObjectTestCase {
+
+    public void testGetScope() {
+        assertEquals(Scope.COMPOSITE, new Composite().getScope());
+    }
+
+    public void testInvalidType() {
+        Composite composite = new Composite();
+        try {
+            composite.register(getAtomic("foo"));
+            fail();
+        } catch (InvalidComponentTypeException e) {
+            // expected
+        }
+    }
+
+    public void testDuplicateName() {
+        Composite composite = new Composite();
+        composite.register(new ServiceExtension("foo", null, null));
+        try {
+            composite.register(new ServiceExtension("foo", null, null));
+            fail();
+        } catch (DuplicateNameException e) {
+            // expected
+        }
+    }
+
+    public void testGetChildren() {
+        Composite composite = new Composite();
+        composite.register(new ServiceExtension("foo", null, null));
+        assertEquals(1, composite.getChildren().size());
+    }
+
+    public void testGetServices() {
+        Composite composite = new Composite();
+        composite.register(new ServiceExtension("foo", null, null));
+        composite.register(getReference("bar"));
+        assertEquals(1, composite.getServices().size());
+    }
+
+    public void testGetService() {
+        Composite composite = new Composite();
+        composite.register(new ServiceExtension("foo", null, null));
+        composite.start();
+        assertNotNull(composite.getService("foo"));
+    }
+
+    public void testServiceNotFound() {
+        Composite composite = new Composite();
+        composite.register(new ServiceExtension("foo", null, null));
+        composite.start();
+        try {
+            composite.getService("bar");
+            fail();
+        } catch (ComponentNotFoundException e) {
+            // expected
+        }
+    }
+
+    public void testNotService() {
+        Composite composite = new Composite();
+        composite.register(getReference("foo"));
+        composite.start();
+        try {
+            composite.getService("foo");
+            fail();
+        } catch (ComponentNotFoundException e) {
+            // expected
+        }
+    }
+
+    public void testReferencesServices() {
+        Composite composite = new Composite();
+        composite.register(new ServiceExtension("foo", null, null));
+        composite.register(getReference("bar"));
+        assertEquals(1, composite.getReferences().size());
+    }
+
+    public void testServiceInterfaces() {
+        Composite<?> composite = new Composite();
+        Service service1 = getService("foo", Foo.class);
+        composite.register(service1);
+        Service service2 = getService("bar", Bar.class);
+        composite.register(service2);
+
+        List<Class<?>> interfaces = composite.getServiceInterfaces();
+        assertEquals(2, interfaces.size());
+        for (Class o : interfaces) {
+            if (!(Foo.class.isAssignableFrom(o)) && !(Bar.class.isAssignableFrom(o)))
{
+                fail();
+            }
+        }
+    }
+
+    public void testGetServiceInstanceByName() {
+        Composite<?> composite = new Composite();
+        Mock mock = mock(Service.class);
+        mock.stubs().method("getName").will(returnValue("foo"));
+        mock.stubs().method("getInterface").will(returnValue(Foo.class));
+        mock.expects(once()).method("getServiceInstance").will(returnValue(new Foo() {
+        }));
+        Service service = (Service) mock.proxy();
+        composite.register(service);
+        assertNotNull(composite.getServiceInstance("foo"));
+    }
+
+    public void testGetServiceInstanceNotFound() {
+        Composite<?> composite = new Composite();
+        Service service = getService("foo", Foo.class);
+        composite.register(service);
+        try {
+            composite.getServiceInstance("bar");
+            fail();
+        } catch (TargetNotFoundException e) {
+            //expected
+        }
+    }
+
+    public void testGetServiceInstanceNotService() {
+        Composite<?> composite = new Composite();
+        Reference reference = getReference("foo");
+        composite.register(reference);
+        try {
+            composite.getServiceInstance("foo");
+            fail();
+        } catch (IllegalTargetException e) {
+            //expected
+        }
+    }
+
+    public void testOnEvent() {
+        Composite<?> composite = new Composite();
+        Event event = new Event() {
+            public Object getSource() {
+                return null;
+            }
+        };
+        Mock mock = mock(RuntimeEventListener.class);
+        mock.expects(once()).method("onEvent").with(eq(event));
+        composite.addListener((RuntimeEventListener)mock.proxy());
+        composite.onEvent(event);
+    }
+
+    public void testPrepare() {
+        Composite<?> composite = new Composite();
+        composite.prepare();
+    }
+
+// TODO method not implemented
+//    public void testSingleGetServiceInstance(){
+//        Composite<?> composite = new Composite();
+//        Mock mock = mock(Service.class);
+//        mock.stubs().method("getName").will(returnValue("foo"));
+//        mock.stubs().method("getInterface").will(returnValue(Foo.class));
+//        mock.expects(once()).method("getServiceInstance").will(returnValue(new Foo(){}));
+//        Service service = (Service) mock.proxy();
+//        composite.register(service);
+//        assertNotNull(composite.getServiceInstance());
+//    }
+
+    private class Composite<T> extends CompositeComponentExtension<T> {
+        public Composite() {
+            super(null, null, null);
+        }
+
+        public void setScopeContext(ScopeContainer scopeContainer) {
+
+        }
+
+        public TargetInvoker createTargetInvoker(String serviceName, Method operation) {
+            return null;
+        }
+    }
+
+    private AtomicComponent getAtomic(String name) {
+        Mock mock = mock(AtomicComponent.class);
+        mock.stubs().method("getName").will(returnValue(name));
+        return (AtomicComponent) mock.proxy();
+    }
+
+    private Reference getReference(String name) {
+        Mock mock = mock(Reference.class);
+        mock.stubs().method("getName").will(returnValue(name));
+        return (Reference) mock.proxy();
+    }
+
+    private Service getService(String name, Class<?> interfaze) {
+        Mock mock = mock(Service.class);
+        mock.stubs().method("getName").will(returnValue(name));
+        mock.stubs().method("getInterface").will(returnValue(interfaze));
+        return (Service) mock.proxy();
+    }
+
+    private interface Foo {
+    }
+
+    private interface Bar {
+    }
+
+}

Propchange: incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.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