diff --git a/.github/workflows/maven-manual.yml b/.github/workflows/maven-manual.yml index d3ed678..09dcb8e 100644 --- a/.github/workflows/maven-manual.yml +++ b/.github/workflows/maven-manual.yml @@ -27,5 +27,11 @@ jobs: echo " test-secret=secret " >> src/test/resources/secret.properties + - name: Start Unit Test DB + run: | + docker compose up --build -d - name: Build & Test - run: mvn clean test \ No newline at end of file + run: mvn clean test + - name: Docker Compose Down + if: always() + run: docker compose down -v \ No newline at end of file diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index c371827..4621dc1 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -25,12 +25,18 @@ jobs: echo " test-secret=secret " >> src/test/resources/secret.properties + - name: Start Unit Test DB + run: | + docker compose up --build -d - name: Build, Test & Publish uses: ncipollo/release-action@v1 with: allowUpdates: true artifacts: "${{ github.workspace }}/out/artifacts/wasapi_jar/*.jar" token: ${{ secrets.GITHUB_TOKEN }} + - name: Docker Compose Down # check if it's in the right place + if: always() + run: docker compose down -v - name: Publish to the Maven Central Repository run: | mvn \ diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 85c79c9..a63a34a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,5 +30,11 @@ jobs: echo " test-secret=secret " >> src/test/resources/secret.properties + - name: Start Unit Test DB + run: | + docker compose up --build -d - name: Build & Test - run: mvn clean test \ No newline at end of file + run: mvn clean test + - name: Compose Down + if: always() + run: docker compose down -v \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9b68a57..6125b25 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,3 @@ POM-Framework.iml src/test/resources/secret.properties /target/ mongo-init.js -docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..99de387 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +services: + + mongodb: + image: zanmaster/custom-mongo:1.0 + container_name: mongodb + restart: always + environment: + MONGO_INITDB_ROOT_USERNAME: test + MONGO_INITDB_ROOT_PASSWORD: Secret-123 + MONGO_INITDB_DATABASE: food-planner-db + + ports: + - 27017:27017 + + food-planner: + image: zanmaster/food-planner:1.0 + container_name: food-planner + environment: + - SPRING_DATA_MONGODB_URI=mongodb://test:Secret-123@mongodb:27017/food-planner-db?authSource=admin + - SERVER_PORT=5001 + depends_on: + - mongodb + ports: + - "5001:5001" + restart: unless-stopped \ No newline at end of file diff --git a/src/test/java/AppTest.java b/src/test/java/AppTest.java index 3f15502..f3eef99 100644 --- a/src/test/java/AppTest.java +++ b/src/test/java/AppTest.java @@ -10,7 +10,7 @@ public class AppTest { static Printer log = new Printer(AppTest.class); FoodPlanner foodPlanner = new FoodPlanner(); -/* + @Before public void before(){ ContextStore.loadProperties("test.properties", "secret.properties"); @@ -26,6 +26,19 @@ public void before(){ log.success("nice-user authentication is successful!"); } + @After + public void after(){ + log.info("nice-user authentication is in progress..."); + UserAuthRequestModel userAuthRequestModel = new UserAuthRequestModel( + "nice-user", + "Test-123" + ); + UserAuthResponseModel userAuthResponse = foodPlanner.signIn(userAuthRequestModel); + log.info(userAuthResponse.getJwtToken()); + ContextStore.put("jwtToken", userAuthResponse.getJwtToken()); + log.success("nice-user authentication is successful!"); + } + @Test public void deleteUserTest() { FoodPlanner.Auth foodPlannerAuth = new FoodPlanner.Auth(ContextStore.get("jwtToken")); @@ -114,7 +127,6 @@ public void getNiceUserTest() { @Test public void addFoodTest() { - FoodPlanner.Auth foodPlannerAuth = new FoodPlanner.Auth(ContextStore.get("jwtToken")); String randomFoodName = StringUtilities.generateRandomString( "food", 7, @@ -126,16 +138,7 @@ public void addFoodTest() { 1, "1" ); - GetUserResponseModel.Food food = new GetUserResponseModel.Food( - randomFoodName, - "randomFood", - List.of(ingredient), - List.of("Pasta"), - "Main", - true, - "test recipe 01" - ); - GetUserResponseModel responseModel = foodPlannerAuth.addFood(food); + GetUserResponseModel responseModel = addOrUpdateFood(ingredient, randomFoodName); Assert.assertEquals("Username does not match!", "nice-user", responseModel.getUsername()); log.success("Username verified!"); @@ -148,6 +151,20 @@ public void addFoodTest() { log.success("addFoodTest PASSED!"); } + public GetUserResponseModel addOrUpdateFood(GetUserResponseModel.Food.Ingredient ingredient, String foodName) { + FoodPlanner.Auth foodPlannerAuth = new FoodPlanner.Auth(ContextStore.get("jwtToken")); + GetUserResponseModel.Food food = new GetUserResponseModel.Food( + foodName, + "randomFood", + List.of(ingredient), + List.of("Pasta"), + "Main", + true, + "test recipe 01" + ); + return foodPlannerAuth.addFood(food); + } + @Test public void logoutTest() { FoodPlanner foodPlanner = new FoodPlanner(); @@ -208,5 +225,4 @@ public void logoutTest() { } catch (FailedCallException e) { log.success("logoutTest PASSED!");} } -*/ }