Skip to content
Permalink
Browse files

updated JUnit/Surefire, and fixed series of bugs

  • Loading branch information...
arcuri82 committed Jul 4, 2019
1 parent 4b15868 commit 39f530ad9230c682b360b34e9ca4e8638f8db1ca
@@ -17,10 +17,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
</dependency>
</dependencies>

<build>
@@ -17,10 +17,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
</dependency>
</dependencies>

<build>
@@ -22,13 +22,17 @@ is used in the EvoMaster Core (eg, when making HTTP calls) and
* @param locationHeader a URI-reference, coming from a "location" header. See RFC 7231.
* Note: it can be a relative reference
* @param expectedTemplate a full URI of the target resource, but with some path elements
* that might be unresolved. If {@code locationHeader} is not
* that might (or might not) be unresolved. If {@code locationHeader} is not
* empty, it will replace the beginning of this template.
* @return a fully resolved URI for the target resource. If there are problems, just
* return the input locationHeader
* return the input locationHeader. If this latter is empty/null, then return the template
*/
public static String resolveLocation(String locationHeader, String expectedTemplate){

if(locationHeader==null || locationHeader.isEmpty()){
return expectedTemplate;
}

URI locationURI;
try{
locationURI = URI.create(locationHeader);
@@ -36,6 +36,15 @@ public void testResolveLocation_fullURI_different_indirect() {
assertEquals("https://127.0.0.1:80/a/5/x", res);
}

@Test
public void testResolveLocation_null() {
String template = "http://localhost:12345/a/x";
String location = null;

String res = EMTestUtils.resolveLocation(location, template);
assertEquals(template, res);
}

@Test
public void testIsValidURI() {

@@ -117,10 +117,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
@@ -31,10 +31,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
</dependency>


<dependency>
@@ -118,10 +118,6 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
@@ -84,7 +84,7 @@ class TestCaseWriter {
val name = locationVar(id!!)
when {
format.isJava() -> lines.add("String $name = \"\";")
format.isKotlin() -> lines.add("var $name = \"\"")
format.isKotlin() -> lines.add("var $name : String? = \"\"")
}
}
}
@@ -2,9 +2,12 @@ package org.evomaster.core.problem.rest.service

import com.google.inject.Inject
import org.evomaster.client.java.controller.api.EMTestUtils
import org.evomaster.client.java.controller.api.dto.*
import org.evomaster.core.database.DbActionTransformer
import org.evomaster.client.java.controller.api.dto.AdditionalInfoDto
import org.evomaster.client.java.controller.api.dto.HeuristicEntryDto
import org.evomaster.client.java.controller.api.dto.SutInfoDto
import org.evomaster.client.java.controller.api.dto.TestResultsDto
import org.evomaster.core.database.DatabaseExecution
import org.evomaster.core.database.DbActionTransformer
import org.evomaster.core.logging.LoggingUtil
import org.evomaster.core.problem.rest.*
import org.evomaster.core.problem.rest.auth.NoAuth
@@ -137,7 +140,7 @@ class RestFitness : FitnessFunction<RestIndividual>() {
*/
//TODO prioritized list
val ids = randomness.choose(
archive.notCoveredTargets().filter { !IdMapper.isLocal(it)},
archive.notCoveredTargets().filter { !IdMapper.isLocal(it) },
100).toSet()

val dto = rc.getTestResults(ids)
@@ -182,8 +185,9 @@ class RestFitness : FitnessFunction<RestIndividual>() {
extraHeuristicsLogger.writeHeuristics(extra.heuristics, i)

val toMinimize = extra.heuristics
.filter { it != null
&& it.objective == HeuristicEntryDto.Objective.MINIMIZE_TO_ZERO
.filter {
it != null
&& it.objective == HeuristicEntryDto.Objective.MINIMIZE_TO_ZERO
}.map { it.value }
.toList()

@@ -235,15 +239,15 @@ class RestFitness : FitnessFunction<RestIndividual>() {

info.headers
.filter { name ->
! action.parameters.any { it is HeaderParam && it.name.equals(name, ignoreCase = true) }
!action.parameters.any { it is HeaderParam && it.name.equals(name, ignoreCase = true) }
}
.forEach {
action.parameters.add(HeaderParam(it, OptionalGene(it, StringGene(it), false)))
}

info.queryParameters
.filter { name ->
! action.parameters.any { it is QueryParam && it.name.equals(name, ignoreCase = true) }
!action.parameters.any { it is QueryParam && it.name.equals(name, ignoreCase = true) }
}
.forEach { name ->
action.parameters.add(QueryParam(name, OptionalGene(name, StringGene(name), false)))
@@ -305,21 +309,20 @@ class RestFitness : FitnessFunction<RestIndividual>() {

//OK -> 5xx being better than 4xx, as code executed
//FAULT -> 4xx worse than 2xx (can't find bugs if input is invalid)
if(status in 200..299){
if (status in 200..299) {
fv.updateTarget(okId, 1.0, it)
fv.updateTarget(faultId, 0.5, it)
} else if(status in 400..499){
} else if (status in 400..499) {
fv.updateTarget(okId, 0.1, it)
fv.updateTarget(faultId, 0.1, it)
} else if(status in 500..599){
} else if (status in 500..599) {
fv.updateTarget(okId, 0.5, it)
fv.updateTarget(faultId, 1.0, it)
}
}
}



/**
* @return whether the call was OK. Eg, in some cases, we might want to stop
* the test at this action, and do not continue
@@ -336,22 +339,24 @@ class RestFitness : FitnessFunction<RestIndividual>() {

val path = a.resolvedPath()

val fullUri = if (a.locationId != null) {
val locationHeader = chainState[locationName(a.locationId!!)]
val locationHeader = if (a.locationId != null) {
chainState[locationName(a.locationId!!)]
?: throw IllegalStateException("Call expected a missing chained 'location'")

EMTestUtils.resolveLocation(locationHeader, baseUrl + path)!!

} else {
baseUrl + path
}.let {
/*
TODO this will be need to be done properly, and check if
it is or not a valid char
*/
it.replace("\"", "")
null
}

val fullUri = EMTestUtils.resolveLocation(locationHeader, baseUrl + path)!!
.let {
/*
TODO this will be need to be done properly, and check if
it is or not a valid char.
Furthermore, likely needed to be done in resolveLocation,
or at least check how RestAssured would behave
*/
it.replace("\"", "")
}

/*
TODO: This only considers the first in the list of produced responses
This is fine for endpoints that only produce one type of response.
@@ -384,7 +389,6 @@ class RestFitness : FitnessFunction<RestIndividual>() {
*/



val body = a.parameters.find { p -> p is BodyParam }
val forms = a.getBodyFormData()

@@ -395,14 +399,14 @@ class RestFitness : FitnessFunction<RestIndividual>() {
val bodyEntity = if (body != null && body is BodyParam) {
val mode = when {
body.isJson() -> "json"
//body.isXml() -> "xml" // might have to handle here: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
//body.isXml() -> "xml" // might have to handle here: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
body.isTextPlain() -> "text"
else -> throw IllegalStateException("Cannot handle body type: " + body.contentType())
}
Entity.entity(body.gene.getValueAsPrintableString(mode = mode, targetFormat = configuration.outputFormat), body.contentType())
} else if (forms != null) {
Entity.entity(forms, MediaType.APPLICATION_FORM_URLENCODED_TYPE)
} else if(a.verb == HttpVerb.PUT || a.verb == HttpVerb.PATCH){
} else if (a.verb == HttpVerb.PUT || a.verb == HttpVerb.PATCH) {
/*
PUT and PATCH must have a payload. But it might happen that it is missing in the Swagger schema
when objects like WebRequest are used. So we default to urlencoded
@@ -77,10 +77,7 @@
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
</dependency>


</dependencies>

@@ -62,7 +62,7 @@
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<artifactId>junit-platform-launcher</artifactId>
</dependency>

</dependencies>
@@ -5,9 +5,13 @@
import org.junit.platform.launcher.TestPlan;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.CustomSummaryGeneratingListener;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;

/**
@@ -16,7 +20,8 @@
public class JUnitTestRunner {

public static TestExecutionSummary runTestsInClass(Class<?> klass){
SummaryGeneratingListener listener = new SummaryGeneratingListener();

CustomSummaryGeneratingListener listener = new CustomSummaryGeneratingListener();

LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectClass(klass))
@@ -23,7 +23,6 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.time.Duration;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

0 comments on commit 39f530a

Please sign in to comment.
You can’t perform that action at this time.