Search in sources :

Example 1 with Domain

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

the class DomainConverterTests method testConvertDomainWithInvalidName.

@ParameterizedTest
@ValueSource(strings = { "", "42", "almost!valid", "foo-bar", "foo.bar", "foo/bar" })
public void testConvertDomainWithInvalidName(String name) {
    Domain fixture = DomainFactory.eINSTANCE.createDomain();
    fixture.setName(name);
    Optional<EPackage> converted = this.convert(fixture);
    assertThat(converted).isEmpty();
}
Also used : Domain(org.eclipse.sirius.components.domain.Domain) EPackage(org.eclipse.emf.ecore.EPackage) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Domain

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

the class DomainConverterTests method testConvertEntityWithValidName.

@ParameterizedTest
@ValueSource(strings = { "lowercase", "snake_case", "CamelCase", "Sample_Entity", "A1" })
public void testConvertEntityWithValidName(String name) {
    Domain fixture = DomainFactory.eINSTANCE.createDomain();
    fixture.setName(FIXTURE);
    Entity entity = DomainFactory.eINSTANCE.createEntity();
    entity.setName(name);
    fixture.getTypes().add(entity);
    Optional<EPackage> converted = this.convert(fixture);
    assertThat(converted).isPresent();
    EList<EClassifier> convertedTypes = converted.get().getEClassifiers();
    assertThat(convertedTypes).hasSize(1);
    assertThat(convertedTypes.get(0)).extracting(EClassifier::getName).isEqualTo(name);
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) EClassifier(org.eclipse.emf.ecore.EClassifier) Domain(org.eclipse.sirius.components.domain.Domain) EPackage(org.eclipse.emf.ecore.EPackage) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Domain

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

the class DomainConverterTests method testConvertEntityWithInvalidName.

@ParameterizedTest
@ValueSource(strings = { "", "42", "almost!valid", "foo-bar", "foo.bar", "foo/bar" })
public void testConvertEntityWithInvalidName(String name) {
    Domain fixture = DomainFactory.eINSTANCE.createDomain();
    fixture.setName(FIXTURE);
    Entity invalidEntity = DomainFactory.eINSTANCE.createEntity();
    invalidEntity.setName(name);
    fixture.getTypes().add(invalidEntity);
    Optional<EPackage> converted = this.convert(fixture);
    assertThat(converted).isEmpty();
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) Domain(org.eclipse.sirius.components.domain.Domain) EPackage(org.eclipse.emf.ecore.EPackage) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Domain

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

the class DomainConverterTests method testConvertEntityWithNullName.

@Test
public void testConvertEntityWithNullName() {
    Domain fixture = DomainFactory.eINSTANCE.createDomain();
    fixture.setName(FIXTURE);
    Entity invalidEntity = DomainFactory.eINSTANCE.createEntity();
    invalidEntity.setName(null);
    fixture.getTypes().add(invalidEntity);
    Optional<EPackage> converted = this.convert(fixture);
    assertThat(converted).isEmpty();
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) 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 5 with Domain

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

Aggregations

Domain (org.eclipse.sirius.components.domain.Domain)17 Test (org.junit.jupiter.api.Test)11 Entity (org.eclipse.sirius.components.domain.Entity)8 EPackage (org.eclipse.emf.ecore.EPackage)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)4 EClass (org.eclipse.emf.ecore.EClass)2 EClassifier (org.eclipse.emf.ecore.EClassifier)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)2 DiagramDescriptionValidator (org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator)2 NodeDescription (org.eclipse.sirius.components.view.NodeDescription)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 InstanceOfAssertFactories (org.assertj.core.api.InstanceOfAssertFactories)1