Closed rajakumare1 closed 11 months ago
@rajakumare1 i will improve the documentation on that .. because it is not that easy ..
you need to customize your mongodb-starter: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/blob/main/HowTo.md#customize-mongod where you trigger only an import: https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/embed-mongo-4.x/Howto.md#import-json-file-with-mongoimport-command ...
but you should wait for a working sample for that.. (maybe today)
@michaelmosmann Any luck with the sample. Thanks!!
@rajakumare1 not finished yet.. was in a hurry.. stay tuned.. sorry
I have 100's of documents stored inside sample.json and I want to load it in spring project Junit while starting the embeded mongodb. using the below reference , how should I do it. Please advise?
Note: I referred the import section in https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/blob/embed-mongo-4.x/Howto.md. But i didnt understand how I can integrate it with Spring support.
I have multiple collections with multiple records. Tats why I am looking for this support that will help rather than inserting each record for every Junit. Thanks!!!
`@ExtendWith(SpringExtension.class) @activeprofiles("test") @SpringBootTest( properties = "de.flapdoodle.mongodb.embedded.version=5.0.12" ) @Import({TestMongoConfiguration.class}) @AutoConfigureDataMongo() @testinstance(TestInstance.Lifecycle.PER_CLASS) @DirtiesContext class ServiceIntegrationTest {
@Autowired private TestCollectionRepository testCollectionRepository;
@BeforeEach void setup() throws IOException { TestCollection testcollection = populateMockTestCollection(); testCollectionRepository.insert(testcollection); }
......
} @TestConfiguration
public class TestMongoConfiguration {
@Bean public MongoDatabaseFactory mongoDbFactory() throws Exception { return new SimpleMongoClientDatabaseFactory("mongodb://localhost:27017/db-tests"); }
@Bean MongoTemplate mongoTemplate(MongoDatabaseFactory factory) { return new MongoTemplate(factory); } } `