Search in sources :

Example 1 with XSDIdentityConstraintCategory

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

Aggregations

BasicEList (org.eclipse.emf.common.util.BasicEList)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 XSDIdentityConstraintCategory (org.eclipse.xsd.XSDIdentityConstraintCategory)1 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)1 XSDSchema (org.eclipse.xsd.XSDSchema)1 Test (org.junit.Test)1