Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
variety
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
variety
Commits
59c2ec0b
Commit
59c2ec0b
authored
Dec 07, 2015
by
Tomas Dvorak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests adapted to #104
parent
18ec4c82
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
25 deletions
+39
-25
DbResultsValidator.java
...java/com/github/variety/validator/DbResultsValidator.java
+3
-1
JsonResultsValidator.java
...va/com/github/variety/validator/JsonResultsValidator.java
+2
-2
LimitedAccessTest.java
.../test/java/com/github/variety/test/LimitedAccessTest.java
+1
-1
OutputFormatTest.java
...c/test/java/com/github/variety/test/OutputFormatTest.java
+1
-1
PluginsTest.java
test/src/test/java/com/github/variety/test/PluginsTest.java
+3
-1
QuietOptionTest.java
...rc/test/java/com/github/variety/test/QuietOptionTest.java
+1
-1
SampleData.java
test/src/test/java/com/github/variety/test/SampleData.java
+15
-17
csvplugin.js
test/src/test/resources/csvplugin.js
+1
-1
expected_ascii_table.txt
test/src/test/resources/expected_ascii_table.txt
+12
-0
No files found.
test/src/main/java/com/github/variety/validator/DbResultsValidator.java
View file @
59c2ec0b
...
...
@@ -5,6 +5,7 @@ import com.mongodb.*;
import
org.junit.Assert
;
import
java.util.Arrays
;
import
java.util.Set
;
public
class
DbResultsValidator
implements
ResultsValidator
{
...
...
@@ -53,7 +54,8 @@ public class DbResultsValidator implements ResultsValidator {
}
private
void
verifyKeyTypes
(
final
String
key
,
final
DBObject
result
,
final
String
[]
expectedTypes
)
{
final
BasicDBList
types
=
(
BasicDBList
)((
DBObject
)
result
.
get
(
"value"
)).
get
(
"types"
);
final
BasicDBObject
typesObj
=
(
BasicDBObject
)((
BasicDBObject
)
result
.
get
(
"value"
)).
get
(
"types"
);
final
Set
<
String
>
types
=
typesObj
.
keySet
();
Assert
.
assertEquals
(
"Incorrect count of expected("
+
Arrays
.
toString
(
expectedTypes
)
+
") and real types("
+
Arrays
.
toString
(
types
.
toArray
())
...
...
test/src/main/java/com/github/variety/validator/JsonResultsValidator.java
View file @
59c2ec0b
...
...
@@ -25,8 +25,8 @@ public class JsonResultsValidator implements ResultsValidator {
final
String
key
=
((
BasicDBObject
)
obj
.
get
(
"_id"
)).
getString
(
"key"
);
final
long
totalOccurrences
=
obj
.
getLong
(
"totalOccurrences"
);
final
double
percentContaining
=
obj
.
getDouble
(
"percentContaining"
);
final
BasicDB
List
typesList
=
(
BasicDBLis
t
)
((
BasicDBObject
)
obj
.
get
(
"value"
)).
get
(
"types"
);
final
HashSet
<
String
>
types
=
new
HashSet
<>(
Arrays
.
asList
(
typesList
.
toArray
(
new
String
[
typesList
.
size
()]))
);
final
BasicDB
Object
typesObj
=
(
BasicDBObjec
t
)
((
BasicDBObject
)
obj
.
get
(
"value"
)).
get
(
"types"
);
final
Set
<
String
>
types
=
typesObj
.
keySet
(
);
entries
.
add
(
new
VarietyEntry
(
key
,
totalOccurrences
,
percentContaining
,
types
));
}
return
entries
;
...
...
test/src/test/java/com/github/variety/test/LimitedAccessTest.java
View file @
59c2ec0b
...
...
@@ -67,7 +67,7 @@ public class LimitedAccessTest {
@Test
public
void
verifyBasicResultsAscii
()
throws
Exception
{
final
String
stdout
=
variety
.
withPersistResults
(
false
).
withQuiet
(
true
).
runAnalysis
();
Assert
.
assertEquals
(
SampleData
.
EXPECTED_DATA_ASCII_TABLE
,
stdout
);
Assert
.
assertEquals
(
SampleData
.
getExpectedDataAsciiTable
()
,
stdout
);
}
...
...
test/src/test/java/com/github/variety/test/OutputFormatTest.java
View file @
59c2ec0b
...
...
@@ -46,7 +46,7 @@ public class OutputFormatTest {
.
filter
(
line
->
line
.
startsWith
(
"|"
)
||
line
.
startsWith
(
"+"
))
.
collect
(
Collectors
.
joining
(
"\n"
));
Assert
.
assertEquals
(
SampleData
.
EXPECTED_DATA_ASCII_TABLE
,
actual
);
Assert
.
assertEquals
(
SampleData
.
getExpectedDataAsciiTable
()
,
actual
);
}
}
test/src/test/java/com/github/variety/test/PluginsTest.java
View file @
59c2ec0b
...
...
@@ -2,12 +2,14 @@ package com.github.variety.test;
import
com.github.variety.Variety
;
import
com.github.variety.validator.ResultsValidator
;
import
jdk.nashorn.internal.runtime.regexp.joni.Regex
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.net.URL
;
import
java.util.regex.Pattern
;
public
class
PluginsTest
{
...
...
@@ -49,7 +51,7 @@ public class PluginsTest {
public
void
verifyPluginParamParsing
()
throws
Exception
{
final
String
path
=
getPluginPath
(
"/csvplugin.js"
);
final
ResultsValidator
analysis
=
variety
.
withPlugins
(
path
+
"|delimiter=;"
).
runDatabaseAnalysis
();
Assert
.
assertTrue
(
analysis
.
getStdOut
().
contains
(
"Using plugins of [ \""
+
path
+
"\" ]"
));
Assert
.
assertTrue
(
analysis
.
getStdOut
().
contains
(
path
));
}
private
String
getPluginPath
(
final
String
name
)
{
...
...
test/src/test/java/com/github/variety/test/QuietOptionTest.java
View file @
59c2ec0b
...
...
@@ -34,6 +34,6 @@ public class QuietOptionTest {
@Test
public
void
testQuietLogs
()
throws
Exception
{
final
ResultsValidator
varietyAnalysis
=
variety
.
withQuiet
(
true
).
runDatabaseAnalysis
();
Assert
.
assertEquals
(
SampleData
.
EXPECTED_DATA_ASCII_TABLE
,
varietyAnalysis
.
getStdOut
());
Assert
.
assertEquals
(
SampleData
.
getExpectedDataAsciiTable
()
,
varietyAnalysis
.
getStdOut
());
}
}
test/src/test/java/com/github/variety/test/SampleData.java
View file @
59c2ec0b
...
...
@@ -4,6 +4,9 @@ import com.mongodb.BasicDBObjectBuilder;
import
com.mongodb.DBObject
;
import
org.bson.types.Binary
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -12,23 +15,6 @@ import java.util.List;
class
SampleData
{
/**
* Ascii table representation of sample data results. It should be possible to verify actual output of Variety
* against this table, to check correct formatting.
*/
public
static
final
String
EXPECTED_DATA_ASCII_TABLE
=
"+------------------------------------------------------------+\n"
+
"| key | types | occurrences | percents |\n"
+
"| ------------------ | ------------ | ----------- | -------- |\n"
+
"| _id | ObjectId | 5 | 100.0 |\n"
+
"| name | String | 5 | 100.0 |\n"
+
"| bio | String | 3 | 60.0 |\n"
+
"| birthday | String | 2 | 40.0 |\n"
+
"| pets | Array,String | 2 | 40.0 |\n"
+
"| someBinData | BinData-old | 1 | 20.0 |\n"
+
"| someWeirdLegacyKey | String | 1 | 20.0 |\n"
+
"+------------------------------------------------------------+"
;
/**
* Java representation of sample collection provided in variety README:<p>
*
* {name: "Tom", bio: "A nice guy.", pets: ["monkey", "fish"], someWeirdLegacyKey: "I like Ike!"}<p>
...
...
@@ -76,4 +62,16 @@ class SampleData {
return
examples
;
}
/**
* Ascii table representation of sample data results. It should be possible to verify actual output of Variety
* against this table, to check correct formatting.
*/
public
static
String
getExpectedDataAsciiTable
()
{
try
{
return
new
String
(
Files
.
readAllBytes
(
Paths
.
get
(
SampleData
.
class
.
getResource
(
"/expected_ascii_table.txt"
).
getFile
())));
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
test/src/test/resources/csvplugin.js
View file @
59c2ec0b
...
...
@@ -3,7 +3,7 @@ var getCsv = function(varietyResults) {
var
headers
=
[
'key'
,
'types'
,
'occurrences'
,
'percents'
];
var
table
=
[
headers
.
join
(
delimiter
)];
var
rows
=
varietyResults
.
map
(
function
(
key
)
{
return
[
key
.
_id
.
key
,
key
.
value
.
types
,
key
.
totalOccurrences
,
key
.
percentContaining
].
join
(
delimiter
);
return
[
key
.
_id
.
key
,
Object
.
keys
(
key
.
value
.
types
).
sort
()
,
key
.
totalOccurrences
,
key
.
percentContaining
].
join
(
delimiter
);
},
this
);
return
table
.
concat
(
rows
).
join
(
'
\
n'
);
};
...
...
test/src/test/resources/expected_ascii_table.txt
0 → 100644
View file @
59c2ec0b
+--------------------------------------------------------------------+
| key | types | occurrences | percents |
| ------------------ | -------------------- | ----------- | -------- |
| _id | ObjectId | 5 | 100.0 |
| name | String | 5 | 100.0 |
| bio | String | 3 | 60.0 |
| birthday | String | 2 | 40.0 |
| pets | String (1),Array (1) | 2 | 40.0 |
| someBinData | BinData-old | 1 | 20.0 |
| someWeirdLegacyKey | String | 1 | 20.0 |
+--------------------------------------------------------------------+
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment