Revize 4b0fcb8b
Přidáno uživatelem Jitka Poubová před asi 5 roky(ů)
.gitignore | ||
---|---|---|
1 |
# IntelliJ files |
|
2 |
.idea/ |
|
3 |
be/*.iml |
|
4 |
be/fulltextsearch/*.iml |
|
5 |
fe/*.iml |
|
6 |
|
|
7 |
# Build files |
|
8 |
target/ |
be/fulltextsearch/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
|
|
6 |
<parent> |
|
7 |
<groupId>org.springframework.boot</groupId> |
|
8 |
<artifactId>spring-boot-starter-parent</artifactId> |
|
9 |
<version>2.2.5.RELEASE</version> |
|
10 |
<relativePath/> <!-- lookup parent from repository --> |
|
11 |
</parent> |
|
12 |
|
|
13 |
<groupId>cz.zcu.kiv.aswi</groupId> |
|
14 |
<artifactId>fulltextsearch</artifactId> |
|
15 |
<version>0.0.1-SNAPSHOT</version> |
|
16 |
<name>Fulltext Search</name> |
|
17 |
|
|
18 |
<properties> |
|
19 |
<java.version>11</java.version> |
|
20 |
</properties> |
|
21 |
|
|
22 |
<dependencies> |
|
23 |
<dependency> |
|
24 |
<groupId>org.springframework.boot</groupId> |
|
25 |
<artifactId>spring-boot-starter-web</artifactId> |
|
26 |
</dependency> |
|
27 |
|
|
28 |
<dependency> |
|
29 |
<groupId>org.springframework.boot</groupId> |
|
30 |
<artifactId>spring-boot-starter</artifactId> |
|
31 |
</dependency> |
|
32 |
|
|
33 |
<!-- exclude junit 4 --> |
|
34 |
<dependency> |
|
35 |
<groupId>org.springframework.boot</groupId> |
|
36 |
<artifactId>spring-boot-starter-test</artifactId> |
|
37 |
<scope>test</scope> |
|
38 |
<exclusions> |
|
39 |
<exclusion> |
|
40 |
<groupId>junit</groupId> |
|
41 |
<artifactId>junit</artifactId> |
|
42 |
</exclusion> |
|
43 |
</exclusions> |
|
44 |
</dependency> |
|
45 |
|
|
46 |
<!-- junit 5 --> |
|
47 |
<dependency> |
|
48 |
<groupId>org.junit.jupiter</groupId> |
|
49 |
<artifactId>junit-jupiter-engine</artifactId> |
|
50 |
<version>${junit-jupiter.version}</version> |
|
51 |
<scope>test</scope> |
|
52 |
</dependency> |
|
53 |
|
|
54 |
<dependency> |
|
55 |
<groupId>org.springframework</groupId> |
|
56 |
<artifactId>spring-web</artifactId> |
|
57 |
<version>5.2.4.RELEASE</version> |
|
58 |
</dependency> |
|
59 |
</dependencies> |
|
60 |
|
|
61 |
<build> |
|
62 |
<plugins> |
|
63 |
<plugin> |
|
64 |
<groupId>org.springframework.boot</groupId> |
|
65 |
<artifactId>spring-boot-maven-plugin</artifactId> |
|
66 |
</plugin> |
|
67 |
</plugins> |
|
68 |
</build> |
|
69 |
|
|
70 |
</project> |
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/FulltextSearchApplication.java | ||
---|---|---|
1 |
package cz.zcu.kiv.aswi.fulltextsearch; |
|
2 |
|
|
3 |
import org.springframework.boot.SpringApplication; |
|
4 |
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|
5 |
|
|
6 |
@SpringBootApplication |
|
7 |
public class FulltextSearchApplication { |
|
8 |
|
|
9 |
public static void main(String[] args) { |
|
10 |
SpringApplication.run(FulltextSearchApplication.class, args); |
|
11 |
} |
|
12 |
|
|
13 |
} |
be/fulltextsearch/src/main/java/cz/zcu/kiv/aswi/fulltextsearch/IndexController.java | ||
---|---|---|
1 |
package cz.zcu.kiv.aswi.fulltextsearch; |
|
2 |
|
|
3 |
import org.springframework.web.bind.annotation.PostMapping; |
|
4 |
import org.springframework.web.bind.annotation.RestController; |
|
5 |
|
|
6 |
@RestController |
|
7 |
public class IndexController { |
|
8 |
|
|
9 |
@PostMapping("/") |
|
10 |
public String index() { |
|
11 |
return "index"; |
|
12 |
} |
|
13 |
|
|
14 |
} |
|
15 |
|
be/fulltextsearch/src/main/resources/application.properties | ||
---|---|---|
1 |
|
be/fulltextsearch/src/test/java/cz/zcu/kiv/aswi/fulltextsearch/FulltextSearchApplicationTests.java | ||
---|---|---|
1 |
package cz.zcu.kiv.aswi.fulltextsearch; |
|
2 |
|
|
3 |
import org.junit.jupiter.api.Test; |
|
4 |
import org.springframework.boot.test.context.SpringBootTest; |
|
5 |
|
|
6 |
@SpringBootTest |
|
7 |
class FulltextSearchApplicationTests { |
|
8 |
|
|
9 |
@Test |
|
10 |
void contextLoads() { |
|
11 |
} |
|
12 |
|
|
13 |
} |
be/fulltextsearch/src/test/java/cz/zcu/kiv/aswi/fulltextsearch/IndexControllerTest.java | ||
---|---|---|
1 |
package cz.zcu.kiv.aswi.fulltextsearch; |
|
2 |
|
|
3 |
import org.junit.jupiter.api.Test; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.boot.test.context.SpringBootTest; |
|
6 |
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; |
|
7 |
import org.springframework.boot.test.web.client.TestRestTemplate; |
|
8 |
import org.springframework.boot.web.server.LocalServerPort; |
|
9 |
import org.springframework.http.HttpEntity; |
|
10 |
import org.springframework.http.HttpHeaders; |
|
11 |
import org.springframework.http.MediaType; |
|
12 |
import org.springframework.http.ResponseEntity; |
|
13 |
|
|
14 |
import java.net.URI; |
|
15 |
import java.net.URISyntaxException; |
|
16 |
|
|
17 |
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
18 |
|
|
19 |
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) |
|
20 |
public class IndexControllerTest { |
|
21 |
|
|
22 |
// bind the above RANDOM_PORT |
|
23 |
@LocalServerPort |
|
24 |
private int port; |
|
25 |
|
|
26 |
@Autowired |
|
27 |
private TestRestTemplate restTemplate; |
|
28 |
|
|
29 |
@Test |
|
30 |
public void testIndex() throws URISyntaxException |
|
31 |
{ |
|
32 |
final String baseUrl = "http://localhost:" + port +"/"; |
|
33 |
URI uri = new URI(baseUrl); |
|
34 |
|
|
35 |
HttpHeaders headers = new HttpHeaders(); |
|
36 |
headers.setContentType(MediaType.APPLICATION_JSON); |
|
37 |
|
|
38 |
String string = ""; |
|
39 |
HttpEntity<String> request = new HttpEntity<>(string, headers); |
|
40 |
|
|
41 |
ResponseEntity<String> result = restTemplate.postForEntity(uri, request, String.class); |
|
42 |
|
|
43 |
assertEquals(200, result.getStatusCodeValue()); |
|
44 |
assertEquals("index", result.getBody()); |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
} |
Také k dispozici: Unified diff
Re #7655: Inicializace backendu
- ve složce be
- použití Springu
- jedna POST metoda
- jeden test