Search in sources :

Example 1 with DomainValidator

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

the class DomainValidatorTests method testEntityNameUniqueInDomain.

@Test
public void testEntityNameUniqueInDomain() {
    Domain domain = DomainFactory.eINSTANCE.createDomain();
    domain.setName(FAMILY);
    Entity e1 = DomainFactory.eINSTANCE.createEntity();
    e1.setName(PERSON);
    domain.getTypes().add(e1);
    Entity e2 = DomainFactory.eINSTANCE.createEntity();
    e2.setName(PERSON);
    domain.getTypes().add(e2);
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    boolean validationResult = new DomainValidator().validate(e2.eClass(), e2, diagnosticChain, defaultContext);
    assertThat(validationResult).isFalse();
    // @formatter:off
    BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.ERROR, DomainValidator.SIRIUS_COMPONENTS_EMF_PACKAGE, 0, DomainValidator.ENTITY_DISTINCT_NAME_ERROR_MESSAGE, new Object[] { e2, DomainPackage.Literals.NAMED_ELEMENT__NAME });
    // @formatter:on
    assertThat(diagnosticChain).contains(expected);
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) DomainValidator(org.eclipse.sirius.components.emf.domain.DomainValidator) Domain(org.eclipse.sirius.components.domain.Domain) Test(org.junit.jupiter.api.Test)

Example 2 with DomainValidator

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

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

the class DomainValidatorTests method assertNameIsInvalid.

private void assertNameIsInvalid(NamedElement namedElement) {
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    boolean validationResult = new DomainValidator().validate(namedElement.eClass(), namedElement, diagnosticChain, defaultContext);
    assertThat(validationResult).isFalse();
    BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.WARNING, null, 0, null, null);
    // @formatter:off
    expected.add(new BasicDiagnostic(Diagnostic.WARNING, DomainValidator.SIRIUS_COMPONENTS_EMF_PACKAGE, 0, String.format(DomainValidator.INVALID_NAME_ERROR_MESSAGE, namedElement.getName()), new Object[] { namedElement, DomainPackage.Literals.NAMED_ELEMENT__NAME }));
    // @formatter:on
    assertThat(diagnosticChain).isEqualTo(expected);
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) DomainValidator(org.eclipse.sirius.components.emf.domain.DomainValidator)

Example 4 with DomainValidator

use of org.eclipse.sirius.components.emf.domain.DomainValidator 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 5 with DomainValidator

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

the class EMFConfiguration method getEValidatorRegistry.

@Bean
public EValidator.Registry getEValidatorRegistry() {
    Registry eValidatorRegistry = new EValidatorRegistryImpl(EValidator.Registry.INSTANCE);
    eValidatorRegistry.put(DomainPackage.eINSTANCE, new DomainValidator());
    eValidatorRegistry.put(ViewPackage.eINSTANCE, new DiagramDescriptionValidator());
    return eValidatorRegistry;
}
Also used : DomainValidator(org.eclipse.sirius.components.emf.domain.DomainValidator) Registry(org.eclipse.emf.ecore.EValidator.Registry) LabelFeatureProviderRegistry(org.eclipse.sirius.components.emf.services.LabelFeatureProviderRegistry) EValidatorRegistryImpl(org.eclipse.emf.ecore.impl.EValidatorRegistryImpl) DiagramDescriptionValidator(org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator) Bean(org.springframework.context.annotation.Bean)

Aggregations

DomainValidator (org.eclipse.sirius.components.emf.domain.DomainValidator)7 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)6 Entity (org.eclipse.sirius.components.domain.Entity)4 Test (org.junit.jupiter.api.Test)4 Attribute (org.eclipse.sirius.components.domain.Attribute)2 Relation (org.eclipse.sirius.components.domain.Relation)2 Registry (org.eclipse.emf.ecore.EValidator.Registry)1 EValidatorRegistryImpl (org.eclipse.emf.ecore.impl.EValidatorRegistryImpl)1 Domain (org.eclipse.sirius.components.domain.Domain)1 LabelFeatureProviderRegistry (org.eclipse.sirius.components.emf.services.LabelFeatureProviderRegistry)1 DiagramDescriptionValidator (org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator)1 Bean (org.springframework.context.annotation.Bean)1