-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test generating from Micronaut (#19)
* example of using the generator with Micronaut * added forgotten test fixtures * Revert "added forgotten test fixtures" This reverts commit 2ee3c5e. * added javadoc (fixed violation)
- Loading branch information
Showing
7 changed files
with
137 additions
and
1 deletion.
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
75 changes: 75 additions & 0 deletions
75
...rary/src/test/groovy/com/agorapulse/micronaut/grails/domain/MicronautGeneratorSpec.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2020 Vladimir Orany. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.agorapulse.micronaut.grails.domain | ||
|
||
// tag::body[] | ||
import com.agorapulse.micronaut.grails.jpa.generator.MicronautJpaGenerator | ||
import com.agorapulse.testing.fixt.Fixt | ||
import io.micronaut.context.ApplicationContext | ||
import org.grails.datastore.gorm.validation.constraints.eval.DefaultConstraintEvaluator | ||
import org.grails.orm.hibernate.HibernateDatastore | ||
import spock.lang.AutoCleanup | ||
import spock.lang.Specification | ||
|
||
/** | ||
* Example specification generating JPA entities from GORM entities. | ||
*/ | ||
class MicronautGeneratorSpec extends Specification { | ||
|
||
Fixt fixt = Fixt.create(MicronautGeneratorSpec) | ||
|
||
@AutoCleanup ApplicationContext context = ApplicationContext.run() | ||
|
||
MicronautJpaGenerator generator = new MicronautJpaGenerator( | ||
context.getBean(HibernateDatastore), | ||
new DefaultConstraintEvaluator() | ||
) | ||
|
||
void 'generate domains'() { | ||
given: | ||
File root = initRootDirectory() | ||
when: | ||
generator.generate(root) | ||
then: | ||
noExceptionThrown() | ||
|
||
when: | ||
File entityFile = new File(root, 'com/agorapulse/micronaut/grails/domain/Manager.groovy') | ||
File repositoryFile = new File(root, 'com/agorapulse/micronaut/grails/domain/ManagerRepository.groovy') | ||
then: | ||
entityFile.exists() | ||
entityFile.text.trim() == fixt.readText('Manager.groovy.txt').trim() | ||
|
||
repositoryFile.exists() | ||
repositoryFile.text.trim() == fixt.readText('ManagerRepository.groovy.txt').trim() | ||
} | ||
|
||
private static File initRootDirectory() { | ||
File root = new File(System.getProperty('java.io.tmpdir'), 'micronaut-data-model') | ||
|
||
if (root.exists()) { | ||
root.deleteDir() | ||
} | ||
|
||
root.mkdirs() | ||
|
||
return root | ||
} | ||
|
||
} | ||
// end::body[] |
7 changes: 7 additions & 0 deletions
7
examples/micronaut-grails-domain-library/src/test/resources/application-test.yml
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,7 @@ | ||
dataSource: | ||
dbCreate: "create-drop" | ||
url: "jdbc:tc:mariadb:10.5.10:///test?useSSL=false" | ||
driverClassName: "org.testcontainers.jdbc.ContainerDatabaseDriver" | ||
dialect: org.hibernate.dialect.MySQL5InnoDBDialect | ||
username: "username" | ||
password: "password" |
26 changes: 26 additions & 0 deletions
26
...esources/com/agorapulse/micronaut/grails/domain/MicronautGeneratorSpec/Manager.groovy.txt
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,26 @@ | ||
package com.agorapulse.micronaut.grails.domain | ||
|
||
import groovy.transform.CompileStatic | ||
import javax.persistence.Entity | ||
import javax.persistence.GeneratedValue | ||
import javax.persistence.GenerationType | ||
import javax.persistence.Id | ||
import javax.persistence.Version | ||
import javax.validation.constraints.NotNull | ||
import javax.validation.constraints.Size | ||
|
||
@Entity | ||
@CompileStatic | ||
class Manager { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
Long id | ||
|
||
@Version | ||
Long version | ||
|
||
@NotNull | ||
@Size(max = 255) | ||
String name | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...om/agorapulse/micronaut/grails/domain/MicronautGeneratorSpec/ManagerRepository.groovy.txt
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 com.agorapulse.micronaut.grails.domain | ||
|
||
import io.micronaut.data.annotation.Repository | ||
import io.micronaut.data.repository.CrudRepository | ||
|
||
@Repository | ||
interface ManagerRepository extends CrudRepository<Manager, 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