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