-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
48 deletions.
There are no files selected for viewing
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
13 changes: 0 additions & 13 deletions
13
src/test/java/me/afibarra/liveproject/ecommerce/EcommerceApplicationTests.java
This file was deleted.
Oops, something went wrong.
67 changes: 32 additions & 35 deletions
67
src/test/java/me/afibarra/liveproject/ecommerce/controller/CatalogControllerTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,39 @@ | ||
package me.afibarra.liveproject.ecommerce.controller; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.gargoylesoftware.htmlunit.WebClient; | ||
import com.gargoylesoftware.htmlunit.html.HtmlAnchor; | ||
import com.gargoylesoftware.htmlunit.html.HtmlDivision; | ||
import com.gargoylesoftware.htmlunit.html.HtmlElement; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPlainText; | ||
import java.util.List; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import me.afibarra.liveproject.ecommerce.repository.ICatalogRepository; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class CatalogControllerTest { | ||
|
||
private WebClient webClient; | ||
|
||
@BeforeEach | ||
public void init() throws Exception { | ||
webClient = new WebClient(); | ||
} | ||
|
||
@AfterEach | ||
public void close() throws Exception { | ||
webClient.close(); | ||
} | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
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.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@ActiveProfiles("test") | ||
@AutoConfigureMockMvc | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class CatalogControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mvc; | ||
|
||
@Autowired | ||
private ICatalogRepository catalogRepository; | ||
|
||
@Test | ||
public void success_whenRetrievingCatalog() throws Exception { | ||
String URL = "http://127.0.0.1:8080/catalog"; | ||
String XPATH_CARD_BODY = "//div[@class='card-body']"; | ||
|
||
final HtmlPage htmlPage = webClient.getPage(URL); | ||
List<HtmlDivision> cards = htmlPage.getByXPath(XPATH_CARD_BODY); | ||
|
||
assertThat(cards).isNotNull(); | ||
assertThat(cards).isNotEmpty(); | ||
public void catalogTest() throws Exception { | ||
int catalogSize = catalogRepository.findAll().size(); | ||
|
||
this.mvc.perform(get("/catalog")) | ||
.andExpect(status().isOk()) | ||
.andExpect(view().name("welcome")) | ||
.andExpect(model().attributeExists("catalog")) | ||
.andExpect(model().attribute("catalog", hasSize(catalogSize))); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
spring.datasource.driver-class-name=org.h2.Driver | ||
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE | ||
spring.datasource.username=sa | ||
spring.datasource.password=password |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
___________ __ .__ | ||
\__ ___/___ _______/ |_|__| ____ ____ | ||
| |_/ __ \ / ___/\ __\ |/ \ / ___\ | ||
| |\ ___/ \___ \ | | | | | \/ /_/ > | ||
|____| \___ >____ > |__| |__|___| /\___ / | ||
\/ \/ \//_____/ |