11/*
2- * Copyright 2019 the original authors
2+ * Copyright 2019-2020 the original authors
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -18,7 +18,9 @@ package com.github.hauner.openapi.generatr
1818
1919import com.github.difflib.DiffUtils
2020import com.github.difflib.UnifiedDiffUtils
21+ import com.github.hauner.openapi.spring.generatr.MappingReader
2122import com.github.hauner.openapi.spring.generatr.SpringGeneratr
23+ import com.github.hauner.openapi.spring.generatr.mapping.Mapping
2224import groovy.io.FileType
2325import org.junit.Rule
2426import org.junit.Test
@@ -32,6 +34,11 @@ abstract class GeneratrTestBase {
3234 @Rule
3335 public TemporaryFolder folder = new TemporaryFolder ()
3436
37+ String DEFAULT_OPTIONS = """ \
38+ options:
39+ package-name: generated
40+ """ ;
41+
3542 TestSet testSet
3643
3744 GeneratrTestBase (TestSet testSet ) {
@@ -41,23 +48,27 @@ abstract class GeneratrTestBase {
4148 @Test
4249 void " generatr creates expected files for api set " () {
4350 def source = testSet. name
44- def packageName = ' generated'
45- def expectedPath = [' .' , ' src' , ' testInt' , ' resources' , source, packageName]. join(File . separator)
46- def generatedPath = [folder. root. absolutePath, packageName]. join(File . separator)
4751
4852 def generatr = new SpringGeneratr ()
4953 def options = [
5054 apiPath : " ./src/testInt/resources/${ source} /openapi.yaml" ,
51- targetDir : folder. root,
52- packageName : packageName,
53- beanValidation : testSet. beanValidation
55+ targetDir : folder. root
5456 ]
5557
56- def mapping = new File (" ./src/testInt/resources/${ source} /mapping.yaml" )
57- if (mapping. exists ()) {
58- options. typeMappings = mapping
58+ def mappingYaml = new File (" ./src/testInt/resources/${ source} /mapping.yaml" )
59+ if (mappingYaml. exists ()) {
60+ options. mapping = mappingYaml
61+ } else {
62+ options. mapping = DEFAULT_OPTIONS
5963 }
6064
65+ def reader = new MappingReader ()
66+ Mapping mapping = reader. read (options. mapping as String )
67+
68+ def packageName = mapping. options. packageName
69+ def expectedPath = [' .' , ' src' , ' testInt' , ' resources' , source, packageName]. join(File . separator)
70+ def generatedPath = [folder. root. absolutePath, packageName]. join(File . separator)
71+
6172 when :
6273 generatr. run (options)
6374
0 commit comments