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

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

Source:InterfaceSchema.java Github

copy

Full Screen

1package org.evomaster.client.java.controller.problem.rpc.schema;2import org.evomaster.client.java.controller.api.dto.problem.rpc.RPCActionDto;3import org.evomaster.client.java.controller.api.dto.problem.rpc.RPCInterfaceSchemaDto;4import org.evomaster.client.java.controller.api.dto.problem.rpc.RPCType;5import org.evomaster.client.java.controller.api.dto.problem.rpc.SeededRPCActionDto;6import org.evomaster.client.java.controller.problem.rpc.schema.params.NamedTypedValue;7import org.evomaster.client.java.controller.problem.rpc.schema.types.CycleObjectType;8import org.evomaster.client.java.controller.problem.rpc.schema.types.TypeSchema;9import java.util.ArrayList;10import java.util.HashMap;11import java.util.List;12import java.util.Map;13import java.util.stream.Collectors;14/**15 * schema dto of the RCP service16 */17public final class InterfaceSchema{18 /**19 * name of the interface20 */21 private final String name;22 /**23 * name of the client24 */25 private final String clientInfo;26 /**27 * a list of available endpoints in the service28 */29 private List<EndpointSchema> endpoints;30 public Map<Integer, EndpointSchema> getAuthEndpoints() {31 return authEndpoints;32 }33 /**34 * a map of endpoints with their references for handling authentication35 * key - index of the auth info specified in the driver36 * value - the endpoint for handling such authentication with concrete info37 *38 * note that compared with [endpointsForAuth], authEndpoints contain concrete info for invocation39 * eg, for a login endpoint, it might have different inputs representing different authentication40 */41 private Map<Integer, EndpointSchema> authEndpoints;42 /**43 * a list of endpoints (in this interface) which are responsible for auth setup44 * eg, login45 */46 private List<EndpointSchema> endpointsForAuth;47 /**48 * key is the full name of type49 * value is its type schema50 */51 private Map<String, TypeSchema> typeCollections = new HashMap<>();52 /**53 * key is the full name of type54 * value is one example of param with the TypeSchema55 */56 private Map<String, NamedTypedValue> objParamCollections = new HashMap<>();57 /**58 * type of the RPC59 */60 private final RPCType rpcType;61 /**62 * a list of endpoints which are skipped to test63 */64 private final List<String> skippedEndpoints;65 /**66 *67 * @param name is the name of the interface68 * @param endpoints is a list of endpoints which are involved for testing69 * @param client is the client name70 * @param rpcType is the rpc type71 */72 public InterfaceSchema(String name, List<EndpointSchema> endpoints, String client, RPCType rpcType) {73 this(name, endpoints, client, rpcType, null, null, null);74 }75 /**76 *77 * @param name is the name of the interface78 * @param endpoints is a list of endpoints which are involved for testing79 * @param client is the client name80 * @param rpcType is the rpc type81 * @param skippedEndpoints is a list of endpoints which are specified to be skipped82 * @param authEndpoints is a map of authentication info which could be handled with the endpoint83 * key - index of authentication info in the driver84 * value - the endpoint which contains concrete info for its invocation85 * @param endpointsForAuth is a list of endpoints in this interface that are responsible for auth setup86 */87 public InterfaceSchema(String name, List<EndpointSchema> endpoints, String client, RPCType rpcType, List<String> skippedEndpoints, Map<Integer, EndpointSchema> authEndpoints, List<EndpointSchema> endpointsForAuth) {88 this.name = name;89 this.endpoints = endpoints;90 this.clientInfo = client;91 this.rpcType = rpcType;92 this.skippedEndpoints = skippedEndpoints;93 this.authEndpoints = authEndpoints;94 this.endpointsForAuth = endpointsForAuth;95 }96 /**97 * this method is used to collect all objects in sut98 * @param type is the type schema of the param for an object99 * @param param is the concrete param example100 * note that multiple params could belong to the same type schema101 */102 public void registerType(TypeSchema type, NamedTypedValue param){103 String typeName = type.getFullTypeNameWithGenericType();104 if (!(type instanceof CycleObjectType)){105 typeCollections.put(typeName, type);106 }107 if (!(param.getType() instanceof CycleObjectType))108 objParamCollections.put(param.getType().getFullTypeNameWithGenericType(), param);109 }110 public Map<String, NamedTypedValue> getObjParamCollections() {111 return objParamCollections;112 }113 public TypeSchema getTypeOrNull(String name){114 return typeCollections.get(name);115 }116 public List<EndpointSchema> getEndpoints(){117 return endpoints;118 }119 public RPCType getRpcType() {120 return rpcType;121 }122 /**123 * find endpoints based on the name124 * note that [endpoints] and [endpointsForAuth] contains all endpoints could be invoked in this interface125 * @param name is the name of an endpoint126 * @return a list of endpoints based on the specified name127 */128 public List<EndpointSchema> findEndpoints(String name){129 List<EndpointSchema> found = endpoints.stream().filter(s-> s.getName().equals(name)).collect(Collectors.toList());130 if (found.isEmpty() && endpointsForAuth!=null && !endpointsForAuth.isEmpty())131 return endpointsForAuth.stream().filter(s-> s.getName().equals(name)).collect(Collectors.toList());132 return found;133 }134 /**135 *136 * @param dto is a rpc action dto137 * @return one endpoint based on an action dto138 * note that there should only exist one endpoint which conforms with the specified dto.139 */140 public EndpointSchema getOneEndpoint(RPCActionDto dto){141 List<EndpointSchema> list = endpoints.stream().filter(s-> s.sameEndpoint(dto)).collect(Collectors.toList());142 if (list.isEmpty()){143 list.addAll(endpointsForAuth.stream().filter(s-> s.sameEndpoint(dto)).collect(Collectors.toList()));144 }145 if (list.size() == 1)146 return list.get(0);147 if (list.size() > 1)148 throw new RuntimeException("ERROR: there exists more than 1 endpoint which conforms with the specified dto");149 throw new RuntimeException("ERROR: there does not exist any endpoint which conforms with the specified dto");150 }151 /**152 * find an endpoint in this interface with seeded schema153 * @param dto the seeded rpc action dto154 * @return an endpoint schema155 */156 public EndpointSchema getOneEndpointWithSeededDto(SeededRPCActionDto dto){157 List<EndpointSchema> list = endpoints.stream().filter(s-> s.sameEndpoint(dto)).collect(Collectors.toList());158 if (list.size() == 1)159 return list.get(0);160 if (list.size() > 1)161 throw new RuntimeException("ERROR: there exists more than 1 endpoint which conforms with the specified seeded test dto");162 throw new RuntimeException("ERROR: there does not exist any endpoint which conforms with the specified seeded test dto");163 }164 public String getName() {165 return name;166 }167 public String getClientInfo(){168 return clientInfo;169 }170 public Map<String, TypeSchema> getTypeCollections() {171 return typeCollections;172 }173 /**174 *175 * @return a dto of the RPC interface schema which would be sent to core as a part of sut info176 */177 public RPCInterfaceSchemaDto getDto(){178 RPCInterfaceSchemaDto dto = new RPCInterfaceSchemaDto();179 dto.types = objParamCollections.values().stream().map(NamedTypedValue::getDto).collect(Collectors.toList());180 dto.interfaceId = this.getName();181 dto.clientInfo = this.getClientInfo();182 dto.endpoints = endpoints.stream().map(EndpointSchema::getDto).collect(Collectors.toList());183 if (skippedEndpoints != null)184 dto.skippedEndpoints = new ArrayList<>(skippedEndpoints);185 if (authEndpoints!= null && !authEndpoints.isEmpty()){186 dto.authEndpointReferences = new ArrayList<>();187 dto.authEndpoints = new ArrayList<>();188 authEndpoints.forEach((k, v)->{189 dto.authEndpointReferences.add(k);190 dto.authEndpoints.add(v.getDto());191 });192 }...

Full Screen

Full Screen

Source:RPCEndpointsBuilderTestBase.java Github

copy

Full Screen

...3import com.thrift.example.artificial.RPCInterfaceExampleImpl;4import org.evomaster.client.java.controller.api.dto.AuthenticationDto;5import org.evomaster.client.java.controller.api.dto.CustomizedRequestValueDto;6import org.evomaster.client.java.controller.problem.rpc.schema.EndpointSchema;7import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;8import org.evomaster.client.java.controller.api.dto.problem.rpc.RPCType;9import org.evomaster.client.java.controller.problem.rpc.schema.params.NamedTypedValue;10import java.util.Arrays;11import java.util.List;12import static org.junit.jupiter.api.Assertions.assertEquals;13/**14 * created by manzhang on 2021/11/1215 */16public abstract class RPCEndpointsBuilderTestBase {17 public InterfaceSchema schema = RPCEndpointsBuilder.build(getInterfaceName(), getRPCType(), new RPCInterfaceExampleImpl(), null, null, null, null, getAuthInfo(), getCustomizedValueInRequests(), specifyCustomizedNotNullAnnotation());18 public abstract String getInterfaceName();19 public abstract int expectedNumberOfEndpoints();20 public List<CustomizedRequestValueDto> getCustomizedValueInRequests(){21 return null;22 }23 public List<CustomizedNotNullAnnotationForRPCDto> specifyCustomizedNotNullAnnotation() {24 return Arrays.asList(25 new CustomizedNotNullAnnotationForRPCDto(){{26 annotationType = "com.thrift.example.artificial.CustomAnnotation";27 annotationMethod = "necessity";28 equalsTo = Necessity.REQUIRED;29 }}30 );31 }...

Full Screen

Full Screen

InterfaceSchema

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;2import org.evomaster.client.java.controller.problem.rpc.schema.RpcCall;3import org.evomaster.client.java.controller.problem.rpc.schema.RpcCallSchema;4import org.evomaster.client.java.controller.problem.rpc.schema.RpcCallType;5import org.evomaster.client.java.controller.problem.rpc.schema.RpcReturnSchema;6import org.evomaster.client.java.controller.problem.rpc.schema.TypeSchema;7import java.util.ArrayList;8import java.util.List;9public class InterfaceSchemaExample {10 public static void main(String[] args) {11 InterfaceSchema interfaceSchema = new InterfaceSchema();12 interfaceSchema.setBasePath("basePath");13 interfaceSchema.setHost("host");14 interfaceSchema.setPort(8080);15 interfaceSchema.setSchemes(new ArrayList<>());16 interfaceSchema.getSchemes().add("https");17 interfaceSchema.getSchemes().add("http");18 interfaceSchema.setConsumes(new ArrayList<>());19 interfaceSchema.getConsumes().add("application/json");20 interfaceSchema.getConsumes().add("application/xml");21 interfaceSchema.setProduces(new ArrayList<>());22 interfaceSchema.getProduces().add("application/json");23 interfaceSchema.getProduces().add("application/xml");24 interfaceSchema.setCalls(new ArrayList<>());25 RpcCallSchema rpcCallSchema = new RpcCallSchema();26 rpcCallSchema.setPath("path");27 rpcCallSchema.setMethod("method");28 rpcCallSchema.setCallType(RpcCallType.POST);29 rpcCallSchema.setParameters(new ArrayList<>());30 TypeSchema typeSchema = new TypeSchema();31 typeSchema.setType("type");32 typeSchema.setClassName("className");33 rpcCallSchema.getParameters().add(typeSchema);34 rpcCallSchema.setReturnSchema(new RpcReturnSchema());35 rpcCallSchema.getReturnSchema().setTypeSchema(typeSchema);36 rpcCallSchema.getReturnSchema().setBodySchema(typeSchema);37 interfaceSchema.getCalls().add(rpcCallSchema);38 System.out.println(interfaceSchema.toJson());39 }40}41import org.evomaster.client.java.controller.problem.rest.schema.*;42import org.evomaster.client.java.controller.problem.rest.schema.ObjectSchema;43import java.util.ArrayList;44import java.util.List;45public class InterfaceSchemaExample {46 public static void main(String[] args) {47 InterfaceSchema interfaceSchema = new InterfaceSchema();

Full Screen

Full Screen

InterfaceSchema

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;2import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;3import org.evomaster.client.java.controller.problem.rpc.schema.Schema;4public class 3 {5 public static void main(String[] args) {6 Schema schema = InterfaceSchema.createSchema(Interface.class);7 System.out.println(schema.toJson());8 }9 public interface Interface {10 ObjectSchema method(ObjectSchema param);11 }12}13import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;14import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;15import org.evomaster.client.java.controller.problem.rpc.schema.Schema;16public class 4 {17 public static void main(String[] args) {18 Schema schema = InterfaceSchema.createSchema(Interface.class);19 System.out.println(schema.toJson());20 }21 public interface Interface {22 ObjectSchema method(ObjectSchema param);23 }24}

Full Screen

Full Screen

InterfaceSchema

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;2import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;3import org.evomaster.client.java.controller.problem.rpc.schema.TypeSchema;4import java.util.List;5public class 3 {6 public static void main(String[] args) {7 InterfaceSchema schema = new InterfaceSchema();8 schema.setClassName("com.foo.bar.FooBar");9 schema.setMethods(new ObjectSchema[]{10 new ObjectSchema(new TypeSchema[]{11 new TypeSchema("java.lang.String"),12 new TypeSchema("int")13 })14 });15 System.out.println(schema.toJson());16 }17}18import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;19import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;20import org.evomaster.client.java.controller.problem.rpc.schema.TypeSchema;21import java.util.List;22public class 4 {23 public static void main(String[] args) {24 InterfaceSchema schema = new InterfaceSchema();25 schema.setClassName("com.foo.bar.FooBar");26 schema.setMethods(new ObjectSchema[]{27 new ObjectSchema(new TypeSchema[]{28 new TypeSchema("java.lang.String"),29 new TypeSchema("int")30 })31 });32 System.out.println(schema.toJson());33 }34}35import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;36import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;37import org.evomaster.client.java.controller.problem.rpc.schema.TypeSchema;38import java.util.List;39public class 5 {40 public static void main(String[] args) {41 InterfaceSchema schema = new InterfaceSchema();42 schema.setClassName("com.foo.bar.FooBar");43 schema.setMethods(new ObjectSchema[]{44 new ObjectSchema(new TypeSchema[]{45 new TypeSchema("java.lang.String"),46 new TypeSchema("int")47 })48 });49 System.out.println(schema.toJson());50 }51}

Full Screen

Full Screen

InterfaceSchema

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;2import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;3import org.evomaster.client.java.controller.problem.rpc.schema.Schema;4import org.evomaster.client.java.controller.problem.rpc.schema.StringSchema;5import java.util.Arrays;6public class 3 {7 public static void main(String[] args) {8 InterfaceSchema schema = new InterfaceSchema();9 schema.setName("3");10 schema.setMethods(Arrays.asList(11 new InterfaceSchema.MethodSchema("bar", Arrays.asList(12 new InterfaceSchema.MethodSchema.Parameter("input", new StringSchema(), false)13 ), new ObjectSchema("output", Arrays.asList(14 new ObjectSchema.Property("output", new StringSchema())15 ));16 System.out.println(schema.toJson());17 }18}19import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;20import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;21import org.evomaster.client.java.controller.problem.rpc.schema.Schema;22import org.evomaster.client.java.controller.problem.rpc.schema.StringSchema;23import java.util.Arrays;24public class 2 {25 public static void main(String[] args) {26 InterfaceSchema schema = new InterfaceSchema();27 schema.setName("2");28 schema.setMethods(Arrays.asList(29 new InterfaceSchema.MethodSchema("bar", Arrays.asList(30 new InterfaceSchema.MethodSchema.Parameter("input", new StringSchema(), false)31 ), new ObjectSchema("output", Arrays.asList(32 new ObjectSchema.Property("output", new StringSchema())33 ));34 System.out.println(schema.toJson());35 }36}37import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;38import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;39import org.evomaster.client.java.controller.problem.rpc.schema.Schema;40import org.evomaster.client.java.controller.problem.rpc.schema

Full Screen

Full Screen

InterfaceSchema

Using AI Code Generation

copy

Full Screen

1public class 3 {2 public static void main(String[] args) {3 InterfaceSchema interfaceSchema = new InterfaceSchema();4 InterfaceSchema interfaceSchema = new InterfaceSchema();5 interfaceSchema.setInterfaceName("org.evomaster.client.java.controller.problem.rpc.RpcInterface");6 interfaceSchema.setMethods(new ArrayList<>());7 interfaceSchema.setMethods(new ArrayList<>());8 MethodSchema methodSchema = new MethodSchema();9 MethodSchema methodSchema = new MethodSchema();10 methodSchema.setMethodName("foo");11 methodSchema.setMethodName("foo");12 methodSchema.setParameters(new ArrayList<>());13 methodSchema.setParameters(new ArrayList<>());14 ParameterSchema parameterSchema = new ParameterSchema();15 ParameterSchema parameterSchema = new ParameterSchema();16 parameterSchema.setParameterName("a");17 parameterSchema.setParameterName("a");18 parameterSchema.setParameterType("java.lang.String");19 parameterSchema.setParameterType("java.lang.String");20 methodSchema.getParameters().add(parameterSchema);21 methodSchema.getParameters().add(parameterSchema);22 interfaceSchema.getMethods().add(methodSchema);23 interfaceSchema.getMethods().add(methodSchema);24 String schema = interfaceSchema.toJson();25 String schema = interfaceSchema.toJson();26 System.out.println(schema);27 System.out.println(schema);28 }29}30{"interfaceName":"org.evomaster.client.java.controller.problem.rpc.RpcInterface","methods":[{"methodName":"foo","parameters":[{"parameterName":"a","parameterType":"java.lang.String"}]}]}31public static String generateInterface(InterfaceSchema interfaceSchema)32public static String generateStub(InterfaceSchema interfaceSchema)33public class 4 {34 public static void main(String[] args) {

Full Screen

Full Screen

InterfaceSchema

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.problem.rpc;2import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;3import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;4public class InterfaceSchema3 extends InterfaceSchema {5 public InterfaceSchema3() {6 super("org.evomaster.client.java.controller.problem.rpc.RpcController3");7 addProperty("name", new ObjectSchema("java.lang.String", true));8 addProperty("age", new ObjectSchema("java.lang.Integer", true));9 addProperty("height", new ObjectSchema("java.lang.Double", true));10 }11 public Object newInstance() {12 return new org.evomaster.client.java.controller.problem.rpc.RpcController3();13 }14}15package org.evomaster.client.java.controller.problem.rpc;16import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;17import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;18public class InterfaceSchema4 extends InterfaceSchema {19 public InterfaceSchema4() {20 super("org.evomaster.client.java.controller.problem.rpc.RpcController4");21 addProperty("name", new ObjectSchema("java.lang.String", true));22 addProperty("age", new ObjectSchema("java.lang.Integer", true));23 addProperty("height", new ObjectSchema("java.lang.Double", true));24 }25 public Object newInstance() {26 return new org.evomaster.client.java.controller.problem.rpc.RpcController4();27 }28}29package org.evomaster.client.java.controller.problem.rpc;30import org.evomaster.client.java.controller.problem.rpc.schema.InterfaceSchema;31import org.evomaster.client.java.controller.problem.rpc.schema.ObjectSchema;

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