use of org.eclipse.sirius.components.domain.Attribute 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.Attribute 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.domain.Attribute 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.domain.Attribute in project sirius-components by eclipse-sirius.
the class EntityItemProvider method collectNewChildDescriptors.
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children that can be created
* under this object. <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);
Attribute newAttribute = DomainFactory.eINSTANCE.createAttribute();
// $NON-NLS-1$
newAttribute.setName("newString");
newAttribute.setType(DataType.STRING);
newChildDescriptors.add(this.createChildParameter(DomainPackage.Literals.ENTITY__ATTRIBUTES, newAttribute));
Relation newRelation = DomainFactory.eINSTANCE.createRelation();
// $NON-NLS-1$
newRelation.setName("relation");
newRelation.setMany(true);
if (object instanceof Entity) {
Entity owner = (Entity) object;
newRelation.setTargetType(owner);
}
newChildDescriptors.add(this.createChildParameter(DomainPackage.Literals.ENTITY__RELATIONS, newRelation));
}
use of org.eclipse.sirius.components.domain.Attribute in project sirius-components by eclipse-sirius.
the class DomainValidatorTests method testAttributeNameWithInvalidCharacters.
@Test
public void testAttributeNameWithInvalidCharacters() {
Attribute attribute = DomainFactory.eINSTANCE.createAttribute();
// $NON-NLS-1$
attribute.setName("an-attribute");
this.assertNameIsInvalid(attribute);
}
Aggregations