Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,17 @@ public void setNotNullValue() {
stringValue = NOT_NULL_MARK_OBJ_DATE;
}

public ParamDto findObjectByTypeName(String typeName){
if (typeName == null || innerContent == null || innerContent.isEmpty()) return null;
for (ParamDto p : innerContent){
if (p.type.fullTypeNameWithGenericType.equals(typeName) && p.innerContent != null && !p.innerContent.isEmpty()){
return p;
}
ParamDto ip = p.findObjectByTypeName(typeName);
if (ip != null)
return ip;
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ private static NamedTypedValue build(InterfaceSchema schema, Class<?> clazz, Typ
// note that here we only extract class name and message
StringParam msgField = new StringParam("message", new AccessibleSchema(false, null, "getMessage"));
ObjectType exceptionType = new ObjectType(clazz.getSimpleName(), clazz.getName(), Collections.singletonList(msgField), clazz, genericTypes);
exceptionType.ownerSchema = schema;
namedValue = new ObjectParam(name, exceptionType, accessibleSchema);
} else {
if (clazz.getName().startsWith("java")){
Expand Down Expand Up @@ -590,13 +591,15 @@ private static NamedTypedValue build(InterfaceSchema schema, Class<?> clazz, Typ
handleNativeRPCConstraints(clazz, fields, rpcType);

ObjectType otype = new ObjectType(clazz.getSimpleName(), clazz.getName(), fields, clazz, genericTypes);
otype.ownerSchema = schema;
otype.setOriginalType(originalType);
otype.depth = getDepthLevel(clazz, depth, clazzWithGenericTypes);
ObjectParam oparam = new ObjectParam(name, otype, accessibleSchema);
schema.registerType(otype.copy(), oparam, isTypeToIdentify);
namedValue = oparam;
}else {
CycleObjectType otype = new CycleObjectType(clazz.getSimpleName(), clazz.getName(), clazz, genericTypes);
otype.ownerSchema = schema;
otype.depth = getDepthLevel(clazz, depth, clazzWithGenericTypes);
ObjectParam oparam = new ObjectParam(name, otype, accessibleSchema);
schema.registerType(otype.copy(), oparam, isTypeToIdentify);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import org.evomaster.client.java.controller.api.dto.problem.rpc.ParamDto;
import org.evomaster.client.java.controller.problem.rpc.CodeJavaGenerator;
import org.evomaster.client.java.controller.problem.rpc.schema.types.AccessibleSchema;
import org.evomaster.client.java.controller.problem.rpc.schema.types.ObjectType;
import org.evomaster.client.java.controller.problem.rpc.schema.types.PrimitiveOrWrapperType;
import org.evomaster.client.java.controller.problem.rpc.schema.types.TypeSchema;
import org.evomaster.client.java.controller.problem.rpc.schema.types.*;
import org.evomaster.client.java.utils.SimpleLogger;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -106,6 +103,10 @@ public void setValueBasedOnDto(ParamDto dto) {

if (dto.innerContent!=null && !dto.innerContent.isEmpty()){
List<NamedTypedValue> fields = getType().getFields();
List<NamedTypedValue> fs = getFieldsForCycleObjectType();
if (fs != null)
fields = fs;

List<NamedTypedValue> values = new ArrayList<>();

for (ParamDto p: dto.innerContent){
Expand All @@ -122,12 +123,21 @@ public void setValueBasedOnDto(ParamDto dto) {
protected void setValueBasedOnValidInstance(Object instance) {
List<NamedTypedValue> values = new ArrayList<>();
List<NamedTypedValue> fields = getType().getFields();

if (instance != null && (fields == null || fields.isEmpty())){
List<NamedTypedValue> fs = getFieldsForCycleObjectType();
if (fs != null)
fields = fs;
}

Class<?> clazz;
try {
clazz = Class.forName(getType().getFullTypeName());
} catch (ClassNotFoundException e) {
throw new RuntimeException("ERROR: fail to get class with the name"+getType().getFullTypeName()+" Msg:"+e.getMessage());
}


for (NamedTypedValue f: fields){
NamedTypedValue copy = f.copyStructureWithProperties();
try {
Expand All @@ -149,7 +159,6 @@ protected void setValueBasedOnValidInstance(Object instance) {

values.add(copy);
}

setValue(values);
}

Expand Down Expand Up @@ -178,6 +187,10 @@ public void setValueBasedOnInstanceOrJson(Object json) throws JsonProcessingExce
if (!(instance instanceof Map))
throw new RuntimeException("cannot parse the map param "+getName()+ " with the type" + instance.getClass().getName());

List<NamedTypedValue> fs = getFieldsForCycleObjectType();
if (fs != null)
fields = fs;

for (NamedTypedValue f: fields){
NamedTypedValue copy = f.copyStructureWithProperties();
Object fiv = ((Map)instance).get(f.getName());
Expand Down Expand Up @@ -258,4 +271,20 @@ public String getValueAsJavaString() {
return null;
}

private List<NamedTypedValue> getFieldsForCycleObjectType(){
if (!(getType() instanceof CycleObjectType))
return null;

if (getType().ownerSchema == null)
SimpleLogger.warn("owner schema of the type is null");
else {
TypeSchema typeSchema = getType().ownerSchema.getTypeCollections().get(getType().getFullTypeNameWithGenericType());
if (typeSchema == null || !(typeSchema instanceof ObjectType))
SimpleLogger.warn("cannot find the object type with name "+getType().getFullTypeNameWithGenericType());
else
return ((ObjectType)typeSchema.copy()).getFields();
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TypeDto getDto() {
}

@Override
public BigDecimalType copy() {
public BigDecimalType copyContent() {
return new BigDecimalType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TypeDto getDto() {
}

@Override
public BigDecimalType copy() {
public BigDecimalType copyContent() {
return new BigDecimalType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public TypeDto getDto() {
}

@Override
public ByteBufferType copy() {
public ByteBufferType copyContent() {
return new ByteBufferType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String getTypeNameForInstance() {
}

@Override
public CollectionType copy() {
public CollectionType copyContent() {
return new CollectionType(getType(), getFullTypeName(), template, getClazz());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public CycleObjectType(String type, String fullTypeName, Class<?> clazz, List<St
super(type, fullTypeName, new ArrayList<>(), clazz, genericTypes);
}

public CycleObjectType copyContent(){
List<String> genericTypes = this.genericTypes != null? new ArrayList<>(this.genericTypes): null;
return new CycleObjectType(getType(), getFullTypeName(), getClazz(), genericTypes);
}

@Override
public TypeDto getDto() {
TypeDto dto = super.getDto();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public TypeDto getDto() {


@Override
public DateType copy() {
public DateType copyContent() {
return new DateType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TypeDto getDto() {
}

@Override
public EnumType copy() {
public EnumType copyContent() {
return new EnumType(getType(), getFullTypeName(), items, getClazz());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String getTypeNameForInstance() {
}

@Override
public MapType copy() {
public MapType copyContent() {
return new MapType(getType(),getFullTypeName(), template, getClazz());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ObjectType extends TypeSchema {
/**
* a list of generic types
*/
private final List<String> genericTypes;
protected final List<String> genericTypes;


public ObjectType(String type, String fullTypeName, List<NamedTypedValue> fields, Class<?> clazz, List<String> genericTypes) {
Expand All @@ -41,7 +41,7 @@ public TypeDto getDto() {
return dto;
}

public ObjectType copy(){
public ObjectType copyContent(){
List<NamedTypedValue> cfields = new ArrayList<>();
if (fields != null){
for (NamedTypedValue f: fields){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public TypeDto getDto() {
}

@Override
public PairType copy() {
public PairType copyContent() {
return new PairType(getFirstTemplate(), getSecondTemplate());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static boolean isPrimitiveOrTypes(Class<?> clazz){


@Override
public PrimitiveOrWrapperType copy() {
public PrimitiveOrWrapperType copyContent() {
return new PrimitiveOrWrapperType(getType(), getFullTypeName(), isWrapper, getClazz());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TypeDto getDto() {
}

@Override
public StringType copy() {
public StringType copyContent() {
return new StringType();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.evomaster.client.java.controller.problem.rpc.schema.types;

import org.evomaster.client.java.controller.api.dto.problem.rpc.TypeDto;
import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;

/**
* type schema
Expand Down Expand Up @@ -51,7 +52,16 @@ public String getFullTypeNameWithGenericType(){
return fullTypeName;
}

public abstract TypeSchema copy();
public InterfaceSchema ownerSchema;

public abstract TypeSchema copyContent();

public TypeSchema copy(){
TypeSchema content = copyContent();
// keep refer to schema
content.ownerSchema = ownerSchema;
return content;
}

public TypeDto getDto(){
TypeDto dto = new TypeDto();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.thrift.example.artificial;

public class CycleAObj {

public String aID;
public CycleBObj obj;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.thrift.example.artificial;

public class CycleBObj {

public String bID;
public CycleAObj obj;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface RPCInterfaceExample {

ObjectResponse objResponse();

CycleAObj objCycleA();
CycleAObj objCycleA(CycleAObj objA);

CycleBObj objCycleB();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public ObjectResponse objResponse() {
}

@Override
public CycleAObj objCycleA() {
return null;
public CycleAObj objCycleA(CycleAObj objA) {
return objA;
}

@Override
Expand Down
Loading