use of org.eclipse.sirius.components.domain.Relation 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
}
use of org.eclipse.sirius.components.domain.Relation in project sirius-components by eclipse-sirius.
the class DomainValidatorTests method testRelationEmptyName.
@Test
public void testRelationEmptyName() {
Relation relation = DomainFactory.eINSTANCE.createRelation();
// $NON-NLS-1$
relation.setName("");
this.assertNameIsInvalid(relation);
}
use of org.eclipse.sirius.components.domain.Relation in project sirius-components by eclipse-sirius.
the class DomainValidatorTests method testRelationNameWithUnderscore.
@Test
public void testRelationNameWithUnderscore() {
Relation relation = DomainFactory.eINSTANCE.createRelation();
// $NON-NLS-1$
relation.setName("some_relation");
this.assertNameIsValid(relation);
}
use of org.eclipse.sirius.components.domain.Relation in project sirius-components by eclipse-sirius.
the class DomainValidatorTests method testRelationNameWithInvalidCharacters.
@Test
public void testRelationNameWithInvalidCharacters() {
Relation relation = DomainFactory.eINSTANCE.createRelation();
// $NON-NLS-1$
relation.setName("some-relation");
this.assertNameIsInvalid(relation);
}
use of org.eclipse.sirius.components.domain.Relation 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);
}
Aggregations