Fixes folder names for generated tests

without this change the generated tests reference a package that is not actually resolved to a proper folder. That's because we're not escaping the folder name properly
with this change we ensure that all folders have good name

fixes gh-836
fixes gh-850
This commit is contained in:
Marcin Grzejszczak
2019-01-14 20:19:01 +01:00
parent 4b028ea48a
commit 9d538b7393
10 changed files with 188 additions and 7 deletions

View File

@@ -212,7 +212,7 @@ class SingleTestGeneratorSpec extends Specification {
int size = new TestGenerator(properties).generate()
then:
size > 0
asserter(new File(newFolder.parent, '/org/springframework/cloud/contract/verifier/tests/com_uscm/dale_api44_spec/0_1_0_dev_1_uncommitted_d1174dd/' + testName).text)
asserter(new File(newFolder.parent, '/org/springframework/cloud/contract/verifier/tests/com_uscm/dale_api44_spec/_0_1_0_dev_1_uncommitted_d1174dd/' + testName).text)
where:
testFramework | mode | asserter | testName
JUNIT | MOCKMVC | JAVA_ASSERTER | 'ContractsTest.java'

View File

@@ -1,12 +1,17 @@
package org.springframework.cloud.contract.verifier.util
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
import org.springframework.util.FileSystemUtils
/**
* @author Marcin Grzejszczak
*/
class NamesUtilSpec extends Specification {
@Rule TemporaryFolder folder = new TemporaryFolder()
def "should return the whole string before the last one"() {
given:
String string = "a.b.c.d.e"
@@ -98,6 +103,13 @@ class NamesUtilSpec extends Specification {
NamesUtil.directoryToPackage(string) == "a.b.c._1_0_0.e"
}
def "should convert a directory notation to package when folder is only a digit"() {
given:
String string = "1.0.0"
expect:
NamesUtil.directoryToPackage(string) == "_1_0_0"
}
def "should convert all illegal package chars to legal ones"() {
given:
String string = "a-b c.1.0.x+d1174dd"
@@ -111,4 +123,30 @@ class NamesUtilSpec extends Specification {
expect:
NamesUtil.convertIllegalMethodNameChars(string) == '10a_b_c_1_0_x_d1174$dd'
}
def "should recursively convert the names of folders to package names"() {
given:
File tmp = folder.newFolder()
URL resource = getClass().getResource("/prependFolderName")
File folder = new File(resource.toURI())
FileSystemUtils.copyRecursively(folder, tmp)
when:
NamesUtil.recrusiveDirectoryToPackage(tmp)
then:
new File(tmp, "META-INF/1_0_0_SNAPSHOT").exists() == false
new File(tmp, "META-INF/2_0_0_SNAPSHOT").exists() == false
new File(tmp, "META-INF/1_0_0_SNAPSHOT/3_0_0_SNAPSHOT").exists() == false
new File(tmp, "META-INF/_1_0_0_SNAPSHOT").exists() == true
new File(tmp, "META-INF/_2_0_0_SNAPSHOT").exists() == true
new File(tmp, "META-INF/_1_0_0_SNAPSHOT/_3_0_0_SNAPSHOT").exists() == true
new File(tmp, "META-INF/_1_0_0_SNAPSHOT/normal").exists() == true
new File(tmp, "META-INF/_1_0_0_SNAPSHOT/_3_0_0_SNAPSHOT/normal").exists() == true
}
def "should not throw exception if folder does not exist"() {
when:
NamesUtil.recrusiveDirectoryToPackage(new File("I/do/not/exist"))
then:
noExceptionThrown()
}
}

View File

@@ -0,0 +1,16 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* 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
*
* http://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.
*/

View File

@@ -0,0 +1,16 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* 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
*
* http://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.
*/

View File

@@ -0,0 +1,16 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* 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
*
* http://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.
*/

View File

@@ -0,0 +1,16 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* 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
*
* http://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.
*/

View File

@@ -0,0 +1,16 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* 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
*
* http://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.
*/