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

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

Source:RPCEndpointsBuilder.java Github

copy

Full Screen

...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){...

Full Screen

Full Screen

getAuthEndpointInInterface

Using AI Code Generation

copy

Full Screen

1 public void testGetAuthEndpointInInterface() {2 String actual = RPCEndpointsBuilder.getAuthEndpointInInterface();3 assertEquals(expected, actual);4 }5 public void testGetAuthEndpointInInterface1() {6 String actual = RPCEndpointsBuilder.getAuthEndpointInInterface();7 assertEquals(expected, actual);8 }9 public void testGetAuthEndpointInInterface2() {10 String actual = RPCEndpointsBuilder.getAuthEndpointInInterface();11 assertEquals(expected, actual);12 }13 public void testGetAuthEndpointInInterface3() {14 String actual = RPCEndpointsBuilder.getAuthEndpointInInterface();15 assertEquals(expected, actual);16 }17 public void testGetAuthEndpointInInterface4() {18 String actual = RPCEndpointsBuilder.getAuthEndpointInInterface();19 assertEquals(expected, actual);20 }21 public void testGetAuthEndpointInInterface5() {

Full Screen

Full Screen

getAuthEndpointInInterface

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.problem.rest;2import org.evomaster.client.java.controller.problem.rpc.RPCEndpointsBuilder;3import org.evomaster.client.java.controller.problem.rpc.RPCResult;4import org.evomaster.client.java.controller.problem.rpc.RPCResultBuilder;5import org.evomaster.client.java.controller.problem.rpc.RPCTarget;6import java.util.ArrayList;7import java.util.List;8public class RestCallResultBuilder {9 private final List<RestCallResult> results = new ArrayList<>();10 public RestCallResultBuilder(RPCEndpointsBuilder rpcBuilder) {11 for (RPCTarget target : rpcBuilder.getTargets()) {12 String rpcEndpoint = rpcBuilder.getAuthEndpointInInterface(target);13 results.add(new RestCallResult(target, rpcEndpoint));14 }15 }16 public RestCallResultBuilder(RPCResultBuilder rpcBuilder) {17 for (RPCResult target : rpcBuilder.getResults()) {18 String rpcEndpoint = rpcBuilder.getAuthEndpointInInterface(target);19 results.add(new RestCallResult(target, rpcEndpoint));20 }21 }22 public List<RestCallResult> getResults() {23 return results;24 }25}26package org.evomaster.client.java.controller.problem.rest;27import org.evomaster.client.java.controller.problem.ProblemInfo;28import org.evomaster.client.java.controller.problem.rpc.RPCResult;29import org.evomaster.client.java.controller.problem.rpc.RPCTarget;30public class RestCallResult extends RPCResult {31 private final String restEndpoint;32 public RestCallResult(RPCTarget target, String restEndpoint) {33 super(target);34 this.restEndpoint = restEndpoint;35 }36 public RestCallResult(RPCResult result, String restEndpoint) {37 super(result);38 this.restEndpoint = restEndpoint;39 }40 public String getRestEndpoint() {41 return restEndpoint;42 }43 public ProblemInfo getProblemInfo() {44 return ProblemInfo.REST;45 }46}47package org.evomaster.client.java.controller.problem.rpc;48import org.evomaster.client.java.controller.problem.ProblemInfo;49import org.evomaster.client.java.controller.problem.ProblemInfoBuilder;50import org.evomaster.client.java.controller

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