public void testOperationCallExp() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Film"), null); VariableExp source = factory1.createVariableExp(variable); List <object> paramTypes = new List <object> (); paramTypes.Add(getClassifier("Integer")); CoreOperation operation = getClassifier("Film").lookupOperation("getRentalFee", paramTypes); List <object> arguments = new List <object> (); arguments.Add(factory1.createIntegerLiteralExp(100, getClassifier("Integer"))); OperationCallExp exp = factory1.createOperationCallExp(source, operation, arguments, operation.getReturnType(), false); Assert.AreEqual("abc.getRentalFee(100)", exp.ToString()); Assert.AreEqual("Real", exp.getType().getName()); CollectionLiteralExp literalCollection = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createSetType( getClassifier("Integer"))); CollectionTypeImpl type1 = (CollectionTypeImpl)factory1.createSetType(getClassifier("Integer")); CoreOperation collectionOper = type1.lookupOperation("size", new List <object>()); OperationCallExp exp1 = factory1.createOperationCallExp(literalCollection, collectionOper, new List <object>(), getClassifier("Integer"), false); Assert.IsNotNull(exp1); }
public void testCollectionLiteralExp() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); CollectionLiteralExp exp = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createSetType( getClassifier("Integer"))); Assert.AreEqual("Set{ 100, 200, 300 }", exp.ToString()); Assert.AreEqual("Set(Integer)", exp.getType().getName()); CollectionLiteralExp exp2 = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createSetType( getClassifier("Integer"))); Assert.AreEqual("Set{ 100, 200, 300 }", exp2.ToString()); Assert.AreEqual("Set(Integer)", exp2.getType().getName()); exp = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createBagType(getClassifier("Integer"))); Assert.AreEqual("Bag{ 100, 200, 300 }", exp.ToString()); Assert.AreEqual("Bag(Integer)", exp.getType().getName()); exp = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createSequenceType(getClassifier("Integer"))); Assert.AreEqual("Sequence{ 100, 200, 300 }", exp.ToString()); Assert.AreEqual("Sequence(Integer)", exp.getType().getName()); exp = factory1.createCollectionLiteralExp(createCollectionParts(), factory1.createOrderedSetType(getClassifier("Integer"))); Assert.AreEqual("OrderedSet{ 100, 200, 300 }", exp.ToString()); Assert.AreEqual("OrderedSet(Integer)", exp.getType().getName()); OclExpression elem1 = factory1.createIntegerLiteralExp(100, getClassifier("Integer")); OclExpression elem2 = factory1.createIntegerLiteralExp(200, getClassifier("Integer")); CollectionRange range = factory1.createCollectionRange(elem1, elem2); List <object> parts = new List <object> (); parts.Add(range); exp = factory1.createCollectionLiteralExp(parts, factory1.createSetType(getClassifier("Integer"))); Assert.AreEqual("Set{ 100 .. 200 }", exp.ToString()); Assert.AreEqual("Set(Integer)", exp.getType().getName()); }
public void testLookupOperation() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); CollectionTypeImpl type1 = (CollectionTypeImpl)factory1.createSetType(getClassifier("Integer")); Assert.IsNotNull(type1.lookupOperation("size", new List <object>())); CoreClassifier intType = getClassifier("Integer"); List <object> paramTypes = new List <object>(); paramTypes.Add(getClassifier("Integer")); Assert.IsNotNull(intType.lookupOperation("+", paramTypes)); Assert.IsNull(intType.lookupOperation("*", new List <object>())); }
public void testCollectionType_01() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); CollectionTypeImpl type1 = (CollectionTypeImpl)factory1.createSetType(getClassifier("Integer")); CollectionTypeImpl type2 = (CollectionTypeImpl)factory1.createSetType(getClassifier("Real")); CollectionTypeImpl type3 = (CollectionTypeImpl)factory1.createSetType(factory1.createSetType(getClassifier("Real"))); CollectionTypeImpl type4 = (CollectionTypeImpl)factory1.createBagType(getClassifier("Integer")); CollectionTypeImpl type5 = (CollectionTypeImpl)factory1.createBagType(getClassifier("Real")); CollectionTypeImpl type6 = (CollectionTypeImpl)factory1.createBagType(getClassifier("Boolean")); CollectionTypeImpl type7 = (CollectionTypeImpl)factory1.createOrderedSetType(getClassifier("Integer")); CollectionTypeImpl type8 = (CollectionTypeImpl)factory1.createSetType(getClassifier("Film")); CollectionTypeImpl type9 = (CollectionTypeImpl)factory1.createSetType(getClassifier("SpecialFilm")); CollectionTypeImpl type10 = (CollectionTypeImpl)factory1.createCollectionType(getClassifier("OclAny")); Assert.AreEqual("Integer", type1.getInnerMostElementType().getName()); Assert.AreEqual("Real", type3.getInnerMostElementType().getName()); Assert.AreEqual("Set(Real)", type1.getMostSpecificCommonSuperType(type2).getName()); Assert.AreEqual("Collection(Integer)", type1.getMostSpecificCommonSuperType(type4).getName()); Assert.AreEqual("Set(OclAny)", type1.getMostSpecificCommonSuperType(type3).getName()); Assert.AreEqual("OclAny", type1.getMostSpecificCommonSuperType(getClassifier("Integer")).getName()); Assert.AreEqual("Collection(Real)", type1.getMostSpecificCommonSuperType(type5).getName()); Assert.AreEqual("Collection(OclAny)", type1.getMostSpecificCommonSuperType(type6).getName()); Assert.IsTrue(getClassifier("Integer").conformsTo(getClassifier("Real"))); Assert.IsTrue(getClassifier("Integer").conformsTo(getClassifier("OclAny"))); Assert.IsTrue(type1.conformsTo(type2)); Assert.IsFalse(type2.conformsTo(type1)); Assert.IsFalse(type1.conformsTo(type3)); Assert.IsFalse(type1.conformsTo(type4)); Assert.IsTrue(type1.conformsTo(type1.getMostSpecificCommonSuperType(type2))); Assert.IsTrue(type1.conformsTo(type1.getMostSpecificCommonSuperType(type5))); Assert.IsTrue(type1.conformsTo(type1.getMostSpecificCommonSuperType(type6))); Assert.IsFalse(type1.conformsTo(getClassifier("Integer"))); Assert.IsTrue(type1.conformsTo(getClassifier("OclAny"))); type1.setInnerMostElementType(getClassifier("Real")); Assert.AreEqual("Real", type1.getInnerMostElementType().getName()); Assert.AreEqual("Set(Real)", type1.getName()); Assert.IsTrue(type7.conformsTo(type1)); Assert.IsFalse(type1.conformsTo(type7)); Assert.IsTrue(type7.conformsTo(type7.createGenericCollectionType(type7.getInnerMostElementType()))); Assert.IsTrue(type9.conformsTo(type8)); Assert.IsTrue(type9.conformsTo(type10)); Assert.IsFalse(type8.conformsTo(type9)); }
public void testIteratorExp() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Distributor"), null); VariableExp source = factory1.createVariableExp(variable); VariableDeclaration iter = factory1.createVariableDeclaration("iter", getClassifier("SpecialFilm"), null); VariableExp iterRef = factory1.createVariableExp(iter); CoreAttribute attr = getClassifier("SpecialFilm").lookupAttribute("name"); AttributeCallExp body = factory1.createAttributeCallExp(iterRef, attr, false); CoreClassifier setSpecialFilm = factory1.createSetType(getClassifier("SpecialFilm")); List <object> iterators = new List <object> (); iterators.Add(iter); IteratorExp exp = factory1.createIteratorExp("select", setSpecialFilm, source, body, iterators); Assert.AreEqual("abc->select(iter : SpecialFilm | iter.name)", exp.ToString()); Assert.AreEqual("Set(SpecialFilm)", exp.getType().getName()); }
public void testTupleType() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); factory1.resetTypes(); TupleTypeImpl type1 = (TupleTypeImpl)factory1.createTupleType(); type1.addElement("a", getClassifier(("Integer"))); type1.addElement("b", getClassifier(("Boolean"))); TupleTypeImpl type2 = (TupleTypeImpl)factory1.createTupleType(); type2.addElement("a", getClassifier(("Real"))); type2.addElement("b", getClassifier(("Boolean"))); TupleTypeImpl type3 = (TupleTypeImpl)factory1.createTupleType(); type3.addElement("a", getClassifier(("Integer"))); type3.addElement("b", getClassifier(("Integer"))); TupleTypeImpl type4 = (TupleTypeImpl)factory1.createTupleType(); type4.addElement("a", getClassifier(("Real"))); type4.addElement("c", getClassifier(("Boolean"))); TupleTypeImpl type5 = (TupleTypeImpl)factory1.createTupleType(); type5.addElement("a", getClassifier(("Integer"))); type5.addElement("b", getClassifier(("Boolean"))); type5.addElement("c", getClassifier(("Boolean"))); TupleTypeImpl type6 = (TupleTypeImpl)factory1.createTupleType(); type6.addElement("a", getClassifier(("Integer"))); TupleTypeImpl type7 = (TupleTypeImpl)factory1.createTupleType(); type7.addElement("a", getClassifier(("Integer"))); type7.addElement("b", type1); Assert.IsTrue(type1.conformsTo(type2)); Assert.IsFalse(type1.conformsTo(type3)); Assert.IsFalse(type1.conformsTo(type4)); Assert.IsFalse(type1.conformsTo(type5)); Assert.IsFalse(type1.conformsTo(type6)); Assert.IsNotNull(type1.lookupAttribute("a")); Assert.AreEqual("Integer", type1.lookupAttribute("a").getFeatureType().getName()); Assert.AreEqual("Tuple(a : Integer, b : Boolean)", type1.getName()); Assert.AreEqual("Tuple(a : Integer, b : Boolean, c : Boolean)", type5.getName()); foreach (TuplePartType part in type1.getTupleParts()) { } CollectionTypeImpl col = (CollectionTypeImpl)factory1.createSetType(type1); Assert.AreEqual("Set(Tuple(a : Integer, b : Boolean))", col.getName()); CollectionTypeImpl col2 = (CollectionTypeImpl)factory1.createSetType(type7); Assert.AreEqual("Set(Tuple(a : Integer, b : Tuple(a : Integer, b : Boolean)))", col2.getName()); }