Created
May 1, 2019 13:35
-
-
Save tbelmega/238ac62d7f31c08de1218c80e4214e7c 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
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
@ActiveProfiles("test") | |
@RunWith(SpringJUnit4ClassRunner::class) | |
class ProductE2ESpringBootTest { | |
@Autowired | |
lateinit var client: TestRestTemplate | |
@Autowired | |
lateinit var repository: ProductRepository | |
@MockBean | |
lateinit var authService: AuthService | |
@MockBean | |
lateinit var auditLoggerClient: AuditLoggerClient | |
@Before | |
@After | |
fun cleanUpDb() { | |
repository.deleteAll() | |
} | |
@Test | |
fun `create new product - success - return 201 CREATED`() { | |
//given | |
given(authService.isProductAdmin()).willReturn(true) | |
val createProductRequest = CreateProductRequest("ROG Strix Z390-F Gaming Mainboard", "ASUS") | |
// when | |
val response = client.postForEntity( | |
"/api/v1/products", | |
createProductRequest, | |
Void::class.java) | |
//then | |
assertThat(response.statusCode).isEqualTo(HttpStatus.CREATED) | |
assertThat(response.body).isNull() | |
assertThat(repository.findByProductName(createProductRequest.productName)).hasSize(1) | |
verify(auditLoggerClient).logProductCreated(createProductRequest) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment