Tests for interception of attribute changes added. BLD200206060100
authordbalek@netbeans.org
Tue, 04 Jun 2002 15:38:07 +0000
changeset 8617f38ba9e8dd3
parent 860 33c0f03fc2ae
child 862 e96f06aeaba2
Tests for interception of attribute changes added.
mdr/test/build-unit.xml
mdr/test/cfg-unit.xml
mdr/test/unit/src/org/netbeans/mdr/test/InterceptionTest.java
mdr/test/unit/src/org/netbeans/mdr/test/data/interception.xml
     1.1 --- a/mdr/test/build-unit.xml	Tue Jun 04 15:29:39 2002 +0000
     1.2 +++ b/mdr/test/build-unit.xml	Tue Jun 04 15:38:07 2002 +0000
     1.3 @@ -216,6 +216,7 @@
     1.4              <pathelement location="../test/unit/src/org/netbeans/mdr/test/data/java-jmi.jar"/>
     1.5              <pathelement location="../test/unit/src/org/netbeans/mdr/test/data/pkg_inh-jmi.jar"/>
     1.6  	    <pathelement location="../test/unit/src/org/netbeans/mdr/test/data/component.jar"/>
     1.7 +	    <pathelement location="../test/unit/src/org/netbeans/mdr/test/data/interception.jar"/>
     1.8      	</path>
     1.9      </target>
    1.10          
     2.1 --- a/mdr/test/cfg-unit.xml	Tue Jun 04 15:29:39 2002 +0000
     2.2 +++ b/mdr/test/cfg-unit.xml	Tue Jun 04 15:38:07 2002 +0000
     2.3 @@ -32,6 +32,7 @@
     2.4                  <include name="org/netbeans/mdr/test/MultivaluedIndexTest.class"/>                
     2.5  		<include name="org/netbeans/mdr/test/FederationTest.class"/>
     2.6  		<include name="org/netbeans/mdr/test/HandlerStorageTest.class"/>
     2.7 +		<include name="org/netbeans/mdr/test/InterceptionTest.class"/>
     2.8                  <exclude name=""/>
     2.9              </patternset>
    2.10          </testset>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/mdr/test/unit/src/org/netbeans/mdr/test/InterceptionTest.java	Tue Jun 04 15:38:07 2002 +0000
     3.3 @@ -0,0 +1,109 @@
     3.4 +/*
     3.5 + * FederationTest.java
     3.6 + *
     3.7 + * Created on May 24, 2002, 8:05 PM
     3.8 + */
     3.9 +
    3.10 +package org.netbeans.mdr.test;
    3.11 +
    3.12 +import java.util.*;
    3.13 +
    3.14 +import org.netbeans.api.mdr.*;
    3.15 +import org.netbeans.junit.*;
    3.16 +
    3.17 +import javax.jmi.reflect.*;
    3.18 +import javax.jmi.model.*;
    3.19 +
    3.20 +/**
    3.21 + *
    3.22 + * @author  Dusan Balek
    3.23 + */
    3.24 +public class InterceptionTest extends MDRTestCase {
    3.25 +    
    3.26 +    private static final String MODEL_XMI = "interception.xml";
    3.27 +    private static final String MODEL_PKG_NAME = "InterceptionTest";
    3.28 +    private static final String PKG_ELEMENT = "Test";
    3.29 +    private static final String PKG_NAME = "InterceptionExtent";
    3.30 +    
    3.31 +    public static short componentPreSet = 0;
    3.32 +    public static short componentPostSet = 0;
    3.33 +    public static boolean componentPreSetVersion = false;
    3.34 +    public static short servicePreSet = 0;
    3.35 +    public static short servicePostSet = 0;
    3.36 +    public static boolean providesPreAdd = false;
    3.37 +    public static boolean providesPostAdd = false;
    3.38 +    
    3.39 +    /** Creates a new instance of InterceptionTest */
    3.40 +    public InterceptionTest(String testName) {
    3.41 +        super(testName);
    3.42 +    }
    3.43 +
    3.44 +    public static NbTest suite() {
    3.45 +        NbTestSuite suite = new NbTestSuite();
    3.46 +        suite.addTestSuite(InterceptionTest.class);
    3.47 +        NbTestSetup setup = new NbTestSetup(suite) {
    3.48 +            public void setUp() {
    3.49 +            }
    3.50 +            
    3.51 +            public void tearDown() {
    3.52 +            }
    3.53 +        };
    3.54 +        return setup;
    3.55 +    }
    3.56 +    
    3.57 +    public static void main(String[] args) {
    3.58 +        junit.textui.TestRunner.run(suite());
    3.59 +    }
    3.60 +    
    3.61 +    public void test() {
    3.62 +        // Init
    3.63 +        ModelPackage pkg = this.loadMOFModel(MODEL_XMI, MODEL_PKG_NAME);
    3.64 +        // Create extent
    3.65 +        test.TestPackage testPkg = (test.TestPackage) createExtent(findMofPackage(pkg, PKG_ELEMENT), PKG_NAME);
    3.66 +        if (testPkg == null)
    3.67 +            fail("Extent creation failed.");
    3.68 +
    3.69 +        // Create objects
    3.70 +        test.ComponentClass cClass = testPkg.getComponent();
    3.71 +        test.ServiceClass sClass = testPkg.getService();
    3.72 +        test.Component comp = cClass.createComponent("aComponent", 1);
    3.73 +        test.Service serv = sClass.createService("aService");
    3.74 +
    3.75 +        if (comp == null || serv == null)
    3.76 +            fail("Object creation failed.");
    3.77 +
    3.78 +        // Attribute test
    3.79 +        comp.setName("X");
    3.80 +        comp.setVersion(2);
    3.81 +        serv.setName("Y");
    3.82 +        if (! comp.getName().equals("X"))
    3.83 +            fail("Invalid attribute value");
    3.84 +        if (comp.getVersion() != 2)
    3.85 +            fail("Invalid attribute value");
    3.86 +        if (componentPreSet != 2)
    3.87 +            fail("_interceptPreSet(...) not called (Component)");
    3.88 +        if (componentPostSet != 2)
    3.89 +            fail("_interceptPostSet(...) not called (Component)");
    3.90 +        if (!componentPreSetVersion)
    3.91 +            fail("_preSetVersion(...) not called");
    3.92 +        if (!serv.getName().equals("Y"))
    3.93 +            fail("Invalid attribute value");
    3.94 +        if (servicePreSet != 1)
    3.95 +            fail("_interceptPreSet(...) not called (Service)");
    3.96 +        if (servicePostSet != 1)
    3.97 +            fail("_interceptPostSet(...) not called (Service)");
    3.98 +        
    3.99 +        // Association test
   3.100 +        comp.getProvidedService().add(serv);
   3.101 +        Collection c = comp.getProvidedService();
   3.102 +        if (c.size() != 1)
   3.103 +            fail("Adding association failed (C->S)");
   3.104 +        c = serv.getProvider();
   3.105 +        if (c.size() != 1)
   3.106 +            fail("Adding association failed (S->C)");
   3.107 +        if (!providesPreAdd)
   3.108 +            fail("_interceptPreAdd(...) not called (Provides)");
   3.109 +        if (!providesPostAdd)
   3.110 +            fail("_interceptPostAdd(...) not called (Provides)");
   3.111 +    }
   3.112 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/mdr/test/unit/src/org/netbeans/mdr/test/data/interception.xml	Tue Jun 04 15:38:07 2002 +0000
     4.3 @@ -0,0 +1,208 @@
     4.4 +<?xml version = '1.0' encoding = 'ISO-8859-1' ?>
     4.5 +<!-- <!DOCTYPE XMI SYSTEM 'Model.dtd' > -->
     4.6 +<XMI xmi.version = '1.1' xmlns:Model='org.omg.mof/Model/1.3' timestamp = 'Mon May 27 14:41:01 2002' >
     4.7 + <XMI.header>
     4.8 +  <XMI.documentation>
     4.9 +   <XMI.exporter>Unisys.JCR.1</XMI.exporter>
    4.10 +   <XMI.exporterVersion>1.3</XMI.exporterVersion>
    4.11 +  </XMI.documentation>
    4.12 +  <XMI.metamodel xmi.name = 'org.omg.mof.Model' xmi.version = '1.3'/>
    4.13 + </XMI.header>
    4.14 +<XMI.content>
    4.15 +<!-- ==================== Test    [Package] ==================== -->
    4.16 +<Model:Package xmi.id = 'a3C8141250000' 
    4.17 +  name = 'Test' annotation = '' 
    4.18 +  isRoot = 'false' isLeaf = 'false' isAbstract = 'false' visibility = 'public_vis' >
    4.19 +  <Model:Namespace.contents>
    4.20 +    <!-- ==================== Test.Component    [Class] ==================== -->
    4.21 +    <Model:Class xmi.id = 'a3C81479D03AF' 
    4.22 +      name = 'Component' annotation = '' 
    4.23 +      isRoot = 'false' isLeaf = 'false' isAbstract = 'false' visibility = 'public_vis' 
    4.24 +      isSingleton = 'false' >
    4.25 +      <Model:Namespace.contents>
    4.26 +        <!-- ==================== providedService{3CE3AB5A0213}    [Reference] ==================== -->
    4.27 +        <Model:Reference xmi.id = 'ra3CE3AB5A0213' 
    4.28 +          name = 'providedService' annotation = '' 
    4.29 +          scope = 'instance_level' visibility = 'public_vis' 
    4.30 +          isChangeable = 'true' 
    4.31 +          type = 'a3CE3AB120261' 
    4.32 +          referencedEnd = 'a3CE3AB5A0213' >
    4.33 +          <Model:StructuralFeature.multiplicity>
    4.34 +            <Model:MultiplicityType lower = '1' upper = '-1' is_ordered = 'false' is_unique = 'true' />
    4.35 +          </Model:StructuralFeature.multiplicity>
    4.36 +        </Model:Reference>
    4.37 +        <!-- ==================== requiredService{3CE3AB5E038A}    [Reference] ==================== -->
    4.38 +        <Model:Reference xmi.id = 'ra3CE3AB5E038A' 
    4.39 +          name = 'requiredService' annotation = '' 
    4.40 +          scope = 'instance_level' visibility = 'public_vis' 
    4.41 +          isChangeable = 'true' 
    4.42 +          type = 'a3CE3AB120261' 
    4.43 +          referencedEnd = 'a3CE3AB5E038A' >
    4.44 +          <Model:StructuralFeature.multiplicity>
    4.45 +            <Model:MultiplicityType lower = '1' upper = '-1' is_ordered = 'false' is_unique = 'true' />
    4.46 +          </Model:StructuralFeature.multiplicity>
    4.47 +        </Model:Reference>
    4.48 +        <!-- ==================== Test.Component.name    [Attribute] ==================== -->
    4.49 +        <Model:Attribute xmi.id = 'a3C8147A902C6' 
    4.50 +          name = 'name' annotation = '' 
    4.51 +          scope = 'instance_level' visibility = 'public_vis' 
    4.52 +          isChangeable = 'true' 
    4.53 +          isDerived = 'false' 
    4.54 +          type = 'a3C8201FD00AA' >
    4.55 +          <Model:StructuralFeature.multiplicity>
    4.56 +            <Model:MultiplicityType lower = '1' upper = '1' is_ordered = 'false' is_unique = 'false' />
    4.57 +          </Model:StructuralFeature.multiplicity>
    4.58 +        </Model:Attribute>
    4.59 +        <!-- ==================== Test.Component.version    [Attribute] ==================== -->
    4.60 +        <Model:Attribute xmi.id = 'a3CE3AC7C0271' 
    4.61 +          name = 'version' annotation = '' 
    4.62 +          scope = 'instance_level' visibility = 'public_vis' 
    4.63 +          isChangeable = 'true' 
    4.64 +          isDerived = 'false' 
    4.65 +          type = 'a3CE3AE76005D' >
    4.66 +          <Model:StructuralFeature.multiplicity>
    4.67 +            <Model:MultiplicityType lower = '1' upper = '1' is_ordered = 'false' is_unique = 'false' />
    4.68 +          </Model:StructuralFeature.multiplicity>
    4.69 +        </Model:Attribute>
    4.70 +      </Model:Namespace.contents>
    4.71 +    </Model:Class>
    4.72 +    <!-- ==================== Test.org.netbeans.mdr.interceptable=true    [Tag] ==================== -->
    4.73 +    <Model:Tag xmi.id = 'G.7' 
    4.74 +      name = 'org.netbeans.mdr.interceptable=true' annotation = '' 
    4.75 +      tagId = 'org.netbeans.mdr.interceptable' 
    4.76 +      elements = 'a3CE3AB2701E4 a3CE3AC7C0271 a3CE3AB120261 a3CE3AB590280' >
    4.77 +      <Model:Tag.values>
    4.78 +        <XMI.any xmi.type = 'string' xmi.name = ''>true</XMI.any>
    4.79 +      </Model:Tag.values>
    4.80 +    </Model:Tag>
    4.81 +    <!-- ==================== Test.String    [DataType] ==================== -->
    4.82 +    <Model:DataType xmi.id = 'a3C8201FD00AA' 
    4.83 +      name = 'String' annotation = '' 
    4.84 +      isRoot = 'true' isLeaf = 'true' isAbstract = 'false' visibility = 'public_vis' >
    4.85 +      <Model:DataType.typeCode>
    4.86 +        <XMI.CorbaTypeCode>
    4.87 +          <XMI.CorbaTcString xmi.tcLength = '0'/>
    4.88 +        </XMI.CorbaTypeCode>
    4.89 +      </Model:DataType.typeCode>
    4.90 +    </Model:DataType>
    4.91 +    <!-- ==================== Test.org.omg.uml2mof.corbaType=string    [Tag] ==================== -->
    4.92 +    <Model:Tag xmi.id = 'G.8' 
    4.93 +      name = 'org.omg.uml2mof.corbaType=string' annotation = '' 
    4.94 +      tagId = 'org.omg.uml2mof.corbaType' 
    4.95 +      elements = 'a3C8201FD00AA' >
    4.96 +      <Model:Tag.values>
    4.97 +        <XMI.any xmi.type = 'string' xmi.name = ''>string</XMI.any>
    4.98 +      </Model:Tag.values>
    4.99 +    </Model:Tag>
   4.100 +    <!-- ==================== Test.Service    [Class] ==================== -->
   4.101 +    <Model:Class xmi.id = 'a3CE3AB120261' 
   4.102 +      name = 'Service' annotation = '' 
   4.103 +      isRoot = 'false' isLeaf = 'false' isAbstract = 'false' visibility = 'public_vis' 
   4.104 +      isSingleton = 'false' >
   4.105 +      <Model:Namespace.contents>
   4.106 +        <!-- ==================== provider{3CE3AB5A0214}    [Reference] ==================== -->
   4.107 +        <Model:Reference xmi.id = 'ra3CE3AB5A0214' 
   4.108 +          name = 'provider' annotation = '' 
   4.109 +          scope = 'instance_level' visibility = 'public_vis' 
   4.110 +          isChangeable = 'true' 
   4.111 +          type = 'a3C81479D03AF' 
   4.112 +          referencedEnd = 'a3CE3AB5A0214' >
   4.113 +          <Model:StructuralFeature.multiplicity>
   4.114 +            <Model:MultiplicityType lower = '0' upper = '-1' is_ordered = 'false' is_unique = 'true' />
   4.115 +          </Model:StructuralFeature.multiplicity>
   4.116 +        </Model:Reference>
   4.117 +        <!-- ==================== requestor{3CE3AB5E038B}    [Reference] ==================== -->
   4.118 +        <Model:Reference xmi.id = 'ra3CE3AB5E038B' 
   4.119 +          name = 'requestor' annotation = '' 
   4.120 +          scope = 'instance_level' visibility = 'public_vis' 
   4.121 +          isChangeable = 'true' 
   4.122 +          type = 'a3C81479D03AF' 
   4.123 +          referencedEnd = 'a3CE3AB5E038B' >
   4.124 +          <Model:StructuralFeature.multiplicity>
   4.125 +            <Model:MultiplicityType lower = '0' upper = '-1' is_ordered = 'false' is_unique = 'true' />
   4.126 +          </Model:StructuralFeature.multiplicity>
   4.127 +        </Model:Reference>
   4.128 +        <!-- ==================== Test.Service.name    [Attribute] ==================== -->
   4.129 +        <Model:Attribute xmi.id = 'a3CE3AB2701E4' 
   4.130 +          name = 'name' annotation = '' 
   4.131 +          scope = 'instance_level' visibility = 'public_vis' 
   4.132 +          isChangeable = 'true' 
   4.133 +          isDerived = 'false' 
   4.134 +          type = 'a3C8201FD00AA' >
   4.135 +          <Model:StructuralFeature.multiplicity>
   4.136 +            <Model:MultiplicityType lower = '1' upper = '1' is_ordered = 'false' is_unique = 'false' />
   4.137 +          </Model:StructuralFeature.multiplicity>
   4.138 +        </Model:Attribute>
   4.139 +      </Model:Namespace.contents>
   4.140 +    </Model:Class>
   4.141 +    <!-- ==================== Test.Integer    [DataType] ==================== -->
   4.142 +    <Model:DataType xmi.id = 'a3CE3AE76005D' 
   4.143 +      name = 'Integer' annotation = '' 
   4.144 +      isRoot = 'true' isLeaf = 'true' isAbstract = 'false' visibility = 'public_vis' >
   4.145 +      <Model:DataType.typeCode>
   4.146 +        <XMI.CorbaTypeCode>
   4.147 +          <XMI.CorbaTcLong/>
   4.148 +        </XMI.CorbaTypeCode>
   4.149 +      </Model:DataType.typeCode>
   4.150 +    </Model:DataType>
   4.151 +    <!-- ==================== Test.org.omg.uml2mof.corbaType=long    [Tag] ==================== -->
   4.152 +    <Model:Tag xmi.id = 'G.9' 
   4.153 +      name = 'org.omg.uml2mof.corbaType=long' annotation = '' 
   4.154 +      tagId = 'org.omg.uml2mof.corbaType' 
   4.155 +      elements = 'a3CE3AE76005D' >
   4.156 +      <Model:Tag.values>
   4.157 +        <XMI.any xmi.type = 'string' xmi.name = ''>long</XMI.any>
   4.158 +      </Model:Tag.values>
   4.159 +    </Model:Tag>
   4.160 +    <!-- ==================== Test.provides    [Association] ==================== -->
   4.161 +    <Model:Association xmi.id = 'a3CE3AB590280' 
   4.162 +      name = 'provides' annotation = '' 
   4.163 +      isRoot = 'true' isLeaf = 'true' isAbstract = 'false' visibility = 'public_vis' 
   4.164 +      isDerived = 'false' >
   4.165 +      <Model:Namespace.contents>
   4.166 +        <Model:AssociationEnd xmi.id = 'a3CE3AB5A0213' 
   4.167 +          name = 'providedService' annotation = '' 
   4.168 +          isNavigable = 'true' aggregation = 'none' isChangeable = 'true' 
   4.169 +          type = 'a3CE3AB120261' >
   4.170 +          <Model:AssociationEnd.multiplicity>
   4.171 +            <Model:MultiplicityType lower = '1' upper = '-1' is_ordered = 'false' is_unique = 'true' />
   4.172 +          </Model:AssociationEnd.multiplicity>
   4.173 +        </Model:AssociationEnd>
   4.174 +        <Model:AssociationEnd xmi.id = 'a3CE3AB5A0214' 
   4.175 +          name = 'provider' annotation = '' 
   4.176 +          isNavigable = 'true' aggregation = 'none' isChangeable = 'true' 
   4.177 +          type = 'a3C81479D03AF' >
   4.178 +          <Model:AssociationEnd.multiplicity>
   4.179 +            <Model:MultiplicityType lower = '0' upper = '-1' is_ordered = 'false' is_unique = 'true' />
   4.180 +          </Model:AssociationEnd.multiplicity>
   4.181 +        </Model:AssociationEnd>
   4.182 +      </Model:Namespace.contents>
   4.183 +    </Model:Association>
   4.184 +    <!-- ==================== Test.requires    [Association] ==================== -->
   4.185 +    <Model:Association xmi.id = 'a3CE3AB5D0399' 
   4.186 +      name = 'requires' annotation = '' 
   4.187 +      isRoot = 'true' isLeaf = 'true' isAbstract = 'false' visibility = 'public_vis' 
   4.188 +      isDerived = 'false' >
   4.189 +      <Model:Namespace.contents>
   4.190 +        <Model:AssociationEnd xmi.id = 'a3CE3AB5E038A' 
   4.191 +          name = 'requiredService' annotation = '' 
   4.192 +          isNavigable = 'true' aggregation = 'none' isChangeable = 'true' 
   4.193 +          type = 'a3CE3AB120261' >
   4.194 +          <Model:AssociationEnd.multiplicity>
   4.195 +            <Model:MultiplicityType lower = '1' upper = '-1' is_ordered = 'false' is_unique = 'true' />
   4.196 +          </Model:AssociationEnd.multiplicity>
   4.197 +        </Model:AssociationEnd>
   4.198 +        <Model:AssociationEnd xmi.id = 'a3CE3AB5E038B' 
   4.199 +          name = 'requestor' annotation = '' 
   4.200 +          isNavigable = 'true' aggregation = 'none' isChangeable = 'true' 
   4.201 +          type = 'a3C81479D03AF' >
   4.202 +          <Model:AssociationEnd.multiplicity>
   4.203 +            <Model:MultiplicityType lower = '0' upper = '-1' is_ordered = 'false' is_unique = 'true' />
   4.204 +          </Model:AssociationEnd.multiplicity>
   4.205 +        </Model:AssociationEnd>
   4.206 +      </Model:Namespace.contents>
   4.207 +    </Model:Association>
   4.208 +  </Model:Namespace.contents>
   4.209 +</Model:Package>
   4.210 +</XMI.content>
   4.211 +</XMI>