You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by ti...@apache.org on 2022/11/13 17:31:32 UTC

[db-jdo] branch annotation-convert-on-type-tck created (now 7594de0b)

This is an automated email from the ASF dual-hosted git repository.

tilmannz pushed a change to branch annotation-convert-on-type-tck
in repository https://gitbox.apache.org/repos/asf/db-jdo.git


      at 7594de0b Added TCK test

This branch includes the following new commits:

     new 7594de0b Added TCK test

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[db-jdo] 01/01: Added TCK test

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tilmannz pushed a commit to branch annotation-convert-on-type-tck
in repository https://gitbox.apache.org/repos/asf/db-jdo.git

commit 7594de0b51fe44a467e73e784d5fee18aa90be1d
Author: Tilmann <zo...@gmx.de>
AuthorDate: Sun Nov 13 18:29:36 2022 +0100

    Added TCK test
---
 .../api/converter/PointAttributeConverterTest.java |  26 ++++++
 .../tck/pc/converter/PCRectPointTypeAnnotated.java | 101 +++++++++++++++++++++
 .../apache/jdo/tck/pc/mylib/ConvertiblePoint.java  |  75 +++++++++++++++
 .../org/apache/jdo/tck/pc/converter/package.jdo    |   5 +
 .../org/apache/jdo/tck/pc/converter/package.jdo    |   2 +
 .../jdo/tck/pc/converter/package-standard.orm      |   4 +
 6 files changed, 213 insertions(+)

diff --git a/tck/src/main/java/org/apache/jdo/tck/api/converter/PointAttributeConverterTest.java b/tck/src/main/java/org/apache/jdo/tck/api/converter/PointAttributeConverterTest.java
index 6f05acdb..2dc64a12 100644
--- a/tck/src/main/java/org/apache/jdo/tck/api/converter/PointAttributeConverterTest.java
+++ b/tck/src/main/java/org/apache/jdo/tck/api/converter/PointAttributeConverterTest.java
@@ -25,6 +25,7 @@ import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.converter.IPCRect;
 import org.apache.jdo.tck.pc.converter.PCRect;
 import org.apache.jdo.tck.pc.converter.PCRectAnnotated;
+import org.apache.jdo.tck.pc.converter.PCRectPointTypeAnnotated;
 import org.apache.jdo.tck.pc.mylib.Point;
 import org.apache.jdo.tck.util.BatchTestRunner;
 import org.apache.jdo.tck.util.PointToStringConverter;
@@ -111,6 +112,31 @@ public class PointAttributeConverterTest extends JDO_Test {
     runQueryWithStringParameter(PCRectAnnotated.class);
   }
 
+  /** Test method creating and storing a PCRectStringAnnotated instance. */
+  public void testStorePCRectPointTypeAnnotatedInstance() {
+    runStoreIPCRectInstance(PCRectPointTypeAnnotated.class);
+  }
+
+  /** Test method reading a PCRectStringAnnotated instance from the datastore. */
+  public void testReadPCRectPointTypeAnnotatedInstance() {
+    runReadIPCRectInstance(PCRectPointTypeAnnotated.class);
+  }
+
+  /** Test method modifying a PCRectStringAnnotated instance and storing in the datastore. */
+  public void testModifyPCRectPointTypeAnnotatedInstance() {
+    runModifyIPCRectInstance(PCRectPointTypeAnnotated.class);
+  }
+
+  /** Test method running a PCRectStringAnnotated query with a query parameter of type String. */
+  public void testPCRectPointTypeAnnotatedQueryWithPointParam() {
+    runQueryWithPointParameter(PCRectPointTypeAnnotated.class);
+  }
+
+  /** Test method running a PCRectStringAnnotated query with a query parameter of type Point. */
+  public void testPCRectPointTypeAnnotatedQueryWithStringParam() throws Exception {
+    runQueryWithStringParameter(PCRectPointTypeAnnotated.class);
+  }
+
   // Helper methods
 
   /**
diff --git a/tck/src/main/java/org/apache/jdo/tck/pc/converter/PCRectPointTypeAnnotated.java b/tck/src/main/java/org/apache/jdo/tck/pc/converter/PCRectPointTypeAnnotated.java
new file mode 100644
index 00000000..fc5c0d3c
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/pc/converter/PCRectPointTypeAnnotated.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.converter;
+
+import org.apache.jdo.tck.pc.mylib.ConvertiblePoint;
+import org.apache.jdo.tck.pc.mylib.Point;
+import org.apache.jdo.tck.util.PointToStringConverter;
+
+import javax.jdo.annotations.Column;
+import javax.jdo.annotations.Convert;
+import javax.jdo.annotations.PersistenceCapable;
+import java.util.Date;
+
+/**
+ * PersistenceCapable class to test JDO AttributeConverter interface. Its fields of type Point are
+ * converted to strings in the datastore.
+ * The conversion is declared directly on the type ConvertiblePoint.
+ */
+@PersistenceCapable(table = "PCRectConv")
+public class PCRectPointTypeAnnotated implements IPCRect {
+  private static long counter = new Date().getTime();
+
+  private static synchronized long newId() {
+    return counter++;
+  }
+
+  @Column(name = "ID")
+  private long id = newId();
+
+  @Column(name = "UPPER_LEFT")
+  private ConvertiblePoint upperLeft;
+
+  @Column(name = "LOWER_RIGHT")
+  private ConvertiblePoint lowerRight;
+
+  public PCRectPointTypeAnnotated() {}
+
+  public long getId() {
+    return id;
+  }
+
+  public void setId(long id) {
+    this.id = id;
+  }
+
+  public Point getUpperLeft() {
+    return new Point(upperLeft.getX(), upperLeft.getY());
+  }
+
+  public void setUpperLeft(Point upperLeft) {
+    if (this.upperLeft == null) {
+      this.upperLeft = new ConvertiblePoint(upperLeft.getX(), upperLeft.getY());
+    } else {
+      this.upperLeft.setX(upperLeft.getX());
+      this.upperLeft.setY(upperLeft.getY());
+    }
+  }
+
+  public Point getLowerRight() {
+    return new Point(lowerRight.getX(), lowerRight.getY());
+  }
+
+  public void setLowerRight(Point lowerRight) {
+    if (this.lowerRight == null) {
+      this.lowerRight = new ConvertiblePoint(lowerRight.getX(), lowerRight.getY());
+    } else {
+      this.lowerRight.setX(lowerRight.getX());
+      this.lowerRight.setY(lowerRight.getY());
+    }
+  }
+
+  public String toString() {
+    String rc = null;
+    Object obj = this;
+    try {
+      rc =
+          obj.getClass().getName()
+              + " ul: "
+              + getUpperLeft().name()
+              + " lr: "
+              + getLowerRight().name();
+    } catch (NullPointerException ex) {
+      rc = "NPE getting PCRectPointTypeAnnotated's values";
+    }
+    return rc;
+  }
+}
diff --git a/tck/src/main/java/org/apache/jdo/tck/pc/mylib/ConvertiblePoint.java b/tck/src/main/java/org/apache/jdo/tck/pc/mylib/ConvertiblePoint.java
new file mode 100644
index 00000000..d9f54ffe
--- /dev/null
+++ b/tck/src/main/java/org/apache/jdo/tck/pc/mylib/ConvertiblePoint.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jdo.tck.pc.mylib;
+
+import org.apache.jdo.tck.util.PointToStringConverter;
+
+import javax.jdo.annotations.Convert;
+
+/**
+ * A simple point class with two fields. The whole class/type is declared convertible.
+ */
+@Convert(value = PointToStringConverter.class)
+public class ConvertiblePoint {
+  public int x;
+  public Integer y;
+
+  public ConvertiblePoint() {}
+
+  public ConvertiblePoint(int x, int y) {
+    this.x = x;
+    this.y = y;
+  }
+
+  public ConvertiblePoint(int x, Integer y) {
+    this.x = x;
+    this.y = y;
+  }
+
+  public String toString() {
+    String rc = null;
+    try {
+      rc = "Point(" + name() + ")";
+    } catch (NullPointerException ex) {
+      rc = "NPE getting Point's values";
+    }
+    return rc;
+  }
+
+  public int getX() {
+    System.out.println("Hello from Point.getX");
+    return x;
+  }
+
+  public Integer getY() {
+    System.out.println("Hello from Point.getY");
+    return y;
+  }
+
+  public void setX(int x) {
+    this.x = x;
+  }
+
+  public void setY(int y) {
+    this.y = y;
+  }
+
+  public String name() {
+    return "x: " + getX() + ", y: " + getY();
+  }
+}
diff --git a/tck/src/main/resources/jdo/applicationidentity/org/apache/jdo/tck/pc/converter/package.jdo b/tck/src/main/resources/jdo/applicationidentity/org/apache/jdo/tck/pc/converter/package.jdo
index b0a627f3..60baeac6 100644
--- a/tck/src/main/resources/jdo/applicationidentity/org/apache/jdo/tck/pc/converter/package.jdo
+++ b/tck/src/main/resources/jdo/applicationidentity/org/apache/jdo/tck/pc/converter/package.jdo
@@ -33,6 +33,11 @@
       <field name="id" primary-key="true"/>
     </class>
 
+    <class name="PCRectPointTypeAnnotated"
+           identity-type="application" objectid-class="javax.jdo.identity.LongIdentity">
+      <field name="id" primary-key="true"/>
+    </class>
+
     <class name="PCPoint"
            identity-type="application" objectid-class="javax.jdo.identity.LongIdentity">
       <field name="id" primary-key="true"/>
diff --git a/tck/src/main/resources/jdo/datastoreidentity/org/apache/jdo/tck/pc/converter/package.jdo b/tck/src/main/resources/jdo/datastoreidentity/org/apache/jdo/tck/pc/converter/package.jdo
index 297e742f..e33bbf5a 100644
--- a/tck/src/main/resources/jdo/datastoreidentity/org/apache/jdo/tck/pc/converter/package.jdo
+++ b/tck/src/main/resources/jdo/datastoreidentity/org/apache/jdo/tck/pc/converter/package.jdo
@@ -27,6 +27,7 @@
     </class>
 
     <class name="PCRectAnnotated" identity-type="datastore"/>
+    <class name="PCRectPointTypeAnnotated" identity-type="datastore"/>
 
     <class name="PCPoint" identity-type="datastore">
       <field name="x" converter="org.apache.jdo.tck.util.IntegerToStringConverter"/>
@@ -34,6 +35,7 @@
     </class>
 
     <class name="PCPointAnnotated" identity-type="datastore"/>
+    <class name="PCRectPointTypeAnnotated" identity-type="datastore"/>
 
     <class name="PCPointProp" identity-type="datastore">
       <property name="x" converter="org.apache.jdo.tck.util.IntegerToStringConverter"/>
diff --git a/tck/src/main/resources/orm/datastoreidentity/org/apache/jdo/tck/pc/converter/package-standard.orm b/tck/src/main/resources/orm/datastoreidentity/org/apache/jdo/tck/pc/converter/package-standard.orm
index 39f3b3c4..d63ca096 100644
--- a/tck/src/main/resources/orm/datastoreidentity/org/apache/jdo/tck/pc/converter/package-standard.orm
+++ b/tck/src/main/resources/orm/datastoreidentity/org/apache/jdo/tck/pc/converter/package-standard.orm
@@ -32,6 +32,10 @@
       <datastore-identity strategy="identity" column="DATASTORE_IDENTITY"/>
     </class>
 
+    <class name="PCRectPointTypeAnnotated">
+      <datastore-identity strategy="identity" column="DATASTORE_IDENTITY"/>
+    </class>
+
     <class name="PCPoint" table="PCPointConv">
       <datastore-identity strategy="identity" column="DATASTORE_IDENTITY"/>
       <field name="id" column="ID"/>