-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting class attributes and class relationships always seemed oddly …
…difficult, and why should this be in a static method in ERXCopyable.
- Loading branch information
Showing
2 changed files
with
110 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,109 +7,130 @@ | |
|
||
import com.webobjects.eocontrol.EOClassDescription; | ||
import com.webobjects.eocontrol.EOEditingContext; | ||
|
||
import com.webobjects.foundation.NSArray; | ||
import com.webobjects.foundation.NSDictionary; | ||
import com.webobjects.foundation.NSPropertyListSerialization; | ||
import com.webobjects.foundation.NSSet; | ||
|
||
import er.erxtest.ERXTestCase; | ||
|
||
import er.extensions.eof.ERXModelGroup; | ||
import er.extensions.eof.ERXEC; | ||
|
||
/* Test the ERXEntity methods. These tests are extremely minimal. | ||
* This class exists in order to deal with some issues in inheritance, and | ||
* this system is not configured to use models that use inheritance yet. | ||
* | ||
* @author Ray Kiddy, [email protected] | ||
* @author Ray Kiddy, [email protected] | ||
*/ | ||
public class ERXEntityTest extends ERXTestCase { | ||
|
||
static String buildRoot; | ||
static { | ||
buildRoot = System.getProperty("build.root"); | ||
} | ||
EOEditingContext ec; | ||
String adaptorName = "Memory"; | ||
String modelName; | ||
EOModel model; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
|
||
// if (ec != null) ec.dispose(); | ||
// if (model != null) model.dispose(); | ||
static String buildRoot; | ||
static { | ||
buildRoot = System.getProperty("build.root"); | ||
} | ||
EOEditingContext ec; | ||
String adaptorName = "Memory"; | ||
String modelName; | ||
EOModel model; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
|
||
// if (ec != null) ec.dispose(); | ||
// if (model != null) model.dispose(); | ||
// | ||
// EOModelGroup.setDefaultGroup(new EOModelGroup()); | ||
// EOModelGroup.setDefaultGroup(new EOModelGroup()); | ||
// | ||
// modelName = "ERXTest"; | ||
// modelName = "ERXTest"; | ||
// | ||
// URL modelUrl = ERXFileUtilities.pathURLForResourceNamed(modelName+".eomodeld", null, null); | ||
// URL modelUrl = ERXFileUtilities.pathURLForResourceNamed(modelName+".eomodeld", null, null); | ||
// | ||
// EOModelGroup.defaultGroup().addModel(new EOModel(modelUrl)); | ||
// EOModelGroup.defaultGroup().addModel(new EOModel(modelUrl)); | ||
// | ||
// model = EOModelGroup.defaultGroup().modelNamed(modelName); | ||
// model.setConnectionDictionary(ERExtensionsTest.connectionDict(adaptorName)); | ||
// model = EOModelGroup.defaultGroup().modelNamed(modelName); | ||
// model.setConnectionDictionary(ERExtensionsTest.connectionDict(adaptorName)); | ||
|
||
model = EOModelGroup.defaultGroup().modelNamed("ERXTest"); | ||
ec = ERXEC.newEditingContext(); | ||
} | ||
|
||
public void testConstructor() { | ||
ERXEntity entity = new ERXEntity(); | ||
Assert.assertNotNull(entity); | ||
} | ||
|
||
model = EOModelGroup.defaultGroup().modelNamed("ERXTest"); | ||
ec = ERXEC.newEditingContext(); | ||
} | ||
public void testPlistConstructor() { | ||
URL entityUrl = null; | ||
try { | ||
entityUrl = new java.net.URL(model.pathURL()+"/Company.plist"); | ||
} catch (java.net.MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } | ||
|
||
public void testOne() { } | ||
|
||
public void testConstructor() { | ||
ERXEntity entity = new ERXEntity(); | ||
Assert.assertNotNull(entity); | ||
} | ||
NSDictionary plist = (NSDictionary)NSPropertyListSerialization.propertyListWithPathURL(entityUrl); | ||
|
||
public void testPlistConstructor() { | ||
URL entityUrl = null; | ||
try { | ||
entityUrl = new java.net.URL(model.pathURL()+"/Company.plist"); | ||
} catch (java.net.MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } | ||
Assert.assertNotNull(new ERXEntity(plist, model)); | ||
} | ||
|
||
NSDictionary plist = (NSDictionary)NSPropertyListSerialization.propertyListWithPathURL(entityUrl); | ||
public void _testAnyAttributeNamed() { | ||
|
||
Assert.assertNotNull(new ERXEntity(plist, model)); | ||
} | ||
// Should this not return just a "new ERXEntity()"? It returns null. | ||
// | ||
//Assert.assertNotNull(new ERXEntity(null, null)); | ||
} | ||
|
||
public void _testAnyAttributeNamed() { | ||
public void testClassAttributes() { | ||
NSArray<EOAttribute> attrs = ((ERXEntity)ERXModelGroup.defaultGroup().entityNamed("Employee")).classAttributes(); | ||
@SuppressWarnings("unchecked") | ||
NSSet<String> foundAttrs = new NSSet<String>((NSArray<String>)attrs.valueForKey("name")); | ||
NSSet<String> expectedAttrs = new NSSet<String>(new String[] { | ||
"address1", "address2", "bestSalesTotal", "city", "firstName", "lastName", "manager", "state", "zipcode" | ||
} ); | ||
Assert.assertEquals(expectedAttrs, foundAttrs); | ||
} | ||
|
||
// Should this not return just a "new ERXEntity()"? It returns null. | ||
// | ||
//Assert.assertNotNull(new ERXEntity(null, null)); | ||
} | ||
public void testClassRelationships() { | ||
NSArray<EORelationship> rels = ((ERXEntity)ERXModelGroup.defaultGroup().entityNamed("Employee")).classRelationships(); | ||
@SuppressWarnings("unchecked") | ||
NSSet<String> foundRels = new NSSet<String>((NSArray<String>)rels.valueForKey("name")); | ||
NSSet<String> expectedRels = new NSSet<String>(new String[] { "company", "department", "paychecks", "roles" } ); | ||
Assert.assertEquals(expectedRels, foundRels); | ||
} | ||
|
||
public void testHasExternalName() { | ||
URL entityUrl = null; | ||
try { | ||
entityUrl = new java.net.URL(model.pathURL()+"/Company.plist"); | ||
} catch (java.net.MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } | ||
public void testHasExternalName() { | ||
URL entityUrl = null; | ||
try { | ||
entityUrl = new java.net.URL(model.pathURL()+"/Company.plist"); | ||
} catch (java.net.MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } | ||
|
||
NSDictionary plist = (NSDictionary)NSPropertyListSerialization.propertyListWithPathURL(entityUrl); | ||
NSDictionary plist = (NSDictionary)NSPropertyListSerialization.propertyListWithPathURL(entityUrl); | ||
|
||
ERXEntity erxentity = new ERXEntity(plist, model); | ||
ERXEntity erxentity = new ERXEntity(plist, model); | ||
|
||
Assert.assertTrue(erxentity.hasExternalName()); | ||
} | ||
Assert.assertTrue(erxentity.hasExternalName()); | ||
} | ||
|
||
public void testSetClassDescription() { | ||
public void testSetClassDescription() { | ||
|
||
EOEntity entity1 = EOModelGroup.defaultGroup().entityNamed("Company"); | ||
EOClassDescription desc = entity1.classDescriptionForInstances(); | ||
EOEntity entity1 = EOModelGroup.defaultGroup().entityNamed("Company"); | ||
EOClassDescription desc = entity1.classDescriptionForInstances(); | ||
|
||
Assert.assertNotNull(desc); | ||
Assert.assertNotNull(desc); | ||
|
||
URL entityUrl = null; | ||
try { | ||
entityUrl = new java.net.URL(model.pathURL()+"/Employee.plist"); | ||
} catch (java.net.MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } | ||
URL entityUrl = null; | ||
try { | ||
entityUrl = new java.net.URL(model.pathURL()+"/Employee.plist"); | ||
} catch (java.net.MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } | ||
|
||
NSDictionary plist = (NSDictionary)NSPropertyListSerialization.propertyListWithPathURL(entityUrl); | ||
NSDictionary plist = (NSDictionary)NSPropertyListSerialization.propertyListWithPathURL(entityUrl); | ||
|
||
ERXEntity entity2 = new ERXEntity(plist, model); | ||
ERXEntity entity2 = new ERXEntity(plist, model); | ||
|
||
// Using a mis-matched EOClassDescription here, but doing that on purpose so we can verify the superclass did not just ignore the set. | ||
// | ||
entity2.setClassDescription(desc); | ||
// Using a mis-matched EOClassDescription here, but doing that on purpose so we can verify the superclass did not just ignore the set. | ||
// | ||
entity2.setClassDescription(desc); | ||
|
||
//Assert.assertTrue(ERExtensionsTest.equalsForEOAccessObjects(desc, entity2.classDescriptionForInstances())); | ||
} | ||
//Assert.assertTrue(ERExtensionsTest.equalsForEOAccessObjects(desc, entity2.classDescriptionForInstances())); | ||
} | ||
} |