Commit 5a9fc8b4 by Tomas Dvorak

Tests updated to changed query and limit behaviour.

parent 4c6c5045
......@@ -2,13 +2,13 @@ package com.github.variety.test;
import com.github.variety.Variety;
import com.github.variety.validator.ResultsValidator;
import com.mongodb.DBObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Tests limit functionality of variety. It should analyse only first _n_ objects and then compute occurrences from
* all objects in collection.
* Tests limit functionality of variety. It should analyse only first _n_ objects.
*/
public class LimitResultsAnalysisTest {
......@@ -29,9 +29,10 @@ public class LimitResultsAnalysisTest {
@Test
public void verifyLimitedResults() throws Exception {
final ResultsValidator analysis = variety.withLimit(1).runDatabaseAnalysis();
analysis.validate("_id", 5, 100, "ObjectId");
analysis.validate("name", 5, 100, "String");
analysis.validate("someBinData", 1, 20, "BinData-old");
// limit=1 without other params selects the last inserted document (see SampleData class)
// it should equals {name: "Jim", someBinData: new BinData(2,"1234")}
analysis.validate("_id", 1, 100, "ObjectId");
analysis.validate("name", 1, 100, "String");
analysis.validate("someBinData", 1, 100, "BinData-old");
}
}
......@@ -24,13 +24,15 @@ public class QueryLimitedAnalysisTest {
@Test
public void testQueryLimitedAnalysis() throws Exception {
final ResultsValidator analysis = variety.withQuery("{someBinData:{$exists: true}}").runDatabaseAnalysis();
Assert.assertEquals(3, analysis.getResultsCount());
final ResultsValidator analysis = variety.withQuery("{birthday:{$exists: true}}").runDatabaseAnalysis();
Assert.assertEquals(5, analysis.getResultsCount());
analysis.validate("_id", 2, 100, "ObjectId");
analysis.validate("birthday", 2, 100, "String");
analysis.validate("name", 2, 100, "String");
analysis.validate("bio", 1, 50, "String");
analysis.validate("pets", 1, 50, "String");
// we analyzed only the keys of objects defined by query. But total counts and percents are computed from the complete collection
analysis.validate("_id", 5, 100, "ObjectId");
analysis.validate("name", 5, 100, "String");
analysis.validate("someBinData", 1, 20, "BinData-old");
}
}
......@@ -45,15 +45,16 @@ public class SortedAnalysisTest {
// when sorting default SampleData by name desc, first entry becomes Tom. He is only with key 'someWeirdLegacyKey'
// Together with applying limit 1, Tom is the only result in analysis. That gives us chance to assume keys and verify
// that ordering is correct.
// {name: "Tom", bio: "A nice guy.", pets: ["monkey", "fish"], someWeirdLegacyKey: "I like Ike!"}
final ResultsValidator analysis = variety.withSort("{name:-1}").withLimit(1).runDatabaseAnalysis();
Assert.assertEquals(5, analysis.getResultsCount());
analysis.validate("_id", 5, 100, "ObjectId");
analysis.validate("name", 5, 100, "String");
analysis.validate("bio", 3, 60, "String");
analysis.validate("pets", 2, 40, "Array");
analysis.validate("someWeirdLegacyKey", 1, 20, "String");
analysis.validate("_id", 1, 100, "ObjectId");
analysis.validate("name", 1, 100, "String");
analysis.validate("bio", 1, 100, "String");
analysis.validate("pets", 1, 100, "Array");
analysis.validate("someWeirdLegacyKey", 1, 100, "String");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment