Skip to content

Commit

Permalink
Change MongoDBContainerDatabaseNameTest to save a Product
Browse files Browse the repository at this point in the history
  • Loading branch information
silaev committed Jul 15, 2020
1 parent 96e9c10 commit cc3ed2a
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

Expand All @@ -33,7 +34,7 @@
import static org.junit.Assert.assertTrue;

@Slf4j
@DataMongoTest
@DataMongoTest(properties = {"spring.main.banner-mode=off", "data.mongodb.auto-index-creation=true"})
@ContextConfiguration(initializers = MongoDBContainerDatabaseNameTest.Initializer.class)
@RunWith(SpringRunner.class)
public class MongoDBContainerDatabaseNameTest {
Expand Down Expand Up @@ -65,8 +66,8 @@ public void shouldTestDatabaseName() {
isDatabaseInMongoDB(mongoSyncClient, DATABASE_NAME)
);

//3. Perform an operation to create a new collection via mongoTemplate.
mongoTemplate.createCollection(Product.class);
//3. Perform an operation to save a new Product via mongoTemplate.
mongoTemplate.save(new Product(1L));

//4. Now the database is created in MongoDB.
assertTrue(
Expand Down Expand Up @@ -110,6 +111,7 @@ public static void main(String[] args) {
@NoArgsConstructor
@Setter(AccessLevel.NONE)
private static class Product {
@Indexed(unique = true)
private Long article;
}
}

0 comments on commit cc3ed2a

Please sign in to comment.