Last active
August 29, 2019 17:06
-
-
Save aksinghdce/cbd04da524b89e3ceedb57cc9cc7da83 to your computer and use it in GitHub Desktop.
input templated XML file and replace the placeholders with random strings of specific length
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
import groovy.text.GStringTemplateEngine | |
def engine = new GStringTemplateEngine() | |
def pool = ['a'..'z','A'..'Z',0..9,'_'].flatten() | |
Random rand = new Random(System.currentTimeMillis()) | |
def orderidChars = (0..10).collect { pool[rand.nextInt(pool.size())] } | |
def order_id = orderidChars.join() | |
vars.put("order_id", "T_"+order_id) | |
def customeremailidlist = vars.getObject("customeremailidlist") | |
def email_id = customeremailidlist[rand.nextInt(customeremailidlist.size())] | |
vars.put("EMAIL_ID", email_id) | |
String fileContents = new File('${SCRIPT_PATH}/data/German.xml').getText('UTF-8') | |
def replacements = [EMAIL_ID:email_id, order_id:"T_"+order_id] | |
def template = engine.createTemplate(fileContents).make(replacements) | |
vars.put('FILE_CONTENT', template.toString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment