Skip to content

Commit 6fa4a43

Browse files
added spring boot starters module
1 parent 1a812c4 commit 6fa4a43

13 files changed

Lines changed: 366 additions & 0 deletions

File tree

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<module>spring-apache-camel</module>
4343
<module>spring-batch</module>
4444
<module>spring-boot</module>
45+
<module>spring-boot-starters</module>
4546
<module>spring-controller</module>
4647
<module>spring-data-cassandra</module>
4748
<module>spring-data-elasticsearch</module>

‎spring-boot-starters/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

‎spring-boot-starters/README.MD‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
###The Course
2+
The "REST With Spring" Classes: http://bit.ly/restwithspring

‎spring-boot-starters/pom.xml‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>spring-boot-starters</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<name>Spring Boot Starters</name>
8+
<description>This is simple boot application for Spring boot starters</description>
9+
10+
<!-- Inherit defaults from Spring Boot -->
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.3.3.RELEASE</version>
15+
<relativePath/>
16+
</parent>
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<java.version>1.8</java.version>
20+
</properties>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-web</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-test</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.jayway.jsonpath</groupId>
37+
<artifactId>json-path</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-data-jpa</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.h2database</groupId>
46+
<artifactId>h2</artifactId>
47+
<scope>runtime</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-mail</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.subethamail</groupId>
55+
<artifactId>subethasmtp</artifactId>
56+
<version>3.1.7</version>
57+
<scope>test</scope>
58+
</dependency>
59+
</dependencies>
60+
61+
<build>
62+
<finalName>spring-boot</finalName>
63+
<resources>
64+
<resource>
65+
<directory>src/main/resources</directory>
66+
<filtering>true</filtering>
67+
</resource>
68+
</resources>
69+
70+
<plugins>
71+
72+
<plugin>
73+
<groupId>org.springframework.boot</groupId>
74+
<artifactId>spring-boot-maven-plugin</artifactId>
75+
</plugin>
76+
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<configuration>
81+
<source>1.8</source>
82+
<target>1.8</target>
83+
</configuration>
84+
</plugin>
85+
86+
87+
</plugins>
88+
89+
</build>
90+
91+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.context.ApplicationContext;
5+
import org.springframework.context.annotation.Bean;
6+
7+
import java.util.Queue;
8+
9+
@org.springframework.boot.autoconfigure.SpringBootApplication
10+
public class Application {
11+
private static ApplicationContext applicationContext;
12+
13+
public static void main(String[] args) {
14+
applicationContext = SpringApplication.run(Application.class, args);
15+
}
16+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.baeldung.controller;
2+
3+
import org.baeldung.domain.GenericEntity;
4+
import org.springframework.web.bind.annotation.PathVariable;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
12+
@RestController
13+
public class GenericEntityController {
14+
private List<GenericEntity> entityList = new ArrayList<>();
15+
16+
{
17+
entityList.add(new GenericEntity(1l, "entity_1"));
18+
entityList.add(new GenericEntity(2l, "entity_2"));
19+
entityList.add(new GenericEntity(3l, "entity_3"));
20+
entityList.add(new GenericEntity(4l, "entity_4"));
21+
}
22+
23+
@RequestMapping("/entity/all")
24+
public List<GenericEntity> findAll() {
25+
return entityList;
26+
}
27+
28+
@RequestMapping(value = "/entity", method = RequestMethod.POST)
29+
public GenericEntity addEntity(GenericEntity entity) {
30+
entityList.add(entity);
31+
return entity;
32+
}
33+
34+
@RequestMapping("/entity/findby/{id}")
35+
public GenericEntity findById(@PathVariable Long id) {
36+
return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get();
37+
}
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.baeldung.domain;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
@Entity
9+
public class GenericEntity {
10+
@Id
11+
@GeneratedValue(strategy = GenerationType.AUTO)
12+
private Long id;
13+
private String value;
14+
15+
public GenericEntity() {
16+
}
17+
18+
public GenericEntity(String value) {
19+
this.value = value;
20+
}
21+
22+
public GenericEntity(Long id, String value) {
23+
this.id = id;
24+
this.value = value;
25+
}
26+
27+
public Long getId() {
28+
return id;
29+
}
30+
31+
public void setId(Long id) {
32+
this.id = id;
33+
}
34+
35+
public String getValue() {
36+
return value;
37+
}
38+
39+
public void setValue(String value) {
40+
this.value = value;
41+
}
42+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.baeldung.repository;
2+
3+
import org.baeldung.domain.GenericEntity;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface GenericEntityRepository extends JpaRepository<GenericEntity, Long> {
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
server.port=8080
2+
server.contextPath=/springbootapp
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.baeldung;
2+
3+
import org.baeldung.domain.GenericEntity;
4+
import org.baeldung.repository.GenericEntityRepository;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.test.SpringApplicationConfiguration;
10+
import org.springframework.http.MediaType;
11+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12+
import org.springframework.test.context.web.WebAppConfiguration;
13+
import org.springframework.test.web.servlet.MockMvc;
14+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
15+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
16+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
17+
import org.springframework.web.context.WebApplicationContext;
18+
19+
import java.nio.charset.Charset;
20+
21+
import static org.hamcrest.Matchers.hasSize;
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertNotNull;
24+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
25+
26+
@RunWith(SpringJUnit4ClassRunner.class)
27+
@SpringApplicationConfiguration(classes = Application.class)
28+
@WebAppConfiguration
29+
public class SpringBootApplicationTest {
30+
@Autowired
31+
private WebApplicationContext webApplicationContext;
32+
private MockMvc mockMvc;
33+
34+
35+
@Before
36+
public void setupMockMvc() {
37+
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
38+
.build();
39+
}
40+
41+
@Test
42+
public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect() throws Exception {
43+
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(),
44+
MediaType.APPLICATION_JSON.getSubtype(),
45+
Charset.forName("utf8"));
46+
47+
mockMvc.perform(MockMvcRequestBuilders.get("/entity/all")).
48+
andExpect(MockMvcResultMatchers.status().isOk()).
49+
andExpect(MockMvcResultMatchers.content().contentType(contentType)).
50+
andExpect(jsonPath("$", hasSize(4)));
51+
}
52+
53+
54+
}

0 commit comments

Comments
 (0)