How to use filterMethod method of org.evomaster.client.java.controller.problem.rpc.RPCEndpointsBuilder class

Best EvoMaster code snippet using org.evomaster.client.java.controller.problem.rpc.RPCEndpointsBuilder.filterMethod

Source:RPCEndpointsBuilder.java Github

copy

Full Screen

...136 try {137 Class<?> interfaze = Class.forName(interfaceName);138 InterfaceSchema schema = new InterfaceSchema(interfaceName, endpoints, getClientClass(client) , rpcType, skippedEndpoints, authEndpoints, endpointsForAuth);139 for (Method m : interfaze.getDeclaredMethods()) {140 if (filterMethod(m, skipEndpointsByName, skipEndpointsByAnnotation, involveEndpointsByName, involveEndpointsByAnnotation)){141 try{142 EndpointSchema endpointSchema = build(schema, m, rpcType, authenticationDtoList, customizedRequestValueDtos, notNullAnnotations);143 endpoints.add(endpointSchema);144 }catch (RuntimeException exception){145 /*146 TODO might send such log to core in order to better identify problems which is not handled yet147 */148 SimpleLogger.error("EM Driver Error: fail to handle the endpoint schema "+m.getName()+" with the error msg:"+exception.getMessage());149 }150 } else {151 skippedEndpoints.add(m.getName());152 }153 List<AuthenticationDto> auths = getAuthEndpointInInterface(authenticationDtoList, interfaceName, m);154 if (auths != null && !auths.isEmpty()){155 try{156 // handle endpoint which is for auth setup157 EndpointSchema authEndpoint = build(schema, m, rpcType, null, customizedRequestValueDtos,notNullAnnotations);158 endpointsForAuth.add(authEndpoint);159 for (AuthenticationDto auth: auths){160 EndpointSchema copy = authEndpoint.copyStructure();161 if (auth.jsonAuthEndpoint == null){162 throw new IllegalArgumentException("Driver Config Error: now we only support auth info specified with JsonAuthRPCEndpointDto");163 }164 int index = authenticationDtoList.indexOf(auth);165 // set value based on specified info166 if (copy.getRequestParams().size() != auth.jsonAuthEndpoint.jsonPayloads.size())167 throw new IllegalArgumentException("Driver Config Error: mismatched size of jsonPayloads ("+auth.jsonAuthEndpoint.classNames.size()+") with real endpoint ("+authEndpoint.getRequestParams().size()+").");168 setAuthEndpoint(copy, auth.jsonAuthEndpoint);169 authEndpoints.put(index, copy);170 }171 }catch (RuntimeException exception){172 SimpleLogger.error("EM Driver Error: fail to handle the authEndpoint schema "+m.getName()+" with the error msg:"+exception.getMessage());173 }174 }175 }176 return schema;177 } catch (ClassNotFoundException e) {178 throw new RuntimeException("cannot find the interface with the name (" + interfaceName + ") and the error message is " + e.getMessage());179 }180 }181 /**182 * build the local auth setup183 * @param authenticationDtoList a list of auth info specified by user184 * @return a map of such local auth setup185 * key - index at a list of auth info specified by user186 * value - local endpoint187 */188 public static Map<Integer, LocalAuthSetupSchema> buildLocalAuthSetup(List<AuthenticationDto> authenticationDtoList){189 if (authenticationDtoList==null || authenticationDtoList.isEmpty()) return null;190 Map<Integer, LocalAuthSetupSchema> map = new HashMap<>();191 for (AuthenticationDto dto : authenticationDtoList){192 if (dto.localAuthSetup != null){193 int index = authenticationDtoList.indexOf(dto);194 LocalAuthSetupSchema local = new LocalAuthSetupSchema();195 local.getRequestParams().get(0).setValueBasedOnInstance(dto.localAuthSetup.authenticationInfo);196 map.put(index, local);197 }198 }199 return map;200 }201 private static void setAuthEndpoint(EndpointSchema authEndpoint, JsonAuthRPCEndpointDto jsonAuthEndpoint) throws ClassNotFoundException{202 if (jsonAuthEndpoint.classNames != null && jsonAuthEndpoint.classNames.size() != jsonAuthEndpoint.jsonPayloads.size())203 throw new IllegalArgumentException("Driver Config Error: to specify inputs for auth endpoint, classNames and jsonPayloads should have same size");204 for (int i = 0; i < authEndpoint.getRequestParams().size(); i++){205 NamedTypedValue inputParam = authEndpoint.getRequestParams().get(i);206 String jsonString = jsonAuthEndpoint.jsonPayloads.get(i);207 if (jsonAuthEndpoint.classNames == null){208 setNamedValueBasedOnJsonString(inputParam,jsonString, i);209 }else{210 Class<?> clazz = Class.forName(jsonAuthEndpoint.classNames.get(i));211 try {212 Object value = objectMapper.readValue(jsonString, clazz);213 inputParam.setValueBasedOnInstance(value);214 } catch (JsonProcessingException e) {215 SimpleLogger.uniqueWarn("Driver Config Error: a jsonPayload at ("+i+") cannot be read as the object "+jsonAuthEndpoint.classNames.get(i));216 setNamedValueBasedOnJsonString(inputParam,jsonString, i);217 }218 }219 }220 }221 private static void setNamedValueBasedOnJsonString(NamedTypedValue inputParam, String jsonString, int index){222 if (inputParam instanceof StringParam || inputParam instanceof PrimitiveOrWrapperParam || inputParam instanceof ByteBufferParam){223 setNamedValueBasedOnCandidates(inputParam, jsonString);224 } else if (inputParam instanceof ObjectParam){225 try {226 JsonNode node = objectMapper.readTree(jsonString);227 List<NamedTypedValue> fields = new ArrayList<>();228 for (NamedTypedValue f: ((ObjectParam) inputParam).getType().getFields()){229 NamedTypedValue v = f.copyStructureWithProperties();230 if (node.has(v.getName())){231 setNamedValueBasedOnCandidates(f, node.textValue());232 fields.add(v);233 }else {234 SimpleLogger.uniqueWarn("Driver Config Error: cannot find field with the name "+v.getName()+" in the specified json");235 }236 }237 inputParam.setValue(fields);238 } catch (JsonProcessingException ex) {239 SimpleLogger.uniqueWarn("Driver Config Error: a jsonPayload at ("+index+") cannot be read as a JSON object with error:" +ex.getMessage());240 }241 }242 }243 private static List<AuthenticationDto> getAuthEndpointInInterface(List<AuthenticationDto> authenticationDtos, String interfaceName, Method method){244 if (authenticationDtos == null) return null;245 for (AuthenticationDto dto : authenticationDtos){246 if (dto.localAuthSetup == null && (dto.jsonAuthEndpoint == null || dto.jsonAuthEndpoint.endpointName == null || dto.jsonAuthEndpoint.interfaceName == null)){247 SimpleLogger.uniqueWarn("Driver Config Error: To specify auth for RPC, either localAuthSetup or jsonAuthEndpoint should be specified." +248 "For JsonAuthRPCEndpointDto, endpointName and interfaceName cannot be null");249 }250 }251 return authenticationDtos.stream().filter(a-> a.jsonAuthEndpoint != null252 && a.jsonAuthEndpoint.endpointName.equals(method.getName())253 && a.jsonAuthEndpoint.interfaceName.equals(interfaceName)).collect(Collectors.toList());254 }255 private static boolean filterMethod(Method endpoint,256 List<String> skipEndpointsByName, List<String> skipEndpointsByAnnotation,257 List<String> involveEndpointsByName, List<String> involveEndpointsByAnnotation){258 if (skipEndpointsByName != null && involveEndpointsByName != null)259 throw new IllegalArgumentException("Driver Config Error: skipEndpointsByName and involveEndpointsByName should not be specified at same time.");260 if (skipEndpointsByAnnotation != null && involveEndpointsByAnnotation != null)261 throw new IllegalArgumentException("Driver Config Error: skipEndpointsByAnnotation and involveEndpointsByAnnotation should not be specified at same time.");262 if (skipEndpointsByName != null || skipEndpointsByAnnotation != null)263 return !anyMatchByNameAndAnnotation(endpoint, skipEndpointsByName, skipEndpointsByAnnotation);264 if (involveEndpointsByName != null || involveEndpointsByAnnotation != null)265 return anyMatchByNameAndAnnotation(endpoint, involveEndpointsByName, involveEndpointsByAnnotation);266 return true;267 }268 private static boolean anyMatchByNameAndAnnotation(Method endpoint, List<String> names, List<String> annotations){269 boolean anyMatch = false;...

Full Screen

Full Screen

filterMethod

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.api.dto.SutInfoDto;2import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;3import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;4import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;5import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;6import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;7import org.evomaster.client.java.controller.api.dto.database.schema.TableRowDto;8import org.evomaster.client.java.controller.api.dto.database.schema.TableSchemaDto;9import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;10import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;11import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;12import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;13import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;14import org.evomaster.client.java.controller.api.dto.database.schema.TableRowDto;15import org.evomaster.client.java.controller.a

Full Screen

Full Screen

filterMethod

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.RPCEndpointsBuilder;2import org.evomaster.client.java.controller.problem.rpc.RPCEndpoint;3import static org.evomaster.client.java.controller.problem.rpc.RPCEndpoint.Method.GET;4import static org.evomaster.client.java.controller.problem.rpc.RPCEndpoint.Method.POST;5import static org.evomaster.client.java.controller.problem.rpc.RPCEndpoint.Method.PUT;6import static org.evomaster.client.java.controller.problem.rpc.RPCEndpoint.Method.DELETE;7import static org.evomaster.client.java.controller.problem.rpc.RPCEndpoint.Method.OPTIONS;8import static org.evomaster.client.java.controller.problem.rpc.RPCEndpoint.Method.HEAD;9import static org.evomaster.client.java.controller.problem.rpc.RPCEndpoint.Method.PATCH;10public class RpcController {11 public static void initController() throws Exception {12 RPCEndpointsBuilder builder = new RPCEndpointsBuilder();13 builder.addEndpoint(RPCEndpoint.builder()14 .setMethod(GET)15 .setPath("/api/v1/employees")16 .setProduces("application/json")17 .setFilterMethod("org.evomaster.client.java.controller.problem.rpc.RPCEndpointsBuilderTest$MyFilter::filter")18 .build());19 builder.build();20 }21}22package org.evomaster.client.java.controller.problem.rpc;23import java.util.Arrays;24import java.util.List;25import java.util.stream.Collectors;26public class MyFilter {27 public static List<String> filter(List<String> list){28 return list.stream().filter(s -> s.length() > 3).collect(Collectors.toList());29 }30}31import org.evomaster.client.java.controller.EmbeddedSutController;32import org.evomaster.client.java.controller.api.dto.SutInfoDto;33import org.evomaster.client.java.controller.problem.ProblemInfo;34import org.evomaster.client.java.controller.problem.rpc.RPCProblem;35import org.evomaster.client.java.controller.problem.rpc.RPCEndpoint;36import org.evomaster.client.java.controller.problem.rpc.RPCResult;37import org.evomaster.client.java.controller.problem.rpc.RPCIndividual;38import org.evomaster.client.java.controller.problem.rpc.RPCIndividualDto;39import org.evomaster.client.java.controller.problem.rpc.RPCEmTestCase;40import org.evomaster.client.java.controller.problem.rpc.RPCExpectation

Full Screen

Full Screen

filterMethod

Using AI Code Generation

copy

Full Screen

1List<String> methodsToInclude = Arrays.asList("add", "subtract", "multiply", "divide");2List<String> methodsToExclude = Arrays.asList("sayHello");3List<String> filteredMethods = filterMethod(methodsToInclude, methodsToExclude);4for (String method : filteredMethods) {5 System.out.println(method);6}7List<String> generatedTestSuite = generateTestSuite(methodsToInclude, methodsToExclude);

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