Java Code Examples for org.eclipse.uml2.uml.Class#getOwnedAttribute()

The following examples show how to use org.eclipse.uml2.uml.Class#getOwnedAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AssociationTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testAssociationShorthand() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "class A\n";
    source += "end;\n";
    source += "class C\n";
    source += "end;\n";
    source += "class B\n";
    source += "  reference a : A;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class classA = (Class) getRepository().findNamedElement("simple::A", IRepository.PACKAGE.getClass_(), null);
    Class classB = (Class) getRepository().findNamedElement("simple::B", IRepository.PACKAGE.getClass_(), null);

    Property propertyA = classB.getOwnedAttribute("a", null);
    assertNotNull(propertyA);

    Association association = propertyA.getAssociation();
    assertNotNull(association);

    assertTrue(association.getMemberEnds().contains(propertyA));
    assertFalse(association.getOwnedEnds().contains(propertyA));
    assertEquals(AggregationKind.NONE_LITERAL, propertyA.getAggregation());
    assertSame(classA, propertyA.getType());

    Property otherEnd = propertyA.getOtherEnd();
    assertTrue(association.getMemberEnds().contains(otherEnd));
    assertTrue(association.getOwnedEnds().contains(otherEnd));
    assertEquals(AggregationKind.NONE_LITERAL, otherEnd.getAggregation());
    assertSame(classB, otherEnd.getType());
}
 
Example 2
Source File: AssociationTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testAggregationShorthand() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "class A\n";
    source += "end;\n";
    source += "class C\n";
    source += "end;\n";
    source += "class B\n";
    source += "  aggregation a : A;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class classA = (Class) getRepository().findNamedElement("simple::A", IRepository.PACKAGE.getClass_(), null);
    Class classB = (Class) getRepository().findNamedElement("simple::B", IRepository.PACKAGE.getClass_(), null);

    Property propertyA = classB.getOwnedAttribute("a", null);
    assertNotNull(propertyA);

    Association association = propertyA.getAssociation();
    assertNotNull(association);

    assertTrue(association.getMemberEnds().contains(propertyA));
    assertFalse(association.getOwnedEnds().contains(propertyA));
    assertEquals(AggregationKind.SHARED_LITERAL, propertyA.getAggregation());
    assertSame(classA, propertyA.getType());

    Property otherEnd = propertyA.getOtherEnd();
    assertTrue(association.getMemberEnds().contains(otherEnd));
    assertTrue(association.getOwnedEnds().contains(otherEnd));
    assertEquals(AggregationKind.NONE_LITERAL, otherEnd.getAggregation());
    assertSame(classB, otherEnd.getType());
}
 
Example 3
Source File: AssociationTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testCompositionShorthand() throws CoreException {
    String source = "";
    source += "model simple;\n";
    source += "class A\n";
    source += "end;\n";
    source += "class C\n";
    source += "end;\n";
    source += "class B\n";
    source += "  composition a : A;\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class classA = (Class) getRepository().findNamedElement("simple::A", IRepository.PACKAGE.getClass_(), null);
    Class classB = (Class) getRepository().findNamedElement("simple::B", IRepository.PACKAGE.getClass_(), null);

    Property propertyA = classB.getOwnedAttribute("a", null);
    assertNotNull(propertyA);

    Association association = propertyA.getAssociation();
    assertNotNull(association);

    assertTrue(association.getMemberEnds().contains(propertyA));
    assertFalse(association.getOwnedEnds().contains(propertyA));
    assertEquals(AggregationKind.COMPOSITE_LITERAL, propertyA.getAggregation());
    assertSame(classA, propertyA.getType());

    Property otherEnd = propertyA.getOtherEnd();
    assertTrue(association.getMemberEnds().contains(otherEnd));
    assertTrue(association.getOwnedEnds().contains(otherEnd));
    assertEquals(AggregationKind.NONE_LITERAL, otherEnd.getAggregation());
    assertSame(classB, otherEnd.getType());
}
 
Example 4
Source File: ClassifierTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void testAttributeWithInvariants() throws CoreException {
    String source = "";
    source += "model someModel;\n";
    source += "import base;\n";
    source += "class SomeClass\n";
    source += "attribute attr1: Boolean\n";
    source += "invariant condition1 { true }\n";
    source += "invariant { true }\n";
    source += "invariant condition3 { not self.attr1 };\n";
    source += "end;\n";
    source += "end.";
    parseAndCheck(source);
    Class class_ = (Class) getRepository().findNamedElement("someModel::SomeClass",
            IRepository.PACKAGE.getClass_(), null);
    assertNotNull(class_);
    Property property = class_.getOwnedAttribute("attr1", null);
    assertNotNull(property);
    assertEquals(3, class_.getOwnedRules().size());

    assertEquals("condition1", class_.getOwnedRules().get(0).getName());
    assertNull(class_.getOwnedRules().get(1).getName());
    assertEquals("condition3", class_.getOwnedRules().get(2).getName());

    assertNotNull(class_.getOwnedRules().get(0).getSpecification());

    for (Constraint constraint : class_.getOwnedRules()) {
        // expect only the return parameter
        checkConstraint(constraint, 1);
        assertEquals(Arrays.asList(property), constraint.getConstrainedElements());
    }
}