Best EvoMaster code snippet using org.evomaster.e2etests.utils.GraphQLTestBase.graphActions
Source:GraphQLTestBase.java
...76 }77 protected void assertNoneWithErrors(Solution<GraphQLIndividual> solution) {78 boolean ok = solution.getIndividuals().stream().allMatch(ind -> noneWithErrors(ind));79 String errorMsg = "Seed " + (defaultSeed-1)+". There exist some errors\n";80 assertTrue(ok, errorMsg + graphActions(solution));81 }82 protected void assertAnyWithErrors(Solution<GraphQLIndividual> solution) {83 boolean ok = solution.getIndividuals().stream().anyMatch(ind -> !noneWithErrors(ind));84 assertTrue(ok);85 }86 protected boolean hasValueInData(EvaluatedIndividual<GraphQLIndividual> ind, String value) {87 List<GraphQLAction> actions = ind.getIndividual().seeMainExecutableActions();88 boolean stopped = false;89 for (int i = 0; i < actions.size() && !stopped; i++) {90 GraphQlCallResult res = (GraphQlCallResult) ind.seeResults(actions).get(i);91 stopped = res.getStopping();92 if (hasValueInData(res, value)){93 return true;94 }95 }96 return false;97 }98 /**99 *100 * @param result is the GraphQL action result to be checked101 * @param propertyName is a property of the results to be extracted102 * @return extracted content based on propertyName103 */104 private JsonNode getDataInGraphQLResults(GraphQlCallResult result, String propertyName){105 Integer statusCode = result.getStatusCode();106 if (!statusCode.equals(200)) {107 return null;108 }109 String body = result.getBody();110 ObjectMapper jackson = new ObjectMapper();111 JsonNode node;112 try {113 node = jackson.readTree(body);114 } catch (JsonProcessingException e) {115 return null;116 }117 return node.findPath(propertyName);118 }119 private boolean hasValueInData(GraphQlCallResult result, String value){120 JsonNode data = getDataInGraphQLResults(result, "data");121 if (data == null) return false;122 /*123 if (!data.isNull() && !data.isMissingNode() && data.asText().contains(value)) {124 return true;125 }*/126 if (!data.isNull() && !data.isMissingNode() && data.toString().contains(value)) {127 return true;128 }129 return false;130 }131 protected void assertValueInDataAtLeastOnce(Solution<GraphQLIndividual> solution, String value) {132 boolean ok = solution.getIndividuals().stream().anyMatch(ind -> hasValueInData(ind, value));133 assertTrue(ok);134 }135 protected void assertHasAtLeastOne(Solution<GraphQLIndividual> solution, String methodName, GQMethodType type, int expectedStatusCode, String inResponse){136 boolean ok = solution.getIndividuals().stream().anyMatch(137 ind -> hasAtLeastOne(ind, methodName, type, expectedStatusCode, inResponse));138 String errorMsg = "Seed " + (defaultSeed-1)+". ";139 errorMsg += "Missing " + expectedStatusCode + " " + type + " " + methodName + " " + inResponse + "\n";140 assertTrue(ok, errorMsg + graphActions(solution));141 }142 protected void assertHasAtLeastOne(Solution<GraphQLIndividual> solution,143 String methodName, GQMethodType type, int expectedStatusCode,144 List<String> inResponse, boolean and){145 boolean ok;146 if (and){147 ok = inResponse.stream().allMatch(s-> solution.getIndividuals().stream().anyMatch(ind ->148 hasAtLeastOne(ind, methodName, type, expectedStatusCode, s)));149 }else{150 ok = inResponse.stream().anyMatch(s-> solution.getIndividuals().stream().anyMatch(ind ->151 hasAtLeastOne(ind, methodName, type, expectedStatusCode, s)));152 }153 String errorMsg = "Seed " + (defaultSeed-1)+". ";154 errorMsg += "Missing " + expectedStatusCode + " " + type + " " + methodName + " " + (and?" all of " : " any of ") +String.join(",", inResponse) + "\n";155 assertTrue(ok, errorMsg + graphActions(solution));156 }157 private boolean hasAtLeastOne(EvaluatedIndividual<GraphQLIndividual> ind, String methodName, GQMethodType type, int expectedStatusCode, String inResponse){158 if (ind.getIndividual().seeAllActions().size() != ind.seeResults(null).size()){159 throw new IllegalStateException(String.format("mismatched size of results (%d) with calls (%d) for GraphQLIndividual",160 ind.seeResults(null).size(), ind.getIndividual().seeAllActions().size()));161 }162 List<GraphQLAction> actions = ind.getIndividual().seeMainExecutableActions();163 boolean stopped = false;164 for (int i = 0; i < actions.size() && !stopped; i++) {165 GraphQlCallResult res = (GraphQlCallResult) ind.seeResults(actions).get(i);166 stopped = res.getStopping();167 boolean matched = actions.get(i).getMethodName().equals(methodName) &&168 actions.get(i).getMethodType().equals(type) && res.getStatusCode() == expectedStatusCode;169 if(!matched) continue;170 if (inResponse == null) continue;171 if (hasValueInData(res, inResponse)) return true;172 }173 return false;174 }175 protected String graphActions(Solution<GraphQLIndividual> solution) {176 StringBuffer msg = new StringBuffer("Graph calls:\n");177 solution.getIndividuals().stream().flatMap(ind -> ind.evaluatedMainActions().stream())178 .filter(ea -> ea.getAction() instanceof GraphQLAction)179 .map(ea -> {180 GraphQlCallResult res = (GraphQlCallResult)ea.getResult();181 String s = res.getStatusCode() + " ";182 JsonNode node = getDataInGraphQLResults(res, "data");183 if (node != null) s += " data:"+node.toString();184 node = getDataInGraphQLResults(res, "errors");185 if (node != null && (!node.isEmpty() || !node.isMissingNode())) s += " errors:"+node.toString();186 s += ea.getAction().toString() + "\n";187 return s;188 })189 .sorted()...
graphActions
Using AI Code Generation
1import org.evomaster.core.Main2import org.evomaster.core.output.OutputFormat3import org.evomaster.core.problem.rest.RestIndividual4import org.evomaster.core.problem.rest.RestIndividual5import org.evomaster.core.problem.rest.auth.NoAuth6import org.evomaster.core.problem.rest.param.BodyParam7import org.evomaster.core.problem.rest.param.PathParam8import org.evomaster.core.search.Action9import org.evomaster.core.search.EvaluatedIndividual10import org.evomaster.core.search.Individual11import org.evomaster.core.search.gene.*12import org.evomaster.core.search.service.*
graphActions
Using AI Code Generation
1import org.evomaster.core.problem.graphql.GraphQLAction2import org.evomaster.core.problem.graphql.GraphQLActionBuilder3import org.evomaster.core.problem.graphql.GraphQLIndividual4import org.evomaster.core.problem.graphql.GraphQLStructure5import org.evomaster.core.problem.graphql.param.GQInputValue6import org.evomaster.core.problem.graphql.param.GQVariable7import org.evomaster.core.problem.graphql.param.InputObjectType8import org.evomaster.core.problem.graphql.param.ObjectType9import org.evomaster.core.problem.graphql.param.ScalarType10import org.evomaster.core.problem.rest.HttpVerb11import org.evomaster.core.problem.rest.RestCallResult12import org.evomaster.core.problem.rest.RestIndividual13import org.evomaster.core.problem.rest.param.BodyParam14import org.evomaster.core.problem.rest.param.HeaderParam15import org.evomaster.core.problem.rest.param.PathParam16import org.evomaster.core.problem.rest.param.QueryParam17import org.evomaster.core.search.Action18import org.evomaster.core.search.ActionResult19import org.evomaster.core.search.FitnessValue20import org.evomaster.core.search.gene.*21import org.evomaster.core.search.service.Randomness22import org.evomaster.core.search.service.mutator.EvaluatedMutation23import org.evomaster.core.search.service.mutator.MutatedGeneSpecification24import org.evomaster.core.search.service.mutator.StandardMutator25import org.evomaster.core.search.service.mutator.geneMutation.SubsetGeneMutation26import org.evomaster.core.search.tracer.TraceableElement27import org.evomaster.e2etests.utils.GraphQLTestBase28import org.evomaster.e2etests.utils.RestTestBase29import org.junit.jupiter.api.Assertions.*30import org.junit.jupiter.api.Test31import org.junit.jupiter.api.TestInstance32import org.junit.jupiter.api.extension.ExtendWith33import org.junit.jupiter.api.extension.Extensions34import org.junit.jupiter.api.extension.RegisterExtension35import org.junit.jupiter.params.ParameterizedTest36import org.junit.jupiter.params.provider.ValueSource37import org.slf4j.Logger38import org.slf4j.LoggerFactory39import java.util.*40@Extensions(41 ExtendWith(RestTestBase.TestTemplateInvocationContextProvider::class)42@TestInstance(TestInstance.Lifecycle
graphActions
Using AI Code Generation
1import com.foo.rest.examples.spring.graphql.GraphQLController2import com.foo.rest.examples.spring.graphql.GraphQLDto3import com.foo.rest.examples.spring.graphql.GraphQLDto.*4import com.foo.rest.examples.spring.graphql.GraphQLDto.GraphQLQuery5import com.foo.rest.examples.spring.graphql.GraphQLDto.GraphQLQuery.*6import org.evomaster.core.problem.graphql.GQInputValue7import org.evomaster.core.problem.graphql.GQInputValue.*8import org.evomaster.core.problem.graphql.GQMutation9import org.evomaster.core.problem.graphql.GQMutation.*10import org.evomaster.core.problem.graphql.GQNode11import org.evomaster.core.problem.graphql.GQNode.*12import org.evomaster.core.problem.graphql.GQOutputValue13import org.evomaster.core.problem.graphql.GQOutputValue.*14import org.evomaster.core.problem.graphql.GQSelection15import org.evomaster.core.problem.graphql.GQSelection.*16import org.evomaster.core.problem.graphql.GQType17import org.evomaster.core.problem.graphql.GQType.*18import org.evomaster.core.problem.graphql.GQVariable19import org.evomaster.core.problem.graphql.GQVariable.*20import org.evomaster.core.problem.graphql.GQVariableType21import org.evomaster.core.problem.graphql.GQVariableType.*22import org.evomaster.e2etests.utils.GraphQLTestBase23import org.junit.jupiter.api.Assertions24import org.junit.jupiter.api.Test25import org.junit.jupiter.api.TestInstance26import org.springframework.boot.test.context.SpringBootTest27import org.springframework.test.context.ActiveProfiles28@SpringBootTest(29@ActiveProfiles("test")30@TestInstance(TestInstance.Lifecycle.PER_CLASS)31class GraphQLTest : GraphQLTestBase() {32 fun testRunEM() {33 super.init()34 val actions = graphActions {35 query(GraphQLQuery(36 type = GQType(
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!