-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JPAQueryBuilder support in Project. (#2212)
Signed-off-by: Tomáš Kraus <[email protected]>
- Loading branch information
1 parent
76e9e04
commit 18b2d9b
Showing
7 changed files
with
217 additions
and
6 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
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
69 changes: 69 additions & 0 deletions
69
...rsistence.core/src/test/java/org/eclipse/persistence/testing/tests/junit/ProjectTest.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,69 @@ | ||
/* | ||
* Copyright (c) 2024 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 | ||
*/ | ||
|
||
// Contributors: | ||
// 07/17/2024-5.0 Tomas Kraus | ||
package org.eclipse.persistence.testing.tests.junit; | ||
|
||
import org.eclipse.persistence.expressions.Expression; | ||
import org.eclipse.persistence.internal.jpa.jpql.HermesParser; | ||
import org.eclipse.persistence.internal.sessions.AbstractSession; | ||
import org.eclipse.persistence.queries.DatabaseQuery; | ||
import org.eclipse.persistence.queries.JPAQueryBuilder; | ||
import org.eclipse.persistence.sessions.Project; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class ProjectTest { | ||
|
||
// Verify that default JPAQueryBuilder returned by Project instance is HermesParser | ||
@Test | ||
public void testDefaultQueryBuilder() { | ||
Project project = new Project(); | ||
JPAQueryBuilder builder = project.getQueryBuilder(); | ||
assertTrue("builder is not an instance of HermesParser class", | ||
HermesParser.class.isAssignableFrom(builder.getClass())); | ||
} | ||
|
||
// Verify that JPAQueryBuilder returned by Project instance matches CustomQueryBuilder | ||
// after CustomQueryBuilder::new is set as JPAQueryBuilder instance factory | ||
@Test | ||
public void testCustomQueryBuilder() { | ||
|
||
class CustomQueryBuilder implements JPAQueryBuilder { | ||
@Override | ||
public void setValidationLevel(String level) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
@Override | ||
public DatabaseQuery buildQuery(CharSequence jpqlQuery, AbstractSession session) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
@Override | ||
public Expression buildSelectionCriteria(String entityName, String selectionCriteria, AbstractSession session) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
@Override | ||
public void populateQuery(CharSequence jpqlQuery, DatabaseQuery query, AbstractSession session) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} | ||
|
||
Project project = new Project(); | ||
project.setQueryBuilderSupplier(CustomQueryBuilder::new); | ||
JPAQueryBuilder builder = project.getQueryBuilder(); | ||
assertTrue("builder is not an instance of CustomQueryBuilder class", | ||
CustomQueryBuilder.class.isAssignableFrom(builder.getClass())); | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
...rsistence.core/src/test/java/org/eclipse/persistence/testing/tests/junit/SessionTest.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,83 @@ | ||
/* | ||
* Copyright (c) 2024 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 | ||
*/ | ||
|
||
// Contributors: | ||
// 07/17/2024-5.0 Tomas Kraus | ||
|
||
package org.eclipse.persistence.testing.tests.junit; | ||
|
||
import org.eclipse.persistence.expressions.Expression; | ||
import org.eclipse.persistence.internal.jpa.jpql.HermesParser; | ||
import org.eclipse.persistence.internal.sessions.AbstractSession; | ||
import org.eclipse.persistence.internal.sessions.DatabaseSessionImpl; | ||
import org.eclipse.persistence.queries.DatabaseQuery; | ||
import org.eclipse.persistence.queries.JPAQueryBuilder; | ||
import org.eclipse.persistence.sessions.Project; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class SessionTest { | ||
|
||
// AbstractSession test. Using DatabaseSessionImpl which does not override tested code. | ||
// Verify that default JPAQueryBuilder returned by session Project instance is HermesParser | ||
@Test | ||
public void testDefaultProjectQueryBuilder() { | ||
AbstractSession session = new DatabaseSessionImpl(); | ||
// Session parent may affect returned JPAQueryBuilder so make sure no one exists | ||
assertNull(session.getParent()); | ||
// Set Project used to initialize JPAQueryBuilder instance | ||
session.setProject(new Project()); | ||
JPAQueryBuilder builder = session.getQueryBuilder(); | ||
assertTrue("builder is not an instance of HermesParser class", | ||
HermesParser.class.isAssignableFrom(builder.getClass())); | ||
} | ||
|
||
// AbstractSession test. Using DatabaseSessionImpl which does not override tested code. | ||
// Verify that JPAQueryBuilder returned by session Project instance matches CustomQueryBuilder | ||
// after CustomQueryBuilder::new is set as JPAQueryBuilder instance factory | ||
@Test | ||
public void testCustomProjectQueryBuilder() { | ||
|
||
class CustomQueryBuilder implements JPAQueryBuilder { | ||
@Override | ||
public void setValidationLevel(String level) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
@Override | ||
public DatabaseQuery buildQuery(CharSequence jpqlQuery, AbstractSession session) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
@Override | ||
public Expression buildSelectionCriteria(String entityName, String selectionCriteria, AbstractSession session) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
@Override | ||
public void populateQuery(CharSequence jpqlQuery, DatabaseQuery query, AbstractSession session) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} | ||
|
||
Project project = new Project(); | ||
project.setQueryBuilderSupplier(CustomQueryBuilder::new); | ||
AbstractSession session = new DatabaseSessionImpl(); | ||
// Session parent may affect returned JPAQueryBuilder so make sure no one exists | ||
assertNull(session.getParent()); | ||
// Set Project used to initialize JPAQueryBuilder instance | ||
session.setProject(project); | ||
JPAQueryBuilder builder = session.getQueryBuilder(); | ||
assertTrue("builder is not an instance of CustomQueryBuilder class", | ||
CustomQueryBuilder.class.isAssignableFrom(builder.getClass())); | ||
} | ||
|
||
} |
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