⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linktest.java

📁 UML设计测试工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * USE - UML based specification environment * Copyright (C) 1999-2004 Mark Richters, University of Bremen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* $ProjectHeader: use 2-3-0-release.1 Mon, 12 Sep 2005 20:18:33 +0200 green $ */package org.tzi.use.uml.sys;import java.util.ArrayList;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;import junit.framework.*;import org.tzi.use.uml.mm.MAssociation;import org.tzi.use.uml.mm.MAssociationClass;import org.tzi.use.uml.mm.MModel;import org.tzi.use.uml.mm.TestModelUtil;import org.tzi.use.uml.ocl.expr.ExpVariable;import org.tzi.use.uml.ocl.expr.Expression;import org.tzi.use.uml.ocl.type.ObjectType;import org.tzi.use.uml.ocl.type.TypeFactory;/** * The class <code>LinkTest</code> creates an instance of an * associationclass. * * @version $ProjectVersion: 2-3-0-release.1 $ * @author <a href="mailto:hanna@tzi.de">Hanna Bauerdick</a> * @author <a href="mailto:gutsche@tzi.de">Fabian Gutsche</a> */public class LinkTest extends TestCase {    /**     * Creates instances of associations and associationclass.     */    public void testLinkCreation() {        MSystem system = createModelWithObject();        // tests weather or not the objects exists        assertEquals( "p1", system.state().objectByName( "p1" ).name() );        assertEquals( "c1", system.state().objectByName( "c1" ).name() );        assertEquals( "j1", system.state().objectByName( "j1" ).name() );        // tests if the link between p1 (Person) and c1 (Company) exists        Set objects = new HashSet();        objects.add( system.state().objectByName( "p1" ) );        objects.add( system.state().objectByName( "c1" ) );        assertTrue( system.state().hasLinkBetweenObjects( system.model()                                                          .getAssociation( "Job" ),                                                          objects ) );        // tests if the link between p1 (Person) and j1 (Job) doesn't exist        objects.clear();        objects.add( system.state().objectByName( "p1" ) );        objects.add( system.state().objectByName( "j1" ) );        assertFalse( system.state().hasLinkBetweenObjects( system.model()                                                           .getAssociation( "Job" ),                                                           objects ) );    }    /**     * Deletes Linkobject between Objects with command     * <code>MCmdDestroyObjects</code>.     */    public void testObjectDestroy() {        try {            MSystem system = createModelWithObject();            assertEquals( "j1", system.state().objectByName( "j1" ).name() );            Set objects = new HashSet();            objects.add( system.state().objectByName( "p1" ) );            objects.add( system.state().objectByName( "c1" ) );            assertTrue( system.state().hasLinkBetweenObjects( system.model().getAssociation( "Job" ),                                                              objects ) );            List names = new ArrayList();            names.add( "j1" );            Expression[] exprs = new Expression[names.size()];            Iterator it = names.iterator();            int i = 0;            while (it.hasNext() ) {                MObject obj =  system.state().objectByName( (String) it.next() );                 exprs[i++] = new ExpVariable( obj.name(), obj.type() );            }            MCmd cmd = new MCmdDestroyObjects( system.state(), exprs );            system.executeCmd( cmd );            assertEquals( null, system.state().objectByName( "j1" ) );            objects = new HashSet();            objects.add( system.state().objectByName( "p1" ) );            objects.add( system.state().objectByName( "c1" ) );            assertFalse( system.state().hasLinkBetweenObjects( system.model().getAssociation( "Job" ),                                                               objects ) );        } catch ( MSystemException e ) {            throw ( new Error( e ) );        }    }    /**     * Deletes Linkobject between Objects with command     * <code>MCmdDeleteLink</code>.     */    public void testLinkDeletion() {        try {            MSystem system = createModelWithObject();            List names = new ArrayList();            names.add( "p1" );            names.add( "c1" );            Expression[] exprs = new Expression[names.size()];            Iterator it = names.iterator();            int i = 0;            while (it.hasNext() ) {                MObject obj =  system.state().objectByName( (String) it.next() );                 exprs[i++] = new ExpVariable( obj.name(), obj.type() );            }            MAssociation assoc = system.model().getAssociation( "Job" );            MCmd cmd = new MCmdDeleteLink( system.state(), exprs, assoc );            system.executeCmd( cmd );            assertEquals( null, system.state().objectByName( "j1" ) );            Set objects = new HashSet();            objects.add( system.state().objectByName( "p1" ) );            objects.add( system.state().objectByName( "c1" ) );            assertFalse( system.state().hasLinkBetweenObjects( assoc, objects ) );        } catch ( MSystemException e ) {            throw ( new Error( e ) );        }    }    public void testLinkCreationAndUndo() {        try {            MSystem system = createModelWithObject();            // tests weather or not the objects exists            assertEquals( "j1", system.state().objectByName( "j1" ).name() );            // tests if the link between p1 (Person) and c1 (Company) exists            Set objects = new HashSet();            objects.add( system.state().objectByName( "p1" ) );            objects.add( system.state().objectByName( "c1" ) );            assertTrue( system.state().hasLinkBetweenObjects( system.model()                                                              .getAssociation( "Job" ),                                                              objects ) );            // Undo the last command (insertion of j1)            system.undoCmd();            // tests if the object j1 does not exists            assertEquals( null, system.state().objectByName( "j1" ) );            // tests if the link between p1 (Person) and c1 (Company) exists            objects = new HashSet();            objects.add( system.state().objectByName( "p1" ) );            objects.add( system.state().objectByName( "c1" ) );            assertFalse( system.state().hasLinkBetweenObjects( system.model()                                                               .getAssociation( "Job" ),                                                               objects ) );        } catch ( MSystemException e ) {            throw ( new Error( e ) );        }    }    /**     * Creates Linkobject between Objects with command     * <code>MCmdInsertLink</code>.     */    public void testCreationLinkObjectWithCmdInsertLink() {        try {            MSystem system = createModelWithoutLinkObject();            List names = new ArrayList();            names.add( "p1" );            names.add( "c1" );            Expression[] exprs = new Expression[names.size()];            Iterator it = names.iterator();            int i = 0;            while (it.hasNext() ) {                MObject obj =  system.state().objectByName( (String) it.next() );                 exprs[i++] = new ExpVariable( obj.name(), obj.type() );            }            MAssociation assoc = system.model().getAssociation( "Job" );            MCmd cmd = new MCmdInsertLink( system.state(), exprs, assoc );            system.executeCmd( cmd );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -