How to use ConfigValue class of com.tngtech.jgiven.config package

Best JGiven code snippet using com.tngtech.jgiven.config.ConfigValue

Source:Config.java Github

copy

Full Screen

1package com.tngtech.jgiven.impl;2import com.tngtech.jgiven.config.ConfigValue;3import java.io.File;4import java.io.IOException;5import java.io.Reader;6import java.nio.charset.Charset;7import java.nio.file.Files;8import java.nio.file.Paths;9import java.util.Optional;10import java.util.Properties;11import org.slf4j.Logger;12import org.slf4j.LoggerFactory;13/**14 * Helper class to access all system properties to configure JGiven.15 */16public class Config {17 private static final Logger log = LoggerFactory.getLogger(Config.class);18 private static final Config INSTANCE = new Config();19 private static final String TRUE = "true";20 private static final String FALSE = "false";21 private static final String AUTO = "auto";22 private static final String JGIVEN_REPORT_ENABLED = "jgiven.report.enabled";23 public static final String JGIVEN_REPORT_DIR = "jgiven.report.dir";24 private static final String JGIVEN_REPORT_TEXT = "jgiven.report.text";25 private static final String JGIVEN_REPORT_TEXT_COLOR = "jgiven.report.text.color";26 private static final String JGIVEN_FILTER_STACK_TRACE = "jgiven.report.filterStackTrace";27 private static final String JGIVEN_REPORT_DRY_RUN = "jgiven.report.dry-run";28 private static final String JGIVEN_CONFIG_PATH = "jgiven.config.path";29 private static final String JGIVEN_CONFIG_CHARSET = "jgiven.config.charset";30 private final Properties configFileProperties = loadConfigFileProperties();31 public static Config config() {32 return INSTANCE;33 }34 static {35 logDryRunEnabled();36 logReportEnabled();37 }38 static void logDryRunEnabled() {39 if (INSTANCE.dryRun()) {40 log.info("Dry Run enabled.");41 }42 }43 static void logReportEnabled() {44 if (!INSTANCE.isReportEnabled()) {45 log.info("Please note that the report generation is turned off.");46 }47 }48 private Config() {49 }50 private static Properties loadConfigFileProperties() {51 String path = System.getProperty(JGIVEN_CONFIG_PATH, "jgiven.properties");52 String charset = System.getProperty(JGIVEN_CONFIG_CHARSET, "UTF-8");53 Properties properties = new Properties();54 try (Reader reader = Files.newBufferedReader(Paths.get(path), Charset.forName(charset))) {55 properties.load(reader);56 } catch (IOException e) {57 log.debug("config file " + path + " not loaded: " + e.getMessage());58 }59 return properties;60 }61 private String resolveProperty(String name) {62 return resolveProperty(name, null);63 }64 private String resolveProperty(String name, String defaultValue) {65 return System.getProperty(name, configFileProperties.getProperty(name, defaultValue));66 }67 /**68 * Returns the directory set either via a configuration file or a system property.69 * If no value is specified and the surefire test classpath is set, the default maven directory will be used,70 * otherwise a default is returned.71 */72 public Optional<File> getReportDir() {73 String reportDirName = resolveProperty(JGIVEN_REPORT_DIR);74 if (reportDirName == null) {75 if (resolveProperty("surefire.test.class.path") != null) {76 reportDirName = "target/jgiven-reports/json";77 log.info(JGIVEN_REPORT_DIR + " not set, but detected surefire plugin, generating reports to "78 + reportDirName);79 } else {80 reportDirName = "jgiven-reports";81 log.debug(JGIVEN_REPORT_DIR + " not set, using default value jgiven-reports");82 }83 }84 File reportDir = new File(reportDirName);85 if (reportDir.exists() && !reportDir.isDirectory()) {86 log.warn(reportDirName + " exists but is not a directory. Will not generate JGiven reports.");87 return Optional.empty();88 }89 log.debug("Using folder " + reportDirName + " to store JGiven reports");90 return Optional.of(reportDir);91 }92 public boolean isReportEnabled() {93 return TRUE.equalsIgnoreCase(resolveProperty(JGIVEN_REPORT_ENABLED, TRUE));94 }95 public void setReportEnabled(boolean enabled) {96 System.setProperty(JGIVEN_REPORT_ENABLED, "" + enabled);97 }98 public ConfigValue textColorEnabled() {99 return ConfigValue.fromString(resolveProperty(JGIVEN_REPORT_TEXT_COLOR, AUTO));100 }101 public boolean textReport() {102 return TRUE.equalsIgnoreCase(resolveProperty(JGIVEN_REPORT_TEXT, TRUE));103 }104 public void setTextReport(boolean b) {105 System.setProperty(JGIVEN_REPORT_TEXT, "" + b);106 }107 public boolean filterStackTrace() {108 return TRUE.equalsIgnoreCase(resolveProperty(JGIVEN_FILTER_STACK_TRACE, TRUE));109 }110 public void setReportDir(File reportDir) {111 System.setProperty(JGIVEN_REPORT_DIR, reportDir.getAbsolutePath());112 }113 public boolean dryRun() {...

Full Screen

Full Screen

Source:PlainTextReporter.java Github

copy

Full Screen

1package com.tngtech.jgiven.report.text;2import java.io.PrintWriter;3import java.io.StringWriter;4import java.io.UnsupportedEncodingException;5import com.tngtech.jgiven.config.ConfigValue;6import com.tngtech.jgiven.impl.Config;7import com.tngtech.jgiven.impl.util.PrintWriterUtil;8import com.tngtech.jgiven.impl.util.ResourceUtil;9import com.tngtech.jgiven.report.model.ReportModel;10import com.tngtech.jgiven.report.model.ScenarioModel;11/**12 * Generates a plain text report to a PrintStream.13 */14public class PlainTextReporter extends PlainTextWriter {15 private static final ConfigValue COLOR_CONFIG = Config.config().textColorEnabled();16 public static String toString(ScenarioModel scenarioModel) throws UnsupportedEncodingException {17 ReportModel model = new ReportModel();18 model.addScenarioModel(scenarioModel);19 return toString(model);20 }21 public static String toString(ReportModel model) throws UnsupportedEncodingException {22 StringWriter stringWriter = new StringWriter();23 PrintWriter printWriter = new PrintWriter(stringWriter);24 PlainTextReporter textWriter = new PlainTextReporter(printWriter, ConfigValue.FALSE);25 try {26 textWriter.write(model);27 return stringWriter.toString();28 } finally {29 ResourceUtil.close(printWriter);30 }31 }32 public PlainTextReporter() {33 this(COLOR_CONFIG);34 }35 public PlainTextReporter(ConfigValue colorConfig) {36 this(PrintWriterUtil.getPrintWriter(System.out, colorConfig), colorConfig);37 }38 public PlainTextReporter(PrintWriter printWriter, ConfigValue colorConfig) {39 super(printWriter, colorConfig != ConfigValue.FALSE);40 }41 public PlainTextReporter write(ReportModel model) {42 model.accept(this);43 return this;44 }45 @Override46 public void visit(ReportModel multiScenarioModel) {47 writer.println();48 String title = bold("Test Class: ");49 title += multiScenarioModel.getClassName();50 writer.println(title);51 }52 @Override53 public void visit(ScenarioModel scenarioModel) {...

Full Screen

Full Screen

Source:PrintWriterUtil.java Github

copy

Full Screen

1package com.tngtech.jgiven.impl.util;2import java.io.*;3import com.google.common.base.Charsets;4import com.google.common.base.Throwables;5import com.tngtech.jgiven.config.ConfigValue;6public class PrintWriterUtil {7 public static PrintWriter getPrintWriter( File file ) {8 try {9 return new PrintWriter( file, Charsets.UTF_8.name() );10 } catch( Exception e ) {11 throw Throwables.propagate( e );12 }13 }14 public static PrintWriter getPrintWriter( OutputStream outputStream, ConfigValue colorConfig ) {15 OutputStream wrappedStream = outputStream;16 if( colorConfig == ConfigValue.TRUE || colorConfig == ConfigValue.AUTO ) {17 wrappedStream = AnsiUtil.wrapOutputStream( outputStream, colorConfig == ConfigValue.AUTO );18 }19 try {20 return new PrintWriter( new OutputStreamWriter( wrappedStream, Charsets.UTF_8.name() ) );21 } catch( UnsupportedEncodingException e ) {22 throw Throwables.propagate( e );23 }24 }25}...

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.example;2import com.tngtech.jgiven.annotation.ScenarioState;3import com.tngtech.jgiven.config.ConfigValue;4import com.tngtech.jgiven.junit.SimpleScenarioTest;5import org.junit.Test;6public class ConfigValueTest extends SimpleScenarioTest<ConfigValueTest> {7 private ConfigValue configValue;8 public void config_value_can_be_set_from_the_command_line() {9 given().the_config_value_$_is_set_to_$( "myConfigValue", "myValue" );10 then().the_config_value_$_is_$( "myConfigValue", "myValue" );11 }12 public ConfigValueTest the_config_value_$_is_set_to$( String key, String value ) {13 configValue.set( key, value );14 return self();15 }16 public void the_config_value_$_is_$( String key, String expectedValue ) {17 assertThat( configValue.get( key ) ).isEqualTo( expectedValue );18 }19}

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.example;2import com.tngtech.jgiven.annotation.*;3import com.tngtech.jgiven.config.*;4import com.tngtech.jgiven.junit.*;5import org.junit.*;6import org.junit.runner.*;7@RunWith(JGivenClassRunner.class)8public class ConfigValueTest {9 GivenStage given;10 WhenStage when;11 ThenStage then;12 public void testConfigValue() {13 given.some_value_$_is_set_to_$( "foo", 42 );14 when.some_action_is_performed();15 then.some_assertion_is_made( 42 );16 }17 public static class GivenStage extends Stage<GivenStage> {18 public GivenStage some_value_$_is_set_to_$( String key, int value ) {19 ConfigValue.set( key, value );20 return self();21 }22 }23 public static class WhenStage extends Stage<WhenStage> {24 public WhenStage some_action_is_performed() {25 return self();26 }27 }28 public static class ThenStage extends Stage<ThenStage> {29 public ThenStage some_assertion_is_made( int expected ) {30 int actual = ConfigValue.get( "foo" );31 assertThat( actual ).isEqualTo( expected );32 return self();33 }34 }35}36package com.tngtech.jgiven.config;37import java.util.*;38import java.util.concurrent.*;39public class ConfigValue {40 private static final Map<String, Object> values = new ConcurrentHashMap<>();41 public static void set( String key, Object value ) {42 values.put( key, value );43 }44 public static <T> T get( String key ) {45 return (T) values.get( key );46 }47}

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.config.ConfigValue;2import com.tngtech.jgiven.config.JGivenConfiguration;3import com.tngtech.jgiven.report.ReportGenerator;4import com.tngtech.jgiven.report.ReportGenerator$;5import com.tngtech.jgiven.report.config.ReportConfig;6import com.tngtech.jgiven.report.html.HtmlReportGenerator;7import com.tngtech.jgiven.report.json.JsonReportGenerator;8import com.tngtech.jgiven.report.model.ReportModel;9import com.tngtech.jgiven.report.text.PlainTextReportGenerator;10import com.tngtech.jgiven.report.text.TextReportGenerator;11import com.tngtech.jgiven.report.xml.XmlReportGenerator;12import com.tngtech.jgiven.report.xml.XmlReportModel;13import com.tngtech.jgiven.tags.FeatureReport;14import com.tngtech.jgiven.tags.Issue;15import com.tngtech.jgiven.tags.IssueTag;16import com.tngtech.jgiven.tags.IssueTag$;17import com.tngtech.jgiven.tags.IssueTagType;18import com.tngtech.jgive

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.examples;2import java.io.File;3import java.io.FileInputStream;4import java.io.FileNotFoundException;5import java.io.IOException;6import java.io.InputStream;7import java.util.Properties;8import com.tngtech.jgiven.config.ConfigValue;9public class ConfigValueExample {10 public static void main(String[] args) {11 ConfigValue<String> configValue = new ConfigValue<String>("default value");12 configValue.set("value1");13 System.out.println("configValue = " + configValue.get());14 configValue.set("value2");15 System.out.println("configValue = " + configValue.get());16 configValue.set(null);17 System.out.println("configValue = " + configValue.get());18 ConfigValue<String> configValue2 = new ConfigValue<String>("default value");19 configValue2.set("value1");20 System.out.println("configValue2 = " + configValue2.get());21 configValue2.set("value2");22 System.out.println("configValue2 = " + configValue2.get());23 configValue2.set(null);24 System.out.println("configValue2 = " + configValue2.get());25 }26}

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.config.ConfigValue;2import com.tngtech.jgiven.config.JGivenConfiguration;3import com.tngtech.jgiven.config.JGivenConfigurationKey;4public class Path {5 public static void main(String[] args) {6 ConfigValue<String> path = JGivenConfiguration.get().getValue( JGivenConfigurationKey.BASE_DIRECTORY );7 System.out.println(path);8 }9}

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.config.ConfigValue;2import com.tngtech.jgiven.config.JGivenConfiguration;3import com.tngtech.jgiven.config.JGivenConfigurationBuilder;4public class JGivenConfig {5 public static void main(String[] args) {6 JGivenConfigurationBuilder builder = new JGivenConfigurationBuilder();7 builder.set( ConfigValue.OUTPUT_FORMAT, "html" );8 JGivenConfiguration config = builder.build();9 System.out.println("Output format is: " + config.getOutputFormat());10 }11}

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.config.ConfigValue;2import com.tngtech.jgiven.config.JGivenConfiguration;3public class 1 {4public static void main(String[] args) {5JGivenConfiguration conf = JGivenConfiguration.getInstance();6conf.setValue(ConfigValue.BASE_PACKAGE, "com.tngtech.jgiven");7String basePackage = conf.getValue(ConfigValue.BASE_PACKAGE);8}9}

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1package com.tngtech.jgiven.report.config;2import com.tngtech.jgiven.config.ConfigValue;3public class ConfigValueTest {4 public static void main(String[] args) {5 ConfigValue configValue = ConfigValue.of("key", "value");6 System.out.println(configValue);

Full Screen

Full Screen

ConfigValue

Using AI Code Generation

copy

Full Screen

1import com.tngtech.jgiven.config.ConfigValue;2import com.tngtech.jgiven.config.JGivenConfiguration;3public class JGivenConfig {4 public static void main(String[] args) {5 String value = JGivenConfiguration.getValue(ConfigValue.JGIVEN_REPORT_DIR);6 JGivenConfiguration.setValue(ConfigValue.JGIVEN_REPORT_DIR, "C:\\Users\\User\\Desktop\\JGivenReport");7 value = JGivenConfiguration.getValue(ConfigValue.JGIVEN_REPORT_DIR);8 JGivenConfiguration.setValue(ConfigValue.JGIVEN_REPORT_DIR, "C:\\Users\\User\\Desktop\\JGivenReport");9 value = JGivenConfiguration.getValue(ConfigValue.JGIVEN_REPORT_DIR);10 JGivenConfiguration.setValue(ConfigValue.JGIVEN_REPORT_DIR, "C:\\Users\\User\\Desktop\\JGivenReport");11 value = JGivenConfiguration.getValue(ConfigValue.JGIVEN_REPORT_DIR);12 JGivenConfiguration.setValue(ConfigValue.JGIVEN_REPORT_DIR, "C:\\Users\\User\\Desktop\\JGivenReport");13 value = JGivenConfiguration.getValue(ConfigValue.JGIVEN_REPORT_DIR);14 JGivenConfiguration.setValue(ConfigValue.JGIVEN_REPORT_DIR, "C:\\Users\\User\\Desktop\\JGivenReport");15 value = JGivenConfiguration.getValue(ConfigValue.JGIVEN_REPORT_DIR);16 JGivenConfiguration.setValue(ConfigValue.JGIVEN_REPORT_DIR, "C:\\Users\\User\\Desktop\\JGivenReport");17 value = JGivenConfiguration.getValue(ConfigValue.JGIVEN_REPORT_DIR);18 JGivenConfiguration.setValue(ConfigValue.JGIVEN_REPORT_DIR, "C:\\Users\\User\\Desktop\\JGivenReport");19 value = JGivenConfiguration.getValue(ConfigValue.JGIVEN_REPORT_DIR);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run JGiven automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in ConfigValue

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful