-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…time.LocalDateTime - code refactoring plus additional unit test Signed-off-by: Radek Felcman <[email protected]>
- Loading branch information
Showing
9 changed files
with
251 additions
and
44 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
97 changes: 97 additions & 0 deletions
97
...rg/eclipse/persistence/testing/models/jpa/persistence32/UnsupportedVersionTypeEntity.java
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.models.jpa.persistence32; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Version; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.Objects; | ||
|
||
// Bug #2343 | ||
@Entity | ||
@Table(name="PERSISTENCE32_UNSUPPORTED_VERSION_ENTITY") | ||
public class UnsupportedVersionTypeEntity { | ||
|
||
@Id | ||
private int id; | ||
|
||
private Timestamp lastUpdated; | ||
|
||
@Version | ||
private String name; | ||
|
||
public UnsupportedVersionTypeEntity(int id, Timestamp lastUpdated, String name) { | ||
this.id = id; | ||
this.lastUpdated = lastUpdated; | ||
this.name = name; | ||
} | ||
|
||
public UnsupportedVersionTypeEntity() { | ||
this(-1, null, null); | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public Timestamp getLastUpdated() { | ||
return lastUpdated; | ||
} | ||
|
||
public void setLastUpdated(Timestamp lastUpdated) { | ||
this.lastUpdated = lastUpdated; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null || obj.getClass() != this.getClass()) { | ||
return false; | ||
} | ||
return id == ((UnsupportedVersionTypeEntity) obj).id | ||
&& Objects.equals(name, ((UnsupportedVersionTypeEntity) obj).name) | ||
&& Objects.equals(lastUpdated, ((UnsupportedVersionTypeEntity) obj).lastUpdated); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name, lastUpdated); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("InstantVersionEntity {id="); | ||
sb.append(id); | ||
sb.append(", name="); | ||
sb.append(name); | ||
sb.append(", lastUpdated="); | ||
sb.append(lastUpdated); | ||
sb.append("}"); | ||
return sb.toString(); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...a.test.persistence32/src/main/resources/META-INF/persistence-unsupported-version-type.xml
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!-- | ||
Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0 which is available at | ||
http://www.eclipse.org/legal/epl-2.0, | ||
or the Eclipse Distribution License v. 1.0 which is available at | ||
http://www.eclipse.org/org/documents/edl-v10.php. | ||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
--> | ||
|
||
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence | ||
https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd" | ||
version="3.0"> | ||
|
||
<persistence-unit name="persistence32_unsupported_version_type" transaction-type="RESOURCE_LOCAL"> | ||
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> | ||
<class>org.eclipse.persistence.testing.models.jpa.persistence32.UnsupportedVersionTypeEntity</class> | ||
<exclude-unlisted-classes>true</exclude-unlisted-classes> | ||
<properties> | ||
<property name="jakarta.persistence.schema-generation.database.action" value="none"/> | ||
<property name="eclipselink.logging.level" value="${eclipselink.logging.level}"/> | ||
<property name="eclipselink.logging.level.sql" value="${eclipselink.logging.sql.level}"/> | ||
<property name="eclipselink.logging.parameters" value="${eclipselink.logging.parameters}"/> | ||
</properties> | ||
</persistence-unit> | ||
|
||
</persistence> |
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
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
63 changes: 63 additions & 0 deletions
63
.../org/eclipse/persistence/testing/tests/jpa/persistence32/VersionUnsupportedTestSuite.java
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.tests.jpa.persistence32; | ||
|
||
import jakarta.persistence.EntityManagerFactory; | ||
import jakarta.persistence.Persistence; | ||
import junit.framework.Test; | ||
import junit.framework.TestSuite; | ||
import org.eclipse.persistence.config.PersistenceUnitProperties; | ||
import org.eclipse.persistence.exceptions.ValidationException; | ||
import org.eclipse.persistence.testing.framework.jpa.junit.JUnitTestCase; | ||
|
||
import java.util.Properties; | ||
|
||
/** | ||
* Verify jakarta.persistence 3.2 @Version attribute types (unsupported type to get exception) | ||
*/ | ||
public class VersionUnsupportedTestSuite extends JUnitTestCase { | ||
|
||
public VersionUnsupportedTestSuite(String name) { | ||
super(name); | ||
} | ||
|
||
public static Test suite() { | ||
TestSuite suite = new TestSuite("VersionUnsupportedTestSuite"); | ||
suite.addTest(new VersionUnsupportedTestSuite("testPersistUnsupportedVersionTypeEntity")); | ||
return suite; | ||
} | ||
|
||
|
||
@Override | ||
public String getPersistenceUnitName() { | ||
return "persistence32_unsupported_version_type"; | ||
} | ||
|
||
public void testPersistUnsupportedVersionTypeEntity() { | ||
//Special persistence.xml file is needed due a EclipseLink JPA agent | ||
Properties properties = new Properties(); | ||
properties.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistence-unsupported-version-type.xml"); | ||
try (EntityManagerFactory emf = Persistence.createEntityManagerFactory(getPersistenceUnitName(), properties)){ | ||
fail("Attempt to continue with unsupported version type shall fail during EntityManagerFactory creation."); | ||
} catch (Exception ex) { | ||
Throwable cause = ex; | ||
while(cause.getCause() != null && cause.getCause() != cause) { | ||
cause = cause.getCause(); | ||
if (cause instanceof ValidationException) { | ||
assertTrue(cause.getMessage().contains("is not valid for a version property")); | ||
return; | ||
} | ||
} | ||
fail("Attempt to continue with unsupported version type shall fail as ValidationException was not detected."); | ||
} | ||
} | ||
} |
Oops, something went wrong.