Comments (10)
Thank you very much, I will take a look, maybe the problem is with cassandra-unit and not nosqlunit, or with something that I am doing wrong with Cassandra Unit, I will write a unit test with your example and see what's happen. Thank you very much.
from nosql-unit.
Pakko can you provide the full json file? I think this json is not well formed for cassandra-unit. There is no keyspacename nor columnfamilies.
from nosql-unit.
I have been creating a sample file following your guidelines and that file cannot be imported using Cassandra-Unit. I will talk with Jérémy about that. Thank you very much.
from nosql-unit.
Closed because it is related with Cassandra Unit issue jsevellec/cassandra-unit#44.
from nosql-unit.
I revised test data as Jérémy suggestion, the json parser error will not occur, but will throw NoSqlAssertionError
my test code:
@test
@UsingDataSet(locations="test_save_workrequest.json", loadStrategy=LoadStrategyEnum.CLEAN_INSERT)
@ShouldMatchDataSet(location="expected_workrequest.json")
public void testSaveWorkRequestRawData() {
WorkRequest workRequest = new WorkRequest();
workRequest.setDevice("989C6E5C-2CC1-11CA-A044-08002B1BB4F6");
workRequest.setTimeuuid("989C6E5C-2CC1-11CA-A044-08002B1BB4F5");
WorkReqTarget workReqTarget = new WorkReqTarget();
workReqTarget.setCfgGUID("cfgGUID");
workReqTarget.setName("989C6E5C-2CC1-11CA-A044-08002B1BB4F6");
workReqTarget.setFwGUID("firmwareGUID");
workReqTarget.setCpu("90.0");
List<WorkReqTarget> workReqTargetList = new ArrayList<WorkReqTarget>();
workReqTargetList.add(workReqTarget);
workRequest.setWorkReqTargetList(workReqTargetList);
monitoringNoSQLDao.saveWorkRequestRawData(workRequest);
}
2 json files:
test_save_workrequest.json
{
"name" : "monitoring_service",
"replicationFactor" : 1,
"strategy" : "org.apache.cassandra.locator.SimpleStrategy",
"columnFamilies" : [{
"name" : "at_mv_workreq",
"type" : "STANDARD",
"keyType" : "CompositeType(UTF8Type,UTF8Type)",
"comparatorType" : "TimeUUIDType",
"defaultColumnValueType" : "UTF8Type"
},
{
"name" : "at_workreq",
"type" : "STANDARD",
"keyType" : "TimeUUIDType",
"comparatorType" : "UTF8Type",
"defaultColumnValueType" : "UTF8Type"
}]
}
expected_workrequest.json
{
"name" : "monitoring_service",
"replicationFactor" : 1,
"strategy" : "org.apache.cassandra.locator.SimpleStrategy",
"columnFamilies" : [{
"name" : "at_workreq",
"type" : "STANDARD",
"keyType" : "TimeUUIDType",
"comparatorType" : "UTF8Type",
"defaultColumnValueType" : "UTF8Type",
"rows" : [{
"key" : "989C6E5C-2CC1-11CA-A044-08002B1BB4F5",
"columns" : [{
"name": "WORKREQUEST",
"value": "[{'name':'device','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F6'},{'name':'timeuuid','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F5'},{'name':'workReqTargetList','value':[{'name':'name','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F6'},{'name':'cfgGUID','value':'cfgGUID'},{'name':'fwGUID','value':'firmwareGUID'},{'name':'cpu','value':'90.0'}]}]"
}]
}]
},
{
"name" : "at_mv_workreq",
"type" : "STANDARD",
"keyType" : "CompositeType(UTF8Type,UTF8Type)",
"comparatorType" : "TimeUUIDType",
"defaultColumnValueType" : "UTF8Type",
"rows" : [{
"key" : "989C6E5C-2CC1-11CA-A044-08002B1BB4F6:-2001057270",
"columns" : [{
"name": "989C6E5C-2CC1-11CA-A044-08002B1BB4F5",
"value": "[{'name':'device','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F6'},{'name':'timeuuid','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F5'},{'name':'workReqTargetList','value':[{'name':'name','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F6'},{'name':'cfgGUID','value':'cfgGUID'},{'name':'fwGUID','value':'firmwareGUID'},{'name':'cpu','value':'90.0'}]}]"
}]
}]
}]
}
Error Trace
com.lordofthejars.nosqlunit.core.NoSqlAssertionError: Row with key 989C6E5C-2CC1-11CA-A044-08002B1BB4F5 does not contain column with name WORKREQUEST and value {"device":"989C6E5C-2CC1-11CA-A044-08002B1BB4F6","timeuuid":"989C6E5C-2CC1-11CA-A044-08002B1BB4F5","workReqTargetList":[{"name":"989C6E5C-2CC1-11CA-A044-08002B1BB4F6","cfgGUID":"cfgGUID","fwGUID":"firmwareGUID","cpu":"90.0"}]}.
at com.lordofthejars.nosqlunit.core.FailureHandler.createFailure(FailureHandler.java:7)
at com.lordofthejars.nosqlunit.cassandra.CassandraAssertion.checkColumnValue(CassandraAssertion.java:217)
at com.lordofthejars.nosqlunit.cassandra.CassandraAssertion.checkStandardColumns(CassandraAssertion.java:194)
at com.lordofthejars.nosqlunit.cassandra.CassandraAssertion.checkColumns(CassandraAssertion.java:77)
at com.lordofthejars.nosqlunit.cassandra.CassandraAssertion.strictAssertEquals(CassandraAssertion.java:52)
at com.lordofthejars.nosqlunit.cassandra.CassandraOperation.databaseIs(CassandraOperation.java:66)
at com.lordofthejars.nosqlunit.core.AbstractNoSqlTestRule$1.assertExpectation(AbstractNoSqlTestRule.java:120)
at com.lordofthejars.nosqlunit.core.AbstractNoSqlTestRule$1.evaluate(AbstractNoSqlTestRule.java:77)
at org.junit.rules.RunRules.evaluate(RunRules.java:18)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I use the managed cassandra, the loaded data in cassandra as picture, it seems db data is same with data file's data, why assertion failed.
Saved data in cassandra
Elapsed time: 31 msec(s).
[default@monitoring_service] list at_mv_workreq;
Using default limit of 100
Using default column limit of 100
RowKey: 989C6E5C-2CC1-11CA-A044-08002B1BB4F6:-2001057270
=> (column=989c6e5c-2cc1-11ca-a044-08002b1bb4f5, value={"device":"989C6E5C-2CC1-
11CA-A044-08002B1BB4F6","timeuuid":"989C6E5C-2CC1-11CA-A044-08002B1BB4F5","workR
eqTargetList":[{"name":"989C6E5C-2CC1-11CA-A044-08002B1BB4F6","cfgGUID":"cfgGUID
","fwGUID":"firmwareGUID","cpu":"90.0"}]}, timestamp=1351065765223000)
1 Row Returned.
Elapsed time: 27 msec(s).
[default@monitoring_service] list at_workreq;
Using default limit of 100
Using default column limit of 100
RowKey: 989c6e5c-2cc1-11ca-a044-08002b1bb4f5
=> (column=WORKREQUEST, value={"device":"989C6E5C-2CC1-11CA-A044-08002B1BB4F6","
timeuuid":"989C6E5C-2CC1-11CA-A044-08002B1BB4F5","workReqTargetList":[{"name":"9
89C6E5C-2CC1-11CA-A044-08002B1BB4F6","cfgGUID":"cfgGUID","fwGUID":"firmwareGUID"
,"cpu":"90.0"}]}, timestamp=1351066088549000)
1 Row Returned.
Elapsed time: 16 msec(s).
from nosql-unit.
I will try this afternoon at home, but I think that the problem is with something as simple as a matter of commas. Inserted data (by your DAOs) are with symbol ("), meanwhile expectation file is created with simple comma (') so when comparing data it tries to compare next values:
"device":"989C6E5C-2CC1-11CA-A044-08002B1BB4F6","
timeuuid":"989C6E5C-2CC1-11CA-A044-08002B1BB4F5","workReqTargetList":[{"name":"9
89C6E5C-2CC1-11CA-A044-08002B1BB4F6","cfgGUID":"cfgGUID","fwGUID":"firmwareGUID"
,"cpu":"90.0"}]
with
'device':'989C6E5C-2CC1-11CA-A044-08002B1BB4F6','
timeuuid':'989C6E5C-2CC1-11CA-A044-08002B1BB4F5','workReqTargetList':[{'name':'9
89C6E5C-2CC1-11CA-A044-08002B1BB4F6','cfgGUID':'cfgGUID','fwGUID':'firmwareGUID'
,'cpu':'90.0'}]
which obviously is different in terms of comparison.
This afternoon I will play around the problem but I think that using " character instead of ', the json parser would read a ("), I am not pretty sure but I think it will work.
from nosql-unit.
The issue resolved
First. I should not use the value string "[{'name':'device','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F6'},{'name':'timeuuid','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F5'},{'name':'workReqTargetList','value':[{'name':'name','value':'989C6E5C-2CC1-11CA-A044-08002B1BB4F6'},{'name':'cfgGUID','value':'cfgGUID'},{'name':'fwGUID','value':'firmwareGUID'},{'name':'cpu','value':'90.0'}]}]" directly just replace (') with ("), because It not be looked as a json string, just a plain text, so I should use "{"device":"989C6E5C-2CC1-11CA-A044-08002B1BB4F6","timeuuid":"989C6E5C-2CC1-11CA-A044-08002B1BB4F5","workReqTargetList":[{"name":"989C6E5C-2CC1-11CA-A044-08002B1BB4F6","cfgGUID":"cfgGUID","fwGUID":"firmwareGUID","cpu":"90.0"}]}" directly.
Second. Make sure using (") replace (')
Thanks for your help, I think my case maybe a good sample for using nosqlunit-cassandra for a complex scenario
from nosql-unit.
Hi pakko, first of all thank you very much for your interest in project, and second one thank you very much for let me use your case as a complex scenario.
Thanks.
from nosql-unit.
I have a question, whether nosql-unit for cassandra support ignore some columes when verfication like dbunit
from nosql-unit.
Hi currently does not support ignoring fields. Keep in mind that in Cassandra can be a column but in MongoDb could be a property, ... of course is something that I keep in mind, if you want you can open an issue and I will implement when I have finished the current development.
Thank you for helping me improving NoSQLUnit.
from nosql-unit.
Related Issues (20)
- Upgrade Neo4j Libraries to 3.2.x or better to for use with Bolt protocol HOT 1
- NoSQL Unit is not compatible with JUnit 5 HOT 7
- which project supports EmbeddedRedisBuilder? HOT 1
- Can't retrieve info with Spring Data from Fongoed MongoDB HOT 4
- Excepion when running multiple tests using MongoDbRule + Spring+Real remote Mongo Db+ CLEAN_INSERT Strategy HOT 10
- [Feature request] allow specify which collections/keyspaces/nodes... get deleted HOT 3
- Can I use multiple @Rule in single test class ? HOT 3
- Add DynamoDB support
- fix(SpringMongoDbRule): let Spring close the connection to Mongo when… #180
- Error when tried HBase unit test code HOT 1
- Support for reactive MongoDB driver HOT 1
- Add support for Elasticsearch 6.x.x HOT 2
- Fix tests and Setup a CI system HOT 10
- Add support for InfluxDB
- MongoFlexibleComparisonStrategy failed on embedded document
- Make static methods in MongoDbAssertion public HOT 1
- Fongo is a dead project HOT 1
- #MongoDB File specified in locations property are not present in classpath HOT 2
- #Redis java.lang.IllegalArgumentException: Windows System is not supported
- #MongoDB how to insert a document with specified _id
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nosql-unit.