-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generated java tests now passes with unique validation #9669
Merged
pascalgrimaud
merged 5 commits into
jhipster:master
from
Gabrui:9666-java-tests-fail-with-unique-validation
May 8, 2019
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c69ff6
generated java tests now passes with unique validation
Gabrui e084ffa
Fix the imports for no-sql databases
Gabrui e53851a
add test to capture the unique constraint bug
Gabrui ce2d80e
minor grammar and documentation fixes
Gabrui f164692
Polish with missing space
pascalgrimaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -35,6 +35,15 @@ import org.springframework.security.test.context.TestSecurityContextHolder; | |
import java.io.IOException; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeParseException; | ||
<%_ if (databaseType === 'sql') { _%> | ||
import java.util.List; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.TypedQuery; | ||
import javax.persistence.criteria.CriteriaBuilder; | ||
import javax.persistence.criteria.CriteriaQuery; | ||
import javax.persistence.criteria.Root; | ||
<%_ } _%> | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
@@ -164,5 +173,23 @@ public final class TestUtil { | |
return dfcs; | ||
} | ||
|
||
<%_ if (databaseType === 'sql') { _%> | ||
/** | ||
* Makes a an executes a query to the EntityManager finding all stored objects. | ||
* @param <T> The type of objects to be searched | ||
* @param em The instance of the EntityManager | ||
* @param clss The class type to be searched | ||
* @return A list of all found objects of the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
public static <T> List<T> findAll(EntityManager em, Class<T> clss) { | ||
CriteriaBuilder cb = em.getCriteriaBuilder(); | ||
CriteriaQuery<T> cq = cb.createQuery(clss); | ||
Root<T> rootEntry = cq.from(clss); | ||
CriteriaQuery<T> all = cq.select(rootEntry); | ||
TypedQuery<T> allQuery = em.createQuery(all); | ||
return allQuery.getResultList(); | ||
} | ||
<%_ } _%> | ||
|
||
private TestUtil() {} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be:
Create an <% if (fieldStatus === 'UPDATED_') { %>updated <% } %>entity for this test.
Otherwise, we can have:
* Create an entity for this test.
, with 2 spaces betweenan
andentity