Skip to content

Commit 5b74f39

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

17 files changed

+195
-130
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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
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;
37
import org.springframework.boot.SpringApplication;
48
import org.springframework.boot.autoconfigure.SpringBootApplication;
59

610
@SpringBootApplication
711
public class PetstoreApplication {
812

913
public static void main(String[] args) {
10-
SpringApplication.run(PetstoreApplication.class, args);
11-
}
1214

15+
try {
16+
17+
PetFlowExample petFlowExample = new PetFlowExample();
18+
petFlowExample.petUseCaseFlow();
19+
AdoptionFlowExample adoptionFlowExample = new AdoptionFlowExample();
20+
adoptionFlowExample.adoptionUseCase();
21+
EmployeeFlowExample employeeFlowExample = new EmployeeFlowExample();
22+
employeeFlowExample.employeeUseCase();
23+
SpringApplication.run(PetstoreApplication.class, args);
24+
} catch (ApiException e) {
25+
System.console().printf(e.getMessage());
26+
}
27+
}
1328
}

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
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;
2313

2414
/**
25-
* The type Adoption flow test.
15+
* The type Adoption flow example.
2616
*/
27-
@SpringBootTest()
28-
@RunWith(SpringRunner.class)
29-
@ActiveProfiles({"oauth"})
17+
3018
@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
31-
public class AdoptionFlowTest {
19+
public class AdoptionFlowExample {
3220

3321
/**
3422
* The Base path. Set in application.properties
3523
*/
3624
@Value("${mastercard.basePath}")
3725
String basePath;
3826

39-
@Mock
4027
private Environment environment;
4128

4229
@Autowired
@@ -47,15 +34,14 @@ public class AdoptionFlowTest {
4734
*
4835
* @throws ApiException the api exception
4936
*/
50-
@Test
5137
public void adoptionUseCase() throws ApiException {
5238

5339
//Skipping test if applications.properties isn't set
5440
if(basePath == null){
5541
return;
5642
}
5743
//Create adoption
58-
NewAdoption newAdoption = TestMockBuilders.buildNewAdoptionObject();
44+
NewAdoption newAdoption = MockDataBuilders.buildNewAdoptionObject();
5945
adoptionsService.adoptPet(newAdoption);
6046

6147
//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: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
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;
1710

1811
/**
19-
* The type Employee flow test.
12+
* The type Employee flow example.
2013
*/
21-
@SpringBootTest()
22-
@RunWith(SpringRunner.class)
23-
@ActiveProfiles({"oauth"})
14+
2415
@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
25-
public class EmployeeFlowTest {
16+
public class EmployeeFlowExample {
2617

2718
/**
2819
* The Base path. Set in application.properties
@@ -38,14 +29,13 @@ public class EmployeeFlowTest {
3829
*
3930
* @throws ApiException the api exception
4031
*/
41-
@Test
4232
public void employeeUseCase() throws ApiException {
4333
//Skipping test if applications.properties isn't set
4434
if(basePath == null){
4535
return;
4636
}
4737
//Add employee
48-
NewEmployee newEmployee = TestMockBuilders.buildNewEmployee();
38+
NewEmployee newEmployee = MockDataBuilders.buildNewEmployee();
4939
NewEmployeeData newEmployeeData = new NewEmployeeData().addNewEmployeesItem(newEmployee);
5040
Employee employee = employeeService.createEmployee(newEmployeeData).getEmployees().get(0);
5141

0 commit comments

Comments
 (0)