Search in sources :

Example 1 with DiagramDescriptionValidator

use of org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator in project sirius-components by eclipse-sirius.

the class ViewValidatorTests method testNodeStyleDescriptionValidQualifiedDomainInResourceSet.

@Test
public void testNodeStyleDescriptionValidQualifiedDomainInResourceSet() {
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    NodeDescription nodeDescription = ViewFactory.eINSTANCE.createNodeDescription();
    // $NON-NLS-1$
    nodeDescription.setDomainType(SAMPLE_DOMAIN_NAME + "::" + SAMPLE_ENTITY_NAME);
    ResourceSetImpl resourceSet = new ResourceSetImpl();
    XMIResourceImpl viewResource = new XMIResourceImpl();
    viewResource.getContents().add(nodeDescription);
    XMIResourceImpl domainResource = new XMIResourceImpl();
    Domain domain = DomainFactory.eINSTANCE.createDomain();
    domain.setName(SAMPLE_DOMAIN_NAME);
    domainResource.getContents().add(domain);
    Entity entity = DomainFactory.eINSTANCE.createEntity();
    entity.setName(SAMPLE_ENTITY_NAME);
    domain.getTypes().add(entity);
    resourceSet.getResources().add(viewResource);
    resourceSet.getResources().add(domainResource);
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    boolean validationResult = new DiagramDescriptionValidator().validate(nodeDescription.eClass(), nodeDescription, diagnosticChain, defaultContext);
    assertThat(validationResult).isTrue();
    assertThat(diagnosticChain).isEqualTo(new BasicDiagnostic(Diagnostic.OK, null, 0, null, null));
}
Also used : Entity(org.eclipse.sirius.components.domain.Entity) NodeDescription(org.eclipse.sirius.components.view.NodeDescription) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Domain(org.eclipse.sirius.components.domain.Domain) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) DiagramDescriptionValidator(org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator) Test(org.junit.jupiter.api.Test)

Example 2 with DiagramDescriptionValidator

use of org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator in project sirius-components by eclipse-sirius.

the class ViewValidatorTests method testConditionalConditionIsAbsent.

@Test
public void testConditionalConditionIsAbsent() {
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    ConditionalNodeStyle conditionalNodeStyle = ViewFactory.eINSTANCE.createConditionalNodeStyle();
    // $NON-NLS-1$
    conditionalNodeStyle.setColor("black");
    // $NON-NLS-1$
    conditionalNodeStyle.setCondition("");
    BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    // @formatter:off
    expected.add(new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, // $NON-NLS-1$
    "The condition should not be empty", new Object[] { conditionalNodeStyle, ViewPackage.Literals.CONDITIONAL__CONDITION }));
    // @formatter:on
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    boolean validationResult = new DiagramDescriptionValidator().validate(conditionalNodeStyle.eClass(), conditionalNodeStyle, diagnosticChain, defaultContext);
    assertThat(validationResult).isFalse();
    assertThat(diagnosticChain).isEqualTo(expected);
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) DiagramDescriptionValidator(org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator) Test(org.junit.jupiter.api.Test)

Example 3 with DiagramDescriptionValidator

use of org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator in project sirius-components by eclipse-sirius.

the class ViewValidatorTests method testConditionalNodeStyleDefaultValuesAreValid.

@Test
public void testConditionalNodeStyleDefaultValuesAreValid() {
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    NodeStyle conditionalNodeStyle = ViewFactory.eINSTANCE.createConditionalNodeStyle();
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    boolean validationResult = new DiagramDescriptionValidator().validate(conditionalNodeStyle.eClass(), conditionalNodeStyle, diagnosticChain, defaultContext);
    assertThat(validationResult).isTrue();
    assertThat(diagnosticChain).isEqualTo(new BasicDiagnostic(Diagnostic.OK, null, 0, null, null));
}
Also used : NodeStyle(org.eclipse.sirius.components.view.NodeStyle) ConditionalNodeStyle(org.eclipse.sirius.components.view.ConditionalNodeStyle) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) DiagramDescriptionValidator(org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator) Test(org.junit.jupiter.api.Test)

Example 4 with DiagramDescriptionValidator

use of org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator 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)

Example 5 with DiagramDescriptionValidator

use of org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator in project sirius-components by eclipse-sirius.

the class ViewValidatorTests method testNodeDescriptionInvalidDomain.

@Test
public void testNodeDescriptionInvalidDomain() {
    Map<Object, Object> defaultContext = Diagnostician.INSTANCE.createDefaultContext();
    NodeDescription nodeDescription = ViewFactory.eINSTANCE.createNodeDescription();
    ResourceSetImpl resourceSet = new ResourceSetImpl();
    XMIResourceImpl xmiResource = new XMIResourceImpl();
    xmiResource.getContents().add(nodeDescription);
    resourceSet.getResources().add(xmiResource);
    BasicDiagnostic expected = new BasicDiagnostic(Diagnostic.ERROR, null, 0, null, null);
    // @formatter:off
    expected.add(new BasicDiagnostic(Diagnostic.ERROR, SIRIUS_COMPONENTS_EMF_PACKAGE, 0, // $NON-NLS-1$
    String.format(DiagramDescriptionValidator.DIAGRAM_ELEMENT_DESCRIPTION_INVALID_DOMAIN_TYPE_ERROR_MESSAGE, Optional.ofNullable(nodeDescription.getDomainType()).orElse("")), new Object[] { nodeDescription, ViewPackage.Literals.DIAGRAM_ELEMENT_DESCRIPTION__DOMAIN_TYPE }));
    // @formatter:on
    BasicDiagnostic diagnosticChain = new BasicDiagnostic(Diagnostic.OK, null, 0, null, null);
    boolean validationResult = new DiagramDescriptionValidator().validate(nodeDescription.eClass(), nodeDescription, diagnosticChain, defaultContext);
    assertThat(validationResult).isFalse();
    assertThat(diagnosticChain).isEqualTo(expected);
}
Also used : NodeDescription(org.eclipse.sirius.components.view.NodeDescription) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl) DiagramDescriptionValidator(org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator) Test(org.junit.jupiter.api.Test)

Aggregations

DiagramDescriptionValidator (org.eclipse.sirius.components.emf.view.diagram.DiagramDescriptionValidator)10 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)9 Test (org.junit.jupiter.api.Test)9 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)5 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)5 NodeDescription (org.eclipse.sirius.components.view.NodeDescription)5 ConditionalNodeStyle (org.eclipse.sirius.components.view.ConditionalNodeStyle)4 EClass (org.eclipse.emf.ecore.EClass)2 EPackage (org.eclipse.emf.ecore.EPackage)2 EPackageRegistryImpl (org.eclipse.emf.ecore.impl.EPackageRegistryImpl)2 Domain (org.eclipse.sirius.components.domain.Domain)2 Entity (org.eclipse.sirius.components.domain.Entity)2 NodeStyle (org.eclipse.sirius.components.view.NodeStyle)2 Registry (org.eclipse.emf.ecore.EValidator.Registry)1 EValidatorRegistryImpl (org.eclipse.emf.ecore.impl.EValidatorRegistryImpl)1 DomainValidator (org.eclipse.sirius.components.emf.domain.DomainValidator)1 LabelFeatureProviderRegistry (org.eclipse.sirius.components.emf.services.LabelFeatureProviderRegistry)1 Bean (org.springframework.context.annotation.Bean)1