forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error about response committed (halo-dev#1301)
* Add index page request test * Add test for first page request * Create session before requesting content
- Loading branch information
Showing
6 changed files
with
92 additions
and
12 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
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
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
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,47 @@ | ||
package run.halo.app.it; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.web.server.LocalServerPort; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.web.client.RestTemplate; | ||
import run.halo.app.model.params.InstallParam; | ||
|
||
/** | ||
* Base api test. | ||
* | ||
* @author johnniang | ||
*/ | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@ActiveProfiles("test") | ||
class BaseApiTest { | ||
|
||
@Autowired | ||
RestTemplate restTemplate; | ||
|
||
@LocalServerPort | ||
int port; | ||
|
||
String blogUrl; | ||
|
||
@BeforeEach | ||
void baseSetUp() { | ||
blogUrl = "http://localhost:" + port; | ||
} | ||
|
||
void installBlog() { | ||
|
||
InstallParam install = new InstallParam(); | ||
install.setUsername("test"); | ||
install.setNickname("test"); | ||
install.setEmail("[email protected]"); | ||
install.setPassword("opentest"); | ||
install.setUrl("http://localhost:" + port); | ||
install.setTitle("Test's Blog"); | ||
|
||
restTemplate.postForObject(blogUrl + "/api/admin/installations", install, | ||
String.class); | ||
} | ||
|
||
} |
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,39 @@ | ||
package run.halo.app.it; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Index page request test. | ||
* | ||
* @author johnniang | ||
*/ | ||
@Slf4j | ||
class IndexPageRequestTest extends BaseApiTest { | ||
|
||
@Test | ||
void indexPage() throws IOException { | ||
installBlog(); | ||
// validate atom.xml link | ||
Document document = Jsoup.connect(blogUrl).get(); | ||
Element atomLink = document.head().getElementsByAttributeValue("title", "atom 1.0").get(0); | ||
assertEquals(blogUrl + "/atom.xml", atomLink.attr("href")); | ||
|
||
// validate title link | ||
Element titleLink = document.body().selectFirst(".logo-title > .title > h3 > a"); | ||
assertEquals(blogUrl, titleLink.attr("href")); | ||
assertEquals("Test's Blog", titleLink.text()); | ||
|
||
// validate post link | ||
Element postTitleLink = | ||
document.body().selectFirst(".content > .post > .post-title > h3 > a"); | ||
assertEquals(blogUrl + "/archives/hello-halo", postTitleLink.attr("href")); | ||
assertEquals("Hello Halo", postTitleLink.text()); | ||
} | ||
} |
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