Skip to content

Commit

Permalink
Add test example
Browse files Browse the repository at this point in the history
  • Loading branch information
o.mohkamkar committed Apr 13, 2024
1 parent ccb4f1a commit 8748113
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
package com.omidmk.iamapi;

import com.omidmk.iamapi.service.CustomerService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
class IAMApiApplicationTests {

@MockBean
private CustomerService customerService;

@LocalServerPort
private int port;

@Autowired
private TestRestTemplate restTemplate;

@Autowired
private MockMvc mockMvc;

@Test
void contextLoads() {
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/", String.class)).contains("Hello, World");
// assertThat(customerService).isNotNull();
// Assertions.assertNull(customerService.findUserByEmail("[email protected]").orElse(null));
}

@Test
void shouldReturnDefaultMessage() throws Exception {
this.mockMvc.perform(get("/v1/plans/beginner")).andDo(print()).andExpect(status().is4xxClientError())
.andExpect(content().string(containsString("")));
}

}

0 comments on commit 8748113

Please sign in to comment.