Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WINDUP-698: JPA tables not resolved for Entity that extends base class
- Loading branch information
Showing
5 changed files
with
167 additions
and
8 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
75 changes: 75 additions & 0 deletions
75
...ts/src/test/java/org/jboss/windup/rules/apps/javaee/tests/DiscoverJPAAnnotationsTest.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,75 @@ | ||
package org.jboss.windup.rules.apps.javaee.tests; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.windup.exec.WindupProcessor; | ||
import org.jboss.windup.exec.configuration.WindupConfiguration; | ||
import org.jboss.windup.graph.GraphContext; | ||
import org.jboss.windup.graph.GraphContextFactory; | ||
import org.jboss.windup.graph.model.ProjectModel; | ||
import org.jboss.windup.graph.model.resource.FileModel; | ||
import org.jboss.windup.graph.service.GraphService; | ||
import org.jboss.windup.rules.apps.java.condition.SourceMode; | ||
import org.jboss.windup.rules.apps.java.config.SourceModeOption; | ||
import org.jboss.windup.rules.apps.javaee.AbstractTest; | ||
import org.jboss.windup.rules.apps.javaee.model.EjbMessageDrivenModel; | ||
import org.jboss.windup.rules.apps.javaee.model.JPAEntityModel; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.inject.Inject; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.UUID; | ||
|
||
/** | ||
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class DiscoverJPAAnnotationsTest extends AbstractTest | ||
{ | ||
@Inject | ||
private WindupProcessor processor; | ||
|
||
@Inject | ||
private GraphContextFactory factory; | ||
|
||
@Test | ||
public void testJPAMetadataExtraction() throws Exception | ||
{ | ||
try (GraphContext context = factory.create(true)) | ||
{ | ||
String inputPath = "src/test/resources/jpa"; | ||
|
||
Path outputPath = Paths.get(FileUtils.getTempDirectory().toString(), "windup_" | ||
+ UUID.randomUUID().toString()); | ||
FileUtils.deleteDirectory(outputPath.toFile()); | ||
Files.createDirectories(outputPath); | ||
|
||
WindupConfiguration windupConfiguration = new WindupConfiguration() | ||
.setGraphContext(context); | ||
windupConfiguration.addInputPath(Paths.get(inputPath)); | ||
windupConfiguration.setOutputDirectory(outputPath); | ||
windupConfiguration.setOptionValue(SourceModeOption.NAME, true); | ||
processor.execute(windupConfiguration); | ||
|
||
GraphService<JPAEntityModel> jpaEntityModelService = new GraphService<>(context, JPAEntityModel.class); | ||
int jpaEntitiesFound = 0; | ||
for (JPAEntityModel jpaEntityModel : jpaEntityModelService.findAll()) | ||
{ | ||
//Assert.assertEquals("ChatBeanDestination", msgDriven.getDestination().getJndiLocation()); | ||
if (jpaEntityModel.getEntityName().equals("SubclassWithDiscriminator")) | ||
Assert.assertEquals("SimpleEntityTable", jpaEntityModel.getTableName()); | ||
else if (jpaEntityModel.getEntityName().equals("BaseEntity")) | ||
Assert.assertEquals("SimpleEntityTable", jpaEntityModel.getTableName()); | ||
else | ||
Assert.fail("Unknown entity found with name: " + jpaEntityModel.getEntityName()); | ||
|
||
jpaEntitiesFound++; | ||
} | ||
Assert.assertEquals(2, jpaEntitiesFound); | ||
} | ||
} | ||
} |
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,8 @@ | ||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name="SimpleEntityTable") | ||
public class BaseEntity { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
rules-java-ee/tests/src/test/resources/jpa/SubclassWithDiscriminator.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,10 @@ | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
import javax.persistence.NamedQuery; | ||
|
||
@Entity | ||
@DiscriminatorValue("DV") | ||
public class SubclassWithDiscriminator extends BaseEntity { | ||
|
||
} |
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