github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/com/sap/piper/tools/neo/NeoCommandHelperTest.groovy (about)

     1  package com.sap.piper.tools.neo
     2  
     3  import org.junit.Assert
     4  import org.junit.Rule
     5  import org.junit.Test
     6  import org.junit.rules.RuleChain
     7  import util.BasePiperTest
     8  import util.JenkinsFileExistsRule
     9  import util.Rules
    10  
    11  class NeoCommandHelperTest extends BasePiperTest {
    12  
    13  
    14      private JenkinsFileExistsRule fileExistsRule = new JenkinsFileExistsRule(this, ['file.mta', 'file.war', 'file.properties'])
    15      @Rule
    16      public RuleChain rules = Rules
    17          .getCommonRules(this)
    18          .around(fileExistsRule)
    19  
    20      NeoCommandHelper getTestFixture(DeployMode deployMode, Set extensions = []) {
    21  
    22          Map deploymentConfiguration = [
    23              host          : 'host_value',
    24              account       : 'account_value',
    25              application   : 'application_value',
    26              environment   : [ENV1: 'value1', ENV2: 'value2'],
    27              vmArguments   : '-Dargument1=value1 -Dargument2=value2',
    28              runtime       : 'neо-javaee6-wp',
    29              runtimeVersion: '2',
    30              size          : 'lite',
    31              propertiesFile: 'file.properties',
    32              azDistribution: '2'
    33          ]
    34  
    35          String source = (deployMode == DeployMode.MTA) ? 'file.mta' : 'file.war'
    36          String username = 'username'
    37          String password = 'password'
    38  
    39          nullScript.STEP_NAME="neoDeploy"
    40  
    41          return new NeoCommandHelper(
    42              nullScript,
    43              deployMode,
    44              deploymentConfiguration,
    45              extensions,
    46              username,
    47              password,
    48              source
    49          )
    50      }
    51  
    52      @Test
    53      void testStatusCommand() {
    54          String actual = getTestFixture(DeployMode.WAR_PARAMS).statusCommand()
    55          String expected = "neo.sh status --host 'host_value' --account 'account_value' " +
    56              "--application 'application_value' --user 'username' --password 'password'"
    57          Assert.assertEquals(expected, actual)
    58      }
    59  
    60      @Test
    61      void testStatusCommandForProperties() {
    62          String actual = getTestFixture(DeployMode.WAR_PROPERTIES_FILE).statusCommand()
    63          String expected = "neo.sh status file.properties --user 'username' --password 'password'"
    64          Assert.assertEquals(expected, actual)
    65      }
    66  
    67      @Test
    68      void testRollingUpdateCommand() {
    69          String actual = getTestFixture(DeployMode.WAR_PARAMS).rollingUpdateCommand()
    70          String basicCommand = "neo.sh rolling-update --host 'host_value' --account 'account_value' " +
    71              "--application 'application_value' --user 'username' --password 'password' --source 'file.war'"
    72  
    73          Assert.assertTrue(actual.contains(basicCommand))
    74          Assert.assertTrue(actual.contains(' --ev \'ENV1\'=\'value1\' --ev \'ENV2\'=\'value2\''))
    75          Assert.assertTrue(actual.contains(' --vm-arguments \'-Dargument1=value1 -Dargument2=value2\''))
    76          Assert.assertTrue(actual.contains('--runtime \'neо-javaee6-wp\''))
    77          Assert.assertTrue(actual.contains(' --runtime-version \'2\''))
    78          Assert.assertTrue(actual.contains(' --size \'lite\''))
    79          Assert.assertTrue(actual.contains(' --az-distribution \'2\''))
    80      }
    81  
    82      @Test
    83      void testRollingUpdateCommandForProperties() {
    84          String actual = getTestFixture(DeployMode.WAR_PROPERTIES_FILE).rollingUpdateCommand()
    85          String expected = "neo.sh rolling-update file.properties --user 'username' --password 'password' --source 'file.war' "
    86          Assert.assertEquals(expected, actual)
    87      }
    88  
    89      @Test
    90      void testDeployCommand() {
    91          String actual = getTestFixture(DeployMode.WAR_PARAMS).deployCommand()
    92          String basicCommand = "neo.sh deploy --host 'host_value' --account 'account_value' " +
    93              "--application 'application_value' --user 'username' --password 'password' --source 'file.war'"
    94  
    95          Assert.assertTrue(actual.contains(basicCommand))
    96          Assert.assertTrue(actual.contains(' --ev \'ENV1\'=\'value1\' --ev \'ENV2\'=\'value2\''))
    97          Assert.assertTrue(actual.contains(' --vm-arguments \'-Dargument1=value1 -Dargument2=value2\''))
    98          Assert.assertTrue(actual.contains(' --runtime \'neо-javaee6-wp\''))
    99          Assert.assertTrue(actual.contains(' --runtime-version \'2\''))
   100          Assert.assertTrue(actual.contains(' --size \'lite\''))
   101          Assert.assertTrue(actual.contains(' --az-distribution \'2\''))
   102      }
   103  
   104      @Test
   105      void testDeployCommandForProperties() {
   106          String actual = getTestFixture(DeployMode.WAR_PROPERTIES_FILE).deployCommand()
   107          String expected = "neo.sh deploy file.properties --user 'username' --password 'password' --source 'file.war' "
   108          Assert.assertEquals(expected, actual)
   109      }
   110  
   111      @Test
   112      void testRestartCommand() {
   113          String actual = getTestFixture(DeployMode.WAR_PARAMS).restartCommand()
   114          String expected = "neo.sh restart --synchronous --host 'host_value' --account 'account_value' " +
   115              "--application 'application_value' --user 'username' --password 'password'"
   116          Assert.assertEquals(expected, actual)
   117      }
   118  
   119      @Test
   120      void testRestartCommandForProperties() {
   121          String actual = getTestFixture(DeployMode.WAR_PROPERTIES_FILE).restartCommand()
   122          String expected = "neo.sh restart --synchronous file.properties --user 'username' --password 'password'"
   123          Assert.assertEquals(expected, actual)
   124      }
   125  
   126      @Test
   127      void deployMta() {
   128          String actual = getTestFixture(DeployMode.MTA, (Set)['myExtension1.yml', 'myExtension2.yml']).deployMta()
   129          String expected = "neo.sh deploy-mta --synchronous --host 'host_value' --account 'account_value' " +
   130              "--user 'username' --password 'password' --extensions 'myExtension1.yml','myExtension2.yml' --source 'file.mta'"
   131          Assert.assertEquals(expected, actual)
   132      }
   133  }