mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-05 15:15:44 +02:00
Merge pull request #78 from alejandraferreirovidal/mtaBuildTest
create test files before class - MTABuildTest
This commit is contained in:
commit
f156509484
@ -1,6 +1,9 @@
|
|||||||
import hudson.AbortException
|
import hudson.AbortException
|
||||||
import org.yaml.snakeyaml.Yaml
|
import org.yaml.snakeyaml.Yaml
|
||||||
import org.yaml.snakeyaml.parser.ParserException
|
import org.yaml.snakeyaml.parser.ParserException
|
||||||
|
|
||||||
|
import org.junit.BeforeClass
|
||||||
|
import org.junit.ClassRule
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -16,31 +19,40 @@ import util.Rules
|
|||||||
|
|
||||||
public class MTABuildTest extends BasePipelineTest {
|
public class MTABuildTest extends BasePipelineTest {
|
||||||
|
|
||||||
|
@ClassRule
|
||||||
|
public static TemporaryFolder tmp = new TemporaryFolder()
|
||||||
|
|
||||||
private ExpectedException thrown = new ExpectedException()
|
private ExpectedException thrown = new ExpectedException()
|
||||||
private TemporaryFolder tmp = new TemporaryFolder()
|
|
||||||
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
||||||
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public RuleChain ruleChain = Rules.getCommonRules(this)
|
public RuleChain ruleChain = Rules.getCommonRules(this)
|
||||||
.around(thrown)
|
.around(thrown)
|
||||||
.around(tmp)
|
|
||||||
.around(jlr)
|
.around(jlr)
|
||||||
.around(jscr)
|
.around(jscr)
|
||||||
|
|
||||||
|
private static currentDir
|
||||||
def currentDir
|
private static newDir
|
||||||
def mtaYaml
|
private static mtaYaml
|
||||||
|
|
||||||
def mtaBuildScript
|
def mtaBuildScript
|
||||||
def cpe
|
def cpe
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
static void createTestFiles() {
|
||||||
|
|
||||||
|
currentDir = "${tmp.getRoot()}"
|
||||||
|
mtaYaml = tmp.newFile('mta.yaml')
|
||||||
|
newDir = "$currentDir/newDir"
|
||||||
|
tmp.newFolder('newDir')
|
||||||
|
tmp.newFile('newDir/mta.yaml') << defaultMtaYaml()
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
currentDir = tmp.newFolder().toURI().getPath()[0..-2] //omit final '/'
|
mtaYaml.text = defaultMtaYaml()
|
||||||
mtaYaml = new File("$currentDir/mta.yaml")
|
|
||||||
mtaYaml << defaultMtaYaml()
|
|
||||||
|
|
||||||
helper.registerAllowedMethod('pwd', [], { currentDir } )
|
helper.registerAllowedMethod('pwd', [], { currentDir } )
|
||||||
|
|
||||||
@ -84,20 +96,13 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
@Test
|
@Test
|
||||||
void mtaBuildWithSurroundingDirTest() {
|
void mtaBuildWithSurroundingDirTest() {
|
||||||
|
|
||||||
def newDirName = 'newDir'
|
helper.registerAllowedMethod('pwd', [], { newDir } )
|
||||||
def newDirPath = "$currentDir/$newDirName"
|
|
||||||
def newDir = new File(newDirPath)
|
|
||||||
|
|
||||||
newDir.mkdirs()
|
|
||||||
new File(newDir, 'mta.yaml') << defaultMtaYaml()
|
|
||||||
|
|
||||||
helper.registerAllowedMethod('pwd', [], { newDirPath } )
|
|
||||||
|
|
||||||
def mtarFilePath = mtaBuildScript.call(buildTarget: 'NEO')
|
def mtarFilePath = mtaBuildScript.call(buildTarget: 'NEO')
|
||||||
|
|
||||||
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/
|
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/
|
||||||
|
|
||||||
assert mtarFilePath == "$currentDir/$newDirName/com.mycompany.northwind.mtar"
|
assert mtarFilePath == "$newDir/com.mycompany.northwind.mtar"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -214,7 +219,7 @@ public class MTABuildTest extends BasePipelineTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private defaultMtaYaml() {
|
private static defaultMtaYaml() {
|
||||||
return '''
|
return '''
|
||||||
_schema-version: "2.0.0"
|
_schema-version: "2.0.0"
|
||||||
ID: "com.mycompany.northwind"
|
ID: "com.mycompany.northwind"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user