Skip to content

Commit

Permalink
fix svc-bip-api service unit and integration test (#2211)
Browse files Browse the repository at this point in the history
* Merge squashing resolve-bip-test-issues with develop after many of the individual changes have been merged in with the cancel claim branch

* merge changes

* bit config and test config changes

* spotless fix

* minor bug fixes

* added back yml files

* minor update

* adding missing vars to app test

* setting default password for truststore

* clean up

* Changed claimBaseUrl to use env

* more env variable fixes

* minor update

* minor update

* minor change

* reduce coverage for now

* added prune docker step in bip integration test workflow

* lint fix

* minor change

* minor change

* revert some changes back

* minor change

* address review comments

* exclude test on anything under config folder

* address review comments

* minor change

* minor change

* minor change

* minor change

* remove some health check

* add a script to remove rabbitmq volume

* added purge queue before each integration test

* test run in sequence

* minor test

* add a time limit for bip integration test

* minor update

* minor update

* test changes:

* test

* minor update

* test

* test changes

* extend the sleep time

* minor change

* minor change

* minor change

* correction

* test

* test

* test pre and post docker prune

* clean up

* revert back some steps

* minor change

* more clean up

* minor change

* clean up

* revert back minor changes

* small change

* comment out kafka integration test for now

---------

Co-authored-by: Erik Nelsestuen <[email protected]>
Co-authored-by: Teja <[email protected]>
Co-authored-by: dfitchett <[email protected]>
  • Loading branch information
4 people authored Nov 17, 2023
1 parent a308606 commit 3cb4ba5
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 120 deletions.
3 changes: 2 additions & 1 deletion .github/actions/build-images/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ runs:
- name: "Build Docker images without testing"
shell: bash
# Do not call ./gradlew build, which will run tests
run: ./gradlew docker
run: |
./gradlew docker
12 changes: 12 additions & 0 deletions .github/actions/check-disk-space/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Check Current Disk Space
description: provides current host machine disk space summery

runs:
using: composite
steps:
- name: 'Check disk space'
shell: bash
run: |
df -h
echo "Free space on /:"
df -h --output=avail /
14 changes: 14 additions & 0 deletions .github/actions/docker-prune/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Docker prune cleanup
description: Prune unused docker images, containers, volumes, networks and systems

runs:
using: composite
steps:
- name: 'Docker Cleanup'
shell: bash
run: |
docker image prune -af
docker container prune -f
docker volume prune -f
docker network prune -f
docker system prune -af
26 changes: 15 additions & 11 deletions .github/workflows/bie-kafka-end2end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,21 @@ jobs:
repository: 'department-of-veterans-affairs/abd-vro-dev-secrets'
path: "${{ env.VRO_DEV_SECRETS_FOLDER }}"

- name: 'Set RABBITMQ_BASIC_AUTH'
run: |
source scripts/setenv.sh
# create basic auth token for RabbitMQ and export to github environment
BASIC_AUTH=$(echo "${RABBITMQ_USERNAME}:${RABBITMQ_PASSWORD}" | base64)
echo "RABBITMQ_BASIC_AUTH=${BASIC_AUTH}" >> "$GITHUB_ENV"
export -p | sed 's/declare -x //'
- name: 'Build the images'
uses: ./.github/actions/build-images

- name: 'Start the containers'
run: |
source scripts/setenv.sh
# create basic auth token for RabbitMQ and export to github environment
BASIC_AUTH=$(echo "${RABBITMQ_USERNAME}:${RABBITMQ_PASSWORD}" | base64)
{
echo "RABBITMQ_USERNAME=${RABBITMQ_USERNAME}"
echo "RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}"
echo "RABBITMQ_BASIC_AUTH=${BASIC_AUTH}"
} >> "$GITHUB_ENV"
export -p | sed 's/declare -x //'
./gradlew :dockerComposeUp
Expand All @@ -51,6 +50,12 @@ jobs:
./gradlew :domain-xample:dockerComposeUp
./gradlew :app:dockerComposeUp
- name: 'Post-Build Docker Cleanup'
uses: ./.github/actions/docker-prune

- name: 'Check disk space (Post-Build)'
uses: ./.github/actions/check-disk-space

- name: 'Wait for RabbitMQ to be ready'
uses: indiesdev/[email protected]
with:
Expand Down Expand Up @@ -157,7 +162,6 @@ jobs:
path: ./bie-kafka-end2end-test-with-mock-container-logs/**
retention-days: 14


- name: 'Clean shutdown of all containers'
if: always()
shell: bash
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ jobs:
uses: ./.github/workflows/svc-bip-api-integration-test.yml
secrets: inherit

svc-bie-kafka-end-to-end:
needs: nondraft-pr
uses: ./.github/workflows/bie-kafka-end2end-test.yml
secrets: inherit
# svc-bie-kafka-end-to-end:
# needs: nondraft-pr
# uses: ./.github/workflows/bie-kafka-end2end-test.yml
# secrets: inherit

ee-ep-merge-end-to-end:
needs: nondraft-pr
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ee-ep-merge-end-to-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
run: sleep 60s
shell: bash

- name: 'Post-Build Docker Cleanup'
uses: ./.github/actions/docker-prune

- name: 'Check disk space (Post-Build)'
uses: ./.github/actions/check-disk-space

- name: 'Wait for RabbitMQ to be ready'
uses: indiesdev/[email protected]
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/svc-bgs-api-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ jobs:
run: sleep 60s
shell: bash

- name: 'Post-Build Docker Cleanup'
uses: ./.github/actions/docker-prune

- name: 'Check disk space (Post-Build)'
uses: ./.github/actions/check-disk-space

- name: 'Check for RabbitMQ to be ready'
uses: indiesdev/[email protected]
with:
Expand Down
42 changes: 14 additions & 28 deletions .github/workflows/svc-bip-api-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jobs:
repository: 'department-of-veterans-affairs/abd-vro-dev-secrets'
path: "${{ env.VRO_DEV_SECRETS_FOLDER }}"

- name: "Set up VRO build env"
uses: ./.github/actions/setup-vro

- name: 'Check disk space'
uses: ./.github/actions/check-disk-space

- name: 'Build the images'
uses: ./.github/actions/build-images

Expand All @@ -42,19 +48,14 @@ jobs:
} >> "$GITHUB_ENV"
export -p | sed 's/declare -x //'
./gradlew :dockerComposeUp
./gradlew -p mocks docker
./gradlew -p mocks :dockerComposeUp
- name: 'Post-Build Docker Cleanup'
uses: ./.github/actions/docker-prune

./gradlew :domain-xample:dockerComposeUp
./gradlew :app:dockerComposeUp
- name: 'Wait for containers to start'
run: sleep 60s
shell: bash
- name: 'Check disk space (Post-Build)'
uses: ./.github/actions/check-disk-space

- name: 'Wait for RabbitMQ to be ready'
uses: indiesdev/[email protected]
Expand All @@ -68,31 +69,16 @@ jobs:
# Quit after 60 seconds
retries: 30

- name: 'Wait for svc-bip-api to be ready'
uses: nev7n/wait_for_response@v1
with:
url: 'http://localhost:10401/actuator/health'
responseCode: 200
# Retry every 2 seconds
interval: 2000
# Quit after 60 seconds
timeout: 60000

- name: "Wait for VRO to be ready"
uses: nev7n/wait_for_response@v1
with:
url: 'http://localhost:8111/actuator/health'
responseCode: 200
# Retry every 2 seconds
interval: 2000
# Quit after 100 seconds
timeout: 100000
- name: 'Wait for containers to start'
run: sleep 60s
shell: bash

- name: "Run the integration test"
run: |
source scripts/setenv.sh
./gradlew :svc-bip-api:integrationTest
timeout-minutes: 15

- name: "Collect docker logs"
if: always()
Expand Down
4 changes: 2 additions & 2 deletions app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ services:
BIP_TRUSTSTORE: ${BIP_TRUSTSTORE}
BIP_PASSWORD: ${BIP_PASSWORD}
BIP_KEYSTORE: ${BIP_KEYSTORE}
BIP_CLAIM_URL: "mock-bip-claims-api:20300"
BIP_EVIDENCE_URL: "mock-bip-ce-api:20310"
BIP_CLAIM_URL: ${BIP_CLAIM_URL}
BIP_EVIDENCE_URL: ${BIP_EVIDENCE_URL}
ports:
- "10401:10401"
networks:
Expand Down
6 changes: 3 additions & 3 deletions mocks/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
# Containers with the `mock-` prefix are used for development and testing.

mock-slack:
profiles: ["all","slack","bip"]
profiles: ["all","slack"]
image: va/vro_mocks-mock-slack:latest
<<: [*common-sde-security, *common-security-opt]
ports:
Expand All @@ -43,7 +43,7 @@ services:
- vro_intranet

mock-lighthouse-api:
profiles: ["all","lh","bip"]
profiles: ["all","lh"]
image: va/vro_mocks-mock-lighthouse-api:latest
<<: [*common-sde-security, *common-security-opt]
ports:
Expand Down Expand Up @@ -124,7 +124,7 @@ services:
- vro_intranet

mock-bip-ce-api:
profiles: ["all","bip"]
profiles: ["all"]
image: va/vro_mocks-mock-bip-ce-api:latest
<<: [*common-sde-security, *common-security-opt]
ports:
Expand Down
2 changes: 0 additions & 2 deletions scripts/bip-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ source scripts/setenv.sh
./gradlew :dockerComposeUp
./gradlew -p mocks docker
./gradlew -p mocks :dockerComposeUp
./gradlew :domain-xample:dockerComposeUp
./gradlew :app:dockerComposeUp
18 changes: 18 additions & 0 deletions scripts/purge-rabbitmq-volume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Define the service name
service_name="rabbitmq-service"

# Stop the RabbitMQ service using Docker Compose
echo "Stopping the $service_name service using Docker Compose..."
docker-compose stop $service_name

# Remove all unused volumes (caution: this will delete data in all unused volumes)
echo "Pruning unused Docker volumes..."
docker volume prune -f

# Restart the RabbitMQ service using Docker Compose
echo "Restarting the $service_name service..."
docker-compose up -d $service_name

echo "Script completed."
5 changes: 3 additions & 2 deletions scripts/setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,6 @@ exportSecretIfUnset BIE_KAFKA_TRUSTSTORE_PASSWORD

exportSecretIfUnset BIP_TRUSTSTORE
exportSecretIfUnset BIP_KEYSTORE

export truststore_password=keystore_pw
exportSecretIfUnset BIP_PASSWORD
exportSecretIfUnset BIP_CLAIM_URL
exportSecretIfUnset BIP_EVIDENCE_URL
3 changes: 2 additions & 1 deletion svc-bip-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ plugins {
}

ext {
jacocoExclude = ['**/*model*']
jacocoExclude = ['**/*model*', '**/config']
}


dependencies {
implementation project(':domain-xample:xample-shared')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,33 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import gov.va.vro.bip.config.BipApiConfig;
import gov.va.vro.bip.model.BipClaimResp;
import gov.va.vro.bip.model.BipCloseClaimPayload;
import gov.va.vro.bip.model.BipCloseClaimReason;
import gov.va.vro.bip.model.BipCloseClaimResp;
import gov.va.vro.bip.model.BipUpdateClaimResp;
import gov.va.vro.bip.model.ClaimStatus;
import gov.va.vro.bip.model.HasStatusCodeAndMessage;
import gov.va.vro.bip.model.RequestForUpdateClaimStatus;
import gov.va.vro.bip.model.UpdateContention;
import gov.va.vro.bip.model.UpdateContentionModel;
import gov.va.vro.bip.model.UpdateContentionReq;
import gov.va.vro.bip.model.contentions.GetClaimContentionsRequest;
import gov.va.vro.bip.model.contentions.GetClaimContentionsResponse;
import gov.va.vro.bip.service.BipApiProps;
import gov.va.vro.bip.service.BipApiService;
import gov.va.vro.bip.service.RabbitMqController;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.TestPropertySource;

import java.util.Arrays;
import java.util.List;

@ActiveProfiles("test")
@SpringBootTest
@ActiveProfiles("local")
@EnableConfigurationProperties
@ContextHierarchy({
@ContextConfiguration(classes = {BipApiProps.class}),
@ContextConfiguration(classes = {BipApiConfig.class})
})
@TestPropertySource({"classpath:application.yaml", "classpath:application-test.yaml"})
@ExtendWith(MockitoExtension.class)
@Slf4j
@ActiveProfiles("test")
class RabbitMqIntegrationTest {
@Autowired BipApiService service;
@Autowired RabbitMqController controller;
Expand Down Expand Up @@ -125,22 +105,8 @@ void testUpdateClaimContention(@Value("${updateClaimContentionQueue}") String qN
assertResponseIsSuccess(response);
}

@Test
void testCancelClaim(@Value("${cancelClaimQueue}") String qName) {
BipCloseClaimReason reason =
BipCloseClaimReason.builder()
.closeReasonText("because we are testing")
.lifecycleStatusReasonCode("60")
.build();
BipCloseClaimPayload req =
BipCloseClaimPayload.builder().claimId(CLAIM_ID1_LONG).reason(reason).build();
BipCloseClaimResp response =
(BipCloseClaimResp) rabbitTemplate.convertSendAndReceive(exchangeName, qName, req);
assertResponseIsSuccess(response);
}

@SneakyThrows
private void assertResponseIsSuccess(HasStatusCodeAndMessage response) {
private void assertResponseIsSuccess(BipUpdateClaimResp response) {
log.info("response: {}", response);
Assertions.assertNotNull(response);
Assertions.assertEquals(response.statusCode, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
@Setter
public class BipApiConfig {

@Value("${BIP_TRUSTSTORE}")
@Value("${truststore}")
private String trustStore;

@Value("${truststore_password:keystore_pw}")
@Value("${truststore_password}")
private String password;

@Value("${BIP_KEYSTORE}")
@Value("${keystore}")
private String keystore;

@Bean
Expand Down Expand Up @@ -78,8 +78,6 @@ private KeyStore getKeyStore(String base64, String password)
@Bean(name = "bipCERestTemplate")
public RestTemplate getHttpsRestTemplate(RestTemplateBuilder builder) throws BipException {
try {
log.info("trustStore:" + trustStore.substring(0, 60));
log.info("password:" + password);
if (trustStore.isEmpty() & password.isEmpty()) { // skip if it is test.
log.info("No valid BIP mTLS setup. Skip related setup.");
return new RestTemplate();
Expand All @@ -89,7 +87,6 @@ public RestTemplate getHttpsRestTemplate(RestTemplateBuilder builder) throws Bip
KeyStore keyStoreObj = getKeyStore(keystore, password);
log.info("-------load truststore");
KeyStore trustStoreObj = getKeyStore(trustStore, password);
log.info("trustStoreObj", trustStoreObj);

log.info("------build SSLContext");
SSLContext sslContext =
Expand Down
Loading

0 comments on commit 3cb4ba5

Please sign in to comment.