Open Abhishekgith opened 9 years ago
Hi, first of all thank you so much for using nosqlunit. Is it possible to push this example in github so it would be easy to debug and's happen? If cannot then I can help you to debug nosqlunit to see what's happening. Keep in mind that nosqlunit relies findone query with all the expected document to mongodb, so if it is not found it is because the findone query returned no results.
I'm getting exactly the same error. Debugging the code I've found that the findOne method does not return anything but it is looking for expectedDataObject which is an instance of DBObject.
If I try a findOne with the object id it works. If I try to add a definition to my repository interface it will not autowire any more: "nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findOne found for type User!"
What should we be using to make this work?
Thanks
have you inspected the mongodb database connecting with CLI if the same object that is passed in findOne is in reality inside db?
Connecting to a real Mongo does indeed insert the user. I have a single test which inserts 1 user and I am using Fongo. In your checkCollectionObjects method the count() check passes it is just the findOne which is failing. If I manually retrieve by id and print out properties within the test it matches the JSON values.
Any update on this.I am also getting the same error while trying to save.
I have created a web application using spring mongodb, maven. I trying to test mongo db save operation but facing issues with nosqllordofthejars. Please find below the details:
I am getting below error: below is the stack trace:
com.lordofthejars.nosqlunit.core.NoSqlAssertionError: Object # { "_id" : "54f8242ce281d80fcaebc723" , "_class" : "com.docworks.domain.CRDetails" , "cr" : "cr2" , "desc" : "cr2 desc" , "packageNumber" : 34 , "certGuidelines" : { "certG" : "
certg
" , "userType" : "Certification Team" , "status" : "Pending with Document Developer" , "count" : 0} , "dueDate" : "Fri Oct 02 00:00:00 IST 2015" , "solutionName" : "Patient Accounting" , "certGuidelinesList" : " "} # is not found into collection [certguidelines] at com.lordofthejars.nosqlunit.core.FailureHandler.createFailure(FailureHandler.java:7) at com.lordofthejars.nosqlunit.mongodb.MongoDbAssertion.checkCollectionObjects(MongoDbAssertion.java:102) at com.lordofthejars.nosqlunit.mongodb.MongoDbAssertion.strictAssertEquals(MongoDbAssertion.java:36) at com.lordofthejars.nosqlunit.mongodb.DefaultComparisonStrategy.compare(DefaultComparisonStrategy.java:17) at com.lordofthejars.nosqlunit.mongodb.DefaultComparisonStrategy.compare(DefaultComparisonStrategy.java:1) at com.lordofthejars.nosqlunit.core.AbstractCustomizableDatabaseOperation.executeComparison(AbstractCustomizableDatabaseOperation.java:15) at com.lordofthejars.nosqlunit.mongodb.MongoOperation.compareData(MongoOperation.java:103) at com.lordofthejars.nosqlunit.mongodb.MongoOperation.databaseIs(MongoOperation.java:96) at com.lordofthejars.nosqlunit.core.AbstractNoSqlTestRule$1.assertExpectation(AbstractNoSqlTestRule.java:229) at com.lordofthejars.nosqlunit.core.AbstractNoSqlTestRule$1.evaluate(AbstractNoSqlTestRule.java:78) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) 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:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)Below is the json data. I am populating for my test class. { "certguidelines":[ { "_id" : "54f8242ce281d80fcaebc723", "_class" : "com.docworks.domain.CRDetails", "cr" : "cr2", "desc" : "cr2 desc", "packageNumber" : 34, "certGuidelines" : { "certG" : "
certg
", "userType" : "Certification Team", "status" : "Pending with Document Developer", "count" : 0 }, "dueDate" : "Fri Oct 02 00:00:00 IST 2015", "solutionName" : "Patient Accounting", "certGuidelinesList" : [] } ]}
Below is test class that I am trying to run:
package com.docworks.service.test; import static com.lordofthejars.nosqlunit.mongodb.MongoDbRule.MongoDbRuleBuilder.newMongoDbRule; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.config.AbstractMongoConfiguration; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.docworks.domain.CRDetails; import com.docworks.domain.CertificateGuidelines; import com.docworks.exception.CRAlreadyExistsException; import com.docworks.service.CRService; import com.github.fakemongo.Fongo; import com.lordofthejars.nosqlunit.annotation.ShouldMatchDataSet; import com.lordofthejars.nosqlunit.mongodb.MongoDbRule; import com.mongodb.Mongo;
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath:test-context.xml"}) public class CRServiceTest {
/* * Expected results are in "one-person.json" file \ @throws CRAlreadyExistsException
@throws ParseException */ @Test @ShouldMatchDataSet(location = "/cr1-data.json") public void testSaveCertification() throws CRAlreadyExistsException, ParseException{
System.out.println(createCertGuide().getDueDate()); //insertPersonWithNameJohnathan(35); // this.personRepository.insertPersonWithNameJohnathan(67); }
@Configuration @EnableMongoRepositories @ComponentScan(basePackageClasses = {CRService.class}) //@PropertySource("classpath:application.properties") static class CRServiceTestConfiguration extends AbstractMongoConfiguration {
@Override protected String getMappingBasePackage() { return "com.docworks"; }
}
}
Below is the Pojo "CRDetails" class: with collection name: "certguidelines"
package com.docworks.domain; import static com.docworks.util.Constants.COLLECTION_NAME; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.format.annotation.DateTimeFormat;
@Document(collection = COLLECTION_NAME) public class CRDetails {
}
This is my save implementation in the service class :
public void saveCertification(CRDetails certGuide, String userTypeSubmitted) throws CRAlreadyExistsException {