Search in sources :

Example 46 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tmdm-studio-se by Talend.

the class XSDUtilTest method testGetEntityName.

@Test
public void testGetEntityName() {
    XSDSchema mockSchema = mock(XSDSchema.class);
    List<String> declNames = new ArrayList<String>();
    // $NON-NLS-1$
    declNames.add("Product");
    // $NON-NLS-1$
    declNames.add("Family");
    // $NON-NLS-1$
    declNames.add("Store");
    EList<XSDElementDeclaration> decls = new BasicEList<XSDElementDeclaration>();
    for (String name : declNames) {
        XSDElementDeclaration mockDecl = mock(XSDElementDeclaration.class);
        when(mockDecl.getName()).thenReturn(name);
        decls.add(mockDecl);
    }
    when(mockSchema.getElementDeclarations()).thenReturn(decls);
    List<String> entityNames = XSDUtil.getEntityName(mockSchema);
    assertNotNull(entityNames);
    assertEquals(decls.size(), entityNames.size());
    assertTrue(entityNames.containsAll(declNames));
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Example 47 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tmdm-studio-se by Talend.

the class EditXSDEleDecNameValidatorTest method testIsValid.

@Test
public void testIsValid() {
    EList<XSDElementDeclaration> decls = new BasicEList<XSDElementDeclaration>();
    XSDElementDeclaration mockDecl = mock(XSDElementDeclaration.class);
    // $NON-NLS-1$
    when(mockDecl.getName()).thenReturn("Product");
    decls.add(mockDecl);
    XSDSchema mockSchema = mock(XSDSchema.class);
    when(mockSchema.getElementDeclarations()).thenReturn(decls);
    EditXSDEleDecNameValidator nameValidaor = new EditXSDEleDecNameValidator(mockSchema);
    // $NON-NLS-1$
    String decname = "";
    String msg = nameValidaor.isValid(decname);
    assertEquals(Messages.EditXSDEleDecNameValidator_EntityNameCannotbeEmpty, msg);
    decname = null;
    msg = nameValidaor.isValid(decname);
    assertEquals(Messages.EditXSDEleDecNameValidator_EntityNameCannotbeEmpty, msg);
    // ///
    // $NON-NLS-1$ blank string on the head
    decname = " Prod_897";
    msg = nameValidaor.isValid(decname);
    assertEquals(Messages.EditXSDEleDecNameValidator_EntityNameCannotContainEmpty, msg);
    // $NON-NLS-1$ blank string among it
    decname = "Prod 897";
    msg = nameValidaor.isValid(decname);
    assertEquals(Messages.EditXSDEleDecNameValidator_EntityNameCannotContainEmpty, msg);
    PowerMockito.mockStatic(XSDUtil.class);
    PowerMockito.when(XSDUtil.isValidatedXSDName(anyString())).thenReturn(false);
    // $NON-NLS-1$
    decname = "PP";
    msg = nameValidaor.isValid(decname);
    assertEquals(Messages.InvalidName_Message, msg);
    PowerMockito.when(XSDUtil.isValidatedXSDName(anyString())).thenReturn(true);
    // $NON-NLS-1$
    decname = "Product";
    msg = nameValidaor.isValid(decname);
    assertEquals(Messages.EditXSDEleDecNameValidator_EntityAlreadyExist, msg);
    // $NON-NLS-1$
    decname = "aabb";
    msg = nameValidaor.isValid(decname);
    assertNull(msg);
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) BasicEList(org.eclipse.emf.common.util.BasicEList) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 48 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tmdm-studio-se by Talend.

the class EditXSDIdentityConstraintNameValidatorTest method testIsValid.

@Test
public void testIsValid() {
    // $NON-NLS-1$
    String entityName = "Product";
    XSDElementDeclaration mockEntity = mock(XSDElementDeclaration.class);
    when(mockEntity.getName()).thenReturn(entityName);
    XSDSchema mockSchema = mock(XSDSchema.class);
    XSDIdentityConstraintDefinition mockConstraintDef0 = mock(XSDIdentityConstraintDefinition.class);
    when(mockConstraintDef0.getName()).thenReturn(entityName);
    when(mockConstraintDef0.getSchema()).thenReturn(mockSchema);
    when(mockConstraintDef0.getIdentityConstraintCategory()).thenReturn(XSDIdentityConstraintCategory.UNIQUE_LITERAL);
    when(mockConstraintDef0.getContainer()).thenReturn(mockEntity);
    EList<XSDIdentityConstraintDefinition> constraintDefs = new BasicEList<XSDIdentityConstraintDefinition>();
    XSDIdentityConstraintDefinition mockConstraintDef1 = mock(XSDIdentityConstraintDefinition.class);
    // $NON-NLS-1$
    when(mockConstraintDef1.getName()).thenReturn("Family");
    constraintDefs.add(mockConstraintDef0);
    constraintDefs.add(mockConstraintDef1);
    when(mockSchema.getIdentityConstraintDefinitions()).thenReturn(constraintDefs);
    EditXSDIdentityConstraintNameValidator validator = new EditXSDIdentityConstraintNameValidator(mockConstraintDef0);
    // /////////
    String constraintName = null;
    String msg = validator.isValid(constraintName);
    assertEquals(Messages.EditXSDIdXXValidator_UniqueKeyNameCannotbeEmpty, msg);
    // $NON-NLS-1$
    constraintName = "";
    msg = validator.isValid(constraintName);
    assertEquals(Messages.EditXSDIdXXValidator_UniqueKeyNameCannotbeEmpty, msg);
    // ///
    // $NON-NLS-1$ blank string on the head
    constraintName = " Prod_897";
    msg = validator.isValid(constraintName);
    assertEquals(Messages.EditXSDIdXXValidator_UniqueKeyNameCannotContainEmpty, msg);
    // $NON-NLS-1$ blank string among it
    constraintName = "Prod 897";
    msg = validator.isValid(constraintName);
    assertEquals(Messages.EditXSDIdXXValidator_UniqueKeyNameCannotContainEmpty, msg);
    // ///
    // $NON-NLS-1$ not equal to entity name
    constraintName = entityName + "_tail";
    msg = validator.isValid(constraintName);
    assertEquals(Messages.EditXSDIdXXValidator_UniqueKeyNameMustbeEqualXX, msg);
    // 
    constraintName = entityName;
    msg = validator.isValid(constraintName);
    assertEquals(Messages.EditXSDIdXXValidator_KeyAlreadyExist, msg);
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) BasicEList(org.eclipse.emf.common.util.BasicEList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Example 49 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project tmdm-studio-se by Talend.

the class NewXSDIndentityConstraintValidatorTest method testIsValid.

@Test
public void testIsValid() {
    // $NON-NLS-1$
    String name = "Product";
    XSDIdentityConstraintCategory type = XSDIdentityConstraintCategory.UNIQUE_LITERAL;
    XSDElementDeclaration mockEntity = mock(XSDElementDeclaration.class);
    EList<XSDIdentityConstraintDefinition> constraintDefs = new BasicEList<XSDIdentityConstraintDefinition>();
    XSDIdentityConstraintDefinition mockConstraintDef = mock(XSDIdentityConstraintDefinition.class);
    // $NON-NLS-1$
    when(mockConstraintDef.getName()).thenReturn("Product");
    when(mockConstraintDef.getContainer()).thenReturn(mockEntity);
    when(mockConstraintDef.getIdentityConstraintCategory()).thenReturn(XSDIdentityConstraintCategory.UNIQUE_LITERAL);
    constraintDefs.add(mockConstraintDef);
    XSDSchema mockSchema = mock(XSDSchema.class);
    when(mockSchema.getIdentityConstraintDefinitions()).thenReturn(constraintDefs);
    NewXSDIndentityConstraintValidator validator = new NewXSDIndentityConstraintValidator(mockSchema);
    // ///
    String keyName = null;
    String msg = validator.isValid(keyName, type, mockEntity);
    assertEquals(Messages.NewXSDIndentityConstraintValidator_KeyNameCannotbeEmpty, msg);
    // $NON-NLS-1$
    keyName = "";
    msg = validator.isValid(keyName, type, mockEntity);
    assertEquals(Messages.NewXSDIndentityConstraintValidator_KeyNameCannotbeEmpty, msg);
    // $NON-NLS-1$
    keyName = " ";
    msg = validator.isValid(keyName, type, mockEntity);
    assertEquals(Messages.NewXSDIndentityConstraintValidator_KeyNameCannotbeEmpty, msg);
    // $NON-NLS-1$ UNIQUE_LITERAL
    keyName = "Family";
    msg = validator.isValid(keyName, type, mockEntity);
    assertEquals(Messages.NewXSDIndentityConstraintValidator_BElemntAlreadyHasUniqueKey, msg);
    keyName = name;
    when(mockConstraintDef.getIdentityConstraintCategory()).thenReturn(XSDIdentityConstraintCategory.KEY_LITERAL);
    msg = validator.isValid(keyName, type, mockEntity);
    assertEquals(Messages.bind(Messages.NewXSDIndentityConstraintValidator_KeyInfo, keyName), msg);
    // $NON-NLS-1$ not UNIQUE_LITERAL
    keyName = "Family";
    msg = validator.isValid(keyName, type, mockEntity);
    assertNull(msg);
}
Also used : XSDIdentityConstraintCategory(org.eclipse.xsd.XSDIdentityConstraintCategory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) BasicEList(org.eclipse.emf.common.util.BasicEList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Example 50 with BasicEList

use of org.eclipse.emf.common.util.BasicEList in project webtools.sourceediting by eclipse.

the class DTDUtil method parse.

/**
 * Invoke parse to parse a .dtd file into a MOF object model This is
 * invoked by the RegisteredDTDParser that registers this parser for MOF
 * to use against the .dtd type
 *
 * @param filename -
 *            the fully qualifed name of a .dtd file
 */
public void parse(ResourceSet resources, String filename) {
    // Get the dtd name from the file name
    Path path = new Path(filename);
    IPath iPath = path.removeFileExtension();
    String dtdName = iPath.toFile().getName();
    try {
        parser = new DTDParser(false);
        if (expandEntityReferences) {
            parser.setExpandEntityReferences(expandEntityReferences);
        }
        parser.parse(filename);
    } catch (IOException ex) {
        ex.printStackTrace(System.err);
    }
    dtdModelFile = filename;
    factory = DTDFactoryImpl.instance();
    extent = new BasicEList();
    dtdFile = factory.createDTDFile();
    extent.add(dtdFile);
    dtdFile.setName(dtdName);
    populateDTD(resources, expandEntityReferences);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) BasicEList(org.eclipse.emf.common.util.BasicEList) DTDParser(org.eclipse.wst.dtd.core.internal.saxparser.DTDParser) IOException(java.io.IOException)

Aggregations

BasicEList (org.eclipse.emf.common.util.BasicEList)75 Test (org.junit.Test)25 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)16 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)16 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)16 EEFFeatureEditorDialog (org.eclipse.emf.eef.runtime.ui.widgets.EEFFeatureEditorDialog)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)16 GridData (org.eclipse.swt.layout.GridData)16 TdExpression (org.talend.cwm.relational.TdExpression)11 EObject (org.eclipse.emf.ecore.EObject)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)9 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)9 ProductVersion (org.talend.utils.ProductVersion)9 Button (org.eclipse.swt.widgets.Button)8 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)6 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)6 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)5 Widget (org.eclipse.smarthome.model.sitemap.Widget)5