From e2bdab810298a2ba17e5dbc251933d6bc0864d3d Mon Sep 17 00:00:00 2001 From: mdsage1 <122999770+mdsage1@users.noreply.github.com> Date: Fri, 3 Nov 2023 08:38:08 -0700 Subject: [PATCH] feat(openchallenges): added unit tests to the image service (#2291) * added unit tests for api, model and exception * update the unit tests * fix typos in files for unit test * move folder to correct top folder * comment out failing test * remove files * update istest * Update label of the Discord button (#2288) * fix(openchallenges): upgrade legacy components (#2290) * not-found page: upgrade MatCard * org-profile page: remove unused tabs component * github-button: upgrade MatButton * _app-theme: upgrade legacy; fix fonts * navbar: upgrade MatButton; fix colors and padding * fix typography for buttons * signup page: upgrade components * add required `mat-label` * update styles to account for changes * user-button: upgrade MatButton, MatMenu * update styles to account for changes * upgrade component in commented code * remove dependency on legacy-* in _app-theme * add typography to discord button; add discord theme * schematic: remove unused font; upgrade legacies * fix(openchallenges): remove Sage from sponsor list (#2287) * remove Sage from sponsor list * apply section-title styling * link out to ITCR website * use more descriptive variable name * chore(schematic): remove `schematic-app` and `schematic-api-client-angular` (#2293) * Remove schematic-app and schematic-api-client-angular * Update `tsconfig.base.json` * feat(sage-monorepo): enable Format on Save for JSON and JSON with Comments (#2294) * Format JSON on save * Enable format on save for jsonc * hide page size options on search pages (#2298) * delete * img hgt exception test * final image height exception test * update * additional variable formatting * updtate unittest --------- Co-authored-by: Thomas Schaffter Co-authored-by: Verena Chung <9377970+vpchung@users.noreply.github.com> Co-authored-by: Rongrong Chai <73901500+rrchai@users.noreply.github.com> --- .../ImageHeightNotSpecifiedExceptionTest.java | 58 ++++++++++++++++ .../SimpleChallengeGlobalExceptionTest.java | 68 +++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 apps/openchallenges/image-service/src/test/java/org/sagebionetworks/exception/ImageHeightNotSpecifiedExceptionTest.java create mode 100644 apps/openchallenges/image-service/src/test/java/org/sagebionetworks/exception/SimpleChallengeGlobalExceptionTest.java diff --git a/apps/openchallenges/image-service/src/test/java/org/sagebionetworks/exception/ImageHeightNotSpecifiedExceptionTest.java b/apps/openchallenges/image-service/src/test/java/org/sagebionetworks/exception/ImageHeightNotSpecifiedExceptionTest.java new file mode 100644 index 0000000000..edd24e7245 --- /dev/null +++ b/apps/openchallenges/image-service/src/test/java/org/sagebionetworks/exception/ImageHeightNotSpecifiedExceptionTest.java @@ -0,0 +1,58 @@ +package org.sagebionetworks.openchallenges.image.service.exception; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +public class ImageHeightNotSpecifiedExceptionTest { + + @Test + public void ImageHeightNotSpecifiedException_ConstructorTypeShouldMatch() { + // Define the exception detail + String detail = "Image height is not specified"; + + // Create an instance of ImageHeightNotSpecifiedException + ImageHeightNotSpecifiedException exception = new ImageHeightNotSpecifiedException(detail); + + // Verify the exception details + assertThat(ErrorConstants.IMAGE_HEIGHT_NOT_SPECIFIED.getType()).isEqualTo(exception.getType()); + } + + @Test + public void ImageHeightNotSpecifiedException_ConstructorTitle_Match() { + // Define the exception detail + String detail = "Image height is not specified"; + + // Create an instance of ImageHeightNotSpecifiedException + ImageHeightNotSpecifiedException exception = new ImageHeightNotSpecifiedException(detail); + + // Verify the exception details + assertThat(ErrorConstants.IMAGE_HEIGHT_NOT_SPECIFIED.getTitle()) + .isEqualTo(exception.getTitle()); + } + + @Test + public void ImageHeightNotSpecifiedException_ConstructorStatusMatch() { + // Define the exception detail + String detail = "Image height is not specified"; + + // Create an instance of ImageHeightNotSpecifiedException + ImageHeightNotSpecifiedException exception = new ImageHeightNotSpecifiedException(detail); + + // Verify the exception details + assertThat(ErrorConstants.IMAGE_HEIGHT_NOT_SPECIFIED.getStatus()) + .isEqualTo(exception.getStatus()); + } + + @Test + public void ImageHeightNotSpecifiedException_ConstructorDetailMatch() { + // Define the exception detail + String detail = "Image height is not specified"; + + // Create an instance of ImageHeightNotSpecifiedException + ImageHeightNotSpecifiedException exception = new ImageHeightNotSpecifiedException(detail); + + // Verify the exception details + assertThat(exception.getDetail()).isEqualTo(detail); + } +} diff --git a/apps/openchallenges/image-service/src/test/java/org/sagebionetworks/exception/SimpleChallengeGlobalExceptionTest.java b/apps/openchallenges/image-service/src/test/java/org/sagebionetworks/exception/SimpleChallengeGlobalExceptionTest.java new file mode 100644 index 0000000000..6e33fa1a4c --- /dev/null +++ b/apps/openchallenges/image-service/src/test/java/org/sagebionetworks/exception/SimpleChallengeGlobalExceptionTest.java @@ -0,0 +1,68 @@ +package org.sagebionetworks.openchallenges.challenge.service.exception; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; +import org.sagebionetworks.openchallenges.image.service.exception.SimpleChallengeGlobalException; +import org.springframework.http.HttpStatus; + +public class SimpleChallengeGlobalExceptionTest { + + @Test + public void SimpleChallengeGlobalException_ConstructorDetailsShouldMatch() { + // Create an instance of SimpleChallengeGlobalException using the constructor with details + String details = "Something went wrong"; + SimpleChallengeGlobalException exception = new SimpleChallengeGlobalException(details); + + // Verify the exception details + assertThat(exception.getMessage()).isEqualTo(details); + } + + @Test + public void SimpleChallengeGlobalException_ConstructorTypeShouldMatch() { + // Define the exception details + String type = "ExceptionType"; + String title = "Exception Title"; + HttpStatus status = HttpStatus.BAD_REQUEST; + String detail = "Exception detail message"; + + // Create an instance of SimpleChallengeGlobalException using the all-args constructor + SimpleChallengeGlobalException exception = + new SimpleChallengeGlobalException(type, title, status, detail); + + // Verify the exception details + assertThat(exception.getType()).isEqualTo(type); + } + + @Test + public void SimpleChallengeGlobalException_ConstructorTitleShouldMatch() { + // Define the exception details + String type = "ExceptionType"; + String title = "Exception Title"; + HttpStatus status = HttpStatus.BAD_REQUEST; + String detail = "Exception detail message"; + + // Create an instance of SimpleChallengeGlobalException using the all-args constructor + SimpleChallengeGlobalException exception = + new SimpleChallengeGlobalException(type, title, status, detail); + + // Verify the exception details + assertThat(exception.getTitle()).isEqualTo(title); + } + + @Test + public void SimpleChallengeGlobalException_ConstructorStatusShouldMatch() { + // Define the exception details + String type = "ExceptionType"; + String title = "Exception Title"; + HttpStatus status = HttpStatus.BAD_REQUEST; + String detail = "Exception detail message"; + + // Create an instance of SimpleChallengeGlobalException using the all-args constructor + SimpleChallengeGlobalException exception = + new SimpleChallengeGlobalException(type, title, status, detail); + + // Verify the exception details + assertThat(exception.getStatus()).isEqualTo(status); + } +}