use of org.eclipse.xsd.XSDIdentityConstraintCategory 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);
}
Aggregations