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