diff --git a/.github/workflow/maven-test.yml b/.github/workflow/maven-test.yml new file mode 100644 index 0000000..20639fc --- /dev/null +++ b/.github/workflow/maven-test.yml @@ -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 diff --git a/.github/workflow/sonarcloud.yml b/.github/workflow/sonarcloud.yml new file mode 100644 index 0000000..517b8e3 --- /dev/null +++ b/.github/workflow/sonarcloud.yml @@ -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 + diff --git a/README.md b/README.md index e1baaa4..83a6610 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/pom.xml b/pom.xml index 561d869..54f16c8 100644 --- a/pom.xml +++ b/pom.xml @@ -71,8 +71,15 @@ ${okhttp-version} - junit - junit + org.junit.jupiter + junit-jupiter-api + 5.7.0 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.7.0 test @@ -148,6 +155,11 @@ + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + diff --git a/src/main/java/com/mastercard/app/petstore/PetstoreApplication.java b/src/main/java/com/mastercard/app/petstore/PetstoreApplication.java index 4d0f1eb..74cfd1f 100644 --- a/src/main/java/com/mastercard/app/petstore/PetstoreApplication.java +++ b/src/main/java/com/mastercard/app/petstore/PetstoreApplication.java @@ -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); } - } diff --git a/src/main/java/com/mastercard/app/petstore/configuration/Configuration.java b/src/main/java/com/mastercard/app/petstore/configuration/Configuration.java index a8f98a5..dedd115 100644 --- a/src/main/java/com/mastercard/app/petstore/configuration/Configuration.java +++ b/src/main/java/com/mastercard/app/petstore/configuration/Configuration.java @@ -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 diff --git a/src/test/java/com/mastercard/app/petstore/flow/AdoptionFlowTest.java b/src/main/java/com/mastercard/app/petstore/examples/AdoptionFlowExample.java similarity index 70% rename from src/test/java/com/mastercard/app/petstore/flow/AdoptionFlowTest.java rename to src/main/java/com/mastercard/app/petstore/examples/AdoptionFlowExample.java index 77c8d11..7b02f23 100644 --- a/src/test/java/com/mastercard/app/petstore/flow/AdoptionFlowTest.java +++ b/src/main/java/com/mastercard/app/petstore/examples/AdoptionFlowExample.java @@ -1,34 +1,24 @@ -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 @@ -36,7 +26,6 @@ public class AdoptionFlowTest { @Value("${mastercard.basePath}") String basePath; - @Mock private Environment environment; @Autowired @@ -47,7 +36,6 @@ public class AdoptionFlowTest { * * @throws ApiException the api exception */ - @Test public void adoptionUseCase() throws ApiException { //Skipping test if applications.properties isn't set @@ -55,7 +43,7 @@ public void adoptionUseCase() throws ApiException { return; } //Create adoption - NewAdoption newAdoption = TestMockBuilders.buildNewAdoptionObject(); + NewAdoption newAdoption = MockDataBuilders.buildNewAdoptionObject(); adoptionsService.adoptPet(newAdoption); //Get Adoption diff --git a/src/test/java/com/mastercard/app/petstore/flow/EmployeeFlowTest.java b/src/main/java/com/mastercard/app/petstore/examples/EmployeeFlowExample.java similarity index 71% rename from src/test/java/com/mastercard/app/petstore/flow/EmployeeFlowTest.java rename to src/main/java/com/mastercard/app/petstore/examples/EmployeeFlowExample.java index 44a6d59..1c89052 100644 --- a/src/test/java/com/mastercard/app/petstore/flow/EmployeeFlowTest.java +++ b/src/main/java/com/mastercard/app/petstore/examples/EmployeeFlowExample.java @@ -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 @@ -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); diff --git a/src/test/java/com/mastercard/app/petstore/flow/PetFlowTest.java b/src/main/java/com/mastercard/app/petstore/examples/PetFlowExample.java similarity index 64% rename from src/test/java/com/mastercard/app/petstore/flow/PetFlowTest.java rename to src/main/java/com/mastercard/app/petstore/examples/PetFlowExample.java index 8891cc7..0e3c6a0 100644 --- a/src/test/java/com/mastercard/app/petstore/flow/PetFlowTest.java +++ b/src/main/java/com/mastercard/app/petstore/examples/PetFlowExample.java @@ -1,29 +1,20 @@ -package com.mastercard.app.petstore.flow; +package com.mastercard.app.petstore.examples; -import com.mastercard.app.petstore.TestMockBuilders; import com.mastercard.app.petstore.services.CatService; import com.mastercard.app.petstore.services.PetService; -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.CatsApi; -import org.openapitools.client.api.PetsApi; import org.openapitools.client.model.Cat; 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.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; -@SpringBootTest() -@RunWith(SpringRunner.class) -@ActiveProfiles({"oauth"}) @ComponentScan(basePackages = {"com.mastercard.app.petstore.utils"}) -public class PetFlowTest { +@Component("PetFlowExample") +public class PetFlowExample { /** * The Base path. @@ -41,15 +32,9 @@ public class PetFlowTest { * * @throws ApiException the api exception */ - @Test public void petUseCaseFlow () throws ApiException { - //Skipping test if applications.properties isn't set - if(basePath == null){ - return; - } - //Add pet - NewCat newCat = TestMockBuilders.buildNewCat(); + NewCat newCat = MockDataBuilders.buildNewCat(); Cat cat = catService.addCat(newCat); cat = catService.getCat(cat.getId().toString()); diff --git a/src/test/java/com/mastercard/app/petstore/TestMockBuilders.java b/src/main/java/com/mastercard/app/petstore/utils/MockDataBuilders.java similarity index 98% rename from src/test/java/com/mastercard/app/petstore/TestMockBuilders.java rename to src/main/java/com/mastercard/app/petstore/utils/MockDataBuilders.java index 7f5f396..567714e 100644 --- a/src/test/java/com/mastercard/app/petstore/TestMockBuilders.java +++ b/src/main/java/com/mastercard/app/petstore/utils/MockDataBuilders.java @@ -1,4 +1,4 @@ -package com.mastercard.app.petstore; +package com.mastercard.app.petstore.utils; import org.openapitools.client.model.*; @@ -9,7 +9,7 @@ import java.util.Date; import java.util.UUID; -public class TestMockBuilders { +public class MockDataBuilders { public static NewCat buildNewCat(){ NewCat newCat = new NewCat(); diff --git a/src/main/resources/application-oauth.properties b/src/main/resources/application-oauth.properties index 2700234..21edf77 100644 --- a/src/main/resources/application-oauth.properties +++ b/src/main/resources/application-oauth.properties @@ -2,4 +2,4 @@ mastercard.oauth.pkcs12KeyFile= mastercard.oauth.consumerKey= mastercard.oauth.keyAlias= -mastercard.oauth.keyPassword= \ No newline at end of file +mastercard.oauth.keyPassword= diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5ff9511..34edc39 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,9 +1,10 @@ spring.application.name=petstore + mastercard.basePath= #ENCRYPTION mastercard.encryption.encryptionCert= -mastercard.encryption.decryptionKeys= +mastercard.encryption.decryptionKeys=/ mastercard.encryption.decryptionKeyAlias= -mastercard.encryption.decryptionKeyPassword= \ No newline at end of file +mastercard.encryption.decryptionKeyPassword= diff --git a/src/test/java/com/mastercard/app/petstore/unit/AdoptionsServiceTest.java b/src/test/java/com/mastercard/app/petstore/AdoptionsServiceTest.java similarity index 84% rename from src/test/java/com/mastercard/app/petstore/unit/AdoptionsServiceTest.java rename to src/test/java/com/mastercard/app/petstore/AdoptionsServiceTest.java index cbbcbfa..611b309 100644 --- a/src/test/java/com/mastercard/app/petstore/unit/AdoptionsServiceTest.java +++ b/src/test/java/com/mastercard/app/petstore/AdoptionsServiceTest.java @@ -1,9 +1,9 @@ -package com.mastercard.app.petstore.unit; +package com.mastercard.app.petstore; -import com.mastercard.app.petstore.TestMockBuilders; import com.mastercard.app.petstore.services.AdoptionsService; -import org.junit.Before; -import org.junit.Test; +import com.mastercard.app.petstore.utils.MockDataBuilders; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.openapitools.client.ApiException; import org.openapitools.client.api.AdoptionsApi; @@ -27,7 +27,7 @@ public class AdoptionsServiceTest { @InjectMocks AdoptionsService adoptionsService; - @Before + @BeforeEach public void setUp() { adoptionsApiFle = mock(AdoptionsApi.class); adoptionsApiFullBody = mock(AdoptionsApi.class); @@ -36,7 +36,7 @@ public void setUp() { @Test public void adoptPet_shouldRun() throws ApiException { - NewAdoption newAdoption = TestMockBuilders.buildNewAdoptionObject(); + NewAdoption newAdoption = MockDataBuilders.buildNewAdoptionObject(); doNothing().when(adoptionsApiFle).adoptPet(newAdoption); adoptionsService.adoptPet(newAdoption); @@ -46,7 +46,7 @@ public void adoptPet_shouldRun() throws ApiException { @Test public void getAdoption_shouldReturnAnAdoption() throws ApiException { - Adoption adoption = TestMockBuilders.buildAdoptionObject(); + Adoption adoption = MockDataBuilders.buildAdoptionObject(); when(adoptionsApiFle.getAdoption(any())).thenReturn(adoption); Adoption returnedAdoption = adoptionsService.getAdoption(adoption.getId().toString()); @@ -56,7 +56,7 @@ public void getAdoption_shouldReturnAnAdoption() throws ApiException { @Test public void searchAdoption_shouldReturnAnAdoptionSearch() throws ApiException { - AdoptionSearch adoptionSearch = TestMockBuilders.buildAdoptionSearch(); + AdoptionSearch adoptionSearch = MockDataBuilders.buildAdoptionSearch(); when(adoptionsApiFle.searchAdoptedPets(adoptionSearch.getFromDate(), adoptionSearch.getToDate(), adoptionSearch.getPetCategory(), adoptionSearch.getPetIdentifier())).thenReturn(adoptionSearch); @@ -67,8 +67,8 @@ public void searchAdoption_shouldReturnAnAdoptionSearch() throws ApiException { @Test public void adoptionPayment_shouldReturnAnAdoptionPayment() throws ApiException { - Payment payment = TestMockBuilders.buildPayment(); - PaymentDetails paymentDetails = TestMockBuilders.buildPaymentDetailsFromPayment(payment); + Payment payment = MockDataBuilders.buildPayment(); + PaymentDetails paymentDetails = MockDataBuilders.buildPaymentDetailsFromPayment(payment); UUID id = UUID.randomUUID(); when(adoptionsApiFullBody.adoptionPayment(id, payment)).thenReturn(paymentDetails); diff --git a/src/test/java/com/mastercard/app/petstore/unit/CatServiceTest.java b/src/test/java/com/mastercard/app/petstore/CatServiceTest.java similarity index 78% rename from src/test/java/com/mastercard/app/petstore/unit/CatServiceTest.java rename to src/test/java/com/mastercard/app/petstore/CatServiceTest.java index e759048..5608ab8 100644 --- a/src/test/java/com/mastercard/app/petstore/unit/CatServiceTest.java +++ b/src/test/java/com/mastercard/app/petstore/CatServiceTest.java @@ -1,9 +1,9 @@ -package com.mastercard.app.petstore.unit; +package com.mastercard.app.petstore; -import com.mastercard.app.petstore.TestMockBuilders; import com.mastercard.app.petstore.services.CatService; -import org.junit.Before; -import org.junit.Test; +import com.mastercard.app.petstore.utils.MockDataBuilders; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.openapitools.client.ApiException; import org.openapitools.client.api.CatsApi; @@ -20,7 +20,7 @@ public class CatServiceTest { @InjectMocks CatService catService; - @Before + @BeforeEach public void setUp() { catsApi = mock(CatsApi.class); catService = new CatService(catsApi); @@ -28,8 +28,8 @@ public void setUp() { @Test public void addCat_shouldReturnACat() throws ApiException { - NewCat newCat = TestMockBuilders.buildNewCat(); - Cat expectedCat = TestMockBuilders.buildCat(); + NewCat newCat = MockDataBuilders.buildNewCat(); + Cat expectedCat = MockDataBuilders.buildCat(); when(catsApi.addCat(any())).thenReturn(expectedCat); @@ -40,7 +40,7 @@ public void addCat_shouldReturnACat() throws ApiException { @Test public void getCat_shouldReturnACat() throws ApiException { - Cat cat = TestMockBuilders.buildCat(); + Cat cat = MockDataBuilders.buildCat(); when(catsApi.getCat(any())).thenReturn(cat); Cat returnedCat = catService.getCat(cat.getId().toString()); @@ -50,7 +50,7 @@ public void getCat_shouldReturnACat() throws ApiException { @Test public void updateCat_shouldUpdateACat() throws ApiException { - Cat cat = TestMockBuilders.buildCat(); + Cat cat = MockDataBuilders.buildCat(); String etag = "33a64df551425f"; doNothing().when(catsApi).updateCat(cat.getId(), etag, cat); diff --git a/src/test/java/com/mastercard/app/petstore/unit/DogServiceTest.java b/src/test/java/com/mastercard/app/petstore/DogServiceTest.java similarity index 78% rename from src/test/java/com/mastercard/app/petstore/unit/DogServiceTest.java rename to src/test/java/com/mastercard/app/petstore/DogServiceTest.java index 79fc29f..82a6e44 100644 --- a/src/test/java/com/mastercard/app/petstore/unit/DogServiceTest.java +++ b/src/test/java/com/mastercard/app/petstore/DogServiceTest.java @@ -1,9 +1,9 @@ -package com.mastercard.app.petstore.unit; +package com.mastercard.app.petstore; -import com.mastercard.app.petstore.TestMockBuilders; import com.mastercard.app.petstore.services.DogService; -import org.junit.Before; -import org.junit.Test; +import com.mastercard.app.petstore.utils.MockDataBuilders; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.openapitools.client.ApiException; import org.openapitools.client.api.DogsApi; @@ -20,7 +20,7 @@ public class DogServiceTest { @InjectMocks DogService dogService; - @Before + @BeforeEach public void setUp() { dogsApi = mock(DogsApi.class); dogService = new DogService(dogsApi); @@ -28,8 +28,8 @@ public void setUp() { @Test public void addDog_shouldReturnADog() throws ApiException { - NewDog newDog = TestMockBuilders.buildNewDog(); - Dog expectedDog = TestMockBuilders.buildDog(); + NewDog newDog = MockDataBuilders.buildNewDog(); + Dog expectedDog = MockDataBuilders.buildDog(); when(dogsApi.addDog(any())).thenReturn(expectedDog); @@ -40,7 +40,7 @@ public void addDog_shouldReturnADog() throws ApiException { @Test public void getDog_shouldReturnADog() throws ApiException { - Dog dog = TestMockBuilders.buildDog(); + Dog dog = MockDataBuilders.buildDog(); when(dogsApi.getDog(any())).thenReturn(dog); Dog returnedDog = dogService.getDog(dog.getId().toString()); @@ -50,7 +50,7 @@ public void getDog_shouldReturnADog() throws ApiException { @Test public void updateDog_shouldUpdateADog() throws ApiException { - Dog dog = TestMockBuilders.buildDog(); + Dog dog = MockDataBuilders.buildDog(); String etag = "33a64df551425f"; doNothing().when(dogsApi).updateDog(dog.getId(), etag, dog); diff --git a/src/test/java/com/mastercard/app/petstore/unit/EmployeeServiceTest.java b/src/test/java/com/mastercard/app/petstore/EmployeeServiceTest.java similarity index 86% rename from src/test/java/com/mastercard/app/petstore/unit/EmployeeServiceTest.java rename to src/test/java/com/mastercard/app/petstore/EmployeeServiceTest.java index b5d1fcd..d4e8139 100644 --- a/src/test/java/com/mastercard/app/petstore/unit/EmployeeServiceTest.java +++ b/src/test/java/com/mastercard/app/petstore/EmployeeServiceTest.java @@ -1,9 +1,9 @@ -package com.mastercard.app.petstore.unit; +package com.mastercard.app.petstore; -import com.mastercard.app.petstore.TestMockBuilders; import com.mastercard.app.petstore.services.EmployeeService; -import org.junit.Before; -import org.junit.Test; +import com.mastercard.app.petstore.utils.MockDataBuilders; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.openapitools.client.ApiException; import org.openapitools.client.api.EmployeesApi; @@ -25,7 +25,7 @@ public class EmployeeServiceTest { @InjectMocks EmployeeService employeeService; - @Before + @BeforeEach public void setUp() { employeesApi = mock(EmployeesApi.class); employeesApiEncryptedForBody = mock(EmployeesApi.class); @@ -35,9 +35,9 @@ public void setUp() { @Test public void createEmployee_shouldCreateAnEmployee() throws ApiException { - NewEmployee newEmployee = TestMockBuilders.buildNewEmployee(); + NewEmployee newEmployee = MockDataBuilders.buildNewEmployee(); NewEmployeeData newEmployeeData = new NewEmployeeData().addNewEmployeesItem(newEmployee); - Employee employee = TestMockBuilders.buildEmployee(); + Employee employee = MockDataBuilders.buildEmployee(); EmployeeListData employeeData = new EmployeeListData().addEmployeesItem(employee); when(employeesApiEncryptedForBody.addEmployees(newEmployeeData)).thenReturn(employeeData); @@ -49,7 +49,7 @@ public void createEmployee_shouldCreateAnEmployee() throws ApiException { @Test public void returnEmployee_shouldReturnAnEmployee() throws ApiException { - Employee employee = TestMockBuilders.buildEmployee(); + Employee employee = MockDataBuilders.buildEmployee(); EmployeeData employeeData = new EmployeeData(); employeeData.setEmployee(employee); when(employeesApiEncryptedForFLE.getEmployee(employee.getUsername())).thenReturn(employeeData); diff --git a/src/test/java/com/mastercard/app/petstore/unit/PetServiceTest.java b/src/test/java/com/mastercard/app/petstore/PetServiceTest.java similarity index 80% rename from src/test/java/com/mastercard/app/petstore/unit/PetServiceTest.java rename to src/test/java/com/mastercard/app/petstore/PetServiceTest.java index 4e1e955..7640ec9 100644 --- a/src/test/java/com/mastercard/app/petstore/unit/PetServiceTest.java +++ b/src/test/java/com/mastercard/app/petstore/PetServiceTest.java @@ -1,9 +1,10 @@ -package com.mastercard.app.petstore.unit; +package com.mastercard.app.petstore; -import com.mastercard.app.petstore.TestMockBuilders; import com.mastercard.app.petstore.services.PetService; -import org.junit.Before; -import org.junit.Test; +import com.mastercard.app.petstore.utils.MockDataBuilders; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; import org.mockito.InjectMocks; import org.openapitools.client.ApiException; import org.openapitools.client.api.PetsApi; @@ -24,7 +25,7 @@ public class PetServiceTest { @InjectMocks PetService petService; - @Before + @BeforeEach public void setUp() { petsApi = mock(PetsApi.class); petService = new PetService(petsApi); @@ -32,8 +33,8 @@ public void setUp() { @Test public void updatePet_shouldUpdateAPet() throws ApiException { - Pet pet = TestMockBuilders.buildPet(); - PetStatus petStatus = TestMockBuilders.buildPetStatus(); + Pet pet = MockDataBuilders.buildPet(); + PetStatus petStatus = MockDataBuilders.buildPetStatus(); String etag = "33a64df551425f"; doNothing().when(petsApi).updatePetStatus(pet.getId(), etag, petStatus); @@ -46,7 +47,7 @@ public void updatePet_shouldUpdateAPet() throws ApiException { @Test public void searchForPets_shouldReturnAListofPets() throws ApiException { String status = "RESERVED"; - List petCollection = Collections.singletonList(TestMockBuilders.buildPet()); + List petCollection = Collections.singletonList(MockDataBuilders.buildPet()); PetList pets = new PetList(); pets.setItems(petCollection); pets.setLimit(10); @@ -63,7 +64,7 @@ public void searchForPets_shouldReturnAListofPets() throws ApiException { @Test public void removePet_shouldRemoveAPet() throws ApiException { - Pet pet = TestMockBuilders.buildPet(); + Pet pet = MockDataBuilders.buildPet(); doNothing().when(petsApi).deletePet(pet.getId()); diff --git a/src/test/java/com/mastercard/app/petstore/PetstoreApplicationTests.java b/src/test/java/com/mastercard/app/petstore/PetstoreApplicationTests.java deleted file mode 100644 index 3229e82..0000000 --- a/src/test/java/com/mastercard/app/petstore/PetstoreApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mastercard.app.petstore; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class PetstoreApplicationTests { - - @Test - void contextLoads() { - } - -}