Skip to content

Commit b442f9c

Browse files
Fixing the docoumentation
Adding Actions for Sonar and Build
1 parent 2c8f53a commit b442f9c

18 files changed

+231
-135
lines changed

.github/workflow/maven-test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build & Test
2+
'on':
3+
push:
4+
branches:
5+
- "**"
6+
pull_request:
7+
branches:
8+
- "**"
9+
schedule:
10+
- cron: 0 16 * * *
11+
workflow_dispatch:
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
java:
18+
- 17
19+
steps:
20+
- uses: actions/checkout@v1
21+
with:
22+
fetch-depth: 0
23+
- name: 'Set up JDK ${{ matrix.java }}'
24+
uses: actions/setup-java@v1
25+
with:
26+
java-version: '${{ matrix.java }}'
27+
- name: Build and test with Maven
28+
run: mvn -B package -Dgpg.signature.skip=true -Dspring.profiles.active=oauth

.github/workflow/sonarcloud.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Sonar
2+
'on':
3+
push:
4+
branches:
5+
- "**"
6+
pull_request_target:
7+
branches:
8+
- "**"
9+
types: [opened, synchronize, reopened, labeled]
10+
schedule:
11+
- cron: 0 16 * * *
12+
workflow_dispatch:
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
18+
- name: Set up JDK
19+
uses: actions/setup-java@v1
20+
with:
21+
java-version: 17
22+
java-package: jdk
23+
24+
- uses: actions/checkout@v1
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Check for external PR
29+
if: ${{ !(contains(github.event.pull_request.labels.*.name, 'safe') ||
30+
github.event.pull_request.head.repo.full_name == github.repository ||
31+
github.event_name != 'pull_request_target') }}
32+
run: echo "Unsecure PR, must be labelled with the 'safe' label, then run the workflow again" && exit 1
33+
34+
- name: Build with Maven
35+
36+
mvn clean install
37+
38+
- name: Sonar Scan
39+
env:
40+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
41+
SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}'
42+
run: >-
43+
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
44+
-Dsonar.projectName=client-encryption-java
45+
-Dsonar.projectKey=Mastercard_client-encryption-java
46+
-Dsonar.organization=mastercard -Dsonar.host.url=https://sonarcloud.io
47+
-Dsonar.login=$SONAR_TOKEN -Dsonar.cpd.exclusions=**/OkHttp*.java
48+
-Dsonar.exclusions=**/*.xml -Dgpg.signature.skip=true
49+

README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
Mastercard Petstore API
44
- API version: 1.0.0
55
- App version: 1.0.0
6-
7-
This is a sample API to demonstrate an API that aligns to Mastercard's API Gold Standards. It covers all expected use cases. Please see [here](https://developer.mastercard.com/reference-service-ngw/documentation) to view our sample documentation.
86

9-
For more information, please visit [https://developer.mastercard.com/support](https://developer.mastercard.com/support)
7+
This application provides examples of how a Mastercard API should implement authentication, authorization, and payload encryption.
8+
Please follow the steps in the documentation [here](https://developer.mastercard.com/reference-service-ngw/documentation)
9+
to understand how to utilize this application and adapt it for your service.
1010

1111
## Requirements
1212

@@ -16,7 +16,7 @@ Building the API client library requires:
1616

1717
## Installation
1818

19-
To being please run
19+
Please follow the instruction below to begin
2020

2121
```shell
2222
mvn clean install
@@ -28,19 +28,19 @@ This will generate all required files as defined in [petstore.yaml](src/main/res
2828

2929
Set properties in [application.properties](src/main/resources/application.properties)
3030

31-
The authentication mode must be set using (mTLS or oAuth).
31+
The authentication mode (MTLS or OAuth1.0a) must be set using
3232
```
3333
-Dspring.profiles.active=oauth
3434
-Dspring.profiles.active=mtls
3535
```
36-
If using the API in oAuth mode the following are required in [application-oauth.properties](src/main/resources/application-oauth.properties)
36+
If using the API in OAuth1.0a mode the following are required in [application-oauth.properties](src/main/resources/application-oauth.properties)
3737
```
3838
mastercard.oauth.pkcs12KeyFile
3939
mastercard.oauth.consumerKey
4040
mastercard.oauth.keyAlias
4141
mastercard.oauth.keyPassword
4242
```
43-
If using the API in mTLS mode the following are required in [application-mtls.properties](src/main/resources/application-mtls.properties)
43+
If using the API in MTLS mode the following are required in [application-mtls.properties](src/main/resources/application-mtls.properties)
4444
```
4545
mastercard.mtls.pfxKeyFile
4646
mastercard.mtls.keyPassword
@@ -53,11 +53,11 @@ mastercard.encryption.decryptionKeyAlias
5353
mastercard.encryption.decryptionKeyPassword
5454
```
5555

56-
## Use Cases
56+
## Running the Application
5757

5858
To see how the average flow of each use case please see the [flow folder](src/test/java/com/mastercard/app/petstore/flow) and run a test. Note this tests will not
5959
run if a `basePath` in [application.properties](src/main/resources/application.properties) is not set. These tests call
60-
out to the service so they must be set.
60+
out to the service, so they must be set.
6161

6262
The tests can be run using
6363
```shell
@@ -68,26 +68,35 @@ or
6868
mvn test -Dspring.profiles.active=mtls
6969
```
7070

71-
### Adoption Flow Test Case
71+
## Example Scenarios
72+
73+
Example scenarios can be found under `src/main/java/com/mastercard/app/petstore/examples`
74+
There are provide simples uses cases, documented below
75+
76+
### Adoption Flow Example
7277
This demonstrates the typical flow for an adoption.
7378
1) A new adoption is created
7479
2) The adoption is then retrieved using the adoption id from step 1
7580
3) Information is updated before removing it using the same id
7681
4) Clean up. The adoption is removed from the system
7782

78-
### Employee Flow Test Case
83+
### Employee Flow Example
7984
This demonstrates the typical flow for managing an employee.
8085
1) A new employee is added to the system
8186
2) The employee's information is then searched for via SSN
8287
3) Clean up. The employee is removed from the system
8388

84-
### Pet Flow Test Case
89+
### Pet Flow Example
8590
This demonstrates the typical flow for adding a new cat.
8691
1) A new cat is added to the system
8792
2) The cat's information is retrieved via it's id
8893
3) That cat's status is updated to `RESERVED`
8994
4) Clean up. The cat is removed from the system
9095

96+
97+
## Support
98+
For more information, please visit [https://developer.mastercard.com/support](https://developer.mastercard.com/support)
99+
91100
## Author
92101

93102

pom.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,15 @@
7171
<version>${okhttp-version}</version>
7272
</dependency>
7373
<dependency>
74-
<groupId>junit</groupId>
75-
<artifactId>junit</artifactId>
74+
<groupId>org.junit.jupiter</groupId>
75+
<artifactId>junit-jupiter-api</artifactId>
76+
<version>5.7.0</version>
77+
<scope>test</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.junit.jupiter</groupId>
81+
<artifactId>junit-jupiter-engine</artifactId>
82+
<version>5.7.0</version>
7683
<scope>test</scope>
7784
</dependency>
7885
<dependency>
@@ -148,6 +155,11 @@
148155
</execution>
149156
</executions>
150157
</plugin>
158+
<plugin>
159+
<groupId>org.apache.maven.plugins</groupId>
160+
<artifactId>maven-surefire-plugin</artifactId>
161+
<version>3.0.0-M7</version>
162+
</plugin>
151163
</plugins>
152164
</build>
153165
</project>
Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,55 @@
11
package com.mastercard.app.petstore;
22

3+
import com.mastercard.app.petstore.examples.AdoptionFlowExample;
4+
import com.mastercard.app.petstore.examples.EmployeeFlowExample;
5+
import com.mastercard.app.petstore.examples.PetFlowExample;
6+
import org.openapitools.client.ApiException;
7+
import org.openapitools.client.model.Adoption;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.CommandLineRunner;
310
import org.springframework.boot.SpringApplication;
411
import org.springframework.boot.autoconfigure.SpringBootApplication;
12+
import org.springframework.context.ApplicationContext;
13+
import org.springframework.context.annotation.Bean;
514

615
@SpringBootApplication
716
public class PetstoreApplication {
17+
@Autowired
18+
PetFlowExample petFlowExample;
19+
@Autowired
20+
AdoptionFlowExample adoptionFlowExample;
21+
@Autowired
22+
EmployeeFlowExample employeeFlowExample;
23+
24+
@Bean
25+
PetFlowExample petFlowExample() throws ApiException {
26+
petFlowExample = new PetFlowExample();
27+
return petFlowExample;
28+
}
29+
30+
@Bean
31+
AdoptionFlowExample adoptionFlowExample() {
32+
adoptionFlowExample = new AdoptionFlowExample();
33+
return adoptionFlowExample;
34+
}
35+
36+
@Bean
37+
EmployeeFlowExample employeeFlowExample() {
38+
employeeFlowExample = new EmployeeFlowExample();
39+
return employeeFlowExample;
40+
}
41+
42+
@Bean
43+
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
44+
45+
return args -> {
46+
petFlowExample.petUseCaseFlow();
47+
adoptionFlowExample.adoptionUseCase();
48+
employeeFlowExample.employeeUseCase();
49+
};
50+
}
851

952
public static void main(String[] args) {
1053
SpringApplication.run(PetstoreApplication.class, args);
1154
}
12-
1355
}

src/main/java/com/mastercard/app/petstore/configuration/Configuration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import org.openapitools.client.api.EmployeesApi;
88
import org.openapitools.client.api.PetsApi;
99
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.ComponentScan;
1011

1112
@org.springframework.context.annotation.Configuration
13+
@ComponentScan("com.mastercard.app.petstore")
1214
public class Configuration {
1315

1416
@Bean

src/test/java/com/mastercard/app/petstore/flow/AdoptionFlowTest.java renamed to src/main/java/com/mastercard/app/petstore/examples/AdoptionFlowExample.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
1-
package com.mastercard.app.petstore.flow;
1+
package com.mastercard.app.petstore.examples;
22

3-
import com.mastercard.app.petstore.TestMockBuilders;
43
import com.mastercard.app.petstore.services.AdoptionsService;
5-
import org.junit.Test;
6-
import org.junit.runner.RunWith;
7-
import org.mockito.Mock;
4+
import com.mastercard.app.petstore.utils.MockDataBuilders;
85
import org.openapitools.client.ApiException;
96
import org.openapitools.client.model.Adoption;
107
import org.openapitools.client.model.AdoptionWrapper;
118
import org.openapitools.client.model.NewAdoption;
129
import org.springframework.beans.factory.annotation.Autowired;
1310
import org.springframework.beans.factory.annotation.Value;
14-
import org.springframework.boot.test.context.SpringBootTest;
1511
import org.springframework.context.annotation.ComponentScan;
1612
import org.springframework.core.env.Environment;
17-
import org.springframework.test.context.ActiveProfiles;
18-
import org.springframework.test.context.junit4.SpringRunner;
19-
20-
import java.lang.reflect.Array;
21-
22-
import static org.mockito.Mockito.when;
13+
import org.springframework.stereotype.Component;
2314

2415
/**
25-
* The type Adoption flow test.
16+
* The type Adoption flow example.
2617
*/
27-
@SpringBootTest()
28-
@RunWith(SpringRunner.class)
29-
@ActiveProfiles({"oauth"})
18+
3019
@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
31-
public class AdoptionFlowTest {
20+
@Component("AdoptionFLowExample")
21+
public class AdoptionFlowExample {
3222

3323
/**
3424
* The Base path. Set in application.properties
3525
*/
3626
@Value("${mastercard.basePath}")
3727
String basePath;
3828

39-
@Mock
4029
private Environment environment;
4130

4231
@Autowired
@@ -47,15 +36,14 @@ public class AdoptionFlowTest {
4736
*
4837
* @throws ApiException the api exception
4938
*/
50-
@Test
5139
public void adoptionUseCase() throws ApiException {
5240

5341
//Skipping test if applications.properties isn't set
5442
if(basePath == null){
5543
return;
5644
}
5745
//Create adoption
58-
NewAdoption newAdoption = TestMockBuilders.buildNewAdoptionObject();
46+
NewAdoption newAdoption = MockDataBuilders.buildNewAdoptionObject();
5947
adoptionsService.adoptPet(newAdoption);
6048

6149
//Get Adoption

src/test/java/com/mastercard/app/petstore/flow/EmployeeFlowTest.java renamed to src/main/java/com/mastercard/app/petstore/examples/EmployeeFlowExample.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
package com.mastercard.app.petstore.flow;
1+
package com.mastercard.app.petstore.examples;
22

3-
import com.mastercard.app.petstore.TestMockBuilders;
43
import com.mastercard.app.petstore.services.EmployeeService;
5-
import org.junit.Before;
6-
import org.junit.Test;
7-
import org.junit.runner.RunWith;
4+
import com.mastercard.app.petstore.utils.MockDataBuilders;
85
import org.openapitools.client.ApiException;
9-
import org.openapitools.client.api.EmployeesApi;
106
import org.openapitools.client.model.*;
117
import org.springframework.beans.factory.annotation.Autowired;
128
import org.springframework.beans.factory.annotation.Value;
13-
import org.springframework.boot.test.context.SpringBootTest;
149
import org.springframework.context.annotation.ComponentScan;
15-
import org.springframework.test.context.ActiveProfiles;
16-
import org.springframework.test.context.junit4.SpringRunner;
10+
import org.springframework.stereotype.Component;
1711

1812
/**
19-
* The type Employee flow test.
13+
* The type Employee flow example.
2014
*/
21-
@SpringBootTest()
22-
@RunWith(SpringRunner.class)
23-
@ActiveProfiles({"oauth"})
15+
2416
@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
25-
public class EmployeeFlowTest {
17+
@Component("EmployeeFlowExample")
18+
public class EmployeeFlowExample {
2619

2720
/**
2821
* The Base path. Set in application.properties
@@ -38,14 +31,13 @@ public class EmployeeFlowTest {
3831
*
3932
* @throws ApiException the api exception
4033
*/
41-
@Test
4234
public void employeeUseCase() throws ApiException {
4335
//Skipping test if applications.properties isn't set
4436
if(basePath == null){
4537
return;
4638
}
4739
//Add employee
48-
NewEmployee newEmployee = TestMockBuilders.buildNewEmployee();
40+
NewEmployee newEmployee = MockDataBuilders.buildNewEmployee();
4941
NewEmployeeData newEmployeeData = new NewEmployeeData().addNewEmployeesItem(newEmployee);
5042
Employee employee = employeeService.createEmployee(newEmployeeData).getEmployees().get(0);
5143

0 commit comments

Comments
 (0)