Skip to content

Commit dc47278

Browse files
authored
Merge pull request #1 from companieshouse/PCI-578-create-basic-spring-boot-app
PCI 578 create basic spring boot app
2 parents e77c3f0 + de20256 commit dc47278

File tree

13 files changed

+400
-1
lines changed

13 files changed

+400
-1
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# Package Files #
8+
*.jar
9+
*.war
10+
*.nar
11+
*.ear
12+
*.zip
13+
*.tar.gz
14+
*.rar
15+
16+
# OS files
17+
.DS_Store
18+
19+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
20+
hs_err_pid*
21+
22+
### IntelliJ IDEA ###
23+
.idea
24+
*.iws
25+
*.iml
26+
*.ipr
27+
.mvn/
28+
29+
target/
30+
.classpath
31+
.project
32+
.settings/
33+
.vscode/
34+
.factorypath
35+
36+
orders.api.ch.gov.uk.jar

Makefile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
artifact_name := orders.api.ch.gov.uk
2+
3+
.PHONY: all
4+
all: build
5+
6+
.PHONY: clean
7+
clean:
8+
mvn clean
9+
rm -f ./$(artifact_name).jar
10+
rm -f ./$(artifact_name)-*.zip
11+
rm -rf ./build-*
12+
13+
.PHONY: build
14+
build:
15+
mvn compile
16+
17+
.PHONY: test
18+
test: test-unit test-integration
19+
20+
.PHONY: test-unit
21+
test-unit: clean
22+
mvn test
23+
24+
.PHONY: test-integration
25+
test-integration: clean
26+
mvn -Dtest=*IntegrationTest test
27+
28+
.PHONY: test-contract-provider
29+
test-contract-provider: clean
30+
mvn -Dtest=*ProviderContractTest test
31+
32+
.PHONY: test-contract-consumer
33+
test-contract-consumer: clean
34+
mvn -Dtest=*ConsumerContractTest test
35+
36+
.PHONY: dev
37+
dev: clean
38+
mvn package -DskipTests=true
39+
cp target/$(artifact_name)-unversioned.jar $(artifact_name).jar
40+
41+
.PHONY: package
42+
package:
43+
ifndef version
44+
$(error No version given. Aborting)
45+
endif
46+
$(info Packaging version: $(version))
47+
mvn versions:set -DnewVersion=$(version) -DgenerateBackupPoms=false
48+
mvn package -DskipTests=true
49+
$(eval tmpdir:=$(shell mktemp -d build-XXXXXXXXXX))
50+
cp ./start.sh $(tmpdir)
51+
cp ./routes.yaml $(tmpdir)
52+
cp ./target/$(artifact_name)-$(version).jar $(tmpdir)/$(artifact_name).jar
53+
cd $(tmpdir); zip -r ../$(artifact_name)-$(version).zip *
54+
rm -rf $(tmpdir)
55+
56+
.PHONY: dist
57+
dist: clean build package
58+
59+
.PHONY: sonar
60+
sonar:
61+
mvn sonar:sonar
62+
63+
.PHONY: sonar-pr-analysis
64+
sonar-pr-analysis:
65+
mvn sonar:sonar -P sonar-pr-analysis
66+

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# orders.api.ch.gov.uk
1+
# Companies House Orders API
2+
## orders.api.ch.gov.uk
23
API handling CRUD operations on CH Ordering Service
4+
5+
### Requirements
6+
* [Java 8][1]
7+
* [Maven][2]
8+
* [Git][3]
9+
10+
### Getting Started
11+
1. Run `make` to build
12+
2. Run `./start.sh` to run
13+
14+
### Environment Variables
15+
Name | Description | Mandatory | Location
16+
--- | --- | --- | ---
17+
ORDERS_API_PORT | Port this application runs on when deployed. | ✓ | start.sh
18+
19+
### Endpoints
20+
Path | Method | Description
21+
--- | --- | ---
22+
*`/healthcheck`* | GET | Returns HTTP OK (`200`) to indicate a healthy application instance.
23+
24+
[1]: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
25+
[2]: https://maven.apache.org/download.cgi
26+
[3]: https://git-scm.com/downloads

pom.xml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
<parent>
6+
<groupId>uk.gov.companieshouse</groupId>
7+
<artifactId>companies-house-spring-boot-parent</artifactId>
8+
<version>1.2.0</version>
9+
</parent>
10+
<artifactId>orders.api.ch.gov.uk</artifactId>
11+
<version>unversioned</version>
12+
<name>orders.api.ch.gov.uk</name>
13+
<description>CH API handling CRUD operations on Ordering Service</description>
14+
15+
<properties>
16+
<java.version>1.8</java.version>
17+
<org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
18+
<jacoco-maven-plugin.version>0.7.7.201606060606</jacoco-maven-plugin.version>
19+
<junit-jupiter-engine-version>5.2.0</junit-jupiter-engine-version>
20+
<mockito-junit-jupiter-version>2.18.0</mockito-junit-jupiter-version>
21+
<hamcrest-all-version>1.3</hamcrest-all-version>
22+
<start-class>uk.gov.companieshouse.orders.api.OrdersApiApplication</start-class>
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-data-rest</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
<exclusions>
36+
<exclusion>
37+
<groupId>org.junit.vintage</groupId>
38+
<artifactId>junit-vintage-engine</artifactId>
39+
</exclusion>
40+
</exclusions>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.junit.jupiter</groupId>
44+
<artifactId>junit-jupiter-engine</artifactId>
45+
<version>${junit-jupiter-engine-version}</version>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.mockito</groupId>
50+
<artifactId>mockito-junit-jupiter</artifactId>
51+
<version>${mockito-junit-jupiter-version}</version>
52+
<scope>test</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.hamcrest</groupId>
56+
<artifactId>hamcrest-all</artifactId>
57+
<version>${hamcrest-all-version}</version>
58+
<scope>test</scope>
59+
</dependency>
60+
</dependencies>
61+
62+
<build>
63+
<plugins>
64+
65+
<plugin>
66+
<groupId>org.springframework.boot</groupId>
67+
<artifactId>spring-boot-maven-plugin</artifactId>
68+
<configuration>
69+
<mainClass>${start-class}</mainClass>
70+
<layout>ZIP</layout>
71+
</configuration>
72+
<executions>
73+
<execution>
74+
<goals>
75+
<goal>repackage</goal>
76+
</goals>
77+
</execution>
78+
</executions>
79+
</plugin>
80+
81+
<plugin>
82+
<groupId>org.jacoco</groupId>
83+
<artifactId>jacoco-maven-plugin</artifactId>
84+
<version>${jacoco-maven-plugin.version}</version>
85+
<executions>
86+
<execution>
87+
<id>default-prepare-agent</id>
88+
<goals>
89+
<goal>prepare-agent</goal>
90+
</goals>
91+
</execution>
92+
<execution>
93+
<id>default-report</id>
94+
<phase>prepare-package</phase>
95+
<goals>
96+
<goal>report</goal>
97+
</goals>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-compiler-plugin</artifactId>
105+
<version>${maven-compiler-plugin.version}</version>
106+
<configuration>
107+
<source>${java.version}</source>
108+
<target>${java.version}</target>
109+
<fork>true</fork>
110+
<meminitial>128m</meminitial>
111+
<encoding>${project.build.sourceEncoding}</encoding>
112+
<maxmem>512m</maxmem>
113+
<annotationProcessorPaths>
114+
<path>
115+
<groupId>org.mapstruct</groupId>
116+
<artifactId>mapstruct-processor</artifactId>
117+
<version>${org.mapstruct.version}</version>
118+
</path>
119+
<!-- other annotation processors -->
120+
</annotationProcessorPaths>
121+
</configuration>
122+
</plugin>
123+
124+
</plugins>
125+
</build>
126+
127+
</project>

routes.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
app_name: orders.api.ch.gov.uk
2+
group: api
3+
weight: 991
4+
routes:
5+
1: ^/orders/healthcheck
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package uk.gov.companieshouse.orders.api;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class OrdersApiApplication {
8+
9+
public static final String APPLICATION_NAMESPACE = "orders.api.ch.gov.uk";
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(OrdersApiApplication.class, args);
13+
}
14+
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package uk.gov.companieshouse.orders.api.controller;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
/**
9+
* Returns HTTP OK response to indicate a healthy service is running
10+
*/
11+
@RestController
12+
public class HealthcheckController {
13+
@GetMapping("${uk.gov.companieshouse.orders.api.health}")
14+
public ResponseEntity<Void> getHealthCheck (){
15+
return ResponseEntity.status(HttpStatus.OK).build();
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
server:
2+
servlet:
3+
context-path: /orders
4+
5+
uk:
6+
gov:
7+
companieshouse:
8+
orders:
9+
api:
10+
health: /healthcheck
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package uk.gov.companieshouse.orders.api;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
7+
class OrdersApiApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package uk.gov.companieshouse.orders.api.controller;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
7+
import org.springframework.boot.test.context.SpringBootTest;
8+
import org.springframework.test.web.servlet.MockMvc;
9+
10+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
11+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
12+
13+
@AutoConfigureMockMvc
14+
@SpringBootTest
15+
class HealthcheckControllerIntegrationTest {
16+
@Autowired
17+
private MockMvc mockMvc;
18+
19+
@Test
20+
@DisplayName("Successfully returns health status")
21+
public void returnHealthStatusSuccessfully() throws Exception {
22+
mockMvc.perform(get("/healthcheck"))
23+
.andExpect(status().isOk());
24+
}
25+
}

0 commit comments

Comments
 (0)