How to use reset method of org.evomaster.client.java.controller.internal.db.SqlHandler class

Best EvoMaster code snippet using org.evomaster.client.java.controller.internal.db.SqlHandler.reset

Source:SutController.java Github

copy

Full Screen

...146 */147 public final void initSqlHandler() {148 sqlHandler.setConnection(getConnection());149 }150 public final void resetExtraHeuristics() {151 sqlHandler.reset();152 }153 public final List<ExtraHeuristicsDto> getExtraHeuristics() {154 if (extras.size() == actionIndex) {155 extras.add(computeExtraHeuristics());156 }157 return new ArrayList<>(extras);158 }159 public final ExtraHeuristicsDto computeExtraHeuristics() {160 ExtraHeuristicsDto dto = new ExtraHeuristicsDto();161 if(sqlHandler.isCalculateHeuristics()) {162 sqlHandler.getDistances().stream()163 .map(p ->164 new HeuristicEntryDto(165 HeuristicEntryDto.Type.SQL,166 HeuristicEntryDto.Objective.MINIMIZE_TO_ZERO,167 p.sqlCommand,168 p.distance169 ))170 .forEach(h -> dto.heuristics.add(h));171 }172 if (sqlHandler.isCalculateHeuristics() || sqlHandler.isExtractSqlExecution()){173 ExecutionDto executionDto = sqlHandler.getExecutionDto();174 dto.databaseExecutionDto = executionDto;175 }176 return dto;177 }178 /**179 * Extra information about the SQL Database Schema, if any is present.180 * Note: this is extracted by querying the database itself.181 * So the database must be up and running.182 *183 * @return a DTO with the schema information184 * @see SutController#getConnection185 */186 public final DbSchemaDto getSqlDatabaseSchema() {187 if (schemaDto != null) {188 return schemaDto;189 }190 if (getConnection() == null) {191 return null;192 }193 try {194 schemaDto = SchemaExtractor.extract(getConnection());195 } catch (Exception e) {196 SimpleLogger.error("Failed to extract the SQL Database Schema: " + e.getMessage());197 return null;198 }199 return schemaDto;200 }201 /**202 * Either there is no connection, or, if there is, then it must have P6Spy configured.203 * But this might not apply to all kind controllers204 *205 * @return false if the verification failed206 */207 public final boolean verifySqlConnection(){208 Connection connection = getConnection();209 if(connection == null210 //check does not make sense for External211 || !(this instanceof EmbeddedSutController)){212 return true;213 }214 /*215 bit hacky/brittle, but seems there is no easy way to check if a connection is216 using P6Spy.217 However, the name of driver's package would appear when doing a toString on it218 */219 String info = connection.toString();220 return info.contains("p6spy");221 }222 /**223 * Re-initialize all internal data to enable a completely new search phase224 * which should be independent from previous ones225 */226 public abstract void newSearch();227 /**228 * Re-initialize some internal data needed before running a new test229 */230 public final void newTest() {231 actionIndex = -1;232 resetExtraHeuristics();233 extras.clear();234 newTestSpecificHandler();235 }236 /**237 * As some heuristics are based on which action (eg HTTP call, or click of button)238 * in the test sequence is executed, and their order, we need to keep track of which239 * action does cover what.240 *241 * @param dto the DTO with the information about the action (eg its index in the test)242 */243 public final void newAction(ActionDto dto) {244 if (dto.index > extras.size()) {245 extras.add(computeExtraHeuristics());246 }247 this.actionIndex = dto.index;248 resetExtraHeuristics();249 newActionSpecificHandler(dto);250 }251 public abstract void newTestSpecificHandler();252 public abstract void newActionSpecificHandler(ActionDto dto);253 /**254 * Check if bytecode instrumentation is on.255 *256 * @return true if the instrumentation is on257 */258 public abstract boolean isInstrumentationActivated();259 /**260 * <p>261 * Check if the system under test (SUT) is running and fully initialized262 * </p>263 *264 * <p>265 * How to implement this method depends on the library/framework used266 * to build the application.267 * In Spring applications, this can be done with something like:268 * {@code ctx != null && ctx.isRunning()}, where {@code ctx} is a field where269 * {@code ConfigurableApplicationContext} should be stored when starting270 * the application.271 * </p>272 * @return true if the SUT is running273 */274 public abstract boolean isSutRunning();275 /**276 * <p>277 * A "," separated list of package prefixes or class names.278 * For example, "com.foo.,com.bar.Bar".279 * This is used to specify for which classes we want to measure280 * code coverage.281 * </p>282 *283 * <p>284 * Note: be careful of using something as general as "com."285 * or "org.", as most likely ALL your third-party libraries286 * would be instrumented as well, which could have a severe287 * impact on performance.288 * </p>289 *290 * @return a String representing the packages to cover291 */292 public abstract String getPackagePrefixesToCover();293 /**294 * <p>295 * If the application uses some sort of authentication, these details296 * need to be provided here.297 * Even if EvoMaster can have access to the database, it would not be able298 * to recover hashed passwords.299 * </p>300 *301 * <p>302 * To test the application, there is the need to provide auth for at least 1 user303 * (and more if they have different authorization roles).304 * When EvoMaster generates test cases, it can decide to use the credential of305 * any user provided by this method.306 * </p>307 *308 * <p>309 * What type of info to provide here depends on the auth mechanism, e.g.,310 * Basic or cookie-based (using {@link CookieLoginDto}).311 * To simplify the creation of these DTOs with auth info, you can look312 * at {@link org.evomaster.client.java.controller.AuthUtils}.313 * </p>314 *315 * <p>316 * If the credential are stored in a database, be careful on how the317 * method {@code resetStateOfSUT} is implemented.318 * If you delete all data with {@link DbCleaner}, then you will need as well to319 * recreate the auth details.320 * This can be put in a script, executed then with {@link SqlScriptRunner}.321 * </p>322 *323 * @return a list of valid authentication credentials, or {@code null} if324 * * none is necessary325 */326 public abstract List<AuthenticationDto> getInfoForAuthentication();327 /**328 * <p>329 * If the system under test (SUT) uses a SQL database, we need to have a330 * configured connection to access it.331 * </p>332 *333 * <p>334 * This method is related to {@link SutHandler#resetStateOfSUT}.335 * When accessing a {@code Connection} object to reset the state of336 * the application, we suggest to save it to field (eg when starting the337 * application), and return such field here, e.g., {@code return connection;}.338 * This connection object will be used by EvoMaster to analyze the state of339 * the database to create better test cases.340 * </p>341 *342 * @return {@code null} if the SUT does not use any SQL database343 */344 public abstract Connection getConnection();345 /**346 * If the system under test (SUT) uses a SQL database, we need to specify347 * the driver used to connect, eg. {@code org.h2.Driver}.348 * This is needed for when we intercept SQL commands with P6Spy349 *...

Full Screen

Full Screen

reset

Using AI Code Generation

copy

Full Screen

1public class ResetDatabaseHandler {2 public static String handle(String body) {3 String[] args = body.split(":");4 if(args.length != 2){5 return "Invalid input";6 }7 String db = args[0];8 String schema = args[1];9 try {10 SqlHandler.reset(db, schema);11 return "OK";12 } catch (SQLException e) {13 return e.getMessage();14 }15 }16}17import groovy.json.JsonSlurper18import groovy.json.JsonOutput19def body = JsonOutput.toJson([db: "db", schema: "schema"])20response.setRequestProperty("Content-Type", "text/plain")21response.setRequestProperty("Content-Length", body.length())22response.outputStream.withWriter("UTF-8") { it << body }23def result = new JsonSlurper().parseText(response.inputStream.text)

Full Screen

Full Screen

reset

Using AI Code Generation

copy

Full Screen

1org.evomaster.client.java.controller.internal.db.SqlHandler.resetDatabase();2org.evomaster.client.java.controller.internal.db.SqlHandler.resetDatabase();3org.evomaster.client.java.controller.internal.db.SqlHandler.resetDatabase();4org.evomaster.client.java.controller.internal.db.SqlHandler.resetDatabase();5org.evomaster.client.java.controller.internal.db.SqlHandler.resetDatabase();6org.evomaster.client.java.controller.internal.db.SqlHandler.resetDatabase();

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