cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1586828 - in /cayenne/main/trunk/cayenne-project/src/test: java/org/apache/cayenne/project/upgrade/v7/ resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/
Date Sat, 12 Apr 2014 08:05:55 GMT
Author: aadamchik
Date: Sat Apr 12 08:05:54 2014
New Revision: 1586828

URL: http://svn.apache.org/r1586828
Log:
CAY-1795 "Invisible" ObjAttribute in subclass

patch by Oleg Artyukevich - v7upgradeTest.patch
(some manual intervention was needed for the patch to apply)

Added:
    cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/
    cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/cayenne-TestProject.xml
    cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap1.map.xml
    cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap2.map.xml
Modified:
    cayenne/main/trunk/cayenne-project/src/test/java/org/apache/cayenne/project/upgrade/v7/ProjectUpgrader_V7Test.java

Modified: cayenne/main/trunk/cayenne-project/src/test/java/org/apache/cayenne/project/upgrade/v7/ProjectUpgrader_V7Test.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-project/src/test/java/org/apache/cayenne/project/upgrade/v7/ProjectUpgrader_V7Test.java?rev=1586828&r1=1586827&r2=1586828&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-project/src/test/java/org/apache/cayenne/project/upgrade/v7/ProjectUpgrader_V7Test.java
(original)
+++ cayenne/main/trunk/cayenne-project/src/test/java/org/apache/cayenne/project/upgrade/v7/ProjectUpgrader_V7Test.java
Sat Apr 12 08:05:54 2014
@@ -25,6 +25,7 @@ import java.util.List;
 
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
 import javax.xml.xpath.XPathFactory;
 
 import org.apache.cayenne.configuration.ConfigurationNameMapper;
@@ -348,7 +349,7 @@ public class ProjectUpgrader_V7Test exte
     }
 
     public void testPerformUpgradeFrom6() throws Exception {
-        File testForlder = setupTestDirectory("testUpgrade6a");
+        File testFolder = setupTestDirectory("testUpgrade6a");
         String sourceUrl = getClass().getPackage().getName().replace('.', '/') + "/6a/";
         System.out.println(sourceUrl);
         Module testModule = new Module() {
@@ -368,7 +369,7 @@ public class ProjectUpgrader_V7Test exte
 
         for (String name : resources) {
             URL xmlUrl = getClass().getClassLoader().getResource(sourceUrl + name);
-            File target = new File(testForlder, name);
+            File target = new File(testFolder, name);
             ResourceUtil.copyResourceToFile(xmlUrl, target);
             files.add(target);
         }
@@ -417,4 +418,81 @@ public class ProjectUpgrader_V7Test exte
         assertEquals("7", xpath.evaluate("/data-map/@project-version", document));
     }
 
+    public void testObjAttributeDelete() throws Exception {
+        System.out.println("Test ObjAttribute deleting.");
+
+        File testFolder = setupTestDirectory("testObjAttribute");
+        String sourceUrl = getClass().getPackage().getName().replace('.', '/') + "/6a/ObjAttributeDeleting/";
+
+        Module testModule = new Module() {
+
+            public void configure(Binder binder) {
+                binder.bind(ProjectSaver.class).to(FileProjectSaver.class);
+                binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
+                binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
+            }
+        };
+
+        ArrayList<String> source = new ArrayList<String>();
+        source.add("cayenne-TestProject.xml");
+        source.add("testProjectMap1.map.xml");
+        source.add("testProjectMap2.map.xml");
+
+        ArrayList<File> file = new ArrayList<File>();
+
+        for (String name : source) {
+            URL xmlUrl = getClass().getClassLoader().getResource(sourceUrl + name);
+            File target = new File(testFolder, name);
+            ResourceUtil.copyResourceToFile(xmlUrl, target);
+            file.add(target);
+        }
+
+        Injector injector = DIBootstrap.createInjector(testModule);
+        ProjectUpgrader_V7 upgrader = new ProjectUpgrader_V7();
+        injector.injectMembers(upgrader);
+
+        Resource resource = new URLResource(file.get(0).toURL());
+        assertNotNull(resource);
+        UpgradeHandler handler = upgrader.getUpgradeHandler(resource);
+        assertNotNull(handler);
+
+        Resource upgraded = handler.performUpgrade();
+        assertNotNull(upgraded);
+        assertNotSame(resource, upgraded);
+
+        assertPerformUpgrade6Cayenne(file.get(0));
+        assertObjAttributeMap1(file.get(1));
+        assertObjAttributeMap2(file.get(2));
+    }
+
+    private void assertObjAttributeMap1(File file) throws Exception {
+        Document document = toDOMTree(file);
+
+        XPath xpath = XPathFactory.newInstance().newXPath();
+        assertEquals("7", xpath.evaluate("/data-map/@project-version", document));
+
+        String xpathValue = "/data-map/obj-entity[@name='GreatArtist']/obj-attribute";
+        XPathExpression expr = xpath.compile(xpathValue);
+        Node node = (Node) expr.evaluate(document, XPathConstants.NODE);
+
+        assertEquals("attribute2", xpath.evaluate("@name", node));
+    }
+
+    private void assertObjAttributeMap2(File file) throws Exception {
+        Document document = toDOMTree(file);
+
+        XPath xpath = XPathFactory.newInstance().newXPath();
+        assertEquals("7", xpath.evaluate("/data-map/@project-version", document));
+
+        String xpath_1 = "/data-map/obj-entity[@name='House']/obj-attribute/@name";
+        String xpath_2 = "/data-map/obj-entity[@name='Penthouse']/obj-attribute/@name";
+        XPathExpression expr = xpath.compile(xpath_1);
+        String houseAttr = (String) expr.evaluate(document, XPathConstants.STRING);
+        expr = xpath.compile(xpath_2);
+        String penthouseAttr = (String) expr.evaluate(document, XPathConstants.STRING);
+
+        assertEquals("attribute2", houseAttr);
+        assertEquals("attribute3", penthouseAttr);
+    }
+
 }

Added: cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/cayenne-TestProject.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/cayenne-TestProject.xml?rev=1586828&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/cayenne-TestProject.xml
(added)
+++ cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/cayenne-TestProject.xml
Sat Apr 12 08:05:54 2014
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain project-version="6">
+	<map name="testProjectMap1"/>
+	<map name="testProjectMap2"/>
+
+	<node name="testProjectNode"
+		 factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory"
+		 schema-update-strategy="org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy"
+		>
+		<map-ref name="testProjectMap1"/>
+		<map-ref name="testProjectMap2"/>
+		<data-source>
+			<driver/>
+			<url/>
+			<connectionPool min="1" max="1"/>
+			<login/>
+		</data-source>
+	</node>
+</domain>

Added: cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap1.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap1.map.xml?rev=1586828&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap1.map.xml
(added)
+++ cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap1.map.xml
Sat Apr 12 08:05:54 2014
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+	 project-version="6">
+	<db-entity name="Artist">
+		<db-attribute name="ATTRIBUTE_1" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="ATTRIBUTE_2" type="VARCHAR" length="30"/>
+		<db-attribute name="ATTRIBUTE_3" type="BOOLEAN"/>
+	</db-entity>
+	<obj-entity name="Artist" dbEntityName="Artist">
+		<obj-attribute name="attribute1" type="int" db-attribute-path="ATTRIBUTE_1"/>
+	</obj-entity>
+	<obj-entity name="GreatArtist" superEntityName="Artist">
+		<obj-attribute name="attribute1" type="boolean" db-attribute-path="ATTRIBUTE_3"/>
+		<obj-attribute name="attribute2" type="java.lang.String" db-attribute-path="ATTRIBUTE_2"/>
+		<attribute-override name="attribute1" db-attribute-path="ATTRIBUTE_3"/>
+	</obj-entity>
+</data-map>

Added: cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap2.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap2.map.xml?rev=1586828&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap2.map.xml
(added)
+++ cayenne/main/trunk/cayenne-project/src/test/resources/org/apache/cayenne/project/upgrade/v7/6a/ObjAttributeDeleting/testProjectMap2.map.xml
Sat Apr 12 08:05:54 2014
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+	 project-version="6">
+	<db-entity name="House">
+		<db-attribute name="attribute1" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="attribute2" type="DOUBLE"/>
+		<db-attribute name="attribute3" type="INTEGER"/>
+	</db-entity>
+	<obj-entity name="House" dbEntityName="House">
+		<obj-attribute name="attribute2" type="java.lang.Double" db-attribute-path="attribute2"/>
+	</obj-entity>
+	<obj-entity name="Penthouse" superEntityName="House">
+		<obj-attribute name="attribute3" type="int" db-attribute-path="attribute3"/>
+	</obj-entity>
+</data-map>



Mime
View raw message