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 @@ -144,32 +144,16 @@ private MongoDistanceWithMetrics computeFindDistance(MongoFindCommand info) {
String databaseName = info.getDatabaseName();
String collectionName = info.getCollectionName();

Object collection = getCollection(databaseName,collectionName);
Object collection = getCollection(databaseName, collectionName);
Iterable<?> documents = getDocuments(collection);
boolean collectionIsEmpty = !documents.iterator().hasNext();

if (collectionIsEmpty) {
emptyCollections.add(new MongoOperation(info.getCollectionName(), info.getQuery(), info.getDatabaseName(), info.getDocumentsType()));
}

double min = Double.MAX_VALUE;
int numberOfEvaluatedDocuments = 0;
for (Object doc : documents) {
numberOfEvaluatedDocuments += 1;
double findDistance;
try {
findDistance = calculator.computeExpression(info.getQuery(), doc);
} catch (Exception ex) {
SimpleLogger.uniqueWarn("Failed to compute find: " + info.getQuery() + " with data " + doc);
findDistance = Double.MAX_VALUE;
}
if (findDistance == 0) {
return new MongoDistanceWithMetrics(0, numberOfEvaluatedDocuments);
} else if (findDistance < min) {
min = findDistance;
}
}
return new MongoDistanceWithMetrics(min, numberOfEvaluatedDocuments);
MongoDistanceWithMetrics mongoDistanceWithMetrics = calculator.computeDistanceDocuments(info.getQuery(), documents); // to update the metrics
return mongoDistanceWithMetrics;
}

private Object getCollection(String databaseName, String collectionName) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
* Represent $all operation.
* Matches arrays that contain all elements specified in the query.
*/
public class AllOperation<V> extends QueryOperation{
private final String fieldName;
public class AllOperation<V> extends QueryOperationWithField {
private final List<V> values;

public AllOperation(String fieldName, List<V> values) {
this.fieldName = fieldName;
super(fieldName);
this.values = values;
}

public String getFieldName() {
return fieldName;
}

public List<V> getValues() {
return values;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Represent $and operation.
* Joins query clauses with a logical AND returns all documents that match the conditions of all clauses.
*/
public class AndOperation extends QueryOperation{
public class AndOperation extends QueryOperation {
private final List<QueryOperation> conditions;

public AndOperation(List<QueryOperation> conditions) {
Expand All @@ -16,4 +16,4 @@ public AndOperation(List<QueryOperation> conditions) {
public List<QueryOperation> getConditions() {
return conditions;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package org.evomaster.client.java.controller.mongo.operations;

public abstract class ComparisonOperation<V> extends QueryOperation{
private final String fieldName;
public abstract class ComparisonOperation<V> extends QueryOperationWithField {
private final V value;

ComparisonOperation(String fieldName, V value) {
this.fieldName = fieldName;
super(fieldName);
this.value = value;
}

public String getFieldName() {
return fieldName;
}

public V getValue() {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
* Selects documents if element in the array field matches all the specified $elemMatch conditions.
* Here it only has one condition to match implementation in "com.mongodb.client.model.Filters"
*/
public class ElemMatchOperation extends QueryOperation{
private final String fieldName;
public class ElemMatchOperation extends QueryOperationWithField {
private final QueryOperation condition;

public ElemMatchOperation(String fieldName, QueryOperation condition) {
this.fieldName = fieldName;
super( fieldName);
this.condition = condition;
}

public String getFieldName() {
return fieldName;
}

public QueryOperation getCondition() {
return condition;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Represent $eq operation.
* Matches documents where the value of a field equals the specified value.
*/
public class EqualsOperation<V> extends ComparisonOperation<V>{
public class EqualsOperation<V> extends ComparisonOperation<V> {
public EqualsOperation(String fieldName, V value) {
super(fieldName, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
* When boolean is true, $exists matches the documents that contain the field.
* When boolean is false, the query returns only the documents that do not contain the field.
*/
public class ExistsOperation extends QueryOperation{
private final String fieldName;
public class ExistsOperation extends QueryOperationWithField {
private final Boolean bool;

public ExistsOperation(String fieldName, Boolean bool) {
this.fieldName = fieldName;
super(fieldName);
this.bool = bool;
}

public String getFieldName() {
return fieldName;
}

public Boolean getBoolean() {
return bool;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Represent $gte operation.
* Selects the documents where the value of the field is greater than or equal to a specified value
*/
public class GreaterThanEqualsOperation<V> extends ComparisonOperation<V>{
public class GreaterThanEqualsOperation<V> extends ComparisonOperation<V> {
public GreaterThanEqualsOperation(String fieldName, V value) {
super(fieldName, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Represent $gt operation.
* Selects the documents where the value of the field is greater than or equal to a specified value
*/
public class GreaterThanOperation<V> extends ComparisonOperation<V>{
public class GreaterThanOperation<V> extends ComparisonOperation<V> {
public GreaterThanOperation(String fieldName, V value) {
super(fieldName, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
* Represent $in operation.
* Selects the documents where the value of a field equals any value in the specified array.
*/
public class InOperation<V> extends QueryOperation{
private final String fieldName;
public class InOperation<V> extends QueryOperationWithField {
private final List<V> values;

public InOperation(String fieldName, List<V> values) {
this.fieldName = fieldName;
super(fieldName);
this.values = values;
}

public String getFieldName() {
return fieldName;
}

public List<V> getValues() {
return values;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Represent $jsonSchema operation.
* Matches documents that satisfy the specified JSON Schema.
*/
public class JsonSchemaOperation extends QueryOperation{
public class JsonSchemaOperation extends QueryOperation {
private final Object schema;

public JsonSchemaOperation(Object schema) {
Expand All @@ -14,4 +14,4 @@ public JsonSchemaOperation(Object schema) {
public Object getSchema() {
return schema;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Represent $lte operation.
* Selects the documents where the value of the field is less than or equal to a specified value
*/
public class LessThanEqualsOperation<V> extends ComparisonOperation<V>{
public class LessThanEqualsOperation<V> extends ComparisonOperation<V> {
public LessThanEqualsOperation(String fieldName, V value) {
super(fieldName, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Represent $lt operation.
* Selects the documents where the value of the field is less than to a specified value
*/
public class LessThanOperation<V> extends ComparisonOperation<V>{
public class LessThanOperation<V> extends ComparisonOperation<V> {
public LessThanOperation(String fieldName, V value) {
super(fieldName, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@
* Represent $mod operation.
* Select documents where the value of a field divided by a divisor has the specified remainder.
*/
public class ModOperation extends QueryOperation{
private final String fieldName;
public class ModOperation extends QueryOperationWithField {
private final Long divisor;
private final Long remainder;

public ModOperation(String fieldName, Long divisor, Long remainder) {
this.fieldName = fieldName;
super(fieldName);
this.divisor = divisor;
this.remainder = remainder;
}

public String getFieldName() {
return fieldName;
}

public Long getDivisor() {
return divisor;
}

public Long getRemainder() {
return remainder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@
* Represent $nearSphere operation.
* Specifies a point for which a geospatial query returns the documents from nearest to farthest.
*/
public class NearSphereOperation extends QueryOperation {
private final String fieldName;
public class NearSphereOperation extends QueryOperationWithField {
private final Double longitude;
private final Double latitude;
private final Double maxDistance;
private final Double minDistance;


public NearSphereOperation(String fieldName, Double longitude, Double latitude, Double maxDistance, Double minDistance) {
this.fieldName = fieldName;
super(fieldName);
this.longitude = longitude;
this.latitude = latitude;
this.maxDistance = maxDistance;
this.minDistance = minDistance;
}

public String getFieldName() {
return fieldName;
}

public Double getLongitude() {
return longitude;
}
Expand All @@ -39,4 +34,4 @@ public Double getMaxDistance() {
public Double getMinDistance() {
return minDistance;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Represent $nor operation.
* Selects the documents that fail all the query expressions in the array.
*/
public class NorOperation extends QueryOperation{
public class NorOperation extends QueryOperation {
private final List<QueryOperation> conditions;

public NorOperation(List<QueryOperation> conditions) {
Expand All @@ -16,4 +16,4 @@ public NorOperation(List<QueryOperation> conditions) {
public List<QueryOperation> getConditions() {
return conditions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Selects the documents where the value of the field is not equal to the specified value.
* This includes documents that do not contain the field.
*/
public class NotEqualsOperation<V> extends ComparisonOperation<V>{
public class NotEqualsOperation<V> extends ComparisonOperation<V> {
public NotEqualsOperation(String fieldName, V value) {
super(fieldName, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
/**
* Represent $nin operation.
* Selects the documents where:
* - the field value is not in the specified array
* - the field does not exist.
* - the field value is not in the specified array
* - the field does not exist.
*/
public class NotInOperation<V> extends QueryOperation{
private final String fieldName;
public class NotInOperation<V> extends QueryOperationWithField {
private final List<V> values;

public NotInOperation(String fieldName, List<V> values) {
this.fieldName = fieldName;
super(fieldName);
this.values = values;
}

public String getFieldName() {
return fieldName;
}

public List<V> getValues() {
return values;
}
}
}
Loading
Loading