Skip to content

Commit e947abe

Browse files
Tweaking travis-cii settings. Adding some code comments. Adding codecov.yml to ignore config classes. Updating README.
1 parent 65bd571 commit e947abe

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ jdk:
33
- oraclejdk8
44
script:
55
- ./gradlew clean
6-
- ./gradlew build
7-
- ./gradlew test
6+
- ./gradlew assemble
87
- ./gradlew jacocoTestReport
98
after_success:
109
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ This repo is an example of a simple spring rest service that demonstrates some g
1818
```
1919

2020
### Testing the Application
21+
* Unit testing
22+
```
23+
./gradlew test
24+
```
2125
* Through swagger-ui
2226
* With the application running navigate to [http://localhost:9000/swagger-ui.html](http://localhost:9000/swagger-ui.html)
2327
* You will see several controllers exposed including the Customer Controller which exposes the functionality for viewing all customers, viewing a specific customer, and adding a customer.

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore:
2+
- "src/main/java/org/cameronchapman/github/webservice/config"

src/main/java/org/cameronchapman/github/webservice/config/SwaggerConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.Profile;
56
import springfox.documentation.builders.PathSelectors;
67
import springfox.documentation.builders.RequestHandlerSelectors;
78
import springfox.documentation.spi.DocumentationType;
@@ -10,6 +11,7 @@
1011

1112
@Configuration
1213
@EnableSwagger2
14+
@Profile({"local", "dev", "test"})
1315
public class SwaggerConfig {
1416

1517
@Bean

src/main/java/org/cameronchapman/github/webservice/controller/CustomerController.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public class CustomerController {
2424
@Autowired
2525
CustomerManager customerManager;
2626

27+
/**
28+
* HTTP GET
29+
* Return a list of all customers.
30+
*
31+
* @return ResponseEntity<List<Customer>>
32+
*/
2733
@RequestMapping(value="/customers", method= RequestMethod.GET)
2834
public ResponseEntity<List<Customer>> getAll() {
2935
List<Customer> customers = null;
@@ -38,12 +44,20 @@ public ResponseEntity<List<Customer>> getAll() {
3844
responseMsg = FAILED;
3945
LOGGER.error("Exception calling getAll! msg={}", e.getMessage());
4046
} finally {
41-
LOGGER.info("{} | {}", responseMsg, httpStatus.toString());
47+
LOGGER.info("{} | {}", responseMsg, httpStatus.toString()); //@NOTE: logging in a real application should be much more robust than this, this is just an example
4248
}
4349

4450
return new ResponseEntity<List<Customer>>(customers, httpStatus);
4551
}
4652

53+
/**
54+
* HTTP GET
55+
* Return a specific customer.
56+
*
57+
* @param @PathVariable Long id
58+
*
59+
* @return ResponseEntity<Customer>
60+
*/
4761
@RequestMapping(value="/customers/{id}", method=RequestMethod.GET)
4862
public ResponseEntity<Customer> getById(@PathVariable Long id) {
4963
Customer customer = null;
@@ -68,6 +82,13 @@ public ResponseEntity<Customer> getById(@PathVariable Long id) {
6882
return new ResponseEntity<Customer>(customer, httpStatus);
6983
}
7084

85+
/**
86+
* HTTP POST
87+
* Create a customer.
88+
*
89+
* @param @RequestBody Customer customer
90+
* @return ResponseEntity<Map<String, Number>>
91+
*/
7192
@RequestMapping(value="customers", method=RequestMethod.POST)
7293
public ResponseEntity<Map<String, Number>> insert(@RequestBody Customer customer) {
7394
Number newId = null;

src/main/java/org/cameronchapman/github/webservice/org/cameronchapman/github/webservice/manager/CustomerManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ public Customer getCustomerById(Long id) {
3737
try {
3838
customer = customerDao.getById(id);
3939
} catch(DataAccessException dae) {
40+
// if no data is returned return null to caller
4041
LOGGER.debug("No data returned from getCustomerById. id={}", id);
4142
}
4243
return customer;
4344
}
4445

4546
public Number insertCustomer(Customer customer) throws Exception {
4647
Number newId = customerDao.insert(customer);
48+
// if no new id was generated from the insert attempt throw an exception
4749
if (null == newId) {
4850
throw new NoNewCustomerIdReturnedException("No new customer id returned.");
4951
}

0 commit comments

Comments
 (0)