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
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Contributing

## Submitting Changes
1. Fork the repository
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Execute the unit tests to ensure all pass
5. Squash your commits (git rebase --interactive --autosquash)
6. Push the branch (git push origin my-new-feature)
7. Create a new Pull Request

### Pull request Approval

Internal developers will verify the changes and approve the request or leave comments for improvements.

### Quality Expectations
Please ensure any contributions include unit tests. The project maintains a high level of test coverage for its functionality.
Submissions are expected to maintain a similar level of coverage.

## Code of Conduct

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## How to engage Maintainers
Leaving Issues using the issue tracker in GitHub.
Maintainers will look for issues posted to the repository and will resolve the issue as soon as possible.

**Copyright © 1994-2024, All Rights Reserved by Mastercard.**
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2024 Mastercard

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Please follow the instruction below to begin
mvn clean install
```

This will generate all required files as defined in [petstore.yaml](src/main/resources/petstore.yaml). They should be built into the target folder.
This will generate all required files as defined in [petstore.yaml](src/main/resources/petstore.yaml) using the [OpenAPI Generator](https://openapi-generator.tech/) plugin. They should be built into the target folder.

## Getting Started

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

The authentication mode (MTLS or OAuth1.0a) must be set using
The authentication mode (mTLS or OAuth1.0a) must be set using
```
-Dspring.profiles.active=oauth
-Dspring.profiles.active=mtls
Expand All @@ -40,7 +40,7 @@ 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 Down
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.5.0</version>
<version>7.9.0</version>
<executions>
<execution>
<id>Petstore REST Client</id>
Expand All @@ -124,12 +124,14 @@
<configuration>
<inputSpec>${project.basedir}/src/main/resources/petstore.yaml</inputSpec>
<generatorName>java</generatorName>
<library>okhttp-gson</library>
<configurationFile>${project.basedir}/src/main/resources/openapi-config.json</configurationFile>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<library>okhttp-gson</library>
<serializationLibrary>jackson</serializationLibrary>
<failOnUnknownProperties>false</failOnUnknownProperties>
</configOptions>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PetstoreApplication {
EmployeeFlowExample employeeFlowExample;

@Bean
PetFlowExample petFlowExample() throws ApiException {
PetFlowExample petFlowExample() {
petFlowExample = new PetFlowExample();
return petFlowExample;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
public class Configuration {

@Bean
public AdoptionsApi adoptionsApiFle(ApiClient apiClientEncryption) throws Exception {
return new AdoptionsApi(apiClientEncryption);
public AdoptionsApi adoptionsApiFle(ApiClient apiClientEncryptionAdoptionFle) {
return new AdoptionsApi(apiClientEncryptionAdoptionFle);
}

@Bean
public AdoptionsApi adoptionsApiFullBody(ApiClient apiClientEncryption) throws Exception {
public AdoptionsApi adoptionsApiFullBody(ApiClient apiClientEncryption) {
return new AdoptionsApi(apiClientEncryption);
}

Expand All @@ -44,14 +44,12 @@ public EmployeesApi employeesApi(ApiClient apiClient) {
}

@Bean
public EmployeesApi employeesApiEncryptedForFLE(ApiClient apiClientEncryption) {
return new EmployeesApi(apiClientEncryption);
public EmployeesApi employeesApiEncryptedForFLE(ApiClient apiClientEncryptionEmployeeFle) {
return new EmployeesApi(apiClientEncryptionEmployeeFle);
}

@Bean
public EmployeesApi employeesApiEncryptedForBody(ApiClient apiClientEncryption) {
return new EmployeesApi(apiClientEncryption);
}


}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.mastercard.app.petstore.examples;

import com.mastercard.app.petstore.services.AdoptionsService;
import com.mastercard.app.petstore.services.CatService;
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.AdoptionSearch;
import org.openapitools.client.model.Cat;
import org.openapitools.client.model.NewAdoption;
import org.openapitools.client.model.NewCat;
import org.openapitools.client.model.PetStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
* The type Adoption flow example.
*/
Expand All @@ -20,37 +24,31 @@
@Component("AdoptionFLowExample")
public class AdoptionFlowExample {

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

private Environment environment;

@Autowired
private AdoptionsService adoptionsService;
@Autowired
private CatService catService;

/**
* Adoption use case. Shows a typical adding an adoption, adopting pet, updating status and then removing it
*
* @throws ApiException the api exception
* @throws ApiException thrown whenever there is an issue sending a request
*/
public void adoptionUseCase() throws ApiException {
//Add cat
NewCat newCat = MockDataBuilders.buildNewCat();
Cat cat = catService.addCat(newCat);

//Skipping test if applications.properties isn't set
if(basePath == null){
return;
}
//Create adoption
NewAdoption newAdoption = MockDataBuilders.buildNewAdoptionObject();
adoptionsService.adoptPet(newAdoption);
NewAdoption newAdoption = MockDataBuilders.buildNewAdoptionObject(cat.getId());
String location = adoptionsService.adoptPet(newAdoption);
String adoptionId = location.substring(location.lastIndexOf('/') + 1).trim();

//Get Adoption
Adoption adoption = adoptionsService.getAdoption(newAdoption.getPetId().toString());
Adoption adoption = adoptionsService.getAdoption(adoptionId);

//Update Adoption
AdoptionWrapper adoptionWrapper = adoptionsService.updateAdoption("1", adoption);
adoptionsService.updateAdoption("0", adoption);

//Remove Adoption
adoptionsService.deleteAdoption(adoption.getId().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.openapitools.client.ApiException;
import org.openapitools.client.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

Expand All @@ -17,25 +16,15 @@
@Component("EmployeeFlowExample")
public class EmployeeFlowExample {

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

@Autowired
private EmployeeService employeeService;

/**
* Employee use case. Show add a new employee, searching for their information, then removing them.
*
* @throws ApiException the api exception
* @throws ApiException thrown whenever there is an issue sending a request
*/
public void employeeUseCase() throws ApiException {
//Skipping test if applications.properties isn't set
if(basePath == null){
return;
}
//Add employee
NewEmployee newEmployee = MockDataBuilders.buildNewEmployee();
NewEmployeeData newEmployeeData = new NewEmployeeData().addNewEmployeesItem(newEmployee);
Expand All @@ -47,6 +36,7 @@ public void employeeUseCase() throws ApiException {
EmployeeWrapper employeeWrapper = employeeService.searchEmployee(employeeSearch);

//Remove employee
employeeService.deleteEmployee(employee.getId().toString());
employeeService.deleteEmployee(employeeWrapper.getUsername());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@
import org.openapitools.client.model.NewCat;
import org.openapitools.client.model.PetStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

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

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

@Autowired
private CatService catService;
@Autowired
Expand All @@ -30,14 +23,18 @@ public class PetFlowExample {
/**
* Pet use case flow. Shows creating a cat, updating their status and then removing them
*
* @throws ApiException the api exception
* @throws ApiException thrown whenever there is an issue sending a request
*/
public void petUseCaseFlow () throws ApiException {
public void petUseCaseFlow() throws ApiException {
//Add pet
NewCat newCat = MockDataBuilders.buildNewCat();
Cat cat = catService.addCat(newCat);
cat = catService.getCat(cat.getId().toString());

//Update cats name
cat.setName("Catso");
catService.updateCat(cat, "0");

//Set pet status
PetStatus status = new PetStatus().value("RESERVED");
petService.updatePetStatus(cat.getId(), status, "1");
Expand Down
Loading
Loading