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));
}
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);
}
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));
}
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;
}
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);
}
Aggregations