Search in sources :

Example 1 with Attribute

use of org.eclipse.sirius.components.domain.Attribute in project sirius-components by eclipse-sirius.

the class DomainConverterTests method testConvertSystemDomainDefinition.

@Test
void testConvertSystemDomainDefinition() {
    Domain componentDomain = DomainFactory.eINSTANCE.createDomain();
    // $NON-NLS-1$
    componentDomain.setName("component");
    Entity namedEntity = DomainFactory.eINSTANCE.createEntity();
    // $NON-NLS-1$
    namedEntity.setName("Named");
    namedEntity.setAbstract(true);
    Attribute nameAttribute = DomainFactory.eINSTANCE.createAttribute();
    // $NON-NLS-1$
    nameAttribute.setName("name");
    nameAttribute.setMany(false);
    nameAttribute.setOptional(false);
    nameAttribute.setType(DataType.STRING);
    namedEntity.getAttributes().add(nameAttribute);
    componentDomain.getTypes().add(namedEntity);
    Entity systemEntity = DomainFactory.eINSTANCE.createEntity();
    // $NON-NLS-1$
    systemEntity.setName("System");
    systemEntity.getSuperTypes().add(namedEntity);
    componentDomain.getTypes().add(systemEntity);
    Entity componentEntity = DomainFactory.eINSTANCE.createEntity();
    // $NON-NLS-1$
    componentEntity.setName("Component");
    componentEntity.getSuperTypes().add(namedEntity);
    componentDomain.getTypes().add(componentEntity);
    Relation systemComponentsRelation = DomainFactory.eINSTANCE.createRelation();
    // $NON-NLS-1$
    systemComponentsRelation.setName("parts");
    systemComponentsRelation.setContainment(true);
    systemComponentsRelation.setMany(true);
    systemComponentsRelation.setOptional(true);
    systemComponentsRelation.setTargetType(componentEntity);
    systemEntity.getRelations().add(systemComponentsRelation);
    Optional<EPackage> converted = this.convert(componentDomain);
    assertThat(converted).isPresent();
    EPackage convertedPackage = converted.get();
    assertThat(convertedPackage.getEClassifiers()).hasSize(3);
    // @formatter:off
    assertThat(convertedPackage.getEClassifier(namedEntity.getName())).asInstanceOf(InstanceOfAssertFactories.type(EClass.class)).matches(EClass::isAbstract).matches(eClass -> eClass.getEAllAttributes().size() == 1).matches(eClass -> eClass.getEAllReferences().isEmpty());
    assertThat(convertedPackage.getEClassifier(systemEntity.getName())).asInstanceOf(InstanceOfAssertFactories.type(EClass.class)).matches(eClass -> !eClass.isAbstract()).matches(eClass -> eClass.getESuperTypes().size() == 1).matches(eClass -> eClass.getEAttributes().isEmpty()).matches(eClass -> eClass.getEAllAttributes().size() == 1);
    assertThat(convertedPackage.getEClassifier(componentEntity.getName())).asInstanceOf(InstanceOfAssertFactories.type(EClass.class)).matches(eClass -> !eClass.isAbstract()).matches(eClass -> eClass.getESuperTypes().size() == 1).matches(eClass -> eClass.getEAttributes().isEmpty()).matches(eClass -> eClass.getEAllAttributes().size() == 1);
// @formatter:on
}
Also used : ValueSource(org.junit.jupiter.params.provider.ValueSource) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EClassifier(org.eclipse.emf.ecore.EClassifier) EList(org.eclipse.emf.common.util.EList) Entity(org.eclipse.sirius.components.domain.Entity) EPackage(org.eclipse.emf.ecore.EPackage) Relation(org.eclipse.sirius.components.domain.Relation) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EClass(org.eclipse.emf.ecore.EClass) DataType(org.eclipse.sirius.components.domain.DataType) Domain(org.eclipse.sirius.components.domain.Domain) DomainFactory(org.eclipse.sirius.components.domain.DomainFactory) Optional(java.util.Optional) Attribute(org.eclipse.sirius.components.domain.Attribute) Entity(org.eclipse.sirius.components.domain.Entity) Relation(org.eclipse.sirius.components.domain.Relation) EClass(org.eclipse.emf.ecore.EClass) Attribute(org.eclipse.sirius.components.domain.Attribute) Domain(org.eclipse.sirius.components.domain.Domain) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Attribute

use of org.eclipse.sirius.components.domain.Attribute in project sirius-components by eclipse-sirius.

the class DomainValidatorTests method testAttributeNameUniqueAmongEntityAttributes.

@Test
public void testAttributeNameUniqueAmongEntityAttributes() {
    Entity entity = DomainFactory.eINSTANCE.createEntity();
    entity.setName(PERSON);
    // $NON-NLS-1$
    String sharedName = "name";
    Attribute name1 = DomainFactory.eINSTANCE.createAttribute();
    name1.setName(sharedName);
    entity.getAttributes().add(name1);
    Attribute name2 = DomainFactory.eINSTANCE.createAttribute();
    name2.setName(sharedName);
    entity.getAttributes().add(name2);
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    boolean validationResult = new DomainValidator().validate(name1.eClass(), name1, diagnosticChain, defaultContext);
    assertThat(validationResult).isFalse();
    // @formatter:off
    BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.ERROR, DomainValidator.SIRIUS_COMPONENTS_EMF_PACKAGE, 0, DomainValidator.FEATURE_DISTINCT_NAME_ERROR_MESSAGE, new Object[] { name1, DomainPackage.Literals.NAMED_ELEMENT__NAME });
    // @formatter:on
    assertThat(diagnosticChain).contains(expected);
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) Attribute(org.eclipse.sirius.components.domain.Attribute) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) DomainValidator(org.eclipse.sirius.components.emf.domain.DomainValidator) Test(org.junit.jupiter.api.Test)

Example 3 with Attribute

use of org.eclipse.sirius.components.domain.Attribute in project sirius-components by eclipse-sirius.

the class DomainValidatorTests method testRelationNameUniqueAmongEntityFeatures.

@Test
public void testRelationNameUniqueAmongEntityFeatures() {
    Entity entity = DomainFactory.eINSTANCE.createEntity();
    entity.setName(PERSON);
    // $NON-NLS-1$
    String sharedName = "reference";
    Relation rel = DomainFactory.eINSTANCE.createRelation();
    rel.setName(sharedName);
    entity.getRelations().add(rel);
    Attribute attr = DomainFactory.eINSTANCE.createAttribute();
    attr.setName(sharedName);
    entity.getAttributes().add(attr);
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    boolean validationResult = new DomainValidator().validate(rel.eClass(), rel, diagnosticChain, defaultContext);
    assertThat(validationResult).isFalse();
    // @formatter:off
    BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.ERROR, DomainValidator.SIRIUS_COMPONENTS_EMF_PACKAGE, 0, DomainValidator.FEATURE_DISTINCT_NAME_ERROR_MESSAGE, new Object[] { rel, DomainPackage.Literals.NAMED_ELEMENT__NAME });
    // @formatter:on
    assertThat(diagnosticChain).contains(expected);
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) Relation(org.eclipse.sirius.components.domain.Relation) Attribute(org.eclipse.sirius.components.domain.Attribute) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) DomainValidator(org.eclipse.sirius.components.emf.domain.DomainValidator) Test(org.junit.jupiter.api.Test)

Example 4 with Attribute

use of org.eclipse.sirius.components.domain.Attribute in project sirius-components by eclipse-sirius.

the class EntityItemProvider method collectNewChildDescriptors.

/**
 * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children that can be created
 * under this object. <!-- begin-user-doc --> <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
    super.collectNewChildDescriptors(newChildDescriptors, object);
    Attribute newAttribute = DomainFactory.eINSTANCE.createAttribute();
    // $NON-NLS-1$
    newAttribute.setName("newString");
    newAttribute.setType(DataType.STRING);
    newChildDescriptors.add(this.createChildParameter(DomainPackage.Literals.ENTITY__ATTRIBUTES, newAttribute));
    Relation newRelation = DomainFactory.eINSTANCE.createRelation();
    // $NON-NLS-1$
    newRelation.setName("relation");
    newRelation.setMany(true);
    if (object instanceof Entity) {
        Entity owner = (Entity) object;
        newRelation.setTargetType(owner);
    }
    newChildDescriptors.add(this.createChildParameter(DomainPackage.Literals.ENTITY__RELATIONS, newRelation));
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) Relation(org.eclipse.sirius.components.domain.Relation) Attribute(org.eclipse.sirius.components.domain.Attribute)

Example 5 with Attribute

use of org.eclipse.sirius.components.domain.Attribute in project sirius-components by eclipse-sirius.

the class DomainValidatorTests method testAttributeNameWithInvalidCharacters.

@Test
public void testAttributeNameWithInvalidCharacters() {
    Attribute attribute = DomainFactory.eINSTANCE.createAttribute();
    // $NON-NLS-1$
    attribute.setName("an-attribute");
    this.assertNameIsInvalid(attribute);
}
Also used : Attribute(org.eclipse.sirius.components.domain.Attribute) Test(org.junit.jupiter.api.Test)

Aggregations

Attribute (org.eclipse.sirius.components.domain.Attribute)9 Test (org.junit.jupiter.api.Test)7 Entity (org.eclipse.sirius.components.domain.Entity)4 Relation (org.eclipse.sirius.components.domain.Relation)3 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)2 DomainValidator (org.eclipse.sirius.components.emf.domain.DomainValidator)2 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 InstanceOfAssertFactories (org.assertj.core.api.InstanceOfAssertFactories)1 EList (org.eclipse.emf.common.util.EList)1 EClass (org.eclipse.emf.ecore.EClass)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 EPackage (org.eclipse.emf.ecore.EPackage)1 DataType (org.eclipse.sirius.components.domain.DataType)1 Domain (org.eclipse.sirius.components.domain.Domain)1 DomainFactory (org.eclipse.sirius.components.domain.DomainFactory)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1