1 19 20 package org.netbeans.modules.j2ee.persistence.unit; 21 22 import junit.framework.*; 23 import java.util.List ; 24 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit; 25 import org.netbeans.modules.xml.multiview.Error; 26 27 31 public class PersistenceValidatorTest extends PersistenceEditorTestBase { 32 33 public PersistenceValidatorTest(String testName) { 34 super(testName); 35 } 36 37 protected void setUp() throws Exception { 38 super.setUp(); 39 } 40 41 44 public void testValidateNameIsUnique() { 45 PersistenceUnit unit1 = new PersistenceUnit(); 46 unit1.setName("name1"); 47 dataObject.addPersistenceUnit(unit1); 48 PersistenceUnit unit2 = new PersistenceUnit(); 49 unit2.setName("name1"); 50 dataObject.addPersistenceUnit(unit2); 51 PersistenceValidator validator = new PersistenceValidatorImpl(dataObject, false); 52 List <Error > errors = validator.validate(); 53 assertEquals(2, errors.size()); 54 assertEquals(Error.DUPLICATE_VALUE_MESSAGE, errors.get(0).getErrorType()); 55 assertEquals(Error.DUPLICATE_VALUE_MESSAGE, errors.get(1).getErrorType()); 56 } 57 58 59 63 public void testValidateExcludeUnlistedClasses(){ 64 PersistenceValidator javaSEvalidator = new PersistenceValidatorImpl(dataObject, true); 66 PersistenceUnit unit1 = new PersistenceUnit(); 67 unit1.setName("unit1"); 68 unit1.setExcludeUnlistedClasses(true); 69 dataObject.addPersistenceUnit(unit1); 70 List <Error > errors = javaSEvalidator.validate(); 71 assertEquals(1, errors.size()); 72 assertEquals(Error.TYPE_WARNING, errors.get(0).getErrorType()); 73 PersistenceValidator javaEEvalidator = new PersistenceValidatorImpl(dataObject, false); 75 errors = javaEEvalidator.validate(); 76 assertTrue(errors.isEmpty());; 77 } 78 79 83 public void testValidateJarFiles(){ 84 PersistenceValidator javaSEvalidator = new PersistenceValidatorImpl(dataObject, true); 86 PersistenceUnit unit1 = new PersistenceUnit(); 87 unit1.setName("unit1"); 88 unit1.addJarFile("my-jar.jar"); 89 dataObject.addPersistenceUnit(unit1); 90 List <Error > errors = javaSEvalidator.validate(); 91 assertEquals(1, errors.size()); 92 assertEquals(Error.TYPE_WARNING, errors.get(0).getErrorType()); 93 PersistenceValidator javaEEvalidator = new PersistenceValidatorImpl(dataObject, false); 95 errors = javaEEvalidator.validate(); 96 assertTrue(errors.isEmpty());; 97 } 98 99 103 private static class PersistenceValidatorImpl extends PersistenceValidator { 104 105 private boolean javaSE; 106 107 public PersistenceValidatorImpl(PUDataObject puDataObject, boolean javaSE){ 108 super(puDataObject); 109 this.javaSE = javaSE; 110 } 111 112 protected boolean isJavaSE() { 113 return javaSE; 114 } 115 116 117 } 118 } 119 | Popular Tags |