-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix schema generator when mapped entity contains property placeholder (…
…#3237) * Fix schema generator when mapped entity contains property placeholder * Fix tests * Fix tests and move to jdbc-example-java * Try to improve test coverage
- Loading branch information
1 parent
b0216d0
commit fa9d9f7
Showing
7 changed files
with
81 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
3 changes: 3 additions & 0 deletions
3
...jdbc/src/test/groovy/io/micronaut/data/jdbc/h2/identity/SameIdentityRepositorySpec.groovy
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
13 changes: 13 additions & 0 deletions
13
doc-examples/jdbc-example-java/src/main/java/example/CustomEntity.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,13 @@ | ||
package example; | ||
|
||
import io.micronaut.data.annotation.GeneratedValue; | ||
import io.micronaut.data.annotation.Id; | ||
import io.micronaut.data.annotation.MappedEntity; | ||
|
||
@MappedEntity("${entity.prefix}entity") | ||
public record CustomEntity( | ||
@Id | ||
@GeneratedValue | ||
Long id, | ||
String name) { | ||
} |
9 changes: 9 additions & 0 deletions
9
doc-examples/jdbc-example-java/src/main/java/example/CustomEntityRepository.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,9 @@ | ||
package example; | ||
|
||
import io.micronaut.data.jdbc.annotation.JdbcRepository; | ||
import io.micronaut.data.model.query.builder.sql.Dialect; | ||
import io.micronaut.data.repository.CrudRepository; | ||
|
||
@JdbcRepository(dialect = Dialect.H2) | ||
public interface CustomEntityRepository extends CrudRepository<CustomEntity, Long> { | ||
} |
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 |
---|---|---|
|
@@ -6,3 +6,5 @@ datasources: | |
password: '' | ||
schema-generate: CREATE_DROP | ||
dialect: H2 | ||
entity: | ||
prefix: demo_ |
24 changes: 24 additions & 0 deletions
24
doc-examples/jdbc-example-java/src/test/java/example/CustomEntityRepositorySpec.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,24 @@ | ||
package example; | ||
|
||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@MicronautTest | ||
class CustomEntityRepositorySpec { | ||
|
||
@Inject | ||
CustomEntityRepository repository; | ||
|
||
@Test | ||
void testSaveAndFind() { | ||
CustomEntity entity = repository.save(new CustomEntity(null, "Entity1")); | ||
CustomEntity found = repository.findById(entity.id()).orElse(null); | ||
Assertions.assertNotNull(found); | ||
Assertions.assertEquals(entity.name(), found.name()); | ||
Assertions.assertEquals(1, repository.count()); | ||
Assertions.assertFalse(repository.findAll().isEmpty()); | ||
repository.deleteAll(); | ||
} | ||
} |