Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflow/maven-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build & Test
'on':
push:
branches:
- "**"
pull_request:
branches:
- "**"
schedule:
- cron: 0 16 * * *
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java:
- 17
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 0
- name: 'Set up JDK ${{ matrix.java }}'
uses: actions/setup-java@v1
with:
java-version: '${{ matrix.java }}'
- name: Build and test with Maven
run: mvn -B package -Dgpg.signature.skip=true -Dspring.profiles.active=oauth
49 changes: 49 additions & 0 deletions .github/workflow/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Sonar
'on':
push:
branches:
- "**"
pull_request_target:
branches:
- "**"
types: [opened, synchronize, reopened, labeled]
schedule:
- cron: 0 16 * * *
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-package: jdk

- uses: actions/checkout@v1
with:
fetch-depth: 0

- name: Check for external PR
if: ${{ !(contains(github.event.pull_request.labels.*.name, 'safe') ||
github.event.pull_request.head.repo.full_name == github.repository ||
github.event_name != 'pull_request_target') }}
run: echo "Unsecure PR, must be labelled with the 'safe' label, then run the workflow again" && exit 1

- name: Build with Maven

mvn clean install

- name: Sonar Scan
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}'
run: >-
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
-Dsonar.projectName=client-encryption-java
-Dsonar.projectKey=Mastercard_client-encryption-java
-Dsonar.organization=mastercard -Dsonar.host.url=https://sonarcloud.io
-Dsonar.login=$SONAR_TOKEN -Dsonar.cpd.exclusions=**/OkHttp*.java
-Dsonar.exclusions=**/*.xml -Dgpg.signature.skip=true

33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Mastercard Petstore API
- API version: 1.0.0
- App version: 1.0.0

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.

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

## Requirements

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

## Installation

To being please run
Please follow the instruction below to begin

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

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

The authentication mode must be set using (mTLS or oAuth).
The authentication mode (MTLS or OAuth1.0a) must be set using
```
-Dspring.profiles.active=oauth
-Dspring.profiles.active=mtls
```
If using the API in oAuth mode the following are required in [application-oauth.properties](src/main/resources/application-oauth.properties)
If using the API in OAuth1.0a mode the following are required in [application-oauth.properties](src/main/resources/application-oauth.properties)
```
mastercard.oauth.pkcs12KeyFile
mastercard.oauth.consumerKey
mastercard.oauth.keyAlias
mastercard.oauth.keyPassword
```
If using the API in mTLS mode the following are required in [application-mtls.properties](src/main/resources/application-mtls.properties)
If using the API in MTLS mode the following are required in [application-mtls.properties](src/main/resources/application-mtls.properties)
```
mastercard.mtls.pfxKeyFile
mastercard.mtls.keyPassword
Expand All @@ -53,11 +53,11 @@ mastercard.encryption.decryptionKeyAlias
mastercard.encryption.decryptionKeyPassword
```

## Use Cases
## Running the Application

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
run if a `basePath` in [application.properties](src/main/resources/application.properties) is not set. These tests call
out to the service so they must be set.
out to the service, so they must be set.

The tests can be run using
```shell
Expand All @@ -68,26 +68,35 @@ or
mvn test -Dspring.profiles.active=mtls
```

### Adoption Flow Test Case
## Example Scenarios

Example scenarios can be found under `src/main/java/com/mastercard/app/petstore/examples`
There are provide simples uses cases, documented below

### Adoption Flow Example
This demonstrates the typical flow for an adoption.
1) A new adoption is created
2) The adoption is then retrieved using the adoption id from step 1
3) Information is updated before removing it using the same id
4) Clean up. The adoption is removed from the system

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

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


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

## Author

API_Consultancy_and_Standards@mastercard.com
16 changes: 14 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@
<version>${okhttp-version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -148,6 +155,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
package com.mastercard.app.petstore;

import com.mastercard.app.petstore.examples.AdoptionFlowExample;
import com.mastercard.app.petstore.examples.EmployeeFlowExample;
import com.mastercard.app.petstore.examples.PetFlowExample;
import org.openapitools.client.ApiException;
import org.openapitools.client.model.Adoption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class PetstoreApplication {
@Autowired
PetFlowExample petFlowExample;
@Autowired
AdoptionFlowExample adoptionFlowExample;
@Autowired
EmployeeFlowExample employeeFlowExample;

@Bean
PetFlowExample petFlowExample() throws ApiException {
petFlowExample = new PetFlowExample();
return petFlowExample;
}

@Bean
AdoptionFlowExample adoptionFlowExample() {
adoptionFlowExample = new AdoptionFlowExample();
return adoptionFlowExample;
}

@Bean
EmployeeFlowExample employeeFlowExample() {
employeeFlowExample = new EmployeeFlowExample();
return employeeFlowExample;
}

@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {

return args -> {
petFlowExample.petUseCaseFlow();
adoptionFlowExample.adoptionUseCase();
employeeFlowExample.employeeUseCase();
};
}

public static void main(String[] args) {
SpringApplication.run(PetstoreApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import org.openapitools.client.api.EmployeesApi;
import org.openapitools.client.api.PetsApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@org.springframework.context.annotation.Configuration
@ComponentScan("com.mastercard.app.petstore")
public class Configuration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
package com.mastercard.app.petstore.flow;
package com.mastercard.app.petstore.examples;

import com.mastercard.app.petstore.TestMockBuilders;
import com.mastercard.app.petstore.services.AdoptionsService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import com.mastercard.app.petstore.utils.MockDataBuilders;
import org.openapitools.client.ApiException;
import org.openapitools.client.model.Adoption;
import org.openapitools.client.model.AdoptionWrapper;
import org.openapitools.client.model.NewAdoption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import java.lang.reflect.Array;

import static org.mockito.Mockito.when;
import org.springframework.stereotype.Component;

/**
* The type Adoption flow test.
* The type Adoption flow example.
*/
@SpringBootTest()
@RunWith(SpringRunner.class)
@ActiveProfiles({"oauth"})

@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
public class AdoptionFlowTest {
@Component("AdoptionFLowExample")
public class AdoptionFlowExample {

/**
* The Base path. Set in application.properties
*/
@Value("${mastercard.basePath}")
String basePath;

@Mock
private Environment environment;

@Autowired
Expand All @@ -47,15 +36,14 @@ public class AdoptionFlowTest {
*
* @throws ApiException the api exception
*/
@Test
public void adoptionUseCase() throws ApiException {

//Skipping test if applications.properties isn't set
if(basePath == null){
return;
}
//Create adoption
NewAdoption newAdoption = TestMockBuilders.buildNewAdoptionObject();
NewAdoption newAdoption = MockDataBuilders.buildNewAdoptionObject();
adoptionsService.adoptPet(newAdoption);

//Get Adoption
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package com.mastercard.app.petstore.flow;
package com.mastercard.app.petstore.examples;

import com.mastercard.app.petstore.TestMockBuilders;
import com.mastercard.app.petstore.services.EmployeeService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.mastercard.app.petstore.utils.MockDataBuilders;
import org.openapitools.client.ApiException;
import org.openapitools.client.api.EmployeesApi;
import org.openapitools.client.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.stereotype.Component;

/**
* The type Employee flow test.
* The type Employee flow example.
*/
@SpringBootTest()
@RunWith(SpringRunner.class)
@ActiveProfiles({"oauth"})

@ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"})
public class EmployeeFlowTest {
@Component("EmployeeFlowExample")
public class EmployeeFlowExample {

/**
* The Base path. Set in application.properties
Expand All @@ -38,14 +31,13 @@ public class EmployeeFlowTest {
*
* @throws ApiException the api exception
*/
@Test
public void employeeUseCase() throws ApiException {
//Skipping test if applications.properties isn't set
if(basePath == null){
return;
}
//Add employee
NewEmployee newEmployee = TestMockBuilders.buildNewEmployee();
NewEmployee newEmployee = MockDataBuilders.buildNewEmployee();
NewEmployeeData newEmployeeData = new NewEmployeeData().addNewEmployeesItem(newEmployee);
Employee employee = employeeService.createEmployee(newEmployeeData).getEmployees().get(0);

Expand Down
Loading