-
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.
- Loading branch information
Showing
11 changed files
with
749 additions
and
504 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
33 changes: 33 additions & 0 deletions
33
examples/micronaut-grails-example/grails-app/domain/micronaut/grails/example/Vehicle.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,33 @@ | ||
/* | ||
* 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 micronaut.grails.example | ||
|
||
class Vehicle { | ||
|
||
String name | ||
|
||
String make | ||
String model | ||
|
||
static constraints = { | ||
name maxSize: 255 | ||
make inList: ['Ford', 'Chevrolet', 'Nissan'] | ||
model nullable: true | ||
} | ||
|
||
} |
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
66 changes: 66 additions & 0 deletions
66
...grails-example/src/test/groovy/micronaut/grails/example/MicronautJdbcGeneratorSpec.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,66 @@ | ||
/* | ||
* 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 micronaut.grails.example | ||
|
||
// tag::body[] | ||
import com.agorapulse.micronaut.grails.jpa.generator.MicronautJdbcGenerator | ||
import com.agorapulse.micronaut.grails.test.MicronautGrailsIntegration | ||
import com.agorapulse.testing.fixt.Fixt | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import spock.lang.Specification | ||
|
||
@MicronautGrailsIntegration | ||
class MicronautJdbcGeneratorSpec extends Specification { | ||
|
||
Fixt fixt = Fixt.create(MicronautJdbcGeneratorSpec) | ||
|
||
@Autowired MicronautJdbcGenerator generator | ||
|
||
void 'generate domains'() { | ||
given: | ||
File root = initRootDirectory() | ||
when: | ||
generator.generate(root) | ||
then: | ||
noExceptionThrown() | ||
|
||
when: | ||
File entityFile = new File(root, 'micronaut/grails/example/Vehicle.groovy') | ||
File repositoryFile = new File(root, 'micronaut/grails/example/VehicleRepository.groovy') | ||
then: | ||
entityFile.exists() | ||
entityFile.text.trim() == fixt.readText('Vehicle.groovy.txt').trim() | ||
|
||
repositoryFile.exists() | ||
repositoryFile.text.trim() == fixt.readText('VehicleRepository.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[] |
37 changes: 37 additions & 0 deletions
37
...src/test/resources/micronaut/grails/example/MicronautJdbcGeneratorSpec/Vehicle.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,37 @@ | ||
package micronaut.grails.example | ||
|
||
import groovy.transform.CompileStatic | ||
import javax.annotation.Nullable | ||
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.Pattern | ||
import javax.validation.constraints.Size | ||
|
||
@Entity | ||
@CompileStatic | ||
class Vehicle { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
Long id | ||
|
||
@Version | ||
Long version | ||
|
||
@NotNull | ||
@Pattern(regexp = 'Ford|Chevrolet|Nissan') | ||
@Size(max = 255) | ||
String make | ||
|
||
@Nullable | ||
@Size(max = 255) | ||
String model | ||
|
||
@NotNull | ||
@Size(max = 255) | ||
String name | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...esources/micronaut/grails/example/MicronautJdbcGeneratorSpec/VehicleRepository.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,10 @@ | ||
package micronaut.grails.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.MYSQL) | ||
interface VehicleRepository extends CrudRepository<Vehicle, Long> { | ||
|
||
} |
Oops, something went wrong.