How to use match method of org.testingisdocumenting.webtau.cfg.ConfigValue class

Best Webtau code snippet using org.testingisdocumenting.webtau.cfg.ConfigValue.match

Source:HttpJavaTest.java Github

copy

Full Screen

...121 body.get(0).get("k1").should(equal("v1"));122 });123 }124 @Test125 public void matchersBasicExample() {126 http.get("/example", (header, body) -> {127 body.get("year").shouldNot(equal(2000));128 body.get("genres").should(contain("RPG"));129 body.get("rating").shouldBe(greaterThan(7));130 });131 }132 @Test133 public void findOnListAndAssert() {134 http.get("/end-point", ((header, body) -> {135 DataNode found = body.get("complexList").find(node -> node.get("id").get().equals("id1"));136 found.get("k1").should(equal("v1"));137 found.get("k2").should(equal(30));138 }));139 }140 @Test141 public void findAllOnComplexList() {142 http.get("/end-point", ((header, body) -> {143 DataNode found = body.get("complexList").findAll(node -> {144 int k2 = node.get("k2").get();145 return k2 > 20;146 });147 found.get("k1").should(containAll("v1", "v11"));148 }));149 }150 @Test151 public void findAllOnMissingProperty() {152 http.get("/end-point", ((header, body) -> {153 DataNode found = body.get("wrongName").findAll(node -> true);154 assert found.isNull();155 }));156 }157 @Test158 public void findOnListAndReturn() {159 Map<String, ?> found = http.get("/end-point", ((header, body) -> {160 return body.get("complexList").find(node -> node.get("id").get().equals("id1"));161 }));162 actual(found).should(equal(aMapOf("id", "id1", "k1", "v1", "k2", 30))); // doc-exclude163 }164 @Test165 public void equalityMatcher() {166 http.get("/end-point", (header, body) -> {167 body.get("id").shouldNot(equal(0));168 body.get("amount").should(equal(30));169 body.get("list").should(equal(Arrays.asList(1, 2, 3)));170 body.get("object").get("k1").should(equal(171 Pattern.compile("v\\d"))); // regular expression matching172 body.get("object").should(equal(aMapOf(173 "k1", "v1",174 "k3", "v3"))); // matching only specified fields and can be nested multiple times175 body.get("complexList").should(equal(table("k1" , "k2", // matching only specified fields, but number of entries must be exact176 ________________,177 "v1" , 30,178 "v11", 40)));179 });180 http.doc.capture("end-point-object-equality-matchers");181 }182 @Test183 public void equalityMatcherTableKey() {184 http.get("/end-point", (header, body) -> {185 body.get("complexList").should(equal(table("*id", "k1" , "k2", // order agnostic key based match186 ________________,187 "id2", "v11", 40,188 "id1", "v1" , 30)));189 });190 }191 @Test192 public void compareNumbersWithGreaterLessMatchers() {193 http.get("/end-point-numbers", (header, body) -> {194 body.get("id").shouldBe(greaterThan(0));195 body.get("price").shouldBe(greaterThanOrEqual(100));196 body.get("amount").shouldBe(lessThan(150));197 body.get("list").get(1).shouldBe(lessThanOrEqual(2));198 body.get("id").shouldNotBe(lessThanOrEqual(0));199 body.get("price").shouldNotBe(lessThan(100));200 body.get("amount").shouldNotBe(greaterThanOrEqual(150));201 body.get("list").get(1).shouldNotBe(greaterThan(2));202 });203 http.doc.capture("end-point-numbers-matchers");204 }205 @Test206 public void conversionOfNumbers() {207 Map<String, ?> bodyAsMap = http.get("/large-numbers", (header, body) -> {208 body.get("longValue").should(equal(9223372036854775807L));209 body.get("doubleValue").should(equal(100.43));210 body.get("intValue").should(equal(30000));211 return body;212 });213 actual(bodyAsMap.get("longValue").getClass()).should(equal(Long.class));214 actual(bodyAsMap.get("doubleValue").getClass()).should(equal(Double.class));215 actual(bodyAsMap.get("intValue").getClass()).should(equal(Integer.class));216 }217 @Test218 public void containMatcher() {219 http.get("/end-point-list", (header, body) -> {220 body.should(contain(aMapOf(221 "k1", "v1",222 "k2", "v2")));223 body.get(1).get("k2").shouldNot(contain(22));224 });225 http.doc.capture("end-point-list-contain-matchers");226 }227 @Test228 public void containAllMatcher() {229 http.get("/end-point-list", (header, body) -> {230 body.get(1).get("k2").should(containAll(10, 30));231 body.get(1).get("k2").shouldNot(containAll(40, 60, 80));232 });233 http.doc.capture("end-point-list-contain-all-matchers");234 }235 @Test236 public void containContainingAllMatcher() {237 http.get("/prices", (header, body) -> {238 body.get("prices").should(contain(containingAll(10, 30)));239 });240 http.doc.capture("prices-contain-containing-all");241 }242 @Test243 public void workingWithDates() {244 http.get("/end-point-dates", (header, body) -> {245 LocalDate expectedDate = LocalDate.of(2018, 6, 12);246 ZonedDateTime expectedTime = ZonedDateTime.of(expectedDate,247 LocalTime.of(9, 0, 0),248 ZoneId.of("UTC"));249 body.get("tradeDate").should(equal(expectedDate));250 body.get("transactionTime").should(equal(expectedTime));251 body.get("transactionTime").shouldBe(greaterThanOrEqual(expectedDate));252 body.get("paymentSchedule").should(contain(expectedDate));253 });254 http.doc.capture("end-point-dates-matchers");255 }256 @Test257 public void matchersCombo() {258 Pattern withNumber = Pattern.compile("v\\d");259 http.get("/end-point-mixed", (header, body) -> {260 body.get("list").should(contain(lessThanOrEqual(2))); // lessThanOrEqual will be matched against each value261 body.get("object").should(equal(aMapOf(262 "k1", "v1",263 "k3", withNumber))); // regular expression match against k3264 body.get("complexList").get(0).should(equal(aMapOf(265 "k1", "v1",266 "k2", lessThan(120)))); // lessThen match against k2267 body.get("complexList").get(1).should(equal(aMapOf(268 "k1", notEqual("v1"), // any value but v1269 "k2", greaterThanOrEqual(120))));270 TableData expected = table("k1" , "k2", // matching only specified fields, but number of entries must be exact271 ________________________________,272 withNumber , lessThan(120),273 "v11" , greaterThan(150));274 body.get("complexList").should(equal(expected));275 });276 http.doc.capture("end-point-mixing-matchers");277 }278 @Test279 public void compression() {280 http.get("/end-point", (header, body) -> {281 body.get("id").shouldNot(equal(0));282 body.get("amount").should(equal(30));283 header.get("content-encoding").shouldNot(equal("gzip"));284 });285 http.get("/end-point", http.header("Accept-Encoding", "gzip"), (header, body) -> {286 body.get("id").shouldNot(equal(0));287 body.get("amount").should(equal(30));288 header.get("content-encoding").should(equal("gzip"));289 header.get("ContentEncoding").should(equal("gzip"));290 });...

Full Screen

Full Screen

Source:WebTauConfig.java Github

copy

Full Screen

...124 @SuppressWarnings("unchecked")125 public <E> E get(String key) {126 Stream<ConfigValue> allValues =127 Stream.concat(enumeratedCfgValues.values().stream(), freeFormCfgValues.stream());128 Optional<ConfigValue> configValue = allValues.filter(v -> v.match(key)).findFirst();129 return (E) configValue.map(ConfigValue::getAsObject).orElse(null);130 }131 public int getVerbosityLevel() {132 return verbosityLevel.getAsInt();133 }134 public boolean getFullStackTrace() {135 return fullStackTrace.getAsBoolean();136 }137 public int getConsolePayloadOutputLimit() {138 return consolePayloadOutputLimit.getAsInt();139 }140 public void acceptConfigValues(String source, Map<String, ?> values) {141 acceptConfigValues(source, Persona.DEFAULT_PERSONA_ID, values);142 }143 public void acceptConfigValues(String source, String personaId, Map<String, ?> values) {144 enumeratedCfgValues.values().forEach(v -> v.accept(source, personaId, values));145 registerFreeFormCfgValues(values);146 freeFormCfgValues.forEach(v -> v.accept(source, personaId, values));147 }148 // for REPL convenience149 public void setUrl(String url) {150 setBaseUrl(url);151 }152 public void setBaseUrl(String url) {153 setBaseUrl(SOURCE_MANUAL, url);154 }155 public void setBaseUrl(String source, String url) {156 WebTauStep.createAndExecuteStep(157 tokenizedMessage(action("setting"), id("url")),158 stepInput("source", source,159 "url", url),160 () -> tokenizedMessage(action("set"), id("url")),161 () -> this.url.set(source, url));162 }163 public String getBaseUrl() {164 return url.getAsString();165 }166 public String getEnv() {167 return env.getAsString();168 }169 public ConfigValue getEnvConfigValue() {170 return env;171 }172 public ConfigValue getConfigFileNameValue() {173 return config;174 }175 public ConfigValue getWorkingDirConfigValue() {176 return workingDir;177 }178 public ConfigValue getBaseUrlConfigValue() {179 return url;180 }181 public ConfigValue getHttpProxyConfigValue() {182 return httpProxy;183 }184 public boolean isHttpProxySet() {185 return !httpProxy.isDefault();186 }187 public int getWaitTimeout() {188 return waitTimeout.getAsInt();189 }190 public int getHttpTimeout() {191 return httpTimeout.getAsInt();192 }193 public ConfigValue getHttpTimeoutValue() {194 return httpTimeout;195 }196 public boolean shouldFollowRedirects() {197 return !disableFollowingRedirects.getAsBoolean();198 }199 public int maxRedirects() {200 return maxRedirects.getAsInt();201 }202 public String getUserAgent() {203 if (userAgent.isDefault()) {204 return userAgent.getAsString();205 }206 String finalUserAgent = userAgent.getAsString();207 if (!removeWebTauFromUserAgent.getAsBoolean()) {208 String defaultValue = userAgent.getDefaultValue().toString();209 finalUserAgent += " (" + defaultValue + ")";210 }211 return finalUserAgent;212 }213 public ConfigValue getUserAgentConfigValue() {214 return userAgent;215 }216 public void setUserAgent(String userAgent) {217 this.userAgent.set(SOURCE_MANUAL, userAgent);218 }219 public void setRemoveWebTauFromUserAgent(boolean remove) {220 this.removeWebTauFromUserAgent.set(SOURCE_MANUAL, remove);221 }222 public ConfigValue getRemoveWebtauFromUserAgentConfigValue() {223 return removeWebTauFromUserAgent;224 }225 public ConfigValue getDocArtifactsPathConfigValue() {226 return docPath;227 }228 public Path getDocArtifactsPath() {229 return getWorkingDir().resolve(docPath.getAsPath());230 }231 public boolean isAnsiEnabled() {232 return !noColor.getAsBoolean();233 }234 public Path getWorkingDir() {235 return workingDir.getAsPath().toAbsolutePath();236 }237 public Path fullPath(String relativeOrFull) {238 return fullPath(Paths.get(relativeOrFull));239 }240 public Path fullPath(Path relativeOrFull) {241 if (relativeOrFull == null) {242 return null;243 }244 if (relativeOrFull.isAbsolute()) {245 return relativeOrFull;246 }247 return getWorkingDir().resolve(relativeOrFull).toAbsolutePath();248 }249 public Path getCachePath() {250 return cachePath.getAsPath();251 }252 public ConfigValue getCachePathValue() {253 return cachePath;254 }255 public Path getReportPath() {256 return fullPath(reportPath.getAsPath());257 }258 public Path getFailedReportPath() {259 if (failedReportPath.isDefault()) {260 return null;261 }262 return fullPath(failedReportPath.getAsPath());263 }264 public ConfigValue getReportPathConfigValue() {265 return reportPath;266 }267 public String getReportName() {268 return reportName.getAsString();269 }270 public String getReportNameUrl() {271 return reportNameUrl.getAsString();272 }273 public String getWorkingDirConfigName() {274 return workingDir.getKey();275 }276 @Override277 public String toString() {278 return Stream.concat(enumeratedCfgValues.values().stream(), freeFormCfgValues.stream())279 .map(ConfigValue::toString)280 .collect(Collectors.joining("\n"));281 }282 public void printEnumerated() {283 printConfig(ConsoleOutputs.asCombinedConsoleOutput(), enumeratedCfgValues.values());284 }285 private void printConfig(ConsoleOutput console, Collection<ConfigValue> configValues) {286 int maxKeyLength = configValues.stream()287 .filter(ConfigValue::nonDefault)288 .map(v -> v.getKey().length()).max(Integer::compareTo).orElse(0);289 int maxValueLength = configValues.stream()290 .filter(ConfigValue::nonDefault)291 .map(v -> v.getAsString().length()).max(Integer::compareTo).orElse(0);292 configValues.stream().filter(ConfigValue::nonDefault).forEach(v -> {293 String valueAsText = v.getAsString();294 int valuePadding = maxValueLength - valueAsText.length();295 console.out(Color.BLUE, String.format("%" + maxKeyLength + "s", v.getKey()), ": ",296 Color.YELLOW, valueAsText,297 StringUtils.createIndentation(valuePadding),298 FontStyle.NORMAL, " // from ", v.getSource());299 }300 );301 }302 private Stream<WebTauConfigHandler> registeredHandlersAndCore() {303 return Stream.concat(handlers.stream(), Stream.of(coreConfigHandler));304 }305 private void registerFreeFormCfgValues(Map<String, ?> values) {306 Stream<String> keys = values.keySet().stream()307 .filter(k -> noConfigValuePresent(enumeratedCfgValues.values(), k));308 keys.filter(k -> noConfigValuePresent(freeFormCfgValues, k))309 .forEach(k -> {310 ConfigValue configValue = declare(k, "free form cfg value", () -> null);311 freeFormCfgValues.add(configValue);312 });313 }314 private boolean noConfigValuePresent(Collection<ConfigValue> configValues, String key) {315 return configValues.stream().noneMatch(cv -> cv.match(key));316 }317 private static Map<String, ?> systemPropsAsMap() {318 return System.getProperties().stringPropertyNames().stream()319 .collect(Collectors.toMap(n -> n, System::getProperty));320 }321 private static Map<String, ?> envVarsAsMap() {322 return System.getenv();323 }324 private Map<String, ?> convertWebTauEnvVarsToPropNames(Map<String, ?> envVarValues) {325 Map<String, String> result = new LinkedHashMap<>();326 envVarValues.forEach((k, v) -> {327 if (k.startsWith(ConfigValue.ENV_VAR_PREFIX)) {328 result.put(convertToCamelCase(k), v.toString());329 }...

Full Screen

Full Screen

Source:ConfigValue.java Github

copy

Full Screen

...66 } else if (configValues.containsKey(prefixedUpperCaseKey)) {67 set(source, personaId, configValues.get(prefixedUpperCaseKey));68 }69 }70 public boolean match(String configKey) {71 return configKey.equals(key) || configKey.equals(prefixedUpperCaseKey);72 }73 public String getKey() {74 return key;75 }76 public String getPrefixedUpperCaseKey() {77 return prefixedUpperCaseKey;78 }79 public String getDescription() {80 return description;81 }82 public String getSource() {83 return (isDefault() ? "default" : currentOrDefaultPersonaValuesForRead().getFirst().getSourceId());84 }...

Full Screen

Full Screen

match

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.cfg.ConfigValue;2import static org.testingisdocumenting.webtau.cfg.ConfigValue.*;3public class 2 {4 public static void main(String[] args) {5 ConfigValue cv = configValue("webtau.http.port", 80);6 System.out.println(cv.match(80, "80", "default"));7 System.out.println(cv.match(81, "81", "default"));8 }9}10import org.testingisdocumenting.webtau.cfg.ConfigValue;11import static org.testingisdocumenting.webtau.cfg.ConfigValue.*;12public class 3 {13 public static void main(String[] args) {14 ConfigValue cv = configValue("webtau.http.port", 80);15 System.out.println(cv.match(80, "80", "default"));16 System.out.println(cv.match(81, "81", "default"));17 System.out.println(cv.match(82, "82"));18 }19}20import org.testingisdocumenting.webtau.cfg.ConfigValue;21import static org.testingisdocumenting.webtau.cfg.ConfigValue.*;22public class 4 {23 public static void main(String[] args) {24 ConfigValue cv = configValue("webtau.http.port", 80);25 System.out.println(cv.match(80, "80", "default"));26 System.out.println(cv.match(81, "81", "default"));27 System.out.println(cv.match(82, "82"));28 System.out.println(cv.match(83, "83", "default"));29 }30}

Full Screen

Full Screen

match

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.cfg.ConfigValue;2import org.testingisdocumenting.webtau.cfg.WebTauConfig;3import java.net.URL;4public class 2 {5 public static void main(String[] args) {6 WebTauConfig config = WebTauConfig.getCfg();7 ConfigValue url = config.get("server.url");8 url.match(URL.class, (value) -> {9 System.out.println("value is a valid URL: " + value);10 });11 }12}13import org.testingisdocumenting.webtau.cfg.ConfigValue;14import org.testingisdocumenting.webtau.cfg.WebTauConfig;15import java.net.URL;16public class 3 {17 public static void main(String[] args) {18 WebTauConfig config = WebTauConfig.getCfg();19 ConfigValue url = config.get("server.url");20 url.match(URL.class, (value) -> {21 System.out.println("value is a valid URL: " + value);22 }, (value) -> {23 System.out.println("value is not a valid URL: " + value);24 });25 }26}27import org.testingisdocumenting.webtau.cfg.ConfigValue;28import org.testingisdocumenting.webtau.cfg.WebTauConfig;29import java.net.URL;30public class 4 {31 public static void main(String[] args) {32 WebTauConfig config = WebTauConfig.getCfg();33 ConfigValue url = config.get("server.url");34 url.match(URL.class, (value) -> {35 System.out.println("value is a valid URL: " + value);36 }, (value) -> {37 System.out.println("value is not a valid URL: " + value);38 }, (value) -> {39 System.out.println("value is not set");40 });41 }42}

Full Screen

Full Screen

match

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.cfg.ConfigValue;2public class 2 {3 public static void main(String[] args) {4 ConfigValue cv = new ConfigValue("test", "test");5 System.out.println(cv.match("test"));6 System.out.println(cv.match("test2"));7 }8}

Full Screen

Full Screen

match

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.cfg.ConfigValue;2import org.testingisdocumenting.webtau.cfg.WebTauConfig;3import org.testingisdocumenting.webtau.cfg.WebTauConfigHandler;4import org.testingisdocumenting.webtau.cfg.WebTauConfigHandlerOptions;5import org.testingisdocumenting.webtau.cfg.WebTauConfigOptions;6import org.testingisdocumenting.webtau.cfg.WebTauConfigValue;7import org.testingisdocumenting.webtau.cfg.WebTauConfigValueOptions;8import org.testingisdocumenting.webtau.cfg.WebTauConfigValueOptionsBuilder;9import org.testingisdocumenting.webtau.cfg.WebTauConfigValueOptionsMatchOptions;10import org.testingisdocumenting.w

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful