Skip to content

Commit f81a756

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

17 files changed

+185
-121
lines changed

.github/workflow/maven-test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
- 11
19+
- 17
20+
steps:
21+
- uses: actions/checkout@v1
22+
with:
23+
fetch-depth: 0
24+
- name: 'Set up JDK ${{ matrix.java }}'
25+
uses: actions/setup-java@v1
26+
with:
27+
java-version: '${{ matrix.java }}'
28+
- name: Build and test with Maven
29+
run: mvn -B package -Dgpg.signature.skip=true -Dspring.profiles.active=oauth --file pom.xml

.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 --file pom.xml
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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Mastercard Petstore API
44
- API version: 1.0.0
55
- App version: 1.0.0
66

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.
7+
This application provides an examples of how an API provided by Mastercard Development will implement authentication, authorisation and payload encryption.
8+
Please see [here](https://developer.mastercard.com/reference-service-ngw/documentation) the documentation which covers all you need to use this application and adopt it to your needs.
89

910
For more information, please visit [https://developer.mastercard.com/support](https://developer.mastercard.com/support)
1011

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

1718
## Installation
1819

19-
To being please run
20+
Please follow the instruction bellow to begin
2021

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

2930
Set properties in [application.properties](src/main/resources/application.properties)
3031

31-
The authentication mode must be set using (mTLS or oAuth).
32+
The authentication mode (MTLS or oOAuth1.0a) must be set using
3233
```
3334
-Dspring.profiles.active=oauth
3435
-Dspring.profiles.active=mtls
3536
```
36-
If using the API in oAuth mode the following are required in [application-oauth.properties](src/main/resources/application-oauth.properties)
37+
If using the API in OAuth-1.0a mode the following are required in [application-oauth.properties](src/main/resources/application-oauth.properties)
3738
```
3839
mastercard.oauth.pkcs12KeyFile
3940
mastercard.oauth.consumerKey
4041
mastercard.oauth.keyAlias
4142
mastercard.oauth.keyPassword
4243
```
43-
If using the API in mTLS mode the following are required in [application-mtls.properties](src/main/resources/application-mtls.properties)
44+
If using the API in MTLS mode the following are required in [application-mtls.properties](src/main/resources/application-mtls.properties)
4445
```
4546
mastercard.mtls.pfxKeyFile
4647
mastercard.mtls.keyPassword
@@ -53,11 +54,11 @@ mastercard.encryption.decryptionKeyAlias
5354
mastercard.encryption.decryptionKeyPassword
5455
```
5556

56-
## Use Cases
57+
## Running the Application
5758

5859
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
5960
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.
61+
out to the service, so they must be set.
6162

6263
The tests can be run using
6364
```shell
@@ -68,6 +69,7 @@ or
6869
mvn test -Dspring.profiles.active=mtls
6970
```
7071

72+
## Tested Scenarios
7173
### Adoption Flow Test Case
7274
This demonstrates the typical flow for an adoption.
7375
1) A new adoption is created

pom.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,22 @@
7070
<artifactId>logging-interceptor</artifactId>
7171
<version>${okhttp-version}</version>
7272
</dependency>
73-
<dependency>
73+
<!--<dependency>
7474
<groupId>junit</groupId>
7575
<artifactId>junit</artifactId>
7676
<scope>test</scope>
77+
</dependency>-->
78+
<dependency>
79+
<groupId>org.junit.jupiter</groupId>
80+
<artifactId>junit-jupiter-api</artifactId>
81+
<version>5.7.0</version>
82+
<scope>test</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.junit.jupiter</groupId>
86+
<artifactId>junit-jupiter-engine</artifactId>
87+
<version>5.7.0</version>
88+
<scope>test</scope>
7789
</dependency>
7890
<dependency>
7991
<groupId>org.springframework.boot</groupId>
@@ -148,6 +160,11 @@
148160
</execution>
149161
</executions>
150162
</plugin>
163+
<plugin>
164+
<groupId>org.apache.maven.plugins</groupId>
165+
<artifactId>maven-surefire-plugin</artifactId>
166+
<version>3.0.0-M7</version>
167+
</plugin>
151168
</plugins>
152169
</build>
153170
</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.flow.AdoptionFlowExample;
4+
import com.mastercard.app.petstore.flow.EmployeeFlowExample;
5+
import com.mastercard.app.petstore.flow.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/flow/AdoptionFlowExample.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
11
package com.mastercard.app.petstore.flow;
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/flow/EmployeeFlowExample.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
package com.mastercard.app.petstore.flow;
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

src/test/java/com/mastercard/app/petstore/flow/PetFlowTest.java renamed to src/main/java/com/mastercard/app/petstore/flow/PetFlowExample.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
package com.mastercard.app.petstore.flow;
22

3-
import com.mastercard.app.petstore.TestMockBuilders;
43
import com.mastercard.app.petstore.services.CatService;
54
import com.mastercard.app.petstore.services.PetService;
6-
import org.junit.Before;
7-
import org.junit.Test;
8-
import org.junit.runner.RunWith;
5+
import com.mastercard.app.petstore.utils.MockDataBuilders;
96
import org.openapitools.client.ApiException;
10-
import org.openapitools.client.api.CatsApi;
11-
import org.openapitools.client.api.PetsApi;
127
import org.openapitools.client.model.Cat;
138
import org.openapitools.client.model.NewCat;
149
import org.openapitools.client.model.PetStatus;
1510
import org.springframework.beans.factory.annotation.Autowired;
1611
import org.springframework.beans.factory.annotation.Value;
17-
import org.springframework.boot.test.context.SpringBootTest;
1812
import org.springframework.context.annotation.ComponentScan;
19-
import org.springframework.test.context.ActiveProfiles;
20-
import org.springframework.test.context.junit4.SpringRunner;
2113

22-
@SpringBootTest()
23-
@RunWith(SpringRunner.class)
24-
@ActiveProfiles({"oauth"})
2514
@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
26-
public class PetFlowTest {
15+
public class PetFlowExample {
2716

2817
/**
2918
* The Base path.
@@ -41,15 +30,14 @@ public class PetFlowTest {
4130
*
4231
* @throws ApiException the api exception
4332
*/
44-
@Test
4533
public void petUseCaseFlow () throws ApiException {
4634
//Skipping test if applications.properties isn't set
4735
if(basePath == null){
4836
return;
4937
}
5038

5139
//Add pet
52-
NewCat newCat = TestMockBuilders.buildNewCat();
40+
NewCat newCat = MockDataBuilders.buildNewCat();
5341
Cat cat = catService.addCat(newCat);
5442
cat = catService.getCat(cat.getId().toString());
5543

src/test/java/com/mastercard/app/petstore/TestMockBuilders.java renamed to src/main/java/com/mastercard/app/petstore/utils/MockDataBuilders.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.mastercard.app.petstore;
1+
package com.mastercard.app.petstore.utils;
22

33
import org.openapitools.client.model.*;
44

@@ -9,7 +9,7 @@
99
import java.util.Date;
1010
import java.util.UUID;
1111

12-
public class TestMockBuilders {
12+
public class MockDataBuilders {
1313

1414
public static NewCat buildNewCat(){
1515
NewCat newCat = new NewCat();

src/main/resources/application-oauth.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
mastercard.oauth.pkcs12KeyFile=
33
mastercard.oauth.consumerKey=
44
mastercard.oauth.keyAlias=
5-
mastercard.oauth.keyPassword=
5+
mastercard.oauth.keyPassword=

0 commit comments

Comments
 (0)