How to use ObjectParam class of org.evomaster.client.java.controller.problem.rpc.schema.params package

Best EvoMaster code snippet using org.evomaster.client.java.controller.problem.rpc.schema.params.ObjectParam

Source:RPCEndpointsBuilder.java Github

copy

Full Screen

...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;270 if (annotations != null){271 for (Annotation annotation : endpoint.getAnnotations()){272 anyMatch = anyMatch || annotations.contains(annotation.annotationType().getName());273 }274 }275 if (names != null)276 anyMatch = anyMatch || names.contains(endpoint.getName());277 return anyMatch;278 }279 private static String getClientClass(Object client){280 if (client == null) return null;281 String clazzType = client.getClass().getName();282 // handle com.sun.proxy283 if (!clazzType.startsWith("com.sun.proxy.")){284 return clazzType;285 }286 Class<?>[] clazz = client.getClass().getInterfaces();287 if (clazz.length == 0){288 SimpleLogger.error("Error: the client is not related to any interface");289 return null;290 }291 if (clazz.length > 1)292 SimpleLogger.error("ERROR: the client has more than one interfaces");293 return clazz[0].getName();294 }295 private static EndpointSchema build(InterfaceSchema schema, Method method, RPCType rpcType, List<AuthenticationDto> authenticationDtoList,296 List<CustomizedRequestValueDto> customizedRequestValueDtos,297 List<CustomizedNotNullAnnotationForRPCDto> notNullAnnotations) {298 List<NamedTypedValue> requestParams = new ArrayList<>();299 List<AuthenticationDto> authAnnotationDtos = getSpecificRelatedAuth(authenticationDtoList, method);300 List<Integer> authKeys = null;301 if (authAnnotationDtos != null)302 authKeys = authAnnotationDtos.stream().map(s-> authenticationDtoList.indexOf(s)).collect(Collectors.toList());303 Set<String> relatedCustomization = new HashSet<>();304 for (Parameter p : method.getParameters()) {305 requestParams.add(buildInputParameter(schema, p, rpcType, getRelatedCustomization(customizedRequestValueDtos, method), relatedCustomization, notNullAnnotations));306 }307 NamedTypedValue response = null;308 if (!method.getReturnType().equals(Void.TYPE)) {309 Map<TypeVariable, Type> genericTypeMap = new HashMap<>();310 response = build(schema, method.getReturnType(), method.getGenericReturnType(), "return", rpcType, new ArrayList<>(), null, null, null, null, null, genericTypeMap);311 }312 List<NamedTypedValue> exceptions = null;313 if (method.getExceptionTypes().length > 0){314 exceptions = new ArrayList<>();315 for (int i = 0; i < method.getExceptionTypes().length; i++){316 NamedTypedValue exception = build(schema, method.getExceptionTypes()[i],317 method.getGenericExceptionTypes()[i], "exception_"+i, rpcType, new ArrayList<>(), null, null, null, null, null, null);318 exceptions.add(exception);319 }320 }321 return new EndpointSchema(method.getName(),322 schema.getName(), schema.getClientInfo(), requestParams, response, exceptions,323 authAnnotationDtos!= null && !authAnnotationDtos.isEmpty(), authKeys, relatedCustomization);324 }325 private static List<AuthenticationDto> getSpecificRelatedAuth(List<AuthenticationDto> authenticationDtoList, Method method){326 if (authenticationDtoList == null) return null;327 List<String> annotations = Arrays.stream(method.getAnnotations()).map(s-> s.annotationType().getName()).collect(Collectors.toList());328 return authenticationDtoList.stream().filter(s->329 (s.localAuthSetup != null && s.localAuthSetup.annotationOnEndpoint != null && annotations.contains(s.localAuthSetup.annotationOnEndpoint)) ||330 (s.jsonAuthEndpoint != null && s.jsonAuthEndpoint.annotationOnEndpoint != null && annotations.contains(s.jsonAuthEndpoint.annotationOnEndpoint))331 ).collect(Collectors.toList());332 }333 private static Map<Integer, CustomizedRequestValueDto> getRelatedCustomization(List<CustomizedRequestValueDto> customizedRequestValueDtos, Method method){334 if (customizedRequestValueDtos == null) return null;335 List<String> annotations = Arrays.stream(method.getAnnotations()).map(s-> s.annotationType().getName()).collect(Collectors.toList());336 List<CustomizedRequestValueDto> list = customizedRequestValueDtos.stream().filter(337 s-> (s.annotationOnEndpoint == null || annotations.contains(s.annotationOnEndpoint)) &&338 (s.specificEndpointName == null || s.specificEndpointName.contains(method.getName()))339 ).collect(Collectors.toList());340 if (list.isEmpty()) return null;341 Map<Integer, CustomizedRequestValueDto> map = new HashMap<>();342 list.forEach(s->map.put(customizedRequestValueDtos.indexOf(s), s));343 return map;344 }345 private static NamedTypedValue buildInputParameter(InterfaceSchema schema, Parameter parameter, RPCType type,346 Map<Integer,CustomizedRequestValueDto> customizationDtos, Set<String> relatedCustomization,347 List<CustomizedNotNullAnnotationForRPCDto> notNullAnnotations) {348 String name = parameter.getName();349 Class<?> clazz = parameter.getType();350 List<String> depth = new ArrayList<>();351 Map<TypeVariable, Type> genericTypeMap = new HashMap<>();352 NamedTypedValue namedTypedValue = build(schema, clazz, parameter.getParameterizedType(), name, type, depth, customizationDtos, relatedCustomization, null, notNullAnnotations, null, genericTypeMap);353 for (Annotation annotation: parameter.getAnnotations()){354 handleConstraint(namedTypedValue, annotation, notNullAnnotations);355 }356 return namedTypedValue;357 }358 private static NamedTypedValue build(InterfaceSchema schema, Class<?> clazz, Type genericType, String name, RPCType rpcType, List<String> depth,359 Map<Integer, CustomizedRequestValueDto> customizationDtos, Set<String> relatedCustomization, AccessibleSchema accessibleSchema,360 List<CustomizedNotNullAnnotationForRPCDto> notNullAnnotations, Class<?> originalType, Map<TypeVariable, Type> genericTypeMap) {361 handleGenericSuperclass(clazz, genericTypeMap);362 List<String> genericTypes = handleGenericType(clazz, genericType, genericTypeMap);363 String clazzWithGenericTypes = CodeJavaGenerator.handleClassNameWithGeneric(clazz.getName(), genericTypes);364 depth.add(getObjectTypeNameWithFlag(clazz, clazzWithGenericTypes));365 NamedTypedValue namedValue = null;366 try{367 if (PrimitiveOrWrapperType.isPrimitiveOrTypes(clazz)) {368 namedValue = PrimitiveOrWrapperParam.build(name, clazz, accessibleSchema);369 } else if (clazz == String.class) {370 StringType stringType = new StringType();371 namedValue = new StringParam(name, stringType, accessibleSchema);372 } else if (clazz == BigDecimal.class){373 BigDecimalType bigDecimalType = new BigDecimalType();374 namedValue = new BigDecimalParam(name, bigDecimalType, accessibleSchema);375 } else if (clazz == BigInteger.class){376 BigIntegerType bigIntegerType = new BigIntegerType();377 namedValue = new BigIntegerParam(name, bigIntegerType, accessibleSchema);378 } else if (clazz.isEnum()) {379 String [] items = Arrays.stream(clazz.getEnumConstants()).map(e-> getNameEnumConstant(e)).toArray(String[]::new);380 EnumType enumType = new EnumType(clazz.getSimpleName(), clazz.getName(), items, clazz);381 EnumParam param = new EnumParam(name, enumType, accessibleSchema);382 //register this type in the schema383 schema.registerType(enumType.copy(), param.copyStructureWithProperties());384 namedValue = param;385 } else if (clazz.isArray()){386 Type type = null;387 Class<?> templateClazz = null;388 if (genericType instanceof GenericArrayType){389 type = ((GenericArrayType)genericType).getGenericComponentType();390 templateClazz = getTemplateClass(type, genericTypeMap);391 }else {392 templateClazz = clazz.getComponentType();393 }394 NamedTypedValue template = build(schema, templateClazz, type,"template", rpcType, depth, customizationDtos, relatedCustomization, null, notNullAnnotations, null, genericTypeMap);395 template.setNullable(false);396 CollectionType ctype = new CollectionType(clazz.getSimpleName(),clazz.getName(), template, clazz);397 ctype.depth = getDepthLevel(clazz, depth, clazzWithGenericTypes);398 namedValue = new ArrayParam(name, ctype, accessibleSchema);399 } else if (clazz == ByteBuffer.class){400 // handle binary of thrift401 namedValue = new ByteBufferParam(name, accessibleSchema);402 } else if (List.class.isAssignableFrom(clazz) || Set.class.isAssignableFrom(clazz)){403 if (genericType == null)404 throw new RuntimeException("genericType should not be null for List and Set class");405 Type type = ((ParameterizedType) genericType).getActualTypeArguments()[0];406 Class<?> templateClazz = getTemplateClass(type, genericTypeMap);407 NamedTypedValue template = build(schema, templateClazz, type,"template", rpcType, depth, customizationDtos, relatedCustomization, null, notNullAnnotations, null, genericTypeMap);408 template.setNullable(false);409 CollectionType ctype = new CollectionType(clazz.getSimpleName(),clazz.getName(), template, clazz);410 ctype.depth = getDepthLevel(clazz, depth, clazzWithGenericTypes);411 if (List.class.isAssignableFrom(clazz))412 namedValue = new ListParam(name, ctype, accessibleSchema);413 else414 namedValue = new SetParam(name, ctype, accessibleSchema);415 } else if (Map.class.isAssignableFrom(clazz)){416 if (genericType == null)417 throw new RuntimeException("genericType should not be null for List and Set class");418 Type keyType = ((ParameterizedType) genericType).getActualTypeArguments()[0];419 Type valueType = ((ParameterizedType) genericType).getActualTypeArguments()[1];420 Class<?> keyTemplateClazz = getTemplateClass(keyType, genericTypeMap);421 NamedTypedValue keyTemplate = build(schema, keyTemplateClazz, keyType,"keyTemplate", rpcType, depth, customizationDtos, relatedCustomization, null, notNullAnnotations, null, genericTypeMap);422 keyTemplate.setNullable(false);423 Class<?> valueTemplateClazz = getTemplateClass(valueType, genericTypeMap);424 NamedTypedValue valueTemplate = build(schema, valueTemplateClazz, valueType,"valueTemplate", rpcType, depth, customizationDtos, relatedCustomization, null, notNullAnnotations, null, genericTypeMap);425 MapType mtype = new MapType(clazz.getSimpleName(), clazz.getName(), new PairParam(new PairType(keyTemplate, valueTemplate), null), clazz);426 mtype.depth = getDepthLevel(clazz, depth, clazzWithGenericTypes);427 namedValue = new MapParam(name, mtype, accessibleSchema);428 } else if (Date.class.isAssignableFrom(clazz)){429 if (clazz == Date.class)430 namedValue = new DateParam(name, accessibleSchema);431 else432 throw new RuntimeException("NOT support "+clazz.getName()+" date type in java yet");433 } else if (Exception.class.isAssignableFrom(clazz) && clazz.getName().startsWith("java")){434 // note that here we only extract class name and message435 StringParam msgField = new StringParam("message", new AccessibleSchema(false, null, "getMessage"));436 ObjectType exceptionType = new ObjectType(clazz.getSimpleName(), clazz.getName(), Collections.singletonList(msgField), clazz, genericTypes);437 namedValue = new ObjectParam(name, exceptionType, accessibleSchema);438 } else {439 if (clazz.getName().startsWith("java")){440 throw new RuntimeException("NOT handle "+clazz.getName()+" class in java yet");441 }442 long cycleSize = depth.stream().filter(s-> s.equals(getObjectTypeNameWithFlag(clazz, clazzWithGenericTypes))).count();443 if (cycleSize == 1){444 List<NamedTypedValue> fields = new ArrayList<>();445 Map<Integer, CustomizedRequestValueDto> objRelatedCustomizationDtos = getCustomizationBasedOnSpecifiedType(customizationDtos, clazz.getName());446 // field list447 List<Field> fieldList = new ArrayList<>();448 getAllFields(clazz, fieldList, rpcType);449 for(Field f: fieldList){450 // skip final field451 if (Modifier.isFinal(f.getModifiers()))452 continue;453 if (doSkipReflection(f.getName()))454 continue;455 AccessibleSchema faccessSchema = null;456 //check accessible457 if (Modifier.isPublic(f.getModifiers())){458 faccessSchema = new AccessibleSchema();459 } else{460 // find getter and setter461 faccessSchema = new AccessibleSchema(false, findGetterOrSetter(clazz, f, false), findGetterOrSetter(clazz, f, true));462 if (faccessSchema.getterMethodName == null || faccessSchema.setterMethodName == null){463 SimpleLogger.warn("Error: skip the field "+f.getName()+" since its setter/getter is not found");464 continue;465 }466 }467 Class<?> fType = f.getType();468 Class<?> foriginalType = null;469 Type fGType = f.getGenericType();470 if (f.getGenericType() instanceof TypeVariable){471 foriginalType = f.getType();472 Type actualType = getActualType(genericTypeMap, (TypeVariable) f.getGenericType());473 if (actualType instanceof Class){474 fType = (Class<?>) actualType;475 fGType = fType;476 }else if (actualType instanceof ParameterizedType){477 fGType = actualType;478 if (((ParameterizedType) actualType).getRawType() instanceof Class<?>)479 fType = (Class<?>) ((ParameterizedType) actualType).getRawType();480 else481 throw new RuntimeException("Error: Fail to handle actual type of a generic type");482 }483 }484 NamedTypedValue field = build(schema, fType, fGType,f.getName(), rpcType, depth, objRelatedCustomizationDtos, relatedCustomization, faccessSchema, notNullAnnotations, foriginalType, genericTypeMap);485 for (Annotation annotation : f.getAnnotations()){486 handleConstraint(field, annotation, notNullAnnotations);487 }488 fields.add(field);489 }490 handleNativeRPCConstraints(clazz, fields, rpcType);491 ObjectType otype = new ObjectType(clazz.getSimpleName(), clazz.getName(), fields, clazz, genericTypes);492 otype.setOriginalType(originalType);493 otype.depth = getDepthLevel(clazz, depth, clazzWithGenericTypes);494 ObjectParam oparam = new ObjectParam(name, otype, accessibleSchema);495 schema.registerType(otype.copy(), oparam);496 namedValue = oparam;497 }else {498 CycleObjectType otype = new CycleObjectType(clazz.getSimpleName(), clazz.getName(), clazz, genericTypes);499 otype.depth = getDepthLevel(clazz, depth, clazzWithGenericTypes);500 ObjectParam oparam = new ObjectParam(name, otype, accessibleSchema);501 schema.registerType(otype.copy(), oparam);502 namedValue = oparam;503 }504 }505 }catch (ClassCastException e){506 throw new RuntimeException(String.format("fail to perform reflection on param/field: %s; class: %s; genericType: %s; class of genericType: %s; depth: %s; error info:%s",507 name, clazz.getName(), genericType==null?"null":genericType.getTypeName(), genericType==null?"null":genericType.getClass().getName(), String.join(",", depth), e.getMessage()));508 }509 namedValue.getType().setOriginalType(originalType);510 if (customizationDtos!=null){511 handleNamedValueWithCustomizedDto(namedValue, customizationDtos, relatedCustomization);512 }513 return namedValue;514 }...

Full Screen

Full Screen

Source:ObjectParam.java Github

copy

Full Screen

...17import java.util.stream.Collectors;18/**19 * object param20 */21public class ObjectParam extends NamedTypedValue<ObjectType, List<NamedTypedValue>> {22 public ObjectParam(String name, ObjectType type, AccessibleSchema accessibleSchema) {23 super(name, type, accessibleSchema);24 }25 @Override26 public Object newInstance() throws ClassNotFoundException {27 if (getValue() == null) return null;28 String clazzName = getType().getFullTypeName();29 Class<?> clazz = Class.forName(clazzName);30 try {31 Object instance = clazz.newInstance();32 for (NamedTypedValue v: getValue()){33 if (v.accessibleSchema == null || v.accessibleSchema.isAccessible){34 Field f = clazz.getField(v.getName());35 f.setAccessible(true);36 Object vins = v.newInstance();37 if (vins != null)38 f.set(instance, vins);39 } else if(v.accessibleSchema.setterMethodName != null){40 Method m = getSetter(clazz, v.accessibleSchema.setterMethodName, v.getType(), v.getType().getClazz(), 0);41 //clazz.getMethod(v.accessibleSchema.setterMethodName, v.getType().getClazz());42 m.invoke(instance, v.newInstance());43 }44 }45 return instance;46 } catch (InstantiationException e) {47 throw new RuntimeException("fail to construct the class:"+clazzName+" with error msg:"+e.getMessage());48 } catch (IllegalAccessException e) {49 throw new RuntimeException("fail to access the class:"+clazzName+" with error msg:"+e.getMessage());50 } catch (NoSuchFieldException e) {51 throw new RuntimeException("fail to access the field:"+clazzName+" with error msg:"+e.getMessage());52 } catch (NoSuchMethodException e) {53 throw new RuntimeException("fail to access the method:"+clazzName+" with error msg:"+e.getMessage());54 } catch (InvocationTargetException e) {55 throw new RuntimeException("fail to invoke the setter method:"+clazzName+" with error msg:"+e.getMessage());56 }57 }58 private Method getSetter(Class<?> clazz, String setterName, TypeSchema type, Class<?> typeClass, int attemptTimes) throws NoSuchMethodException {59 try {60 Method m = clazz.getMethod(setterName, type.getClazz());61 return m;62 } catch (NoSuchMethodException e) {63 if (type instanceof PrimitiveOrWrapperType && attemptTimes == 0){64 Type p = PrimitiveOrWrapperParam.getPrimitiveOrWrapper(type.getClazz());65 if (p instanceof Class){66 return getSetter(clazz, setterName, type, (Class)p, 1);67 }68 }69 throw e;70 }71 }72 @Override73 public ObjectParam copyStructure() {74 return new ObjectParam(getName(), getType(), accessibleSchema);75 }76 @Override77 public ParamDto getDto() {78 ParamDto dto = super.getDto();79 if (getValue() != null){80 dto.innerContent = getValue().stream().map(NamedTypedValue::getDto).collect(Collectors.toList());81 dto.stringValue = NOT_NULL_MARK_OBJ_DATE;82 } else83 dto.innerContent = getType().getFields().stream().map(NamedTypedValue::getDto).collect(Collectors.toList());84 return dto;85 }86 @Override87 public void setValueBasedOnDto(ParamDto dto) {88 if (dto.innerContent!=null && !dto.innerContent.isEmpty()){89 List<NamedTypedValue> fields = getType().getFields();90 List<NamedTypedValue> values = new ArrayList<>();91 for (ParamDto p: dto.innerContent){92 NamedTypedValue f = fields.stream().filter(s-> s.sameParam(p)).findFirst().get().copyStructureWithProperties();93 f.setValueBasedOnDto(p);94 values.add(f);95 }96 setValue(values);97 }98 }99 @Override100 protected void setValueBasedOnValidInstance(Object instance) {101 List<NamedTypedValue> values = new ArrayList<>();102 List<NamedTypedValue> fields = getType().getFields();103 Class<?> clazz;104 try {105 clazz = Class.forName(getType().getFullTypeName());106 } catch (ClassNotFoundException e) {107 throw new RuntimeException("ERROR: fail to get class with the name"+getType().getFullTypeName()+" Msg:"+e.getMessage());108 }109 for (NamedTypedValue f: fields){110 NamedTypedValue copy = f.copyStructureWithProperties();111 try {112 if (f.accessibleSchema == null || f.accessibleSchema.isAccessible){113 Field fi = clazz.getField(f.getName());114 fi.setAccessible(true);115 Object fiv = fi.get(instance);116 copy.setValueBasedOnInstance(fiv);117 } else if(f.accessibleSchema.getterMethodName != null){118 Method m = clazz.getMethod(f.accessibleSchema.getterMethodName);119 copy.setValueBasedOnInstance(m.invoke(instance));120 }121 } catch (NoSuchFieldException | IllegalAccessException e) {122 throw new RuntimeException("ERROR: fail to get value of the field with the name ("+ f.getName()+ ") and error Msg:"+e.getMessage());123 } catch (NoSuchMethodException | InvocationTargetException e) {124 throw new RuntimeException("ERROR: fail to get/invoke getter method for the field with the name ("+ f.getName()+ ") and error Msg:"+e.getMessage());125 }126 values.add(copy);127 }128 setValue(values);129 }130 @Override131 public void setValueBasedOnInstanceOrJson(Object json) throws JsonProcessingException {132 List<NamedTypedValue> values = new ArrayList<>();133 List<NamedTypedValue> fields = getType().getFields();134 if (isValidInstance(json)){135 setValueBasedOnInstance(json);136 }else {137 /*138 in jackson, object would be extracted as a map139 */140 assert json instanceof Map;141 for (NamedTypedValue f: fields){142 NamedTypedValue copy = f.copyStructureWithProperties();143 Object fiv = ((Map)json).get(f.getName());144 copy.setValueBasedOnInstanceOrJson(fiv);145 values.add(copy);146 }147 setValue(values);148 }149 }150 @Override151 public List<String> newInstanceWithJava(boolean isDeclaration, boolean doesIncludeName, String variableName, int indent) {152 String typeName = getType().getTypeNameForInstance();153 String varName = variableName;154 List<String> codes = new ArrayList<>();155 boolean isNull = (getValue() == null);156 String var = CodeJavaGenerator.oneLineInstance(isDeclaration, doesIncludeName, typeName, varName, null);157 CodeJavaGenerator.addCode(codes, var, indent);158 if (isNull) return codes;159 CodeJavaGenerator.addCode(codes, "{", indent);160 // new obj161 CodeJavaGenerator.addCode(codes, CodeJavaGenerator.setInstanceObject(typeName, varName), indent+1);162 for (NamedTypedValue f : getValue()){163 if (f.accessibleSchema == null || f.accessibleSchema.isAccessible){164 String fName = varName+"."+f.getName();165 codes.addAll(f.newInstanceWithJava(false, true, fName, indent+1));166 }else{167 String fName = varName;168 boolean fdeclar = false;169 if (f instanceof ObjectParam || f instanceof MapParam || f instanceof CollectionParam || f instanceof DateParam || f instanceof BigDecimalParam || f instanceof BigIntegerParam){170 fName = varName+"_"+f.getName();171 fdeclar = true;172 }173 codes.addAll(f.newInstanceWithJava(fdeclar, true, fName, indent+1));174 if (f instanceof ObjectParam || f instanceof MapParam || f instanceof CollectionParam || f instanceof DateParam || f instanceof BigDecimalParam || f instanceof BigIntegerParam){175 CodeJavaGenerator.addCode(codes, CodeJavaGenerator.methodInvocation(varName, f.accessibleSchema.setterMethodName, fName)+CodeJavaGenerator.appendLast(),indent+1);176 }177 }178 }179 CodeJavaGenerator.addCode(codes, "}", indent);180 return codes;181 }182 @Override183 public List<String> newAssertionWithJava(int indent, String responseVarName, int maxAssertionForDataInCollection) {184 List<String> codes = new ArrayList<>();185 if (getValue() == null){186 CodeJavaGenerator.addCode(codes, CodeJavaGenerator.junitAssertNull(responseVarName), indent);187 return codes;188 }...

Full Screen

Full Screen

ObjectParam

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.params.ObjectParam;2import org.evomaster.client.java.controller.problem.rpc.schema.params.StringParam;3import org.evomaster.client.java.controller.problem.rpc.schema.params.IntegerParam;4import org.evomaster.client.java.controller.problem.rpc.schema.params.DoubleParam;5import org.evomaster.client.java.controller.problem.rpc.schema.params.BooleanParam;6import org.evomaster.client.java.controller.problem.rpc.schema.params.ArrayParam;7import org.evomaster.client.java.controller.problem.rpc.schema.params.NullParam;8import org.evomaster.client.java.controller.problem.rpc.schema.params.Param;9import java.util.List;10import java.util.ArrayList;11public class ObjectParamExample {12 public static void main(String[] args) {13 ObjectParam objectParam = new ObjectParam();14 objectParam.addParam("id", new IntegerParam(1));15 objectParam.addParam("name", new StringParam("John"));16 objectParam.addParam("height", new DoubleParam(1.8));17 objectParam.addParam("isMale", new BooleanParam(true));18 objectParam.addParam("address", new StringParam("London"));19 objectParam.addParam("age", new IntegerParam(30));20 objectParam.addParam("isMarried", new BooleanParam(false));21 objectParam.addParam("nullParam", new NullParam());22 objectParam.addParam("arrayParam", new ArrayParam(new ArrayList<Param>() {{23 add(new StringParam("a"));24 add(new StringParam("b"));25 add(new StringParam("c"));26 }}));27 objectParam.addParam("objectParam", new ObjectParam(new ArrayList<Param>() {{28 add(new StringParam("a"));29 add(new StringParam("b"));30 add(new StringParam("c"));31 }}));32 System.out.println(objectParam.toString());33 }34}

Full Screen

Full Screen

ObjectParam

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.params.ObjectParam;2import org.evomaster.client.java.controller.problem.rpc.schema.params.Param;3import java.util.List;4import java.util.ArrayList;5import java.util.Map;6import java.util.HashMap;7import java.util.stream.Collectors;8public class ObjectParamExample {9 public static void main(String[] args) {10 ObjectParam objectParam = new ObjectParam("paramName", true);11 objectParam.addParam(new Param("param1Name", true, Param.ParamType.INTEGER, 1));12 objectParam.addParam(new Param("param2Name", true, Param.ParamType.STRING, "param2"));13 Param param1 = objectParam.getParam("param1Name");14 System.out.println("Param1: " + param1);15 List<Param> params = objectParam.getParams();16 System.out.println("Params: " + params);17 List<String> paramNames = objectParam.getParamNames();18 System.out.println("ParamNames: " + paramNames);19 List<Object> paramValues = objectParam.getParamValues();20 System.out.println("ParamValues: " + paramValues);21 List<Param.ParamType> paramTypes = objectParam.getParamTypes();22 System.out.println("ParamTypes: " + paramTypes);23 boolean isParam1 = objectParam.hasParam("param1Name");24 System.out.println("Has Param1: " + isParam1);25 boolean isParam3 = objectParam.hasParam("param3Name");26 System.out.println("Has Param3: " + isParam3);27 objectParam.removeParam("param1Name");28 List<Param> params2 = objectParam.getParams();29 System.out.println("Params2: " + params2);30 }31}32Param1: Param{name='param1Name', optional=true, type=INTEGER, value=1}33Params: [Param{name='param1Name', optional=true, type=INTEGER, value=1

Full Screen

Full Screen

ObjectParam

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.problem.rpc.schema.params;2import org.evomaster.client.java.controller.problem.rest.param.Param;3import org.evomaster.client.java.controller.problem.rest.param.ParamType;4import java.util.Objects;5public class ObjectParam extends Param {6 private Object value;7 public ObjectParam() {8 super(ParamType.OBJECT);9 }10 public Object getValue() {11 return value;12 }13 public void setValue(Object value) {14 this.value = value;15 }16 public String toString() {17 return "ObjectParam{" +18 '}';19 }20 public boolean equals(Object o) {21 if (this == o) return true;22 if (o == null || getClass() != o.getClass()) return false;23 ObjectParam that = (ObjectParam) o;24 return Objects.equals(value, that.value);25 }26 public int hashCode() {27 return Objects.hash(value);28 }29}30package org.evomaster.client.java.controller.problem.rpc.schema.params;31import com.fasterxml.jackson.annotation.JsonSubTypes;32import com.fasterxml.jackson.annotation.JsonTypeInfo;33@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")34@JsonSubTypes({35 @JsonSubTypes.Type(value = ObjectParam.class, name = "object"),36 @JsonSubTypes.Type(value = StringParam.class, name = "string"),37 @JsonSubTypes.Type(value = IntegerParam.class, name = "integer"),38 @JsonSubTypes.Type(value = BooleanParam.class, name = "boolean"),39 @JsonSubTypes.Type(value = ArrayParam.class, name = "array"),40 @JsonSubTypes.Type(value = NullParam.class, name = "null")41})42public abstract class Param {43 private ParamType type;44 public Param() {45 }46 public Param(ParamType type) {47 this.type = type;48 }49 public ParamType getType() {50 return type;51 }52 public void setType(ParamType type) {53 this.type = type;54 }55 public String toString() {56 return "Param{" +57 '}';58 }59}

Full Screen

Full Screen

ObjectParam

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.params.ObjectParam;2import org.evomaster.client.java.controller.problem.rpc.schema.params.Param;3import java.util.ArrayList;4import java.util.List;5import java.util.Map;6import java.util.HashMap;7import java.util.stream.Collectors;8import java.util.stream.Stream;9public class ObjectParamTest {10 public static void main(String[] args) {11 ObjectParam objectParam = new ObjectParam("objectParamName");12 Map<String, Param> map = new HashMap<String, Param>();13 map.put("key1", new ObjectParam("key1"));14 map.put("key2", new ObjectParam("key2"));15 objectParam.setMap(map);16 List<Param> list = new ArrayList<Param>();17 list.add(new ObjectParam("listParam1"));18 list.add(new ObjectParam("listParam2"));19 objectParam.setList(list);20 System.out.println(objectParam.toString());21 }22}23import org.evomaster.client.java.controller.problem.rpc.schema.params.ObjectParam;24import org.evomaster.client.java.controller.problem.rpc.schema.params.Param;25import java.util.ArrayList;26import java.util.List;27import java.util.Map;28import java.util.HashMap;29import java.util.stream.Collectors;30import java.util.stream.Stream;31public class ObjectParamTest {32 public static void main(String[] args) {33 ObjectParam objectParam = new ObjectParam("objectParamName");34 Map<String, Param> map = new HashMap<String, Param>();35 map.put("key1", new ObjectParam("key1"));36 map.put("key2", new ObjectParam("key2"));37 objectParam.setMap(map);38 List<Param> list = new ArrayList<Param>();39 list.add(new ObjectParam("listParam1"));40 list.add(new ObjectParam("listParam2"));41 objectParam.setList(list);42 System.out.println(objectParam.toString());43 }44}

Full Screen

Full Screen

ObjectParam

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.problem.rpc.schema.params;2import java.util.Objects;3public class ObjectParam implements Param {4 private String name;5 private String value;6 public ObjectParam(String name, String value) {7 this.name = name;8 this.value = value;9 }10 public String getName() {11 return name;12 }13 public String getValue() {14 return value;15 }16 public boolean equals(Object o) {17 if (this == o) return true;18 if (o == null || getClass() != o.getClass()) return false;19 ObjectParam that = (ObjectParam) o;20 return Objects.equals(name, that.name) &&21 Objects.equals(value, that.value);22 }23 public int hashCode() {24 return Objects.hash(name, value);25 }26 public String toString() {27 return "ObjectParam{" +28 '}';29 }30}31package org.evomaster.client.java.controller.problem.rpc.schema.params;32public interface Param {33}34package org.evomaster.client.java.controller.problem.rpc.schema.params;35import java.util.ArrayList;36import java.util.List;37public class Params {38 private List<Param> params;39 public Params() {40 this.params = new ArrayList<>();41 }42 public Params(List<Param> params) {43 this.params = params;44 }45 public List<Param> getParams() {46 return params;47 }48 public void addParam(Param param) {49 this.params.add(param);50 }51 public void addParams(List<Param> params) {52 this.params.addAll(params);53 }54 public String toString() {55 return "Params{" +56 '}';57 }58}59package org.evomaster.client.java.controller.problem.rpc.schema.params;60import java.util.Objects;61public class StringParam implements Param {62 private String name;

Full Screen

Full Screen

ObjectParam

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.problem.rpc.schema.params;2import java.util.Objects;3public class ObjectParam implements Param {4 private final String name;5 private final String value;6 public ObjectParam(String name, String value) {7 this.name = name;8 this.value = value;9 }10 public String getName() {11 return name;12 }13 public String getValue() {14 return value;15 }16 public String toString() {17 return "ObjectParam{" +18 '}';19 }20 public boolean equals(Object o) {21 if (this == o) return true;22 if (o == null || getClass() != o.getClass()) return false;23 ObjectParam that = (ObjectParam) o;24 return Objects.equals(name, that.name) &&25 Objects.equals(value, that.value);26 }27 public int hashCode() {28 return Objects.hash(name, value);29 }30}31package org.evomaster.client.java.controller.problem.rpc.schema.params;32import java.util.Objects;33public class ObjectParam implements Param {34 private final String name;35 private final String value;36 public ObjectParam(String name, String value) {37 this.name = name;38 this.value = value;39 }40 public String getName() {41 return name;42 }43 public String getValue() {44 return value;45 }46 public String toString() {47 return "ObjectParam{" +48 '}';49 }50 public boolean equals(Object o) {51 if (this == o) return true;52 if (o == null || getClass() != o.getClass()) return false;53 ObjectParam that = (ObjectParam) o;54 return Objects.equals(name, that.name) &&55 Objects.equals(value, that.value);56 }57 public int hashCode() {58 return Objects.hash(name, value);59 }60}

Full Screen

Full Screen

ObjectParam

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.params.ObjectParam;2import org.evomaster.client.java.controller.problem.rpc.schema.params.StringParam;3import org.evomaster.client.java.controller.problem.rpc.schema.params.IntegerParam;4import org.evomaster.client.java.controller.problem.rpc.schema.params.DoubleParam;5import org.evomaster.client.java.controller.problem.rpc.schema.params.BooleanParam;6import org.evomaster.client.java.controller.problem.rpc.schema.params.ArrayParam;7import org.evomaster.client.java.controller.problem.rpc.schema.Params;8import org.evomaster.client.java.controller.problem.rpc.RpcCallAction;9public class 2 {10 public static void main(String[] args) {11 RpcCallAction action = new RpcCallAction("org.evomaster.examples.java.controller.rpc.RpcController", "testMethod");12 ObjectParam param0 = new ObjectParam();13 param0.addField("myString", new StringParam("test"));14 param0.addField("myInt", new IntegerParam(1));15 param0.addField("myDouble", new DoubleParam(2.0));16 param0.addField("myBoolean", new BooleanParam(true));17 ArrayParam param1 = new ArrayParam();18 param1.addParam(new StringParam("test1"));19 param1.addParam(new StringParam("test2"));20 param0.addField("myStringArray", param1);21 action.addParam(param0);22 Params params = new Params();23 params.addParam(action);24 System.out.println(params.toJson());25 }26}27import org.evomaster.client.java.controller.problem.rest.schema.params.ObjectParam;28import org.evomaster.client.java.controller.problem.rest.schema.params.StringParam;29import org.evomaster.client.java.controller.problem.rest.schema.params.IntegerParam;30import org.evomaster.client.java.controller.problem.rest.schema.params.DoubleParam;31import org.evomaster.client.java.controller.problem.rest.schema.params.BooleanParam;32import org.evomaster.client.java.controller.problem

Full Screen

Full Screen

ObjectParam

Using AI Code Generation

copy

Full Screen

1ObjectParam objectParam = new ObjectParam();2objectParam.setProperty("name", new StringParam("value"));3objectParam.setProperty("age", new IntegerParam(1));4objectParam.setProperty("name", new StringParam("value"));5objectParam.setProperty("age", new IntegerParam(1));6objectParam.setProperty("name", new StringParam("value"));7objectParam.setProperty("age", new IntegerParam(1));8objectParam.setProperty("name", new StringParam("value"));9objectParam.setProperty("age", new IntegerParam(1));10objectParam.setProperty("name", new StringParam("value"));11objectParam.setProperty("age", new IntegerParam(1));12objectParam.setProperty("name", new StringParam("value"));13objectParam.setProperty("age", new IntegerParam(1));14objectParam.setProperty("name", new StringParam("value"));15objectParam.setProperty("age", new IntegerParam(1));16objectParam.setProperty("name", new StringParam("value"));17objectParam.setProperty("age", new IntegerParam(1));18objectParam.setProperty("name", new StringParam("value"));19objectParam.setProperty("age", new IntegerParam(1));

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 EvoMaster automation tests on LambdaTest cloud grid

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

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