Created
August 22, 2019 15:45
-
-
Save mchernyavskaya/b7709f818ba71049bac0af17d269c9e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner::class) | |
@SpringBootTest | |
class MultimongoApplicationTests { | |
@Autowired | |
private val productRepo: ProductRepository? = null | |
@Autowired | |
private val priceRepo: ProductPriceRepository? = null | |
@Autowired | |
private val priceHistoryRepo: PriceHistoryRepository? = null | |
@Autowired | |
private val initializer: DataInitializer? = null | |
@Autowired | |
private val context: ApplicationContext? = null | |
private var mvc: MockMvc? = null | |
@Before | |
fun setUp() { | |
val resource = ProductResource( | |
productRepo!!, | |
priceRepo!!, | |
priceHistoryRepo!! | |
) | |
this.mvc = MockMvcBuilders | |
.standaloneSetup(resource) | |
.build() | |
initializer!!.onApplicationEvent(ContextStartedEvent(context!!)) | |
} | |
@Test | |
fun productsCreated() { | |
mvc!!.perform(get("/api/product")) | |
.andExpect(status().isOk) | |
.andDo { | |
println(it.response.contentAsString) | |
} | |
.andExpect(jsonPath("$.[*].sku").isArray) | |
.andExpect(jsonPath("$.[*].sku") | |
.value(hasItems("123", "456"))) | |
} | |
@Test | |
fun pricesCreated() { | |
mvc!!.perform(get("/api/price")) | |
.andExpect(status().isOk) | |
.andDo { | |
println(it.response.contentAsString) | |
} | |
.andExpect(jsonPath("$.[*].sku").isArray) | |
.andExpect(jsonPath("$.[*].sku") | |
.value(hasItems("123", "456"))) | |
.andExpect(jsonPath("$.[0].price") | |
.value(5.0)) | |
.andExpect(jsonPath("$.[1].price") | |
.value(10.0)) | |
} | |
@Test | |
fun pricesHistoryCreated() { | |
mvc!!.perform(get("/api/priceHistory")) | |
.andExpect(status().isOk) | |
.andDo { | |
println(it.response.contentAsString) | |
} | |
.andExpect(jsonPath("$.[*].sku").isArray) | |
.andExpect(jsonPath("$.[*].sku") | |
.value(hasItems("123", "456"))) | |
.andExpect(jsonPath("$.[0].prices.[*].price") | |
.value(hasItems(5.0, 4.0, 3.0, 2.0, 1.0))) | |
.andExpect(jsonPath("$.[1].prices.[*].price") | |
.value(hasItems(10.0, 8.0, 6.0, 4.0, 2.0))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment