Best EvoMaster code snippet using org.evomaster.client.java.instrumentation.ExternalServiceInfo.copy
Source:AdditionalInfo.java
1package org.evomaster.client.java.instrumentation;2import org.evomaster.client.java.instrumentation.shared.StringSpecializationInfo;3import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer;4import org.evomaster.client.java.utils.SimpleLogger;5import java.io.Serializable;6import java.util.*;7import java.util.concurrent.ConcurrentHashMap;8import java.util.concurrent.CopyOnWriteArraySet;9/**10 * Besides code coverage, there can be additional info that we want11 * to collect at runtime when test cases are executed.12 */13public class AdditionalInfo implements Serializable {14 /**15 * In REST APIs, it can happen that some query parameters do not16 * appear in the schema if they are indirectly accessed via17 * objects like WebRequest.18 * But we can track at runtime when such kind of objects are used19 * to access the query parameters20 */21 private final Set<String> queryParameters = new CopyOnWriteArraySet<>();22 /**23 * In REST APIs, it can happen that some HTTP headers do not24 * appear in the schema if they are indirectly accessed via25 * objects like WebRequest.26 * But we can track at runtime when such kind of objects are used27 * to access the query parameters28 */29 private final Set<String> headers = new CopyOnWriteArraySet<>();30 /**31 * Map from taint input name to string specializations for it32 */33 private final Map<String, Set<StringSpecializationInfo>> stringSpecializations = new ConcurrentHashMap<>();34 private static class StatementDescription implements Serializable{35 public final String line;36 public final String method;37 public StatementDescription(String line, String method) {38 this.line = line;39 this.method = method;40 }41 }42 /**43 * Keep track of the last executed statement done in the SUT.44 * But not in the third-party libraries, just the business logic of the SUT.45 * The statement is represented with a descriptive unique id, like the class name and line number.46 *47 * We need to use a stack to handle method call invocations, as we can know when a statement48 * starts, but not so easily when it ends.49 * For example:50 * foo(bar(), x.npe)51 * here, if x is null, we would end up wrongly marking the last line in bar() as last-statement,52 * whereas it should be the one for foo()53 *54 * Furthermore, we need a stack per execution thread, based on their name.55 */56 private final Map<String, Deque<StatementDescription>> lastExecutedStatementStacks = new ConcurrentHashMap<>();57 /**58 * To keep track of external service hosts called by the SUT.59 * When captured mock hostname will be empty, till the WireMock instance60 * initiated.61 */62 private final Set<ExternalServiceInfo> externalServices = new CopyOnWriteArraySet<>();63 /**64 * In case we pop all elements from stack, keep track of last one separately.65 */66 private StatementDescription noExceptionStatement = null;67 /**68 * Check if the business logic of the SUT (and not a third-party library) is69 * accessing the raw bytes of HTTP body payload (if any) directly70 */71 private boolean rawAccessOfHttpBodyPayload = false;72 /**73 * The name of all DTO that have been parsed (eg, with GSON and Jackson).74 * Note: the actual content of schema is queried separately.75 * Reasons: does not change (DTO classes are static), and quite expensive76 * to send at each action evaluation77 */78 private final Set<String> parsedDtoNames = new CopyOnWriteArraySet<>();79 private String lastExecutingThread = null;80 private final Set<SqlInfo> sqlInfoData = new CopyOnWriteArraySet<>();81 public Set<SqlInfo> getSqlInfoData(){82 return Collections.unmodifiableSet(sqlInfoData);83 }84 public void addSqlInfo(SqlInfo info){85 sqlInfoData.add(info);86 }87 public Set<String> getParsedDtoNamesView(){88 return Collections.unmodifiableSet(parsedDtoNames);89 }90 public void addParsedDtoName(String name){91 parsedDtoNames.add(name);92 }93 public boolean isRawAccessOfHttpBodyPayload() {94 return rawAccessOfHttpBodyPayload;95 }96 public void setRawAccessOfHttpBodyPayload(boolean rawAccessOfHttpBodyPayload) {97 this.rawAccessOfHttpBodyPayload = rawAccessOfHttpBodyPayload;98 }99 public void addSpecialization(String taintInputName, StringSpecializationInfo info){100 if(!ExecutionTracer.getTaintType(taintInputName).isTainted()){101 throw new IllegalArgumentException("No valid input name: " + taintInputName);102 }103 Objects.requireNonNull(info);104 stringSpecializations.putIfAbsent(taintInputName, new CopyOnWriteArraySet<>());105 Set<StringSpecializationInfo> set = stringSpecializations.get(taintInputName);106 set.add(info);107 }108 public Map<String, Set<StringSpecializationInfo>> getStringSpecializationsView(){109 //note: this does not prevent modifying the sets inside it110 return Collections.unmodifiableMap(stringSpecializations);111 }112 public void addQueryParameter(String param){113 if(param != null && ! param.isEmpty()){114 queryParameters.add(param);115 }116 }117 public Set<String> getQueryParametersView(){118 return Collections.unmodifiableSet(queryParameters);119 }120 public void addHeader(String header){121 if(header != null && ! header.isEmpty()){122 headers.add(header);123 }124 }125 public Set<String> getHeadersView(){126 return Collections.unmodifiableSet(headers);127 }128 public String getLastExecutedStatement() {129// if(lastExecutedStatementStacks.values().stream().allMatch(s -> s.isEmpty())){130 /*131 TODO: not super-sure about this... we could have several threads in theory, but hard to132 really say if the last one executing a statement of the SUT is always the one we are really133 interested into... would need to check if there are cases in which this is not the case134 */135 Deque<StatementDescription> stack = null;136 if(lastExecutingThread != null){137 stack = lastExecutedStatementStacks.get(lastExecutingThread);138 }139 if(lastExecutingThread == null || stack == null || stack.isEmpty()){140 if(noExceptionStatement == null){141 return null;142 }143 return noExceptionStatement.line;144 }145 StatementDescription current = stack.peek();146 if(current == null){147 //could happen due to multi-threading148 return null;149 }150 return current.line;151 }152 public void pushLastExecutedStatement(String lastLine, String lastMethod) {153 String key = getThreadIdentifier();154 lastExecutingThread = key;155 lastExecutedStatementStacks.putIfAbsent(key, new ArrayDeque<>());156 Deque<StatementDescription> stack = lastExecutedStatementStacks.get(key);157 noExceptionStatement = null;158 StatementDescription statement = new StatementDescription(lastLine, lastMethod);159 StatementDescription current = stack.peek();160 //if some method, then replace top of stack161 if(current != null && lastMethod.equals(current.method)){162 stack.pop();163 }164 stack.push(statement);165 }166 private String getThreadIdentifier() {167 return "" + Thread.currentThread().getId();168 }169 public void popLastExecutedStatement(){170 String key = getThreadIdentifier();171 Deque<StatementDescription> stack = lastExecutedStatementStacks.get(key);172 if(stack == null || stack.isEmpty()){173 //throw new IllegalStateException("[ERROR] EvoMaster: invalid stack pop on thread " + key);174 SimpleLogger.warn("EvoMaster instrumentation was left in an inconsistent state." +175 " This could happen if you have threads executing business logic in your instrumented" +176 " classes after an action is completed (e.g., an HTTP call)." +177 " This is not a problem, as long as this warning appears only seldom in the logs.");178 /*179 This problem should not really happen in SpringBoot applications, but for example180 it does happen in LanguageTool, as it handles the HTTP connections manually in181 the business logic182 */183 return;184 }185 StatementDescription statementDescription = stack.pop();186 if(stack.isEmpty()){187 noExceptionStatement = statementDescription;188 }189 }190 public void addExternalService(ExternalServiceInfo hostInfo) {191 externalServices.add(hostInfo);192 }193 public Set<ExternalServiceInfo> getExternalServices() {194 return Collections.unmodifiableSet(externalServices);195 }196}...
Source:BootTimeObjectiveInfo.java
...34 externalServiceInfo.clear();35 }36 public void registerExternalServiceInfoAtSutBootTime(ExternalServiceInfo info){37 if (externalServiceInfo.isEmpty() || externalServiceInfo.stream().noneMatch(s-> s.equals(info)))38 externalServiceInfo.add(info.copy());39 }40 public boolean coveredAtBootTime(String descriptiveId){41 return maxObjectiveCoverage.containsKey(descriptiveId) && maxObjectiveCoverage.get(descriptiveId) == 1.0;42 }43 public List<ExternalServiceInfo> getExternalServiceInfo(){44 // read-only45 return Collections.unmodifiableList(externalServiceInfo);46 }47 public void updateMaxObjectiveCoverage(String descriptiveId, double value){48 Double h = maxObjectiveCoverage.get(descriptiveId);49 if (h == null || value > h)50 maxObjectiveCoverage.put(descriptiveId, value);51 }52 public Map<String, Double> getObjectiveCoverageAtSutBootTime(){...
Source:ExternalServiceInfo.java
...31 if (o == null || getClass() != o.getClass()) return false;32 ExternalServiceInfo that = (ExternalServiceInfo) o;33 return Objects.equals(remoteHostname, that.remoteHostname) && Objects.equals(protocol, that.protocol) && Objects.equals(remotePort, that.remotePort);34 }35 public ExternalServiceInfo copy(){36 return new ExternalServiceInfo(protocol, remoteHostname, remotePort);37 }38 @Override39 public int hashCode() {40 return Objects.hash(remoteHostname, protocol, remotePort);41 }42}...
copy
Using AI Code Generation
1import org.evomaster.client.java.instrumentation.ExternalServiceInfo;2import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.StringClassReplacement;3import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.StringBufferClassReplacement;4import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.StringBuilderClassReplacement;5import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.StringTokenizerClassReplacement;6import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.ThrowableClassReplacement;7import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.CalendarClassReplacement;8import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.DateClassReplacement;9import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.TimeClassReplacement;10import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.TimestampClassReplacement;11import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.LocaleClassReplacement;12import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.NumberClassReplacement;13import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.NumberFormatClassReplacement;14import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.SimpleDateFormatClassReplacement;15import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.DecimalFormatClassReplacement;16import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.DecimalFormatSymbolsClassReplacement;17import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.NumberFormatSymbolsClassReplacement;18import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.SimpleTimeZoneClassReplacement;19import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.TimeZoneClassReplacement;20import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.UUIDClassReplacement;21import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.FileClassReplacement;22import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.FileDescriptorClassReplacement;23import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.FileInputStreamClassReplacement;24import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.FileOutputStreamClassReplacement;25import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.RandomClassReplacement;26import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.RandomAccessFileClassReplacement;27import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.ByteArrayOutputStreamClassReplacement
copy
Using AI Code Generation
1import org.evomaster.client.java.instrumentation.ExternalServiceInfo;2import java.io.File;3import java.io.IOException;4import java.nio.file.Files;5import java.nio.file.Path;6import java.nio.file.Paths;7public class 2 {8public static void main(String[] args) throws IOException {9Path source = Paths.get("C:\\Users\\User\\Desktop\\test\\1.java");10Path destination = Paths.get("C:\\Users\\User\\Desktop\\test\\2.java");11ExternalServiceInfo.copy(source, destination);12}13}14import org.evomaster.client.java.instrumentation.ExternalServiceInfo;15import java.io.File;16import java.io.IOException;17import java.nio.file.Files;18import java.nio.file.Path;19import java.nio.file.Paths;20public class 1 {21public static void main(String[] args) throws IOException {22Path source = Paths.get("C:\\Users\\User\\Desktop\\test\\1.java");23Path destination = Paths.get("C:\\Users\\User\\Desktop\\test\\2.java");24ExternalServiceInfo.copy(source, destination);25}26}27import org.evomaster.client.java.instrumentation.ExternalServiceInfo;28import java.io.File;29import java.io.IOException;30import java.nio.file.Files;31import java.nio.file.Path;32import java.nio.file.Paths;33public class 3 {34public static void main(String[] args) throws IOException {35Path source = Paths.get("C:\\Users\\User\\Desktop\\test\\1.java");36Path destination = Paths.get("C:\\Users\\User\\Desktop\\test\\2.java");37ExternalServiceInfo.copy(source, destination);38}39}40import org.evomaster.client.java.instrumentation.ExternalServiceInfo;41import java.io.File;42import java.io.IOException;43import java.nio.file.Files;44import java.nio.file.Path;45import java.nio.file.Paths;46public class 4 {47public static void main(String[] args) throws IOException {48Path source = Paths.get("C:\\Users\\User\\Desktop\\test\\1.java");49Path destination = Paths.get("C:\\Users\\User\\Desktop\\test\\2.java");
copy
Using AI Code Generation
1public class 2 {2 public static void main(String[] args) {3 ExternalServiceInfo e = new ExternalServiceInfo();4 e.copy();5 }6}7public class 3 {8 public static void main(String[] args) {9 ExternalServiceInfo e = new ExternalServiceInfo();10 e.copy();11 }12}13public class 4 {14 public static void main(String[] args) {15 ExternalServiceInfo e = new ExternalServiceInfo();16 e.copy();17 }18}19public class 5 {20 public static void main(String[] args) {21 ExternalServiceInfo e = new ExternalServiceInfo();22 e.copy();23 }24}25public class 6 {26 public static void main(String[] args) {27 ExternalServiceInfo e = new ExternalServiceInfo();28 e.copy();29 }30}31public class 7 {32 public static void main(String[] args) {33 ExternalServiceInfo e = new ExternalServiceInfo();34 e.copy();35 }36}37public class 8 {38 public static void main(String[] args) {39 ExternalServiceInfo e = new ExternalServiceInfo();40 e.copy();41 }42}43public class 9 {44 public static void main(String[] args) {45 ExternalServiceInfo e = new ExternalServiceInfo();46 e.copy();47 }48}49public class 10 {
copy
Using AI Code Generation
1import org.evomaster.client.java.instrumentation.ExternalServiceInfo;2import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.*;3import java.util.*;4import java.io.*;5import java.nio.file.*;6import java.util.stream.*;7public class 2 {8 public static void main(String[] args) throws Exception {9 ExternalServiceInfo esi = new ExternalServiceInfo();10 File file = new File("C:\\Users\\user\\Desktop\\EvoMaster\\EvoMaster\\examples\\java-junit5\\junit5demo\\src\\main\\java\\org\\evomaster\\example\\junit5\\demo\\service\\MathService.java");11 File file2 = new File("C:\\Users\\user\\Desktop\\EvoMaster\\EvoMaster\\examples\\java-junit5\\junit5demo\\src\\main\\java\\org\\evomaster\\example\\junit5\\demo\\service\\MathService2.java");12 esi.copy(file, file2);13 }14}15import org.evomaster.client.java.instrumentation.ExternalServiceInfo;16import org.evomaster.client.java.instrumentation.coverage.methodreplacement.classes.*;17import java.util.*;18import java.io.*;19import java.nio.file.*;20import java.util.stream.*;21public class 2 {22 public static void main(String[] args) throws Exception {23 ExternalServiceInfo esi = new ExternalServiceInfo();24 File file = new File("C:\\Users\\user\\Desktop\\EvoMaster\\EvoMaster\\examples\\java-junit5\\junit5demo\\src\\main\\java\\org\\evomaster\\example\\junit5\\demo\\service\\MathService.java");25 File file2 = new File("C:\\Users\\user\\Desktop\\EvoMaster\\EvoMaster\\examples\\java-junit5\\junit5demo\\src\\main\\java\\org\\evomaster\\example
copy
Using AI Code Generation
1public class Test {2 public static void main(String[] args) {3 System.out.println(serviceInfo.url);4 }5}6public class Test {7 public static void main(String[] args) {8 System.out.println(serviceInfo.url);9 }10}11public class Test {12 public static void main(String[] args) {13 System.out.println(serviceInfo.url);14 }15}16public class Test {17 public static void main(String[] args) {18 System.out.println(serviceInfo.url);19 }20}21public class Test {22 public static void main(String[] args) {23 System.out.println(serviceInfo.url);24 }25}26public class Test {27 public static void main(String[] args) {28 System.out.println(serviceInfo.url);29 }30}
copy
Using AI Code Generation
1org.evomaster.client.java.instrumentation.ExternalServiceInfo esi = new org.evomaster.client.java.instrumentation.ExternalServiceInfo();2esi.copy(objectToBeCopied);3org.evomaster.client.java.instrumentation.ExternalServiceInfo esi = new org.evomaster.client.java.instrumentation.ExternalServiceInfo();4esi.copy(objectToBeCopied);5org.evomaster.client.java.instrumentation.ExternalServiceInfo esi = new org.evomaster.client.java.instrumentation.ExternalServiceInfo();6esi.copy(objectToBeCopied);7org.evomaster.client.java.instrumentation.ExternalServiceInfo esi = new org.evomaster.client.java.instrumentation.ExternalServiceInfo();8esi.copy(objectToBeCopied);9org.evomaster.client.java.instrumentation.ExternalServiceInfo esi = new org.evomaster.client.java.instrumentation.ExternalServiceInfo();10esi.copy(objectToBeCopied);
copy
Using AI Code Generation
1package org.evomaster.client.java.instrumentation.example;2public class CopyObject {3 public static void main(String[] args) {4 ExternalServiceInfo externalServiceInfo = new ExternalServiceInfo();5 externalServiceInfo.setMethod("POST");6 externalServiceInfo.setBody("body");7 externalServiceInfo.setHeaders("header");8 externalServiceInfo.setStatusCode(200);9 ExternalServiceInfo externalServiceInfo1 = new ExternalServiceInfo();10 externalServiceInfo.copy(externalServiceInfo1);11 System.out.println(externalServiceInfo1.getUrl());12 System.out.println(externalServiceInfo1.getMethod());13 System.out.println(externalSer
copy
Using AI Code Generation
1public class 2 {2 public static void main(String[] args) {3 ExternalServiceInfo obj = new ExternalServiceInfo();4 obj.setHttpMethod("GET");5 obj.setMediaType("application/json");6 obj.setStatusCode(200);7 obj.setResponseTime(100);8 obj.setBody("Hello World");9 ExternalServiceInfo obj2 = obj.copy();10 System.out.println(obj2.getUrl());11 System.out.println(obj2.getHttpMethod());12 System.out.println(obj2.getMediaType());13 System.out.println(obj2.getStatusCode());14 System.out.println(obj2.getResponseTime());15 System.out.println(obj2.getBody());16 }17}
copy
Using AI Code Generation
1public class StringSpecialization {2 public static String replace(String s) {3 return s.replace("a", "b");4 }5}6public class StringSpecialization {7 public static String replace(String s) {8 return s.replace("a", "b");9 }10}11public class StringSpecialization {12 public static String replace(String s) {13 return s.replace("a", "b");14 }15}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!