0001: /*
0002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
0003: * Distributed under the terms of either:
0004: * - the common development and distribution license (CDDL), v1.0; or
0005: * - the GNU Lesser General Public License, v2.1 or later
0006: * $Id: TestElementModel.java 3634 2007-01-08 21:42:24Z gbevin $
0007: */
0008: package com.uwyn.rife.gui.model;
0009:
0010: import java.util.Iterator;
0011:
0012: import junit.framework.TestCase;
0013:
0014: import com.uwyn.rife.gui.model.exceptions.GuiModelException;
0015:
0016: public class TestElementModel extends TestCase implements
0017: ParticleModelListener {
0018: private Object mChildAdded = null;
0019: private Object mPropertyAdded = null;
0020: private Object mPropertyRemoved = null;
0021: private Object mPropertyRenamed = null;
0022:
0023: public TestElementModel(String name) {
0024: super (name);
0025: }
0026:
0027: public void testInstantiation() {
0028: ElementModel elementmodel_instance = null;
0029:
0030: try {
0031: elementmodel_instance = new ElementModel("elementmodel1");
0032: } catch (GuiModelException e) {
0033: assertTrue(e.getMessage(), false);
0034: }
0035:
0036: assertTrue(elementmodel_instance != null);
0037: assertTrue(elementmodel_instance instanceof ElementModel);
0038: }
0039:
0040: public void testGetId() {
0041: ElementModel elementmodel_instance = null;
0042: ElementIdModel titlemodel_instance = null;
0043:
0044: try {
0045: elementmodel_instance = new ElementModel("elementmodel1");
0046: } catch (GuiModelException e) {
0047: assertTrue(e.getMessage(), false);
0048: }
0049:
0050: titlemodel_instance = elementmodel_instance.getId();
0051:
0052: assertTrue(titlemodel_instance != null);
0053: assertTrue(titlemodel_instance instanceof ElementIdModel);
0054: assertEquals(titlemodel_instance.getName(), "elementmodel1");
0055: }
0056:
0057: public void testChangeId() {
0058: ElementModel elementmodel_instance = null;
0059: ElementIdModel titlemodel_instance = null;
0060:
0061: try {
0062: elementmodel_instance = new ElementModel("elementmodel1");
0063: } catch (GuiModelException e) {
0064: assertTrue(e.getMessage(), false);
0065: }
0066: assertTrue(elementmodel_instance.addParticleListener(this ));
0067: titlemodel_instance = elementmodel_instance.getId();
0068: assertNull(mPropertyRenamed);
0069:
0070: try {
0071: assertTrue(elementmodel_instance.renameProperty(
0072: titlemodel_instance, "elementmodel2"));
0073: } catch (GuiModelException e) {
0074: assertTrue(e.getMessage(), false);
0075: }
0076: assertSame(mPropertyRenamed, titlemodel_instance);
0077: }
0078:
0079: public void testChangeIdToSameName() {
0080: ElementModel elementmodel_instance = null;
0081: ElementIdModel titlemodel_instance = null;
0082:
0083: try {
0084: elementmodel_instance = new ElementModel("elementmodel1");
0085: } catch (GuiModelException e) {
0086: assertTrue(e.getMessage(), false);
0087: }
0088: assertTrue(elementmodel_instance.addParticleListener(this ));
0089: titlemodel_instance = elementmodel_instance.getId();
0090: assertNull(mPropertyRenamed);
0091:
0092: try {
0093: assertTrue(elementmodel_instance.renameProperty(
0094: titlemodel_instance, "elementmodel1") == false);
0095: } catch (GuiModelException e) {
0096: assertTrue(e.getMessage(), false);
0097: }
0098: assertNull(mPropertyRenamed);
0099: }
0100:
0101: public void testTryToRemoveId() {
0102: ElementModel elementmodel_instance = null;
0103: ElementIdModel titlemodel_instance = null;
0104:
0105: try {
0106: elementmodel_instance = new ElementModel("elementmodel1");
0107: } catch (GuiModelException e) {
0108: assertTrue(e.getMessage(), false);
0109: }
0110: assertTrue(elementmodel_instance.addParticleListener(this ));
0111: titlemodel_instance = elementmodel_instance.getId();
0112: assertNull(mPropertyRemoved);
0113:
0114: try {
0115: elementmodel_instance.removeProperty(titlemodel_instance);
0116: fail();
0117: } catch (GuiModelException e) {
0118: assertTrue(true);
0119: }
0120: assertNull(mPropertyRemoved);
0121: }
0122:
0123: public void testIdConflicts() {
0124: ElementModel elementmodel_instance1 = null;
0125:
0126: try {
0127: elementmodel_instance1 = new ElementModel("elementmodel1");
0128: } catch (GuiModelException e) {
0129: assertTrue(e.getMessage(), false);
0130: }
0131:
0132: try {
0133: elementmodel_instance1.setImplementation("classname1");
0134: elementmodel_instance1.addInput("inputmodel1");
0135: elementmodel_instance1.addOutput("outputmodel1");
0136: elementmodel_instance1.addExit("exitmodel1");
0137: } catch (GuiModelException e) {
0138: assertTrue(e.getMessage(), false);
0139: }
0140:
0141: try {
0142: new ElementModel("classname1");
0143: new ElementModel("inputmodel1");
0144: new ElementModel("outputmodel1");
0145: new ElementModel("exitmodel1");
0146: new ElementModel("elementmodel2");
0147: } catch (GuiModelException e) {
0148: assertTrue(e.getMessage(), false);
0149: }
0150:
0151: try {
0152: new ElementModel("elementmodel1");
0153: } catch (GuiModelException e) {
0154: // no error since they are not part of the same group yet
0155: assertTrue(e.getMessage(), false);
0156: }
0157: }
0158:
0159: public void testNoInitialClassname() {
0160: ElementModel elementmodel_instance = null;
0161:
0162: try {
0163: elementmodel_instance = new ElementModel("elementmodel1");
0164: } catch (GuiModelException e) {
0165: assertTrue(e.getMessage(), false);
0166: }
0167:
0168: assertNull(elementmodel_instance.getImplementation());
0169: }
0170:
0171: public void testSetClassname() {
0172: ElementModel elementmodel_instance = null;
0173: ElementImplementationModel classnamemodel_instance = null;
0174:
0175: try {
0176: elementmodel_instance = new ElementModel("elementmodel1");
0177: } catch (GuiModelException e) {
0178: assertTrue(e.getMessage(), false);
0179: }
0180: assertTrue(elementmodel_instance.addParticleListener(this ));
0181: assertNull(mPropertyAdded);
0182:
0183: try {
0184: classnamemodel_instance = elementmodel_instance
0185: .setImplementation("classnamemodel1");
0186: } catch (GuiModelException e) {
0187: assertTrue(e.getMessage(), false);
0188: }
0189: assertSame(mPropertyAdded, classnamemodel_instance);
0190:
0191: assertSame(elementmodel_instance.getImplementation(),
0192: classnamemodel_instance);
0193: assertEquals(elementmodel_instance
0194: .countProperties(ElementImplementationModel.class), 1);
0195: }
0196:
0197: public void testSetClassnameTwice() {
0198: ElementModel elementmodel_instance = null;
0199: ElementImplementationModel classnamemodel_instance2 = null;
0200:
0201: try {
0202: elementmodel_instance = new ElementModel("elementmodel1");
0203: } catch (GuiModelException e) {
0204: assertTrue(e.getMessage(), false);
0205: }
0206: assertTrue(elementmodel_instance.addParticleListener(this ));
0207: assertNull(mPropertyAdded);
0208:
0209: try {
0210: classnamemodel_instance2 = elementmodel_instance
0211: .setImplementation("classnamemodel2");
0212: } catch (GuiModelException e) {
0213: assertTrue(e.getMessage(), false);
0214: }
0215: assertSame(mPropertyAdded, classnamemodel_instance2);
0216:
0217: assertSame(elementmodel_instance.getImplementation(),
0218: classnamemodel_instance2);
0219: assertEquals(elementmodel_instance
0220: .countProperties(ElementImplementationModel.class), 1);
0221: }
0222:
0223: public void testClassnameConflicts() {
0224: ElementModel elementmodel_instance1 = null;
0225: ElementModel elementmodel_instance2 = null;
0226:
0227: try {
0228: elementmodel_instance1 = new ElementModel("elementmodel1");
0229: elementmodel_instance2 = new ElementModel("elementmodel2");
0230:
0231: elementmodel_instance1.setImplementation("classname1");
0232: elementmodel_instance1.addInput("inputmodel1");
0233: elementmodel_instance1.addOutput("outputmodel1");
0234: elementmodel_instance1.addExit("exitmodel1");
0235: elementmodel_instance2.setImplementation("classname2");
0236: } catch (GuiModelException e) {
0237: assertTrue(e.getMessage(), false);
0238: }
0239:
0240: try {
0241: elementmodel_instance1.setImplementation("elementmodel1");
0242: elementmodel_instance1.setImplementation("classname1");
0243: elementmodel_instance1.setImplementation("inputmodel1");
0244: elementmodel_instance1.setImplementation("outputmodel1");
0245: elementmodel_instance1.setImplementation("exitmodel1");
0246: elementmodel_instance1.setImplementation("elementmodel2");
0247: elementmodel_instance1.setImplementation("classname2");
0248: } catch (GuiModelException e) {
0249: assertTrue(e.getMessage(), false);
0250: }
0251: }
0252:
0253: public void testNoInitialInputs() {
0254: ElementModel elementmodel_instance = null;
0255:
0256: try {
0257: elementmodel_instance = new ElementModel("elementmodel1");
0258: } catch (GuiModelException e) {
0259: assertTrue(e.getMessage(), false);
0260: }
0261:
0262: assertEquals(elementmodel_instance.getInputs().size(), 0);
0263: }
0264:
0265: public void testInitialInputCountIsZero() {
0266: ElementModel elementmodel_instance = null;
0267:
0268: try {
0269: elementmodel_instance = new ElementModel("elementmodel1");
0270: } catch (GuiModelException e) {
0271: assertTrue(e.getMessage(), false);
0272: }
0273:
0274: assertEquals(elementmodel_instance.countInputs(), 0);
0275: }
0276:
0277: public void testAddOneInput() {
0278: ElementModel elementmodel_instance = null;
0279: ElementInputModel inputmodel_instance = null;
0280:
0281: try {
0282: elementmodel_instance = new ElementModel("elementmodel1");
0283: } catch (GuiModelException e) {
0284: assertTrue(e.getMessage(), false);
0285: }
0286: assertTrue(elementmodel_instance.addParticleListener(this ));
0287: assertNull(mPropertyAdded);
0288:
0289: try {
0290: inputmodel_instance = elementmodel_instance
0291: .addInput("inputmodel1");
0292: } catch (GuiModelException e) {
0293: assertTrue(e.getMessage(), false);
0294: }
0295: assertSame(mPropertyAdded, inputmodel_instance);
0296:
0297: Iterator<ElementInputModel> input_it = elementmodel_instance
0298: .getInputs().iterator();
0299: assertTrue(input_it.hasNext());
0300: ElementInputModel input = input_it.next();
0301: assertEquals(input_it.hasNext(), false);
0302: assertSame(input, inputmodel_instance);
0303: }
0304:
0305: public void testAddTheSameInputTwice() {
0306: ElementModel elementmodel_instance = null;
0307: ElementInputModel inputmodel_instance = null;
0308:
0309: try {
0310: elementmodel_instance = new ElementModel("elementmodel1");
0311: } catch (GuiModelException e) {
0312: assertTrue(e.getMessage(), false);
0313: }
0314: assertTrue(elementmodel_instance.addParticleListener(this ));
0315: assertNull(mPropertyAdded);
0316:
0317: try {
0318: inputmodel_instance = elementmodel_instance
0319: .addInput("inputmodel1");
0320: } catch (GuiModelException e) {
0321: assertTrue(e.getMessage(), false);
0322: }
0323: assertSame(mPropertyAdded, inputmodel_instance);
0324:
0325: mPropertyAdded = null;
0326: try {
0327: elementmodel_instance.addInput("inputmodel1");
0328: fail();
0329: } catch (GuiModelException e) {
0330: assertTrue(true);
0331: }
0332: assertNull(mPropertyAdded);
0333: Iterator<ElementInputModel> input_it = elementmodel_instance
0334: .getInputs().iterator();
0335: assertTrue(input_it.hasNext());
0336: ElementInputModel input = input_it.next();
0337: assertEquals(input_it.hasNext(), false);
0338: assertSame(input, inputmodel_instance);
0339: }
0340:
0341: public void testAddTwoInputs() {
0342: ElementModel elementmodel_instance = null;
0343: ElementInputModel inputmodel_instance1 = null;
0344: ElementInputModel inputmodel_instance2 = null;
0345:
0346: try {
0347: elementmodel_instance = new ElementModel("elementmodel1");
0348: } catch (GuiModelException e) {
0349: assertTrue(e.getMessage(), false);
0350: }
0351: assertTrue(elementmodel_instance.addParticleListener(this ));
0352: assertNull(mPropertyAdded);
0353:
0354: try {
0355: inputmodel_instance1 = elementmodel_instance
0356: .addInput("inputmodel1");
0357: assertSame(mPropertyAdded, inputmodel_instance1);
0358: inputmodel_instance2 = elementmodel_instance
0359: .addInput("inputmodel2");
0360: assertSame(mPropertyAdded, inputmodel_instance2);
0361: } catch (GuiModelException e) {
0362: assertTrue(e.getMessage(), false);
0363: }
0364:
0365: Iterator<ElementInputModel> input_it = elementmodel_instance
0366: .getInputs().iterator();
0367: assertTrue(input_it.hasNext());
0368: ElementInputModel input1 = input_it.next();
0369: assertTrue(input_it.hasNext());
0370: ElementInputModel input2 = input_it.next();
0371: assertEquals(input_it.hasNext(), false);
0372: assertTrue((input1 == inputmodel_instance1 && input2 == inputmodel_instance2)
0373: || (input2 == inputmodel_instance1 && input1 == inputmodel_instance2));
0374: }
0375:
0376: public void testCountInputs() {
0377: ElementModel elementmodel_instance = null;
0378: ElementInputModel inputmodel_instance1 = null;
0379: ElementInputModel inputmodel_instance2 = null;
0380: ElementExitModel exitmodel_instance = null;
0381: ElementOutputModel outputmodel_instance = null;
0382:
0383: try {
0384: elementmodel_instance = new ElementModel("elementmodel1");
0385: } catch (GuiModelException e) {
0386: assertTrue(e.getMessage(), false);
0387: }
0388: assertTrue(elementmodel_instance.addParticleListener(this ));
0389: assertNull(mPropertyAdded);
0390:
0391: assertNull(mPropertyAdded);
0392: try {
0393: inputmodel_instance1 = elementmodel_instance
0394: .addInput("inputmodel1");
0395: assertSame(mPropertyAdded, inputmodel_instance1);
0396: inputmodel_instance2 = elementmodel_instance
0397: .addInput("inputmodel2");
0398: assertSame(mPropertyAdded, inputmodel_instance2);
0399: exitmodel_instance = elementmodel_instance
0400: .addExit("exitmodel");
0401: assertSame(mPropertyAdded, exitmodel_instance);
0402: outputmodel_instance = elementmodel_instance
0403: .addOutput("outputmodel");
0404: assertSame(mPropertyAdded, outputmodel_instance);
0405: } catch (GuiModelException e) {
0406: assertTrue(e.getMessage(), false);
0407: }
0408:
0409: assertEquals(elementmodel_instance.countInputs(), 2);
0410: assertEquals(elementmodel_instance
0411: .countProperties(ElementInputModel.class), 2);
0412: assertEquals(elementmodel_instance
0413: .countProperties(ElementVariableModel.class), 3);
0414: assertEquals(elementmodel_instance
0415: .countProperties(ElementPropertyModel.class), 5);
0416: }
0417:
0418: public void testInputConflicts() {
0419: ElementModel elementmodel_instance = null;
0420:
0421: try {
0422: elementmodel_instance = new ElementModel("elementmodel1");
0423:
0424: elementmodel_instance.setImplementation("classname");
0425: elementmodel_instance.addInput("inputmodel1");
0426: elementmodel_instance.addOutput("outputmodel1");
0427: elementmodel_instance.addExit("exitmodel1");
0428: } catch (GuiModelException e) {
0429: assertTrue(e.getMessage(), false);
0430: }
0431:
0432: try {
0433: elementmodel_instance.addInput("inputmodel1");
0434: fail();
0435: } catch (GuiModelException e) {
0436: assertTrue(true);
0437: }
0438: try {
0439: elementmodel_instance.addInput("outputmodel1");
0440: fail();
0441: } catch (GuiModelException e) {
0442: assertTrue(true);
0443: }
0444: try {
0445: elementmodel_instance.addInput("elementmodel1");
0446: elementmodel_instance.addInput("classname");
0447: elementmodel_instance.addInput("exitmodel1");
0448: } catch (GuiModelException e) {
0449: assertTrue(e.getMessage(), false);
0450: }
0451: }
0452:
0453: public void testRenameInputConflict() {
0454: ElementModel elementmodel_instance = null;
0455: ElementInputModel inputmodel_instance1 = null;
0456:
0457: try {
0458: elementmodel_instance = new ElementModel("elementmodel1");
0459: inputmodel_instance1 = elementmodel_instance
0460: .addInput("inputmodel1");
0461: elementmodel_instance.addInput("inputmodel2");
0462: } catch (GuiModelException e) {
0463: assertTrue(e.getMessage(), false);
0464: }
0465: assertTrue(elementmodel_instance.addParticleListener(this ));
0466: assertNull(mPropertyRenamed);
0467:
0468: try {
0469: assertTrue(elementmodel_instance.renameProperty(
0470: inputmodel_instance1, "inputmodel2"));
0471: fail();
0472: } catch (GuiModelException e) {
0473: assertTrue(true);
0474: }
0475: assertNull(mPropertyRenamed);
0476: }
0477:
0478: public void testNoInitialOutputs() {
0479: ElementModel elementmodel_instance = null;
0480:
0481: try {
0482: elementmodel_instance = new ElementModel("elementmodel1");
0483: } catch (GuiModelException e) {
0484: assertTrue(e.getMessage(), false);
0485: }
0486:
0487: assertEquals(elementmodel_instance.getOutputs().size(), 0);
0488: }
0489:
0490: public void testInitialOutputCountIsZero() {
0491: ElementModel elementmodel_instance = null;
0492:
0493: try {
0494: elementmodel_instance = new ElementModel("elementmodel1");
0495: } catch (GuiModelException e) {
0496: assertTrue(e.getMessage(), false);
0497: }
0498:
0499: assertEquals(elementmodel_instance.countOutputs(), 0);
0500: }
0501:
0502: public void testAddOneOutput() {
0503: ElementModel elementmodel_instance = null;
0504: ElementOutputModel outputmodel_instance = null;
0505:
0506: try {
0507: elementmodel_instance = new ElementModel("elementmodel1");
0508: } catch (GuiModelException e) {
0509: assertTrue(e.getMessage(), false);
0510: }
0511: assertTrue(elementmodel_instance.addParticleListener(this ));
0512: assertNull(mPropertyAdded);
0513:
0514: try {
0515: outputmodel_instance = elementmodel_instance
0516: .addOutput("outputmodel1");
0517: } catch (GuiModelException e) {
0518: assertTrue(e.getMessage(), false);
0519: }
0520: assertSame(mPropertyAdded, outputmodel_instance);
0521:
0522: Iterator<ElementOutputModel> output_it = elementmodel_instance
0523: .getOutputs().iterator();
0524: assertTrue(output_it.hasNext());
0525: ElementOutputModel output = output_it.next();
0526: assertEquals(output_it.hasNext(), false);
0527: assertSame(output, outputmodel_instance);
0528: }
0529:
0530: public void testAddTheSameOutputTwice() {
0531: ElementModel elementmodel_instance = null;
0532: ElementOutputModel outputmodel_instance = null;
0533:
0534: try {
0535: elementmodel_instance = new ElementModel("elementmodel1");
0536: } catch (GuiModelException e) {
0537: assertTrue(e.getMessage(), false);
0538: }
0539: assertTrue(elementmodel_instance.addParticleListener(this ));
0540: assertNull(mPropertyAdded);
0541:
0542: try {
0543: outputmodel_instance = elementmodel_instance
0544: .addOutput("outputmodel1");
0545: } catch (GuiModelException e) {
0546: assertTrue(e.getMessage(), false);
0547: }
0548: assertSame(mPropertyAdded, outputmodel_instance);
0549:
0550: mPropertyAdded = null;
0551: try {
0552: elementmodel_instance.addOutput("outputmodel1");
0553: fail();
0554: } catch (GuiModelException e) {
0555: assertTrue(true);
0556: }
0557: assertNull(mPropertyAdded);
0558: Iterator<ElementOutputModel> output_it = elementmodel_instance
0559: .getOutputs().iterator();
0560: assertTrue(output_it.hasNext());
0561: ElementOutputModel output = output_it.next();
0562: assertEquals(output_it.hasNext(), false);
0563: assertSame(output, outputmodel_instance);
0564: }
0565:
0566: public void testAddTwoOutputs() {
0567: ElementModel elementmodel_instance = null;
0568: ElementOutputModel outputmodel_instance1 = null;
0569: ElementOutputModel outputmodel_instance2 = null;
0570:
0571: try {
0572: elementmodel_instance = new ElementModel("elementmodel1");
0573: } catch (GuiModelException e) {
0574: assertTrue(e.getMessage(), false);
0575: }
0576: assertTrue(elementmodel_instance.addParticleListener(this ));
0577:
0578: try {
0579: outputmodel_instance1 = elementmodel_instance
0580: .addOutput("outputmodel1");
0581: assertSame(mPropertyAdded, outputmodel_instance1);
0582: outputmodel_instance2 = elementmodel_instance
0583: .addOutput("outputmodel2");
0584: assertSame(mPropertyAdded, outputmodel_instance2);
0585: } catch (GuiModelException e) {
0586: assertTrue(e.getMessage(), false);
0587: }
0588:
0589: Iterator<ElementOutputModel> output_it = elementmodel_instance
0590: .getOutputs().iterator();
0591: assertTrue(output_it.hasNext());
0592: ElementOutputModel output1 = output_it.next();
0593: assertTrue(output_it.hasNext());
0594: ElementOutputModel output2 = output_it.next();
0595: assertEquals(output_it.hasNext(), false);
0596: assertTrue((output1 == outputmodel_instance1 && output2 == outputmodel_instance2)
0597: || (output2 == outputmodel_instance1 && output1 == outputmodel_instance2));
0598: }
0599:
0600: public void testCountOutputs() {
0601: ElementModel elementmodel_instance = null;
0602: ElementOutputModel outputmodel_instance1 = null;
0603: ElementOutputModel outputmodel_instance2 = null;
0604: ElementExitModel exitmodel_instance = null;
0605: ElementInputModel inputmodel_instance = null;
0606:
0607: try {
0608: elementmodel_instance = new ElementModel("elementmodel1");
0609: } catch (GuiModelException e) {
0610: assertTrue(e.getMessage(), false);
0611: }
0612: assertTrue(elementmodel_instance.addParticleListener(this ));
0613:
0614: assertNull(mPropertyAdded);
0615: try {
0616: exitmodel_instance = elementmodel_instance
0617: .addExit("exitmodel1");
0618: assertSame(mPropertyAdded, exitmodel_instance);
0619: outputmodel_instance1 = elementmodel_instance
0620: .addOutput("outputmodel1");
0621: assertSame(mPropertyAdded, outputmodel_instance1);
0622: outputmodel_instance2 = elementmodel_instance
0623: .addOutput("outputmodel2");
0624: assertSame(mPropertyAdded, outputmodel_instance2);
0625: inputmodel_instance = elementmodel_instance
0626: .addInput("inputmodel");
0627: assertSame(mPropertyAdded, inputmodel_instance);
0628: } catch (GuiModelException e) {
0629: assertTrue(e.getMessage(), false);
0630: }
0631:
0632: assertEquals(elementmodel_instance.countOutputs(), 2);
0633: assertEquals(elementmodel_instance
0634: .countProperties(ElementOutputModel.class), 2);
0635: assertEquals(elementmodel_instance
0636: .countProperties(ElementVariableModel.class), 3);
0637: assertEquals(elementmodel_instance
0638: .countProperties(ElementPropertyModel.class), 5);
0639: }
0640:
0641: public void testOutputConflicts() {
0642: ElementModel elementmodel_instance = null;
0643:
0644: try {
0645: elementmodel_instance = new ElementModel("elementmodel1");
0646:
0647: elementmodel_instance.setImplementation("classname");
0648: elementmodel_instance.addInput("inputmodel1");
0649: elementmodel_instance.addOutput("outputmodel1");
0650: elementmodel_instance.addExit("exitmodel1");
0651: } catch (GuiModelException e) {
0652: assertTrue(e.getMessage(), false);
0653: }
0654:
0655: try {
0656: elementmodel_instance.addOutput("outputmodel1");
0657: fail();
0658: } catch (GuiModelException e) {
0659: assertTrue(true);
0660: }
0661: try {
0662: elementmodel_instance.addOutput("inputmodel1");
0663: fail();
0664: } catch (GuiModelException e) {
0665: assertTrue(true);
0666: }
0667: try {
0668: elementmodel_instance.addOutput("elementmodel1");
0669: elementmodel_instance.addOutput("classname");
0670: elementmodel_instance.addOutput("exitmodel1");
0671: } catch (GuiModelException e) {
0672: assertTrue(e.getMessage(), false);
0673: }
0674: }
0675:
0676: public void testRenameOutputConflict() {
0677: ElementModel elementmodel_instance = null;
0678: ElementOutputModel outputmodel_instance1 = null;
0679:
0680: try {
0681: elementmodel_instance = new ElementModel("elementmodel1");
0682: outputmodel_instance1 = elementmodel_instance
0683: .addOutput("outputmodel1");
0684: elementmodel_instance.addOutput("outputmodel2");
0685: } catch (GuiModelException e) {
0686: assertTrue(e.getMessage(), false);
0687: }
0688: assertTrue(elementmodel_instance.addParticleListener(this ));
0689: assertNull(mPropertyRenamed);
0690:
0691: try {
0692: assertTrue(elementmodel_instance.renameProperty(
0693: outputmodel_instance1, "outputmodel2"));
0694: fail();
0695: } catch (GuiModelException e) {
0696: assertTrue(true);
0697: }
0698: assertNull(mPropertyRenamed);
0699: }
0700:
0701: public void testNoInitialExits() {
0702: ElementModel elementmodel_instance = null;
0703:
0704: try {
0705: elementmodel_instance = new ElementModel("elementmodel1");
0706: } catch (GuiModelException e) {
0707: assertTrue(e.getMessage(), false);
0708: }
0709:
0710: assertEquals(elementmodel_instance.getExits().size(), 0);
0711: }
0712:
0713: public void testInitialExitCountIsZero() {
0714: ElementModel elementmodel_instance = null;
0715:
0716: try {
0717: elementmodel_instance = new ElementModel("elementmodel1");
0718: } catch (GuiModelException e) {
0719: assertTrue(e.getMessage(), false);
0720: }
0721:
0722: assertEquals(elementmodel_instance.countExits(), 0);
0723: }
0724:
0725: public void testAddOneExit() {
0726: ElementModel elementmodel_instance = null;
0727: ElementExitModel exitmodel_instance = null;
0728:
0729: try {
0730: elementmodel_instance = new ElementModel("elementmodel1");
0731: } catch (GuiModelException e) {
0732: assertTrue(e.getMessage(), false);
0733: }
0734: assertTrue(elementmodel_instance.addParticleListener(this ));
0735: assertNull(mPropertyAdded);
0736:
0737: try {
0738: exitmodel_instance = elementmodel_instance
0739: .addExit("exitmodel1");
0740: } catch (GuiModelException e) {
0741: assertTrue(e.getMessage(), false);
0742: }
0743: assertSame(mPropertyAdded, exitmodel_instance);
0744:
0745: Iterator<ElementExitModel> exit_it = elementmodel_instance
0746: .getExits().iterator();
0747: assertTrue(exit_it.hasNext());
0748: ElementExitModel exit = exit_it.next();
0749: assertEquals(exit_it.hasNext(), false);
0750: assertSame(exit, exitmodel_instance);
0751: }
0752:
0753: public void testAddTheSameExitTwice() {
0754: ElementModel elementmodel_instance = null;
0755: ElementExitModel exitmodel_instance = null;
0756:
0757: try {
0758: elementmodel_instance = new ElementModel("elementmodel1");
0759: } catch (GuiModelException e) {
0760: assertTrue(e.getMessage(), false);
0761: }
0762: assertTrue(elementmodel_instance.addParticleListener(this ));
0763: assertNull(mPropertyAdded);
0764:
0765: try {
0766: exitmodel_instance = elementmodel_instance
0767: .addExit("exitmodel1");
0768: } catch (GuiModelException e) {
0769: assertTrue(e.getMessage(), false);
0770: }
0771: assertSame(mPropertyAdded, exitmodel_instance);
0772:
0773: mPropertyAdded = null;
0774: try {
0775: elementmodel_instance.addExit("exitmodel1");
0776: fail();
0777: } catch (GuiModelException e) {
0778: assertTrue(true);
0779: }
0780: assertNull(mPropertyAdded);
0781: Iterator<ElementExitModel> exit_it = elementmodel_instance
0782: .getExits().iterator();
0783: assertTrue(exit_it.hasNext());
0784: Object exit = exit_it.next();
0785: assertEquals(exit_it.hasNext(), false);
0786: assertSame(exit, exitmodel_instance);
0787: }
0788:
0789: public void testAddTwoExits() {
0790: ElementModel elementmodel_instance = null;
0791: ElementExitModel exitmodel_instance1 = null;
0792: ElementExitModel exitmodel_instance2 = null;
0793:
0794: try {
0795: elementmodel_instance = new ElementModel("elementmodel1");
0796: } catch (GuiModelException e) {
0797: assertTrue(e.getMessage(), false);
0798: }
0799: assertTrue(elementmodel_instance.addParticleListener(this ));
0800: assertNull(mPropertyAdded);
0801:
0802: try {
0803: exitmodel_instance1 = elementmodel_instance
0804: .addExit("exitmodel1");
0805: assertSame(mPropertyAdded, exitmodel_instance1);
0806: exitmodel_instance2 = elementmodel_instance
0807: .addExit("exitmodel2");
0808: assertSame(mPropertyAdded, exitmodel_instance2);
0809: } catch (GuiModelException e) {
0810: assertTrue(e.getMessage(), false);
0811: }
0812:
0813: Iterator<ElementExitModel> exit_it = elementmodel_instance
0814: .getExits().iterator();
0815: assertTrue(exit_it.hasNext());
0816: ElementExitModel exit1 = exit_it.next();
0817: assertTrue(exit_it.hasNext());
0818: ElementExitModel exit2 = exit_it.next();
0819: assertTrue(exit_it.hasNext() == false);
0820: assertTrue((exit1 == exitmodel_instance1 && exit2 == exitmodel_instance2)
0821: || (exit2 == exitmodel_instance1 && exit1 == exitmodel_instance2));
0822: }
0823:
0824: public void testCountExits() {
0825: ElementModel elementmodel_instance = null;
0826: ElementExitModel exitmodel_instance1 = null;
0827: ElementExitModel exitmodel_instance2 = null;
0828: ElementOutputModel outputmodel_instance = null;
0829:
0830: try {
0831: elementmodel_instance = new ElementModel("elementmodel1");
0832: } catch (GuiModelException e) {
0833: assertTrue(e.getMessage(), false);
0834: }
0835: assertTrue(elementmodel_instance.addParticleListener(this ));
0836: assertNull(mPropertyAdded);
0837:
0838: try {
0839: outputmodel_instance = elementmodel_instance
0840: .addOutput("outputmodel1");
0841: assertSame(mPropertyAdded, outputmodel_instance);
0842: exitmodel_instance1 = elementmodel_instance
0843: .addExit("exitmodel1");
0844: assertSame(mPropertyAdded, exitmodel_instance1);
0845: exitmodel_instance2 = elementmodel_instance
0846: .addExit("exitmodel2");
0847: assertSame(mPropertyAdded, exitmodel_instance2);
0848: } catch (GuiModelException e) {
0849: assertTrue(e.getMessage(), false);
0850: }
0851:
0852: assertEquals(elementmodel_instance.countExits(), 2);
0853: assertEquals(elementmodel_instance
0854: .countProperties(ElementExitModel.class), 2);
0855: assertEquals(elementmodel_instance
0856: .countProperties(ElementVariableModel.class), 1);
0857: assertEquals(elementmodel_instance
0858: .countProperties(ElementPropertyModel.class), 4);
0859: }
0860:
0861: public void testExitConflicts() {
0862: ElementModel elementmodel_instance = null;
0863:
0864: try {
0865: elementmodel_instance = new ElementModel("elementmodel1");
0866:
0867: elementmodel_instance.setImplementation("classname");
0868: elementmodel_instance.addInput("inputmodel1");
0869: elementmodel_instance.addOutput("outputmodel1");
0870: elementmodel_instance.addExit("exitmodel1");
0871: } catch (GuiModelException e) {
0872: assertTrue(e.getMessage(), false);
0873: }
0874:
0875: try {
0876: elementmodel_instance.addExit("exitmodel1");
0877: fail();
0878: } catch (GuiModelException e) {
0879: assertTrue(true);
0880: }
0881: try {
0882: elementmodel_instance.addExit("elementmodel1");
0883: elementmodel_instance.addExit("classname");
0884: elementmodel_instance.addExit("inputmodel1");
0885: elementmodel_instance.addExit("outputmodel1");
0886: } catch (GuiModelException e) {
0887: assertTrue(e.getMessage(), false);
0888: }
0889: }
0890:
0891: public void testRenameExitConflict() {
0892: ElementModel elementmodel_instance = null;
0893: ElementExitModel exitmodel_instance1 = null;
0894:
0895: try {
0896: elementmodel_instance = new ElementModel("elementmodel1");
0897: exitmodel_instance1 = elementmodel_instance
0898: .addExit("exitmodel1");
0899: elementmodel_instance.addExit("exitmodel2");
0900: } catch (GuiModelException e) {
0901: assertTrue(e.getMessage(), false);
0902: }
0903: assertTrue(elementmodel_instance.addParticleListener(this ));
0904: assertNull(mPropertyRenamed);
0905:
0906: try {
0907: assertTrue(elementmodel_instance.renameProperty(
0908: exitmodel_instance1, "exitmodel2"));
0909: fail();
0910: } catch (GuiModelException e) {
0911: assertTrue(true);
0912: }
0913: assertNull(mPropertyRenamed);
0914: }
0915:
0916: public void testInitialSubmissionCountIsZero() {
0917: ElementModel elementmodel_instance = null;
0918:
0919: try {
0920: elementmodel_instance = new ElementModel("elementmodel1");
0921: } catch (GuiModelException e) {
0922: assertTrue(e.getMessage(), false);
0923: }
0924:
0925: assertEquals(elementmodel_instance.countSubmissions(), 0);
0926: }
0927:
0928: public void testAddOneSubmission() {
0929: ElementModel elementmodel_instance = null;
0930: SubmissionModel submissionmodel_instance = null;
0931:
0932: try {
0933: elementmodel_instance = new ElementModel("elementmodel1");
0934: } catch (GuiModelException e) {
0935: assertTrue(e.getMessage(), false);
0936: }
0937:
0938: assertTrue(elementmodel_instance.addParticleListener(this ));
0939: assertNull(mChildAdded);
0940:
0941: try {
0942: submissionmodel_instance = elementmodel_instance
0943: .addSubmission("submissionmodel1");
0944: } catch (GuiModelException e) {
0945: assertTrue(e.getMessage(), false);
0946: }
0947: assertSame(mChildAdded, submissionmodel_instance);
0948:
0949: Iterator<SubmissionModel> submission_it = elementmodel_instance
0950: .getSubmissions().iterator();
0951: assertTrue(submission_it.hasNext());
0952: Object submission = submission_it.next();
0953: assertEquals(submission_it.hasNext(), false);
0954: assertSame(submission, submissionmodel_instance);
0955: }
0956:
0957: public void testAddAnotherEqualSubmission() {
0958: ElementModel elementmodel_instance = null;
0959: SubmissionModel submissionmodel_instance1 = null;
0960:
0961: try {
0962: elementmodel_instance = new ElementModel("elementmodel1");
0963: } catch (GuiModelException e) {
0964: assertTrue(e.getMessage(), false);
0965: }
0966: assertTrue(elementmodel_instance.addParticleListener(this ));
0967: assertNull(mChildAdded);
0968:
0969: try {
0970: submissionmodel_instance1 = elementmodel_instance
0971: .addSubmission("submissionmodel1");
0972: } catch (GuiModelException e) {
0973: assertTrue(e.getMessage(), false);
0974: }
0975: assertSame(mChildAdded, submissionmodel_instance1);
0976:
0977: try {
0978: elementmodel_instance.addSubmission("submissionmodel1");
0979: fail();
0980: } catch (GuiModelException e) {
0981: assertTrue(true);
0982: assertSame(mChildAdded, submissionmodel_instance1);
0983: }
0984:
0985: Iterator<SubmissionModel> submission_it = elementmodel_instance
0986: .getSubmissions().iterator();
0987: assertTrue(submission_it.hasNext());
0988: Object submission = submission_it.next();
0989: assertEquals(submission_it.hasNext(), false);
0990: assertSame(submission, submissionmodel_instance1);
0991: }
0992:
0993: public void testAddTwoSubmissions() {
0994: ElementModel elementmodel_instance = null;
0995: SubmissionModel submissionmodel_instance1 = null;
0996: SubmissionModel submissionmodel_instance2 = null;
0997:
0998: try {
0999: elementmodel_instance = new ElementModel("elementmodel1");
1000: } catch (GuiModelException e) {
1001: assertTrue(e.getMessage(), false);
1002: }
1003: assertTrue(elementmodel_instance.addParticleListener(this ));
1004: assertNull(mChildAdded);
1005:
1006: try {
1007: submissionmodel_instance1 = elementmodel_instance
1008: .addSubmission("submissionmodel1");
1009: assertSame(mChildAdded, submissionmodel_instance1);
1010: submissionmodel_instance2 = elementmodel_instance
1011: .addSubmission("submissionmodel2");
1012: assertSame(mChildAdded, submissionmodel_instance2);
1013: } catch (GuiModelException e) {
1014: assertTrue(e.getMessage(), false);
1015: }
1016: Iterator<SubmissionModel> submission_it = elementmodel_instance
1017: .getSubmissions().iterator();
1018: assertTrue(submission_it.hasNext());
1019: Object submission1 = submission_it.next();
1020: assertTrue(submission_it.hasNext());
1021: Object submission2 = submission_it.next();
1022: assertEquals(submission_it.hasNext(), false);
1023: assertTrue((submission1 == submissionmodel_instance1 && submission2 == submissionmodel_instance2)
1024: || (submission2 == submissionmodel_instance1 && submission1 == submissionmodel_instance2));
1025: }
1026:
1027: public void testCountSubmissions() {
1028: ElementModel elementmodel_instance = null;
1029:
1030: try {
1031: elementmodel_instance = new ElementModel("elementmodel1");
1032: } catch (GuiModelException e) {
1033: assertTrue(e.getMessage(), false);
1034: }
1035:
1036: try {
1037: elementmodel_instance.addSubmission("submissionmodel1");
1038: elementmodel_instance.addSubmission("submissionmodel2");
1039: } catch (GuiModelException e) {
1040: assertTrue(e.getMessage(), false);
1041: }
1042: assertEquals(elementmodel_instance.countSubmissions(), 2);
1043: }
1044:
1045: public void parentChanged() {
1046: }
1047:
1048: public void childAdded(ParticleModel child) {
1049: mChildAdded = child;
1050: }
1051:
1052: public void childRemoved(ParticleModel child) {
1053: }
1054:
1055: public void propertyAdded(ParticlePropertyModel property) {
1056: mPropertyAdded = property;
1057: }
1058:
1059: public void propertyRemoved(ParticlePropertyModel property) {
1060: mPropertyRemoved = property;
1061: }
1062:
1063: public void propertyRenamed(ParticlePropertyModel property) {
1064: mPropertyRenamed = property;
1065: }
1066: }
|