Search in sources :

Example 1 with Relation

use of org.eclipse.sirius.components.domain.Relation 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 Relation

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

the class DomainValidatorTests method testRelationEmptyName.

@Test
public void testRelationEmptyName() {
    Relation relation = DomainFactory.eINSTANCE.createRelation();
    // $NON-NLS-1$
    relation.setName("");
    this.assertNameIsInvalid(relation);
}
Also used : Relation(org.eclipse.sirius.components.domain.Relation) Test(org.junit.jupiter.api.Test)

Example 3 with Relation

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

the class DomainValidatorTests method testRelationNameWithUnderscore.

@Test
public void testRelationNameWithUnderscore() {
    Relation relation = DomainFactory.eINSTANCE.createRelation();
    // $NON-NLS-1$
    relation.setName("some_relation");
    this.assertNameIsValid(relation);
}
Also used : Relation(org.eclipse.sirius.components.domain.Relation) Test(org.junit.jupiter.api.Test)

Example 4 with Relation

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

the class DomainValidatorTests method testRelationNameWithInvalidCharacters.

@Test
public void testRelationNameWithInvalidCharacters() {
    Relation relation = DomainFactory.eINSTANCE.createRelation();
    // $NON-NLS-1$
    relation.setName("some-relation");
    this.assertNameIsInvalid(relation);
}
Also used : Relation(org.eclipse.sirius.components.domain.Relation) Test(org.junit.jupiter.api.Test)

Example 5 with Relation

use of org.eclipse.sirius.components.domain.Relation 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)

Aggregations

Relation (org.eclipse.sirius.components.domain.Relation)9 Test (org.junit.jupiter.api.Test)7 Entity (org.eclipse.sirius.components.domain.Entity)5 Attribute (org.eclipse.sirius.components.domain.Attribute)3 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)2 EClass (org.eclipse.emf.ecore.EClass)2 EPackage (org.eclipse.emf.ecore.EPackage)2 DomainValidator (org.eclipse.sirius.components.emf.domain.DomainValidator)2 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 InstanceOfAssertFactories (org.assertj.core.api.InstanceOfAssertFactories)1 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 EList (org.eclipse.emf.common.util.EList)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 EReference (org.eclipse.emf.ecore.EReference)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