diff --git a/build.gradle b/build.gradle index c469034fec..9c1bd59dca 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ plugins { id 'jacoco' // After merging a spotless version update which requires a large-scale code reformat, add the // commit hash to .git-blame-ignore-revs to avoid cluttering git blame. - id 'com.diffplug.spotless' version '6.25.0' // SEE ABOVE. + id 'com.diffplug.spotless' version '7.0.1' // SEE ABOVE. id 'com.dorongold.task-tree' version '4.0.0' // enables release info in sentry events id 'com.gorylenko.gradle-git-properties' version '2.4.2' @@ -50,7 +50,7 @@ plugins { allprojects { group 'bio.terra' - version '2.208.0-SNAPSHOT' + version '2.213.0-SNAPSHOT' ext { resourceDir = "${rootDir}/src/main/resources/api" @@ -214,6 +214,7 @@ dependencies { implementation 'com.squareup.okhttp3:okhttp' implementation 'org.springframework.boot:spring-boot-starter-actuator' + implementation 'org.springframework.hateoas:spring-hateoas' implementation 'io.micrometer:micrometer-registry-prometheus' implementation 'com.fasterxml.jackson.core:jackson-core' @@ -224,7 +225,7 @@ dependencies { implementation 'com.azure:azure-identity:1.15.0' implementation 'com.azure.resourcemanager:azure-resourcemanager:2.46.0' implementation 'com.azure.resourcemanager:azure-resourcemanager-loganalytics:1.1.0' - implementation 'com.azure.resourcemanager:azure-resourcemanager-securityinsights:1.0.0-beta.5' + implementation 'com.azure.resourcemanager:azure-resourcemanager-securityinsights:1.0.0' implementation 'com.azure:azure-storage-common:12.28.0' implementation 'com.azure:azure-storage-file-datalake:12.22.0' implementation 'com.azure:azure-data-tables:12.5.0' diff --git a/src/main/java/bio/terra/app/configuration/ApplicationConfiguration.java b/src/main/java/bio/terra/app/configuration/ApplicationConfiguration.java index cc60a29591..b01b8282d4 100644 --- a/src/main/java/bio/terra/app/configuration/ApplicationConfiguration.java +++ b/src/main/java/bio/terra/app/configuration/ApplicationConfiguration.java @@ -389,6 +389,8 @@ public NamedParameterJdbcTemplate synapseJdbcTemplate( return new NamedParameterJdbcTemplate(ds); } + // Use Primary to fix an issue with unqualified ObjectMapper injections in spring-hateoas. + @Primary @Bean("objectMapper") public ObjectMapper objectMapper() { return new ObjectMapper() diff --git a/src/main/java/bio/terra/app/usermetrics/UserLoggingMetrics.java b/src/main/java/bio/terra/app/usermetrics/UserLoggingMetrics.java index dad561c450..c13b1d0a29 100644 --- a/src/main/java/bio/terra/app/usermetrics/UserLoggingMetrics.java +++ b/src/main/java/bio/terra/app/usermetrics/UserLoggingMetrics.java @@ -1,7 +1,9 @@ package bio.terra.app.usermetrics; import java.util.HashMap; +import java.util.Map; import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; /** * This class wraps a ThreadLocal variable to store API request properties to log (e.g. method, @@ -11,38 +13,36 @@ * API request will get grouped together even if they are set in different methods. */ @Component +@RequestScope public class UserLoggingMetrics { - private static final ThreadLocal> metrics = - ThreadLocal.withInitial(() -> new HashMap<>()); + private final Map metrics = new HashMap<>(); /** * Get the current thread's metrics instance. If no metrics have been set, return the default * empty HashMap. * - * @return HashMap metrics + * @return Map metrics */ - public HashMap get() { - return metrics.get(); + public Map get() { + return metrics; } /** - * Add a new value to the current thread's metrics map. If the map already contains a value for - * this key it will be replaced. + * Add a new value to the metrics map. If the map already contains a value for this key it will be + * replaced. */ public void set(String key, Object value) { - metrics.get().put(key, value); + metrics.put(key, value); } /** * Add multiple values to the current thread's metrics map. Any existing values with the same key * will get replaced. * - * @param value HashMap of metrics to add + * @param value Map of metrics to add */ - public void setAll(HashMap value) { - HashMap properties = metrics.get(); - properties.putAll(value); - metrics.set(properties); + public void setAll(Map value) { + metrics.putAll(value); } } diff --git a/src/main/java/bio/terra/app/usermetrics/UserMetricsInterceptor.java b/src/main/java/bio/terra/app/usermetrics/UserMetricsInterceptor.java index 1771203094..8b84bf706e 100644 --- a/src/main/java/bio/terra/app/usermetrics/UserMetricsInterceptor.java +++ b/src/main/java/bio/terra/app/usermetrics/UserMetricsInterceptor.java @@ -25,8 +25,8 @@ public class UserMetricsInterceptor implements HandlerInterceptor { private final AuthenticatedUserRequestFactory authenticatedUserRequestFactory; private final ApplicationConfiguration applicationConfiguration; private final UserMetricsConfiguration metricsConfig; + private final UserLoggingMetrics userLoggingMetrics; private final ExecutorService metricsPerformanceThreadpool; - private final UserLoggingMetrics eventProperties; @Autowired public UserMetricsInterceptor( @@ -34,14 +34,14 @@ public UserMetricsInterceptor( AuthenticatedUserRequestFactory authenticatedUserRequestFactory, ApplicationConfiguration applicationConfiguration, UserMetricsConfiguration metricsConfig, - UserLoggingMetrics eventProperties, + UserLoggingMetrics userLoggingMetrics, @Qualifier("metricsReportingThreadpool") ExecutorService metricsPerformanceThreadpool) { this.bardClient = bardClient; this.authenticatedUserRequestFactory = authenticatedUserRequestFactory; this.applicationConfiguration = applicationConfiguration; this.metricsConfig = metricsConfig; + this.userLoggingMetrics = userLoggingMetrics; this.metricsPerformanceThreadpool = metricsPerformanceThreadpool; - this.eventProperties = eventProperties; } @Override @@ -61,16 +61,13 @@ public void afterCompletion( if (StringUtils.isEmpty(metricsConfig.bardBasePath()) || ignoreEventForPath(path)) { return; } - - HashMap properties = - new HashMap<>( - Map.of( - BardEventProperties.METHOD_FIELD_NAME, method, - BardEventProperties.PATH_FIELD_NAME, path)); + Map properties = new HashMap<>(userLoggingMetrics.get()); + properties.putAll( + Map.of( + BardEventProperties.METHOD_FIELD_NAME, method, + BardEventProperties.PATH_FIELD_NAME, path)); addToPropertiesIfPresentInHeader( request, properties, "X-Transaction-Id", BardEventProperties.TRANSACTION_ID_FIELD_NAME); - eventProperties.setAll(properties); - HashMap bardEventProperties = eventProperties.get(); // Spawn a thread so that sending the metric doesn't slow down the initial request metricsPerformanceThreadpool.submit( @@ -79,7 +76,7 @@ public void afterCompletion( userRequest, new BardEvent( API_EVENT_NAME, - bardEventProperties, + properties, metricsConfig.appId(), applicationConfiguration.getDnsName()))); } diff --git a/src/main/java/bio/terra/common/SynapseColumn.java b/src/main/java/bio/terra/common/SynapseColumn.java index 34065a4d44..c9b3868d76 100644 --- a/src/main/java/bio/terra/common/SynapseColumn.java +++ b/src/main/java/bio/terra/common/SynapseColumn.java @@ -91,13 +91,13 @@ public static String translateDataType( case INTEGER -> "numeric(10, 0)"; case INT64 -> "numeric(19, 0)"; case NUMERIC -> "real"; - // DIRREF and FILEREF store a UUID on ingest - // But, are translated to DRS URI on Snapshot Creation - // Note that the Synapse CSV parser does not support varchars larger than 8000 bytes + // DIRREF and FILEREF store a UUID on ingest + // But, are translated to DRS URI on Snapshot Creation + // Note that the Synapse CSV parser does not support varchars larger than 8000 bytes case DIRREF, FILEREF, TEXT, STRING -> "varchar(%s)".formatted(isForCsv ? "8000" : "max"); case TIME -> "time"; - // Data of type RECORD contains table-like that can be nested or repeated - // It's provided in JSON format, making it hard to parse from inside a CSV/JSON ingest + // Data of type RECORD contains table-like that can be nested or repeated + // It's provided in JSON format, making it hard to parse from inside a CSV/JSON ingest case RECORD -> throw new NotSupportedException("RECORD type is not yet supported for synapse"); }; diff --git a/src/main/java/bio/terra/service/auth/iam/IamAction.java b/src/main/java/bio/terra/service/auth/iam/IamAction.java index ddc4d289ce..a8ffe08bba 100644 --- a/src/main/java/bio/terra/service/auth/iam/IamAction.java +++ b/src/main/java/bio/terra/service/auth/iam/IamAction.java @@ -48,6 +48,7 @@ public enum IamAction { // billing profiles UPDATE_BILLING_ACCOUNT, LINK, + READ_SPEND_REPORT, // journal VIEW_JOURNAL, // lock/unlock resources diff --git a/src/main/java/bio/terra/service/auth/iam/sam/SamIam.java b/src/main/java/bio/terra/service/auth/iam/sam/SamIam.java index 990ba6d091..ab784b08f5 100644 --- a/src/main/java/bio/terra/service/auth/iam/sam/SamIam.java +++ b/src/main/java/bio/terra/service/auth/iam/sam/SamIam.java @@ -935,8 +935,8 @@ public static ErrorReportException convertSamExToDataRepoEx(final ApiException s case HttpStatusCodes.STATUS_CODE_FORBIDDEN -> new IamForbiddenException(message, samEx); case HttpStatusCodes.STATUS_CODE_NOT_FOUND -> new IamNotFoundException(message, samEx); case HttpStatusCodes.STATUS_CODE_CONFLICT -> new IamConflictException(message, samEx); - // SAM does not use a 501 NOT_IMPLEMENTED status code, so that case is skipped here - // A 401 error will only occur when OpenDJ is down and should be raised as a 500 error + // SAM does not use a 501 NOT_IMPLEMENTED status code, so that case is skipped here + // A 401 error will only occur when OpenDJ is down and should be raised as a 500 error default -> new IamInternalServerErrorException(message, samEx); }; } diff --git a/src/main/java/bio/terra/service/profile/ProfileApiController.java b/src/main/java/bio/terra/service/profile/ProfileApiController.java index c605efdabf..29bf47a6fb 100644 --- a/src/main/java/bio/terra/service/profile/ProfileApiController.java +++ b/src/main/java/bio/terra/service/profile/ProfileApiController.java @@ -11,6 +11,7 @@ import bio.terra.model.BillingProfileRequestModel; import bio.terra.model.BillingProfileUpdateModel; import bio.terra.model.EnumerateBillingProfileModel; +import bio.terra.model.EnumerateBillingProfileResourcesModel; import bio.terra.model.JobModel; import bio.terra.model.PolicyMemberRequest; import bio.terra.model.PolicyModel; @@ -20,13 +21,11 @@ import bio.terra.service.auth.iam.IamService; import bio.terra.service.auth.iam.PolicyMemberValidator; import bio.terra.service.job.JobService; -import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.annotations.Api; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -42,7 +41,6 @@ @Api(tags = {"profiles"}) public class ProfileApiController implements ProfilesApi { - private final ObjectMapper objectMapper; private final HttpServletRequest request; private final ProfileService profileService; private final ProfileRequestValidator billingProfileRequestValidator; @@ -56,7 +54,6 @@ public class ProfileApiController implements ProfilesApi { @Autowired public ProfileApiController( - ObjectMapper objectMapper, HttpServletRequest request, ProfileService profileService, ProfileRequestValidator billingProfileRequestValidator, @@ -66,7 +63,6 @@ public ProfileApiController( AuthenticatedUserRequestFactory authenticatedUserRequestFactory, IamService iamService, ApplicationConfiguration applicationConfiguration) { - this.objectMapper = objectMapper; this.request = request; this.profileService = profileService; this.billingProfileRequestValidator = billingProfileRequestValidator; @@ -78,16 +74,6 @@ public ProfileApiController( this.applicationConfiguration = applicationConfiguration; } - @Override - public Optional getObjectMapper() { - return Optional.ofNullable(objectMapper); - } - - @Override - public Optional getRequest() { - return Optional.ofNullable(request); - } - @InitBinder protected void initBinder(final WebDataBinder binder) { binder.addValidators(profileUpdateRequestValidator); @@ -199,4 +185,14 @@ private void verifyAuthorization( // Verify permissions iamService.verifyAuthorization(userReq, resourceType, resourceId, action); } + + @Override + public ResponseEntity getProfileResources(UUID id) { + AuthenticatedUserRequest user = authenticatedUserRequestFactory.from(request); + var resources = + profileService.getProfileResources(id, user).stream() + .map(ProfileOwnedResource::toModel) + .toList(); + return ResponseEntity.ok(new EnumerateBillingProfileResourcesModel().items(resources)); + } } diff --git a/src/main/java/bio/terra/service/profile/ProfileOwnedResource.java b/src/main/java/bio/terra/service/profile/ProfileOwnedResource.java index 64e8350a68..a2cdd6a5fa 100644 --- a/src/main/java/bio/terra/service/profile/ProfileOwnedResource.java +++ b/src/main/java/bio/terra/service/profile/ProfileOwnedResource.java @@ -1,5 +1,6 @@ package bio.terra.service.profile; +import bio.terra.model.ProfileOwnedResourceModel; import java.time.Instant; import java.util.UUID; @@ -9,4 +10,16 @@ public enum Type { DATASET, SNAPSHOT, } + + public ProfileOwnedResourceModel toModel() { + return new ProfileOwnedResourceModel() + .id(id) + .name(name) + .description(description) + .createdDate(createdDate.toString()) + .type( + Type.DATASET == type + ? ProfileOwnedResourceModel.TypeEnum.DATASET + : ProfileOwnedResourceModel.TypeEnum.SNAPSHOT); + } } diff --git a/src/main/java/bio/terra/service/profile/ProfileService.java b/src/main/java/bio/terra/service/profile/ProfileService.java index ce3dc69beb..ef87201c4d 100644 --- a/src/main/java/bio/terra/service/profile/ProfileService.java +++ b/src/main/java/bio/terra/service/profile/ProfileService.java @@ -303,4 +303,11 @@ public void verifyDeployedApplication( + "operation"); } } + + public List getProfileResources( + UUID profileId, AuthenticatedUserRequest user) { + iamService.verifyAuthorization( + user, IamResourceType.SPEND_PROFILE, profileId.toString(), IamAction.READ_SPEND_REPORT); + return profileDao.listProfileOwnedResources(profileId); + } } diff --git a/src/main/java/bio/terra/service/tabulardata/google/bigquery/BigQueryDatasetPdao.java b/src/main/java/bio/terra/service/tabulardata/google/bigquery/BigQueryDatasetPdao.java index e27dc10f46..7a710b32d5 100644 --- a/src/main/java/bio/terra/service/tabulardata/google/bigquery/BigQueryDatasetPdao.java +++ b/src/main/java/bio/terra/service/tabulardata/google/bigquery/BigQueryDatasetPdao.java @@ -1334,7 +1334,7 @@ private LegacySQLTypeName translateType(TableDataType datatype) { return LegacySQLTypeName.INTEGER; // match the SQL type case NUMERIC: return LegacySQLTypeName.NUMERIC; - // case RECORD: return LegacySQLTypeName.RECORD; + // case RECORD: return LegacySQLTypeName.RECORD; case STRING: return LegacySQLTypeName.STRING; case TEXT: diff --git a/src/main/resources/api/data-repository-openapi.yaml b/src/main/resources/api/data-repository-openapi.yaml index 9186d47c0d..0339e69c23 100644 --- a/src/main/resources/api/data-repository-openapi.yaml +++ b/src/main/resources/api/data-repository-openapi.yaml @@ -520,6 +520,42 @@ paths: schema: $ref: '#/components/schemas/ErrorModel' + /api/resources/v1/profiles/{id}/resources: + get: + tags: + - profiles + - resources + description: > + Given a profile ID, return the resources associated with that profile. + operationId: getProfileResources + parameters: + - $ref: '#/components/parameters/Id' + responses: + 200: + description: List of resources + content: + application/json: + schema: + $ref: '#/components/schemas/EnumerateBillingProfileResourcesModel' + 400: + description: Bad request - invalid id, badly formed + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorModel' + 403: + description: No permission to retreive resources + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorModel' + 404: + description: Not found - profile id does not exist + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorModel' + /api/repository/v1/snapshots: get: tags: @@ -5242,6 +5278,33 @@ components: $ref: '#/components/schemas/BillingProfileModel' description: > The total number of billing profiles available and a page of profiles + EnumerateBillingProfileResourcesModel: + type: object + properties: + items: + type: array + items: + $ref: '#/components/schemas/ProfileOwnedResourceModel' + description: > + The resources created using this billing profile + ProfileOwnedResourceModel: + type: object + properties: + id: + $ref: '#/components/schemas/UniqueIdProperty' + name: + type: string + description: Name of the resource + description: + type: string + description: Description of the resource + createdDate: + type: string + description: Date the resource was created + type: + type: string + description: Type of the resource + enum: [ DATASET, SNAPSHOT ] DatasetModel: type: object properties: diff --git a/src/test/java/bio/terra/app/configuration/TestApplicationConfiguration.java b/src/test/java/bio/terra/app/configuration/TestApplicationConfiguration.java index 62eaa3136d..e4fd28f6c7 100644 --- a/src/test/java/bio/terra/app/configuration/TestApplicationConfiguration.java +++ b/src/test/java/bio/terra/app/configuration/TestApplicationConfiguration.java @@ -7,9 +7,9 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.test.context.bean.override.mockito.MockitoBean; @EnableAutoConfiguration( exclude = { @@ -26,6 +26,6 @@ havingValue = "false") public class TestApplicationConfiguration extends ApplicationConfiguration { - @MockBean(name = "jdbcTemplate") + @MockitoBean(name = "jdbcTemplate") public NamedParameterJdbcTemplate namedParameterJdbcTemplate; } diff --git a/src/test/java/bio/terra/app/controller/AdminApiControllerTest.java b/src/test/java/bio/terra/app/controller/AdminApiControllerTest.java index c2c19fe42f..dc3d82d4f7 100644 --- a/src/test/java/bio/terra/app/controller/AdminApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/AdminApiControllerTest.java @@ -31,9 +31,9 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({"google", "unittest"}) @@ -44,13 +44,13 @@ class AdminApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private DrsService drsService; - @MockBean private IamService iamService; - @MockBean private DatasetService datasetService; - @MockBean private SnapshotService snapshotService; - @MockBean private ApplicationConfiguration applicationConfiguration; + @MockitoBean private JobService jobService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private DrsService drsService; + @MockitoBean private IamService iamService; + @MockitoBean private DatasetService datasetService; + @MockitoBean private SnapshotService snapshotService; + @MockitoBean private ApplicationConfiguration applicationConfiguration; private static final AuthenticatedUserRequest TEST_USER = AuthenticationFixtures.randomUserRequest(); diff --git a/src/test/java/bio/terra/app/controller/DataRepositoryServiceApiControllerTest.java b/src/test/java/bio/terra/app/controller/DataRepositoryServiceApiControllerTest.java index 85ac19706d..a591ee83ea 100644 --- a/src/test/java/bio/terra/app/controller/DataRepositoryServiceApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/DataRepositoryServiceApiControllerTest.java @@ -25,10 +25,10 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({"google", "unittest"}) @@ -54,9 +54,9 @@ class DataRepositoryServiceApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private ApplicationConfiguration applicationConfiguration; - @MockBean private DrsService drsService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private ApplicationConfiguration applicationConfiguration; + @MockitoBean private DrsService drsService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; private static final AuthenticatedUserRequest TEST_USER = AuthenticationFixtures.randomUserRequest(); diff --git a/src/test/java/bio/terra/app/controller/DatasetsApiControllerTest.java b/src/test/java/bio/terra/app/controller/DatasetsApiControllerTest.java index baa1070a6d..a5547e52cf 100644 --- a/src/test/java/bio/terra/app/controller/DatasetsApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/DatasetsApiControllerTest.java @@ -69,10 +69,10 @@ import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; @@ -82,16 +82,16 @@ @WebMvcTest class DatasetsApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private DatasetRequestValidator datasetRequestValidator; - @MockBean private DatasetService datasetService; - @MockBean private IamService iamService; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private DataDeletionRequestValidator dataDeletionRequestValidator; - @MockBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; + @MockitoBean private JobService jobService; + @MockitoBean private DatasetRequestValidator datasetRequestValidator; + @MockitoBean private DatasetService datasetService; + @MockitoBean private IamService iamService; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private DataDeletionRequestValidator dataDeletionRequestValidator; + @MockitoBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; private static final AuthenticatedUserRequest TEST_USER = AuthenticationFixtures.randomUserRequest(); diff --git a/src/test/java/bio/terra/app/controller/JobsApiControllerTest.java b/src/test/java/bio/terra/app/controller/JobsApiControllerTest.java index 7af61bd5d3..ab499d2936 100644 --- a/src/test/java/bio/terra/app/controller/JobsApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/JobsApiControllerTest.java @@ -33,10 +33,10 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; @ContextConfiguration(classes = {JobsApiController.class, GlobalExceptionHandler.class}) @@ -59,15 +59,15 @@ class JobsApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; + @MockitoBean private JobService jobService; - @MockBean private BardClient bardClient; - @MockBean private DatasetRequestValidator datasetRequestValidator; - @MockBean private SnapshotRequestValidator snapshotRequestValidator; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private PolicyMemberValidator policyMemberValidator; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private BardClient bardClient; + @MockitoBean private DatasetRequestValidator datasetRequestValidator; + @MockitoBean private SnapshotRequestValidator snapshotRequestValidator; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private PolicyMemberValidator policyMemberValidator; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; @BeforeEach void beforeEach() { diff --git a/src/test/java/bio/terra/app/controller/Oauth2ApiControllerTest.java b/src/test/java/bio/terra/app/controller/Oauth2ApiControllerTest.java index d640566d36..2712fc65f4 100644 --- a/src/test/java/bio/terra/app/controller/Oauth2ApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/Oauth2ApiControllerTest.java @@ -26,13 +26,13 @@ import org.mockito.Captor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.client.RestTemplate; @@ -42,8 +42,8 @@ @WebMvcTest public class Oauth2ApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private RestTemplate restTemplate; - @MockBean private OpenIDConnectConfiguration openIDConnectConfiguration; + @MockitoBean private RestTemplate restTemplate; + @MockitoBean private OpenIDConnectConfiguration openIDConnectConfiguration; @Autowired private ObjectMapper objectMapper; @Captor private ArgumentCaptor> postCaptor; diff --git a/src/test/java/bio/terra/app/controller/SnapshotAccessRequestApiControllerTest.java b/src/test/java/bio/terra/app/controller/SnapshotAccessRequestApiControllerTest.java index 742dced24a..98afe08781 100644 --- a/src/test/java/bio/terra/app/controller/SnapshotAccessRequestApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/SnapshotAccessRequestApiControllerTest.java @@ -37,10 +37,10 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({"google", "unittest"}) @@ -50,9 +50,9 @@ @WebMvcTest class SnapshotAccessRequestApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @MockBean private IamService iamService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private IamService iamService; private static final String ENDPOINT = "/api/repository/v1/snapshotAccessRequests"; private static final String GET_ENDPOINT = ENDPOINT + "/{id}"; diff --git a/src/test/java/bio/terra/app/controller/SnapshotValidationTest.java b/src/test/java/bio/terra/app/controller/SnapshotValidationTest.java index f4b76ca2ac..0bc6919dcd 100644 --- a/src/test/java/bio/terra/app/controller/SnapshotValidationTest.java +++ b/src/test/java/bio/terra/app/controller/SnapshotValidationTest.java @@ -45,12 +45,11 @@ import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -68,14 +67,14 @@ class SnapshotValidationTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private SnapshotService snapshotService; - @MockBean private IamService iamService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @SpyBean private ApplicationConfiguration applicationConfiguration; + @MockitoBean private JobService jobService; + @MockitoBean private SnapshotService snapshotService; + @MockitoBean private IamService iamService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private ApplicationConfiguration applicationConfiguration; private SnapshotRequestModel snapshotByAssetRequest; diff --git a/src/test/java/bio/terra/app/controller/SnapshotsApiControllerTest.java b/src/test/java/bio/terra/app/controller/SnapshotsApiControllerTest.java index 790d614b38..961eb70575 100644 --- a/src/test/java/bio/terra/app/controller/SnapshotsApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/SnapshotsApiControllerTest.java @@ -69,10 +69,10 @@ import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; @@ -84,15 +84,15 @@ class SnapshotsApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private SnapshotRequestValidator snapshotRequestValidator; - @MockBean private SnapshotService snapshotService; - @MockBean private IamService iamService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private JobService jobService; + @MockitoBean private SnapshotRequestValidator snapshotRequestValidator; + @MockitoBean private SnapshotService snapshotService; + @MockitoBean private IamService iamService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; private static final AuthenticatedUserRequest TEST_USER = AuthenticationFixtures.randomUserRequest(); diff --git a/src/test/java/bio/terra/app/controller/UnauthenticatedApiControllerTest.java b/src/test/java/bio/terra/app/controller/UnauthenticatedApiControllerTest.java index 433a1eb2a3..a57bd66994 100644 --- a/src/test/java/bio/terra/app/controller/UnauthenticatedApiControllerTest.java +++ b/src/test/java/bio/terra/app/controller/UnauthenticatedApiControllerTest.java @@ -18,9 +18,9 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({"google", "unittest"}) @@ -30,13 +30,13 @@ class UnauthenticatedApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private OauthConfiguration oauthConfig; - @MockBean private OpenIDConnectConfiguration openIDConnectConfiguration; - @MockBean private JobService jobService; - @MockBean private StatusService statusService; - @MockBean private TerraConfiguration terraConfiguration; - @MockBean private SamConfiguration samConfiguration; - @MockBean private DuosConfiguration duosConfiguration; + @MockitoBean private OauthConfiguration oauthConfig; + @MockitoBean private OpenIDConnectConfiguration openIDConnectConfiguration; + @MockitoBean private JobService jobService; + @MockitoBean private StatusService statusService; + @MockitoBean private TerraConfiguration terraConfiguration; + @MockitoBean private SamConfiguration samConfiguration; + @MockitoBean private DuosConfiguration duosConfiguration; private void mockGetStatus(boolean ok) { when(statusService.getStatus()).thenReturn(new RepositoryStatusModel().ok(ok)); diff --git a/src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java b/src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java index be2bba6825..376b4d344c 100644 --- a/src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java +++ b/src/test/java/bio/terra/app/usermetrics/UserMetricsInterceptorTest.java @@ -35,9 +35,9 @@ import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; @ActiveProfiles({"google", "unittest"}) @ContextConfiguration(classes = UserLoggingMetrics.class) @@ -45,10 +45,10 @@ @Tag(Unit.TAG) class UserMetricsInterceptorTest { @Autowired private UserLoggingMetrics eventProperties; - @MockBean private BardClient bardClient; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private ApplicationConfiguration applicationConfiguration; - @MockBean private UserMetricsConfiguration metricsConfig; + @MockitoBean private BardClient bardClient; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private ApplicationConfiguration applicationConfiguration; + @MockitoBean private UserMetricsConfiguration metricsConfig; private ExecutorService metricsPerformanceThreadpool; private UserMetricsInterceptor userMetricsInterceptor; @@ -70,7 +70,6 @@ class UserMetricsInterceptorTest { @BeforeEach void setUp() { - eventProperties.get().clear(); when(metricsConfig.ignorePaths()).thenReturn(List.of()); when(metricsConfig.appId()).thenReturn(APP_ID); when(metricsConfig.bardBasePath()).thenReturn(BARD_BASE_PATH); diff --git a/src/test/java/bio/terra/integration/FileTest.java b/src/test/java/bio/terra/integration/FileTest.java index f9b0e8e76a..29c2dddfd3 100644 --- a/src/test/java/bio/terra/integration/FileTest.java +++ b/src/test/java/bio/terra/integration/FileTest.java @@ -59,10 +59,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -85,7 +85,7 @@ public class FileTest extends UsersBase { @Autowired private TestConfiguration testConfiguration; - @MockBean private JobService jobService; + @MockitoBean private JobService jobService; private final Storage storage = StorageOptions.getDefaultInstance().getService(); diff --git a/src/test/java/bio/terra/pact/provider/SnapshotsApiControllerTest.java b/src/test/java/bio/terra/pact/provider/SnapshotsApiControllerTest.java index ba4b94dd94..028172ef58 100644 --- a/src/test/java/bio/terra/pact/provider/SnapshotsApiControllerTest.java +++ b/src/test/java/bio/terra/pact/provider/SnapshotsApiControllerTest.java @@ -40,9 +40,9 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; /** @@ -60,15 +60,15 @@ class SnapshotsApiControllerTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private SnapshotRequestValidator snapshotRequestValidator; - @MockBean private SnapshotService snapshotService; - @MockBean private IamService iamService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private JobService jobService; + @MockitoBean private SnapshotRequestValidator snapshotRequestValidator; + @MockitoBean private SnapshotService snapshotService; + @MockitoBean private IamService iamService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; @PactBrokerConsumerVersionSelectors public static SelectorBuilder consumerVersionSelectors() { diff --git a/src/test/java/bio/terra/service/auth/iam/ras/EcmServiceTest.java b/src/test/java/bio/terra/service/auth/iam/ras/EcmServiceTest.java index 3ce54e1079..ac54506c97 100644 --- a/src/test/java/bio/terra/service/auth/iam/ras/EcmServiceTest.java +++ b/src/test/java/bio/terra/service/auth/iam/ras/EcmServiceTest.java @@ -159,14 +159,16 @@ private String toPassportJwt(String visa) throws Exception { String visaJwt = (visa == null) ? "" : String.format("\"%s\"", toJwtToken(visa)); String passportPayload = """ - {"%s": [%s]}""".formatted(EcmService.GA4GH_PASSPORT_V1_CLAIM, visaJwt); + {"%s": [%s]}""" + .formatted(EcmService.GA4GH_PASSPORT_V1_CLAIM, visaJwt); String returned = toJwtToken(passportPayload); System.out.println(returned); return returned; } private String toJwtToken(String payload) throws Exception { - String header = """ + String header = + """ {"alg":"none","typ":"JWT"} """; return new PlainJWT(base64(header), base64(payload)).serialize(); diff --git a/src/test/java/bio/terra/service/dataset/AssetModelValidatorTest.java b/src/test/java/bio/terra/service/dataset/AssetModelValidatorTest.java index 4601028a58..7cc589f79d 100644 --- a/src/test/java/bio/terra/service/dataset/AssetModelValidatorTest.java +++ b/src/test/java/bio/terra/service/dataset/AssetModelValidatorTest.java @@ -22,10 +22,10 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({"google", "unittest"}) @@ -38,16 +38,16 @@ @WebMvcTest @Tag(Unit.TAG) class AssetModelValidatorTest { - @MockBean private JobService jobService; - @MockBean private DatasetService datasetService; - @MockBean private IamService iamService; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private DataDeletionRequestValidator dataDeletionRequestValidator; - @MockBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; - @MockBean private DatasetRequestValidator datasetRequestValidator; + @MockitoBean private JobService jobService; + @MockitoBean private DatasetService datasetService; + @MockitoBean private IamService iamService; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private DataDeletionRequestValidator dataDeletionRequestValidator; + @MockitoBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; + @MockitoBean private DatasetRequestValidator datasetRequestValidator; @Autowired private MockMvc mvc; diff --git a/src/test/java/bio/terra/service/dataset/DataDeletionRequestValidatorTest.java b/src/test/java/bio/terra/service/dataset/DataDeletionRequestValidatorTest.java index 327cc98ae1..c92bdf2f38 100644 --- a/src/test/java/bio/terra/service/dataset/DataDeletionRequestValidatorTest.java +++ b/src/test/java/bio/terra/service/dataset/DataDeletionRequestValidatorTest.java @@ -35,10 +35,10 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -54,16 +54,16 @@ class DataDeletionRequestValidatorTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private DatasetService datasetService; - @MockBean private IamService iamService; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; - @MockBean private DatasetRequestValidator datasetRequestValidator; + @MockitoBean private JobService jobService; + @MockitoBean private DatasetService datasetService; + @MockitoBean private IamService iamService; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; + @MockitoBean private DatasetRequestValidator datasetRequestValidator; private DataDeletionRequest goodGcsRequest; private DataDeletionRequest goodJsonArrayRequest; diff --git a/src/test/java/bio/terra/service/dataset/DatasetConnectedTest.java b/src/test/java/bio/terra/service/dataset/DatasetConnectedTest.java index 52f3e1801c..7d5afe21ae 100644 --- a/src/test/java/bio/terra/service/dataset/DatasetConnectedTest.java +++ b/src/test/java/bio/terra/service/dataset/DatasetConnectedTest.java @@ -59,9 +59,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @@ -81,7 +81,7 @@ public class DatasetConnectedTest { @Autowired private ConfigurationService configService; @Autowired private ConnectedTestConfiguration testConfig; @Autowired private ApplicationConfiguration applicationConfiguration; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired private GoogleResourceManagerService googleResourceManagerService; @Autowired private DatasetBucketDao datasetBucketDao; @Autowired private GoogleResourceDao googleResourceDao; diff --git a/src/test/java/bio/terra/service/dataset/DatasetRequestValidatorTest.java b/src/test/java/bio/terra/service/dataset/DatasetRequestValidatorTest.java index bf696f4d95..07cef5baae 100644 --- a/src/test/java/bio/terra/service/dataset/DatasetRequestValidatorTest.java +++ b/src/test/java/bio/terra/service/dataset/DatasetRequestValidatorTest.java @@ -51,11 +51,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -77,16 +77,16 @@ class DatasetRequestValidatorTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private DatasetService datasetService; - @MockBean private IamService iamService; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; - @MockBean private DataDeletionRequestValidator dataDeletionRequestValidator; + @MockitoBean private JobService jobService; + @MockitoBean private DatasetService datasetService; + @MockitoBean private IamService iamService; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; + @MockitoBean private DataDeletionRequestValidator dataDeletionRequestValidator; @BeforeEach void setup() throws Exception { diff --git a/src/test/java/bio/terra/service/dataset/DatasetSchemaUpdateValidatorTest.java b/src/test/java/bio/terra/service/dataset/DatasetSchemaUpdateValidatorTest.java index 9e36f2aaa0..b5dca1c97b 100644 --- a/src/test/java/bio/terra/service/dataset/DatasetSchemaUpdateValidatorTest.java +++ b/src/test/java/bio/terra/service/dataset/DatasetSchemaUpdateValidatorTest.java @@ -34,11 +34,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -56,15 +56,15 @@ class DatasetSchemaUpdateValidatorTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private DatasetService datasetService; - @MockBean private IamService iamService; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private DataDeletionRequestValidator dataDeletionRequestValidator; + @MockitoBean private JobService jobService; + @MockitoBean private DatasetService datasetService; + @MockitoBean private IamService iamService; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private DataDeletionRequestValidator dataDeletionRequestValidator; @BeforeEach void setup() throws Exception { diff --git a/src/test/java/bio/terra/service/dataset/DatasetServiceTest.java b/src/test/java/bio/terra/service/dataset/DatasetServiceTest.java index 939444af5b..1970b866e3 100644 --- a/src/test/java/bio/terra/service/dataset/DatasetServiceTest.java +++ b/src/test/java/bio/terra/service/dataset/DatasetServiceTest.java @@ -78,10 +78,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -104,9 +104,9 @@ public class DatasetServiceTest { @Autowired private DatasetService datasetService; - @SpyBean private JobService jobService; + @MockitoSpyBean private JobService jobService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired private ConnectedOperations connectedOperations; @@ -116,13 +116,13 @@ public class DatasetServiceTest { @Autowired private NamedParameterJdbcTemplate jdbcTemplate; - @MockBean private ResourceService resourceService; - @MockBean private GcsPdao gcsPdao; - @MockBean private AzureContainerPdao azureContainerPdao; - @MockBean private AzureBlobStorePdao azureBlobStorePdao; - @MockBean private AzureMonitoringService azureMonitoringService; - @MockBean private MetadataDataAccessUtils metadataDataAccessUtils; - @MockBean private AzureSynapsePdao azureSynapsePdao; + @MockitoBean private ResourceService resourceService; + @MockitoBean private GcsPdao gcsPdao; + @MockitoBean private AzureContainerPdao azureContainerPdao; + @MockitoBean private AzureBlobStorePdao azureBlobStorePdao; + @MockitoBean private AzureMonitoringService azureMonitoringService; + @MockitoBean private MetadataDataAccessUtils metadataDataAccessUtils; + @MockitoBean private AzureSynapsePdao azureSynapsePdao; @Captor private ArgumentCaptor> listCaptor; @Captor private ArgumentCaptor requestCaptor; diff --git a/src/test/java/bio/terra/service/dataset/DatasetSoftDeleteConnectedTest.java b/src/test/java/bio/terra/service/dataset/DatasetSoftDeleteConnectedTest.java index 813e3e4477..2b76f9f533 100644 --- a/src/test/java/bio/terra/service/dataset/DatasetSoftDeleteConnectedTest.java +++ b/src/test/java/bio/terra/service/dataset/DatasetSoftDeleteConnectedTest.java @@ -48,10 +48,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MvcResult; @@ -70,7 +70,7 @@ public class DatasetSoftDeleteConnectedTest { @Autowired private ConnectedTestConfiguration testConfig; @Autowired private ResourceService dataLocationService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private DatasetSummaryModel summaryModel; private static final Logger logger = diff --git a/src/test/java/bio/terra/service/dataset/IngestRequestValidatorTest.java b/src/test/java/bio/terra/service/dataset/IngestRequestValidatorTest.java index 03a68ed9cb..04f837f784 100644 --- a/src/test/java/bio/terra/service/dataset/IngestRequestValidatorTest.java +++ b/src/test/java/bio/terra/service/dataset/IngestRequestValidatorTest.java @@ -36,11 +36,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -57,16 +57,16 @@ class IngestRequestValidatorTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private DatasetService datasetService; - @MockBean private IamService iamService; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @MockBean private DataDeletionRequestValidator dataDeletionRequestValidator; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; - @MockBean private DatasetRequestValidator datasetRequestValidator; + @MockitoBean private JobService jobService; + @MockitoBean private DatasetService datasetService; + @MockitoBean private IamService iamService; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private DataDeletionRequestValidator dataDeletionRequestValidator; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private DatasetSchemaUpdateValidator datasetSchemaUpdateValidator; + @MockitoBean private DatasetRequestValidator datasetRequestValidator; private ErrorModel expectBadPostRequest(String url, String content) throws Exception { MvcResult result = diff --git a/src/test/java/bio/terra/service/dataset/flight/update/DatasetSchemaUpdateConnectedTest.java b/src/test/java/bio/terra/service/dataset/flight/update/DatasetSchemaUpdateConnectedTest.java index 8b96228814..cf55832200 100644 --- a/src/test/java/bio/terra/service/dataset/flight/update/DatasetSchemaUpdateConnectedTest.java +++ b/src/test/java/bio/terra/service/dataset/flight/update/DatasetSchemaUpdateConnectedTest.java @@ -63,8 +63,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -84,7 +84,7 @@ public class DatasetSchemaUpdateConnectedTest { @Autowired private ConnectedTestConfiguration testConfig; @Autowired private BigQueryDatasetPdao bigQueryDatasetPdao; @Autowired private DatasetRelationshipDao relationshipDao; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BillingProfileModel billingProfile; private DatasetSummaryModel summaryModel; diff --git a/src/test/java/bio/terra/service/dataset/flight/update/DatasetSchemaUpdateValidateModelStepTest.java b/src/test/java/bio/terra/service/dataset/flight/update/DatasetSchemaUpdateValidateModelStepTest.java index 112723a271..0b7ed71273 100644 --- a/src/test/java/bio/terra/service/dataset/flight/update/DatasetSchemaUpdateValidateModelStepTest.java +++ b/src/test/java/bio/terra/service/dataset/flight/update/DatasetSchemaUpdateValidateModelStepTest.java @@ -48,9 +48,9 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; @ActiveProfiles({"google", "unittest"}) @ContextConfiguration( @@ -63,16 +63,16 @@ @Tag(Unit.TAG) class DatasetSchemaUpdateValidateModelStepTest { - @MockBean private JobService jobService; - @MockBean private DatasetService datasetService; - @MockBean private IamService iamService; - @MockBean private FileService fileService; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private AssetModelValidator assetModelValidator; - @MockBean private DataDeletionRequestValidator dataDeletionRequestValidator; - @MockBean private DatasetRequestValidator datasetRequestValidator; + @MockitoBean private JobService jobService; + @MockitoBean private DatasetService datasetService; + @MockitoBean private IamService iamService; + @MockitoBean private FileService fileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private AssetModelValidator assetModelValidator; + @MockitoBean private DataDeletionRequestValidator dataDeletionRequestValidator; + @MockitoBean private DatasetRequestValidator datasetRequestValidator; private UUID datasetId; private static final String EXISTING_TABLE = "existing_table"; diff --git a/src/test/java/bio/terra/service/filedata/azure/AzureIngestFileConnectedTest.java b/src/test/java/bio/terra/service/filedata/azure/AzureIngestFileConnectedTest.java index d61a332160..4d74fa9444 100644 --- a/src/test/java/bio/terra/service/filedata/azure/AzureIngestFileConnectedTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/AzureIngestFileConnectedTest.java @@ -54,9 +54,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -87,12 +87,12 @@ public class AzureIngestFileConnectedTest { private FileLoadModel fileLoadModel; private TableServiceClient tableServiceClient; - @SpyBean private AzureResourceConfiguration azureResourceConfiguration; + @MockitoSpyBean private AzureResourceConfiguration azureResourceConfiguration; @Autowired AzureSynapsePdao azureSynapsePdao; @Autowired ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; @Autowired DatasetService datasetService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired SynapseUtils synapseUtils; @Autowired AzureAuthService azureAuthService; @Autowired TableDirectoryDao tableDirectoryDao; diff --git a/src/test/java/bio/terra/service/filedata/azure/AzureSynapsePdaoConnectedTest.java b/src/test/java/bio/terra/service/filedata/azure/AzureSynapsePdaoConnectedTest.java index 361735cf40..41000a8ae7 100644 --- a/src/test/java/bio/terra/service/filedata/azure/AzureSynapsePdaoConnectedTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/AzureSynapsePdaoConnectedTest.java @@ -52,8 +52,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -147,7 +147,7 @@ public class AzureSynapsePdaoConnectedTest { @Autowired AzureBlobStorePdao azureBlobStorePdao; @Autowired ConnectedOperations connectedOperations; @Autowired DatasetService datasetService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired SynapseUtils synapseUtils; @Autowired SnapshotDao snapshotDao; @Autowired JsonLoader jsonLoader; diff --git a/src/test/java/bio/terra/service/filedata/azure/AzureSynapsePdaoSnapshotConnectedTest.java b/src/test/java/bio/terra/service/filedata/azure/AzureSynapsePdaoSnapshotConnectedTest.java index 1ee7993a27..665a8f05e1 100644 --- a/src/test/java/bio/terra/service/filedata/azure/AzureSynapsePdaoSnapshotConnectedTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/AzureSynapsePdaoSnapshotConnectedTest.java @@ -56,8 +56,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -91,7 +91,7 @@ public class AzureSynapsePdaoSnapshotConnectedTest { @Autowired AzureBlobStorePdao azureBlobStorePdao; @Autowired ConnectedOperations connectedOperations; @Autowired DatasetService datasetService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired SynapseUtils synapseUtils; @Autowired SnapshotDao snapshotDao; @Autowired JsonLoader jsonLoader; diff --git a/src/test/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdaoTest.java b/src/test/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdaoTest.java index e746815579..a4a3ec0797 100644 --- a/src/test/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdaoTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/blobstore/AzureBlobStorePdaoTest.java @@ -66,10 +66,10 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -117,21 +117,21 @@ public class AzureBlobStorePdaoTest { private BlobContainerClientFactory sourceBlobContainerFactory; private BlobContainerClientFactory targetBlobContainerFactory; private BlobCrl blobCrl; - @MockBean private ProfileDao profileDao; - @MockBean private AzureContainerPdao azureContainerPdao; - @MockBean private AzureResourceConfiguration resourceConfiguration; - @MockBean private AzureResourceDao azureResourceDao; - @MockBean private AzureAuthService azureAuthService; - @MockBean private GcsPdao gcsPdao; - @MockBean private GcsProjectFactory gcsProjectFactory; - @MockBean private AzureBlobService azureBlobService; - - @MockBean(name = AzureResourceConfiguration.TABLE_THREADPOOL_NAME) + @MockitoBean private ProfileDao profileDao; + @MockitoBean private AzureContainerPdao azureContainerPdao; + @MockitoBean private AzureResourceConfiguration resourceConfiguration; + @MockitoBean private AzureResourceDao azureResourceDao; + @MockitoBean private AzureAuthService azureAuthService; + @MockitoBean private GcsPdao gcsPdao; + @MockitoBean private GcsProjectFactory gcsProjectFactory; + @MockitoBean private AzureBlobService azureBlobService; + + @MockitoBean(name = AzureResourceConfiguration.TABLE_THREADPOOL_NAME) private AsyncTaskExecutor asyncTaskExecutor; @Autowired private AzureBlobStorePdao dao; - @MockBean + @MockitoBean @Qualifier("synapseJdbcTemplate") private NamedParameterJdbcTemplate synapseJdbcTemplate; diff --git a/src/test/java/bio/terra/service/filedata/azure/tables/LoadHistoryStorageTableConnectedTest.java b/src/test/java/bio/terra/service/filedata/azure/tables/LoadHistoryStorageTableConnectedTest.java index 62d25d1aa7..1801f22641 100644 --- a/src/test/java/bio/terra/service/filedata/azure/tables/LoadHistoryStorageTableConnectedTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/tables/LoadHistoryStorageTableConnectedTest.java @@ -34,8 +34,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -52,7 +52,7 @@ public class LoadHistoryStorageTableConnectedTest { @Autowired ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; @Autowired DatasetService datasetService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired SynapseUtils synapseUtils; @Autowired AzureAuthService azureAuthService; @Autowired TableDirectoryDao tableDirectoryDao; diff --git a/src/test/java/bio/terra/service/filedata/azure/tables/TableDependencyDaoTest.java b/src/test/java/bio/terra/service/filedata/azure/tables/TableDependencyDaoTest.java index 9c557f6148..bf62f4d5e9 100644 --- a/src/test/java/bio/terra/service/filedata/azure/tables/TableDependencyDaoTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/tables/TableDependencyDaoTest.java @@ -36,8 +36,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -47,9 +47,9 @@ @Category(Unit.class) @EmbeddedDatabaseTest public class TableDependencyDaoTest { - @MockBean private AzureAuthService authService; - @MockBean private TableServiceClient tableServiceClient; - @MockBean private TableClient tableClient; + @MockitoBean private AzureAuthService authService; + @MockitoBean private TableServiceClient tableServiceClient; + @MockitoBean private TableClient tableClient; @Autowired private TableDependencyDao dao; @Captor private ArgumentCaptor queryOptionsCaptor; diff --git a/src/test/java/bio/terra/service/filedata/azure/tables/TableDirectoryDaoConnectedTest.java b/src/test/java/bio/terra/service/filedata/azure/tables/TableDirectoryDaoConnectedTest.java index 6b5a0cee87..49cade7f51 100644 --- a/src/test/java/bio/terra/service/filedata/azure/tables/TableDirectoryDaoConnectedTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/tables/TableDirectoryDaoConnectedTest.java @@ -40,8 +40,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -62,7 +62,7 @@ public class TableDirectoryDaoConnectedTest { @Autowired ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired TableDirectoryDao tableDirectoryDao; @Autowired AzureUtils azureUtils; diff --git a/src/test/java/bio/terra/service/filedata/azure/tables/TableDirectoryDaoTest.java b/src/test/java/bio/terra/service/filedata/azure/tables/TableDirectoryDaoTest.java index f50c9edb9f..8f24400dc5 100644 --- a/src/test/java/bio/terra/service/filedata/azure/tables/TableDirectoryDaoTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/tables/TableDirectoryDaoTest.java @@ -35,8 +35,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; @SpringBootTest @AutoConfigureMockMvc @@ -55,9 +55,9 @@ class TableDirectoryDaoTest { private TableEntity entity; private FireStoreDirectoryEntry directoryEntry; - @MockBean private AzureAuthService authService; - @MockBean private TableServiceClient tableServiceClient; - @MockBean private TableClient tableClient; + @MockitoBean private AzureAuthService authService; + @MockitoBean private TableServiceClient tableServiceClient; + @MockitoBean private TableClient tableClient; @Autowired private TableDirectoryDao dao; @BeforeEach diff --git a/src/test/java/bio/terra/service/filedata/azure/tables/TableServiceClientUtilsConnectedTest.java b/src/test/java/bio/terra/service/filedata/azure/tables/TableServiceClientUtilsConnectedTest.java index 108c6658d7..0aec3dccbe 100644 --- a/src/test/java/bio/terra/service/filedata/azure/tables/TableServiceClientUtilsConnectedTest.java +++ b/src/test/java/bio/terra/service/filedata/azure/tables/TableServiceClientUtilsConnectedTest.java @@ -28,8 +28,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -46,7 +46,7 @@ public class TableServiceClientUtilsConnectedTest { @Autowired ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired AzureUtils azureUtils; @Before diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/ArrayMultiFileLoadTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/ArrayMultiFileLoadTest.java index 3ea60b7f11..564014fc03 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/ArrayMultiFileLoadTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/ArrayMultiFileLoadTest.java @@ -50,10 +50,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MvcResult; @@ -71,7 +71,7 @@ public class ArrayMultiFileLoadTest { @Autowired private ResourceService dataLocationService; @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private static final Logger logger = LoggerFactory.getLogger(ArrayMultiFileLoadTest.class); private BillingProfileModel profileModel; diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/BulkFileLoadTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/BulkFileLoadTest.java index 08f565b414..17f91c5da5 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/BulkFileLoadTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/BulkFileLoadTest.java @@ -38,8 +38,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -55,7 +55,7 @@ public class BulkFileLoadTest { @Autowired private ConnectedTestConfiguration testConfig; @Autowired private ObjectMapper objectMapper; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private static final Logger logger = LoggerFactory.getLogger(BulkFileLoadTest.class); private BillingProfileModel profileModel; diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/EncodeFileTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/EncodeFileTest.java index e0fecc4268..2623049d93 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/EncodeFileTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/EncodeFileTest.java @@ -67,11 +67,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -95,7 +95,7 @@ public class EncodeFileTest { private static final String ID_GARBAGE = "GARBAGE"; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BillingProfileModel profileModel; private Storage storage; diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/FileLoadTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/FileLoadTest.java index 7b9544ea9f..ae24c9a6fb 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/FileLoadTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/FileLoadTest.java @@ -41,10 +41,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @@ -67,9 +67,9 @@ public class FileLoadTest { @Autowired private ConnectedOperations connectedOperations; @Autowired private ConfigurationService configService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; - @SpyBean private GoogleProjectService projectService; + @MockitoSpyBean private GoogleProjectService projectService; private BillingProfileModel profileModel; private DatasetSummaryModel datasetSummary; diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/FileOperationTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/FileOperationTest.java index 35e601a678..c19acff1de 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/FileOperationTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/FileOperationTest.java @@ -44,12 +44,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -68,9 +68,9 @@ public class FileOperationTest { @Autowired private ConfigurationService configService; @Autowired private DatasetDao datasetDao; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; - @SpyBean private GoogleProjectService googleProjectService; + @MockitoSpyBean private GoogleProjectService googleProjectService; private static Logger logger = LoggerFactory.getLogger(FileOperationTest.class); private int validFileCounter; diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreDaoTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreDaoTest.java index 622bb7e7a7..3559889baf 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreDaoTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreDaoTest.java @@ -34,8 +34,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @@ -52,7 +52,7 @@ class FireStoreDaoTest { @Autowired private FireStoreDependencyDao fireStoreDependencyDao; @Autowired private ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired private ConfigurationService configService; private Firestore firestore; diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreDirectoryDaoTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreDirectoryDaoTest.java index 29363a76a2..71833b2e65 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreDirectoryDaoTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreDirectoryDaoTest.java @@ -40,8 +40,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @@ -59,7 +59,7 @@ class FireStoreDirectoryDaoTest { @Autowired private ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Autowired private ConfigurationService configService; private String datasetId; diff --git a/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreFileDaoTest.java b/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreFileDaoTest.java index 05dfb41608..3904b9b2c2 100644 --- a/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreFileDaoTest.java +++ b/src/test/java/bio/terra/service/filedata/google/firestore/FireStoreFileDaoTest.java @@ -36,8 +36,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @@ -55,7 +55,7 @@ class FireStoreFileDaoTest { @Autowired private FireStoreUtils fireStoreUtils; @Autowired private ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private String datasetId; private Firestore firestore; private List directoryEntries; diff --git a/src/test/java/bio/terra/service/filedata/google/gcs/GcsPdaoTest.java b/src/test/java/bio/terra/service/filedata/google/gcs/GcsPdaoTest.java index 8274542c0c..1fd78355da 100644 --- a/src/test/java/bio/terra/service/filedata/google/gcs/GcsPdaoTest.java +++ b/src/test/java/bio/terra/service/filedata/google/gcs/GcsPdaoTest.java @@ -43,8 +43,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -63,7 +63,7 @@ public class GcsPdaoTest { .build(); @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private GoogleResourceDao googleResourceDao; + @MockitoBean private GoogleResourceDao googleResourceDao; @Autowired private GcsPdao gcsPdao; private final Storage storage = StorageOptions.getDefaultInstance().getService(); diff --git a/src/test/java/bio/terra/service/job/JobServiceTest.java b/src/test/java/bio/terra/service/job/JobServiceTest.java index c0f3e029a9..5733840057 100644 --- a/src/test/java/bio/terra/service/job/JobServiceTest.java +++ b/src/test/java/bio/terra/service/job/JobServiceTest.java @@ -50,11 +50,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; @AutoConfigureMockMvc @SpringBootTest @@ -97,9 +97,9 @@ class JobServiceTest { @Autowired private ApplicationConfiguration appConfig; - @MockBean private IamService samService; + @MockitoBean private IamService samService; - @MockBean private BardClient bardClient; + @MockitoBean private BardClient bardClient; @BeforeEach void setUp() throws Exception { @@ -444,7 +444,8 @@ private void updateJobSubmissionTime(String jobId, Instant submitTime) { NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(stairwayJdbcConfiguration.getDataSource()); - String sql = """ + String sql = + """ update flight set submit_time=:submit_time where flightid=:id diff --git a/src/test/java/bio/terra/service/profile/GoogleBillingServiceTest.java b/src/test/java/bio/terra/service/profile/GoogleBillingServiceTest.java index b87a6ad1dc..bf6afac0b5 100644 --- a/src/test/java/bio/terra/service/profile/GoogleBillingServiceTest.java +++ b/src/test/java/bio/terra/service/profile/GoogleBillingServiceTest.java @@ -31,8 +31,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -50,7 +50,7 @@ public class GoogleBillingServiceTest { @Autowired private ConnectedTestConfiguration testConfig; @Autowired private BufferService bufferService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BillingProfileModel profile; private GoogleProjectResource projectResource; diff --git a/src/test/java/bio/terra/service/profile/ProfileAPIControllerTest.java b/src/test/java/bio/terra/service/profile/ProfileAPIControllerTest.java index 391ef2836a..3653fee05e 100644 --- a/src/test/java/bio/terra/service/profile/ProfileAPIControllerTest.java +++ b/src/test/java/bio/terra/service/profile/ProfileAPIControllerTest.java @@ -7,26 +7,34 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; +import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import bio.terra.app.configuration.ApplicationConfiguration; +import bio.terra.app.controller.GlobalExceptionHandler; import bio.terra.common.category.Unit; +import bio.terra.common.fixtures.AuthenticationFixtures; import bio.terra.common.iam.AuthenticatedUserRequest; import bio.terra.common.iam.AuthenticatedUserRequestFactory; import bio.terra.model.BillingProfileModel; import bio.terra.model.BillingProfileRequestModel; import bio.terra.model.BillingProfileUpdateModel; +import bio.terra.model.EnumerateBillingProfileResourcesModel; import bio.terra.model.JobModel; import bio.terra.model.JobModel.JobStatusEnum; import bio.terra.model.PolicyMemberRequest; import bio.terra.model.PolicyModel; import bio.terra.model.PolicyResponse; +import bio.terra.model.ProfileOwnedResourceModel; import bio.terra.service.auth.iam.IamAction; import bio.terra.service.auth.iam.IamResourceType; import bio.terra.service.auth.iam.IamService; @@ -35,87 +43,95 @@ import bio.terra.service.job.JobService; import bio.terra.service.profile.exception.ProfileNotFoundException; import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.servlet.http.HttpServletRequest; +import java.net.URI; +import java.time.Instant; +import java.util.List; import java.util.UUID; import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.web.servlet.MockMvc; -@ExtendWith(MockitoExtension.class) +@ActiveProfiles({"google", "unittest"}) +@ContextConfiguration( + classes = { + ProfileApiController.class, + ProfileRequestValidator.class, + ProfileUpdateRequestValidator.class, + PolicyMemberValidator.class, + GlobalExceptionHandler.class + }) @Tag(Unit.TAG) +@WebMvcTest class ProfileAPIControllerTest { + @MockitoBean private ProfileService profileService; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private JobService jobService; - @Mock private ObjectMapper objectMapper; - @Mock private HttpServletRequest request; - @Mock private ProfileService profileService; - @Mock private ProfileRequestValidator billingProfileRequestValidator; - @Mock private ProfileUpdateRequestValidator profileUpdateRequestValidator; - @Mock private PolicyMemberValidator policyMemberValidator; - @Mock private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @Mock private JobService jobService; + @MockitoBean private IamService iamService; + @MockitoBean private ApplicationConfiguration applicationConfiguration; - @Mock private IamService iamService; - @Mock private ApplicationConfiguration applicationConfiguration; + @Autowired private ObjectMapper objectMapper; + @Autowired private MockMvc mvc; + @Autowired ProfileApiController apiController; + private static final AuthenticatedUserRequest TEST_USER = + AuthenticationFixtures.randomUserRequest(); - private ProfileApiController apiController; - private AuthenticatedUserRequest user; + private static URI createUri(ResponseEntity object) { + return linkTo(object).toUri(); + } + + private static ProfileApiController getApi() { + return methodOn(ProfileApiController.class); + } @BeforeEach void setup() { - apiController = - new ProfileApiController( - objectMapper, - request, - profileService, - billingProfileRequestValidator, - profileUpdateRequestValidator, - policyMemberValidator, - jobService, - authenticatedUserRequestFactory, - iamService, - applicationConfiguration); - user = - AuthenticatedUserRequest.builder() - .setSubjectId("DatasetUnit") - .setEmail("dataset@unit.com") - .setToken("token") - .build(); + when(authenticatedUserRequestFactory.from(any())).thenReturn(TEST_USER); } @Test void testCreateProfile() { - when(authenticatedUserRequestFactory.from(request)).thenReturn(user); - var billingProfileRequestModel = new BillingProfileRequestModel(); + var billingProfileRequestModel = + new BillingProfileRequestModel().profileName("profileName").biller("biller"); String jobId = "jobId"; - when(profileService.createProfile(billingProfileRequestModel, user)).thenReturn("jobId"); + when(profileService.createProfile(billingProfileRequestModel, TEST_USER)).thenReturn(jobId); var jobModel = new JobModel(); jobModel.setJobStatus(JobStatusEnum.RUNNING); - when(jobService.retrieveJob(jobId, user)).thenReturn(jobModel); + when(jobService.retrieveJob(jobId, TEST_USER)).thenReturn(jobModel); ResponseEntity entity = apiController.createProfile(billingProfileRequestModel); assertThat("Correct job model is returned from request", entity.getBody(), is(jobModel)); } + private static BillingProfileUpdateModel createUpdateModel() { + return new BillingProfileUpdateModel() + .id(UUID.randomUUID()) + .billingAccountId("id") + .description("description"); + } + @Test void testUpdateProfile() { - when(authenticatedUserRequestFactory.from(request)).thenReturn(user); - var billingProfileUpdateModel = new BillingProfileUpdateModel().id(UUID.randomUUID()); + var billingProfileUpdateModel = createUpdateModel(); String jobId = "jobId"; - when(profileService.updateProfile(billingProfileUpdateModel, user)).thenReturn(jobId); + when(profileService.updateProfile(billingProfileUpdateModel, TEST_USER)).thenReturn(jobId); var jobModel = new JobModel(); jobModel.setJobStatus(JobStatusEnum.RUNNING); - when(jobService.retrieveJob(jobId, user)).thenReturn(jobModel); + when(jobService.retrieveJob(jobId, TEST_USER)).thenReturn(jobModel); ResponseEntity entity = apiController.updateProfile(billingProfileUpdateModel); assertThat("Correct job model is returned from request", entity.getBody(), is(jobModel)); @@ -123,27 +139,27 @@ void testUpdateProfile() { @Test void testUpdateProfileNotFound() { - UUID profileId = UUID.randomUUID(); - doThrow(ProfileNotFoundException.class).when(profileService).getProfileByIdNoCheck(profileId); - var billingProfileUpdateModel = new BillingProfileUpdateModel().id(profileId); + var billingProfileUpdateModel = createUpdateModel(); + doThrow(ProfileNotFoundException.class) + .when(profileService) + .getProfileByIdNoCheck(billingProfileUpdateModel.getId()); assertThrows( ProfileNotFoundException.class, () -> apiController.updateProfile(billingProfileUpdateModel)); verifyNoInteractions(iamService); - verify(profileService, never()).updateProfile(billingProfileUpdateModel, user); + verify(profileService, never()).updateProfile(billingProfileUpdateModel, TEST_USER); } @Test void testUpdateProfileForbidden() { - when(authenticatedUserRequestFactory.from(request)).thenReturn(user); - UUID profileId = UUID.randomUUID(); + var billingProfileUpdateModel = createUpdateModel(); + UUID profileId = billingProfileUpdateModel.getId(); when(profileService.getProfileByIdNoCheck(profileId)) .thenReturn(new BillingProfileModel().id(profileId)); mockProfileForbidden(profileId, IamAction.UPDATE_BILLING_ACCOUNT); - var billingProfileUpdateModel = new BillingProfileUpdateModel().id(profileId); assertThrows( IamForbiddenException.class, () -> apiController.updateProfile(billingProfileUpdateModel)); - verify(profileService, never()).updateProfile(billingProfileUpdateModel, user); + verify(profileService, never()).updateProfile(billingProfileUpdateModel, TEST_USER); } @ParameterizedTest @@ -152,10 +168,9 @@ void testDeleteProfile( boolean deleteCloudResources, int expectedAdminAuthNumberOfInvocations, int expectedSpendProfileAuthNumberOfInvocations) { - when(authenticatedUserRequestFactory.from(any())).thenReturn(user); - UUID deleteId = UUID.fromString("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); + UUID deleteId = UUID.randomUUID(); String jobId = "jobId"; - when(profileService.deleteProfile(deleteId, deleteCloudResources, user)).thenReturn(jobId); + when(profileService.deleteProfile(deleteId, deleteCloudResources, TEST_USER)).thenReturn(jobId); var applicationId = "broad-jade-dev"; if (deleteCloudResources) { when(applicationConfiguration.getResourceId()).thenReturn(applicationId); @@ -163,17 +178,16 @@ void testDeleteProfile( var jobModel = new JobModel(); jobModel.setJobStatus(JobStatusEnum.RUNNING); - when(jobService.retrieveJob(jobId, user)).thenReturn(jobModel); + when(jobService.retrieveJob(jobId, TEST_USER)).thenReturn(jobModel); ResponseEntity entity = apiController.deleteProfile(deleteId, deleteCloudResources); // Only check for admin auth if deleteCloudResources is true verify(iamService, times(expectedAdminAuthNumberOfInvocations)) - .verifyAuthorization( - eq(user), eq(IamResourceType.DATAREPO), eq(applicationId), eq(IamAction.DELETE)); + .verifyAuthorization(TEST_USER, IamResourceType.DATAREPO, applicationId, IamAction.DELETE); // Only check if user has access on the spend profile if we're not doing the admin check verify(iamService, times(expectedSpendProfileAuthNumberOfInvocations)) .verifyAuthorization( - user, IamResourceType.SPEND_PROFILE, deleteId.toString(), IamAction.DELETE); + TEST_USER, IamResourceType.SPEND_PROFILE, deleteId.toString(), IamAction.DELETE); assertThat("Correct job model is returned from delete request", entity.getBody(), is(jobModel)); } @@ -188,29 +202,26 @@ void testDeleteProfileNotFound() { assertThrows( ProfileNotFoundException.class, () -> apiController.deleteProfile(profileId, false)); verifyNoInteractions(iamService); - verify(profileService, never()).deleteProfile(profileId, false, user); + verify(profileService, never()).deleteProfile(profileId, false, TEST_USER); } @Test void testDeleteProfileForbidden() { - when(authenticatedUserRequestFactory.from(request)).thenReturn(user); UUID profileId = UUID.randomUUID(); when(profileService.getProfileByIdNoCheck(profileId)) .thenReturn(new BillingProfileModel().id(profileId)); mockProfileForbidden(profileId, IamAction.DELETE); assertThrows(IamForbiddenException.class, () -> apiController.deleteProfile(profileId, false)); - verify(profileService, never()).deleteProfile(profileId, false, user); + verify(profileService, never()).deleteProfile(profileId, false, TEST_USER); } @Test void testAddProfilePolicyMember() { - when(authenticatedUserRequestFactory.from(any())).thenReturn(user); - UUID id = UUID.fromString("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); String policyName = "policyName"; - var policyMemberRequest = new PolicyMemberRequest(); + var policyMemberRequest = new PolicyMemberRequest().email("email"); var policyModel = new PolicyModel(); - when(profileService.addProfilePolicyMember(id, policyName, policyMemberRequest, user)) + when(profileService.addProfilePolicyMember(id, policyName, policyMemberRequest, TEST_USER)) .thenReturn(policyModel); ResponseEntity response = @@ -223,6 +234,56 @@ void testAddProfilePolicyMember() { private void mockProfileForbidden(UUID profileId, IamAction action) { doThrow(IamForbiddenException.class) .when(iamService) - .verifyAuthorization(user, IamResourceType.SPEND_PROFILE, profileId.toString(), action); + .verifyAuthorization( + TEST_USER, IamResourceType.SPEND_PROFILE, profileId.toString(), action); + } + + @Test + void getProfileResources() throws Exception { + var dataset = + new ProfileOwnedResource( + UUID.randomUUID(), + "name", + "description", + Instant.now(), + ProfileOwnedResource.Type.DATASET); + var snapshot = + new ProfileOwnedResource( + UUID.randomUUID(), + "name", + "description", + Instant.now(), + ProfileOwnedResource.Type.SNAPSHOT); + var model = + new EnumerateBillingProfileResourcesModel() + .items( + List.of( + new ProfileOwnedResourceModel() + .id(dataset.id()) + .name(dataset.name()) + .description(dataset.description()) + .type(ProfileOwnedResourceModel.TypeEnum.DATASET) + .createdDate(dataset.createdDate().toString()), + new ProfileOwnedResourceModel() + .id(snapshot.id()) + .name(snapshot.name()) + .description(snapshot.description()) + .type(ProfileOwnedResourceModel.TypeEnum.SNAPSHOT) + .createdDate(snapshot.createdDate().toString()))); + UUID profileId = UUID.randomUUID(); + when(profileService.getProfileResources(profileId, TEST_USER)) + .thenReturn(List.of(dataset, snapshot)); + mvc.perform(get(createUri(getApi().getProfileResources(profileId)))) + .andExpect(status().isOk()) + .andExpect(content().json(objectMapper.writeValueAsString(model))); + } + + @Test + void getProfileResourcesForbidden() throws Exception { + UUID profileId = UUID.randomUUID(); + when(profileService.getProfileResources(profileId, TEST_USER)) + .thenThrow(IamForbiddenException.class); + mvc.perform(get(createUri(getApi().getProfileResources(profileId)))) + .andExpect(status().isForbidden()); } } diff --git a/src/test/java/bio/terra/service/profile/ProfileServiceTest.java b/src/test/java/bio/terra/service/profile/ProfileServiceTest.java index f28ce0ddad..d3e226bb09 100644 --- a/src/test/java/bio/terra/service/profile/ProfileServiceTest.java +++ b/src/test/java/bio/terra/service/profile/ProfileServiceTest.java @@ -22,8 +22,6 @@ import bio.terra.service.resourcemanagement.google.GoogleProjectResource; import bio.terra.service.resourcemanagement.google.GoogleProjectService; import bio.terra.service.resourcemanagement.google.GoogleResourceDao; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.UUID; import org.junit.After; @@ -37,9 +35,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -59,13 +57,12 @@ public class ProfileServiceTest { @Autowired private GoogleProjectService googleProjectService; @Autowired private ProfileService profileService; @Autowired private BufferService bufferService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BillingProfileModel profile; private GoogleProjectResource projectResource; private String oldBillingAccountId; private String newBillingAccountId; - private List profiles = new ArrayList<>(); @Before public void setup() throws Exception { @@ -73,7 +70,6 @@ public void setup() throws Exception { newBillingAccountId = testConfig.getNoSpendGoogleBillingAccountId(); profile = connectedOperations.createProfileForAccount(oldBillingAccountId); - profiles.add(profile); connectedOperations.stubOutSamCalls(samService); projectResource = buildProjectResource(); @@ -83,7 +79,6 @@ public void setup() throws Exception { public void teardown() throws Exception { googleBillingService.assignProjectBilling(profile, projectResource); googleResourceDao.deleteProject(projectResource.getId()); - profiles.forEach(profile -> profileDao.deleteBillingProfileById(profile.getId())); // Connected operations resets the configuration connectedOperations.teardown(); } @@ -93,7 +88,7 @@ public void teardown() throws Exception { + "new project, test changing the billing account, and then delete the project") @Test public void updateProfileTest() throws Exception { - logger.debug("profile: " + profile.getProfileName()); + logger.debug("profile: {}", profile.getProfileName()); BillingProfileModel model = profileService.getProfileByIdNoCheck(profile.getId()); assertThat( "BEFORE UPDATE: Billing account should be equal to the oldBillingAccountId", @@ -145,7 +140,6 @@ public void testCreateProfileAddsProfileIdByDefault() throws Exception { .profileName(UUID.randomUUID().toString()) .description("profile description"); BillingProfileModel profile = connectedOperations.createProfile(requestWithoutId); - profiles.add(profile); assertNotNull(profile.getId()); } diff --git a/src/test/java/bio/terra/service/profile/ProfileServiceUnitTest.java b/src/test/java/bio/terra/service/profile/ProfileServiceUnitTest.java index 0c8ce613a7..8d5f538de6 100644 --- a/src/test/java/bio/terra/service/profile/ProfileServiceUnitTest.java +++ b/src/test/java/bio/terra/service/profile/ProfileServiceUnitTest.java @@ -11,6 +11,7 @@ import bio.terra.app.configuration.ApplicationConfiguration; import bio.terra.common.category.Unit; +import bio.terra.common.fixtures.AuthenticationFixtures; import bio.terra.common.iam.AuthenticatedUserRequest; import bio.terra.model.BillingProfileModel; import bio.terra.model.BillingProfileRequestModel; @@ -29,6 +30,8 @@ import bio.terra.service.profile.flight.update.ProfileUpdateFlight; import bio.terra.service.profile.google.GoogleBillingService; import bio.terra.service.resourcemanagement.exception.InaccessibleBillingAccountException; +import java.time.Instant; +import java.util.List; import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -51,7 +54,8 @@ class ProfileServiceUnitTest { @Mock private ApplicationConfiguration applicationConfiguration; private ProfileService profileService; - private AuthenticatedUserRequest user; + private static final AuthenticatedUserRequest TEST_USER = + AuthenticationFixtures.randomUserRequest(); private static final UUID PROFILE_ID = UUID.fromString("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); @BeforeEach @@ -59,12 +63,6 @@ void setup() { profileService = new ProfileService( profileDao, iamService, jobService, googleBillingService, azureAuthzService); - user = - AuthenticatedUserRequest.builder() - .setSubjectId("DatasetUnit") - .setEmail("dataset@unit.com") - .setToken("token") - .build(); } @Test @@ -77,12 +75,15 @@ void testCreateProfile() { billingProfileRequestModel.setProfileName("name"); when(jobService.newJob( - anyString(), eq(ProfileCreateFlight.class), eq(billingProfileRequestModel), eq(user))) + anyString(), + eq(ProfileCreateFlight.class), + eq(billingProfileRequestModel), + eq(TEST_USER))) .thenReturn(jobBuilder); - String result = profileService.createProfile(billingProfileRequestModel, user); + String result = profileService.createProfile(billingProfileRequestModel, TEST_USER); verify(jobBuilder, times(1)).submit(); - assertEquals(result, jobId); + assertEquals(jobId, result); } @Test @@ -105,13 +106,16 @@ void testUpdateProfile() { when(jobBuilder.submit()).thenReturn(jobId); when(jobService.newJob( - anyString(), eq(ProfileUpdateFlight.class), eq(billingProfileUpdateModel), eq(user))) + anyString(), + eq(ProfileUpdateFlight.class), + eq(billingProfileUpdateModel), + eq(TEST_USER))) .thenReturn(jobBuilder); - String result = profileService.updateProfile(billingProfileUpdateModel, user); + String result = profileService.updateProfile(billingProfileUpdateModel, TEST_USER); verify(jobBuilder, times(1)).submit(); - assertEquals(result, jobId); + assertEquals(jobId, result); } @ParameterizedTest @@ -140,31 +144,51 @@ void testDeleteProfile(boolean deleteCloudResources) { billingProfileModel.setCloudPlatform(CloudPlatform.GCP); when(profileDao.getBillingProfileById(deleteId)).thenReturn(billingProfileModel); - when(jobService.newJob(anyString(), eq(ProfileDeleteFlight.class), eq(null), eq(user))) + when(jobService.newJob(anyString(), eq(ProfileDeleteFlight.class), eq(null), eq(TEST_USER))) .thenReturn(jobBuilder); - String result = profileService.deleteProfile(deleteId, deleteCloudResources, user); + String result = profileService.deleteProfile(deleteId, deleteCloudResources, TEST_USER); verify(jobBuilder, times(1)).submit(); - assertEquals(result, jobId); + assertEquals(jobId, result); } @Test void testVerifyAccountHasAccess() { String id = "id"; - when(googleBillingService.canAccess(eq(user), eq(id))).thenReturn(true); + when(googleBillingService.canAccess(TEST_USER, id)).thenReturn(true); - profileService.verifyGoogleBillingAccount(id, user); + profileService.verifyGoogleBillingAccount(id, TEST_USER); } @Test void testVerifyAccountNoAccess() { String id = "id"; - when(googleBillingService.canAccess(eq(user), eq(id))).thenReturn(false); + when(googleBillingService.canAccess(TEST_USER, id)).thenReturn(false); assertThrows( InaccessibleBillingAccountException.class, - () -> profileService.verifyGoogleBillingAccount(id, user)); + () -> profileService.verifyGoogleBillingAccount(id, TEST_USER)); + } + + @Test + void getProfileResources() { + var expected = + List.of( + new ProfileOwnedResource( + UUID.randomUUID(), + "name", + "description", + Instant.now(), + ProfileOwnedResource.Type.DATASET)); + when(profileDao.listProfileOwnedResources(PROFILE_ID)).thenReturn(expected); + assertEquals(expected, profileService.getProfileResources(PROFILE_ID, TEST_USER)); + verify(iamService) + .verifyAuthorization( + TEST_USER, + IamResourceType.SPEND_PROFILE, + PROFILE_ID.toString(), + IamAction.READ_SPEND_REPORT); } } diff --git a/src/test/java/bio/terra/service/resourcemanagement/BufferServiceConnectedTest.java b/src/test/java/bio/terra/service/resourcemanagement/BufferServiceConnectedTest.java index 79075e6a74..482a23e4c8 100644 --- a/src/test/java/bio/terra/service/resourcemanagement/BufferServiceConnectedTest.java +++ b/src/test/java/bio/terra/service/resourcemanagement/BufferServiceConnectedTest.java @@ -46,10 +46,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -72,7 +72,7 @@ public class BufferServiceConnectedTest { @Autowired private GoogleResourceConfiguration googleResourceConfiguration; @Autowired private GoogleResourceManagerService resourceManagerService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private Storage storage = StorageOptions.getDefaultInstance().getService(); private BillingProfileModel billingProfile; diff --git a/src/test/java/bio/terra/service/resourcemanagement/ProfileConnectedTest.java b/src/test/java/bio/terra/service/resourcemanagement/ProfileConnectedTest.java index 7dd9c1b615..2afee667f1 100644 --- a/src/test/java/bio/terra/service/resourcemanagement/ProfileConnectedTest.java +++ b/src/test/java/bio/terra/service/resourcemanagement/ProfileConnectedTest.java @@ -33,9 +33,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -53,7 +53,7 @@ public class ProfileConnectedTest { @Autowired private ConfigurationService configService; @Autowired private ApplicationConfiguration applicationConfiguration; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; @Before public void setup() throws Exception { diff --git a/src/test/java/bio/terra/service/resourcemanagement/google/BucketResourceTest.java b/src/test/java/bio/terra/service/resourcemanagement/google/BucketResourceTest.java index c724823b56..d161e1ebfd 100644 --- a/src/test/java/bio/terra/service/resourcemanagement/google/BucketResourceTest.java +++ b/src/test/java/bio/terra/service/resourcemanagement/google/BucketResourceTest.java @@ -56,8 +56,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -81,7 +81,7 @@ public class BucketResourceTest { @Autowired private ConnectedTestConfiguration testConfig; @Autowired private BufferService bufferService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BucketResourceUtils bucketResourceUtils = new BucketResourceUtils(); private BillingProfileModel profile; diff --git a/src/test/java/bio/terra/service/resourcemanagement/google/GoogleProjectServiceOnDemandTest.java b/src/test/java/bio/terra/service/resourcemanagement/google/GoogleProjectServiceOnDemandTest.java index f94e6e0995..ebb3d082f1 100644 --- a/src/test/java/bio/terra/service/resourcemanagement/google/GoogleProjectServiceOnDemandTest.java +++ b/src/test/java/bio/terra/service/resourcemanagement/google/GoogleProjectServiceOnDemandTest.java @@ -17,8 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -34,7 +34,7 @@ public class GoogleProjectServiceOnDemandTest { @Autowired private ConnectedOperations connectedOperations; @Autowired private ConnectedTestConfiguration testConfig; @Autowired private GoogleProjectService googleProjectService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BillingProfileModel billingProfile; private GoogleRegion region = GoogleRegion.DEFAULT_GOOGLE_REGION; diff --git a/src/test/java/bio/terra/service/snapshot/SnapshotConnectedTest.java b/src/test/java/bio/terra/service/snapshot/SnapshotConnectedTest.java index 4ea8e6d2e5..d2f1d27893 100644 --- a/src/test/java/bio/terra/service/snapshot/SnapshotConnectedTest.java +++ b/src/test/java/bio/terra/service/snapshot/SnapshotConnectedTest.java @@ -64,11 +64,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -97,8 +97,8 @@ public class SnapshotConnectedTest { @Autowired private DrsIdService drsIdService; @Autowired private GoogleResourceManagerService googleResourceManagerService; - @MockBean private IamProviderInterface samService; - @MockBean private EcmService ecmService; + @MockitoBean private IamProviderInterface samService; + @MockitoBean private EcmService ecmService; private String snapshotOriginalName; private BillingProfileModel billingProfile; diff --git a/src/test/java/bio/terra/service/snapshot/SnapshotDaoTest.java b/src/test/java/bio/terra/service/snapshot/SnapshotDaoTest.java index b725e89118..1536c2b1a2 100644 --- a/src/test/java/bio/terra/service/snapshot/SnapshotDaoTest.java +++ b/src/test/java/bio/terra/service/snapshot/SnapshotDaoTest.java @@ -69,8 +69,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -101,11 +101,11 @@ public class SnapshotDaoTest { @Autowired private DaoOperations daoOperations; - @MockBean private DuosClient duosClient; + @MockitoBean private DuosClient duosClient; - @MockBean private DuosService duosService; + @MockitoBean private DuosService duosService; - @MockBean private IamService iamService; + @MockitoBean private IamService iamService; private Dataset dataset; private UUID datasetId; diff --git a/src/test/java/bio/terra/service/snapshot/SnapshotFileLookupConnectedTest.java b/src/test/java/bio/terra/service/snapshot/SnapshotFileLookupConnectedTest.java index 4d1dd9befa..2c5c4daa13 100644 --- a/src/test/java/bio/terra/service/snapshot/SnapshotFileLookupConnectedTest.java +++ b/src/test/java/bio/terra/service/snapshot/SnapshotFileLookupConnectedTest.java @@ -49,8 +49,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.stringtemplate.v4.ST; @@ -71,8 +71,8 @@ public class SnapshotFileLookupConnectedTest { @Autowired private DrsIdService drsIdService; @Autowired private JsonLoader jsonLoader; - @MockBean private IamProviderInterface samService; - @MockBean private EcmService ecmService; + @MockitoBean private IamProviderInterface samService; + @MockitoBean private EcmService ecmService; private BillingProfileModel billingProfile; private final Storage storage = StorageOptions.getDefaultInstance().getService(); diff --git a/src/test/java/bio/terra/service/snapshot/SnapshotHappyPathConnectedTest.java b/src/test/java/bio/terra/service/snapshot/SnapshotHappyPathConnectedTest.java index 41b2c94c3b..620f6efa5d 100644 --- a/src/test/java/bio/terra/service/snapshot/SnapshotHappyPathConnectedTest.java +++ b/src/test/java/bio/terra/service/snapshot/SnapshotHappyPathConnectedTest.java @@ -24,10 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @@ -46,7 +46,7 @@ public class SnapshotHappyPathConnectedTest { @Autowired private JsonLoader jsonLoader; @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private final Storage storage = StorageOptions.getDefaultInstance().getService(); private DatasetSummaryModel datasetSummary; diff --git a/src/test/java/bio/terra/service/snapshot/SnapshotMinimalConnectedTest.java b/src/test/java/bio/terra/service/snapshot/SnapshotMinimalConnectedTest.java index 48f6129a04..93d138b466 100644 --- a/src/test/java/bio/terra/service/snapshot/SnapshotMinimalConnectedTest.java +++ b/src/test/java/bio/terra/service/snapshot/SnapshotMinimalConnectedTest.java @@ -39,10 +39,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -64,7 +64,7 @@ public class SnapshotMinimalConnectedTest { @Autowired private ConnectedTestConfiguration testConfig; @Autowired private ConfigurationService configService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BillingProfileModel billingProfile; private final Storage storage = StorageOptions.getDefaultInstance().getService(); diff --git a/src/test/java/bio/terra/service/snapshot/SnapshotRequestValidatorTest.java b/src/test/java/bio/terra/service/snapshot/SnapshotRequestValidatorTest.java index cdd4a616f1..628297fed2 100644 --- a/src/test/java/bio/terra/service/snapshot/SnapshotRequestValidatorTest.java +++ b/src/test/java/bio/terra/service/snapshot/SnapshotRequestValidatorTest.java @@ -26,10 +26,10 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({"google", "unittest"}) @@ -45,15 +45,15 @@ @Tag(Unit.TAG) class SnapshotRequestValidatorTest { @Autowired private MockMvc mvc; - @MockBean private JobService jobService; - @MockBean private SnapshotService snapshotService; - @MockBean private IamService iamService; - @MockBean private FileService fileService; - @MockBean private ApplicationConfiguration applicationConfiguration; - @MockBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; - @MockBean private SnapshotBuilderService snapshotBuilderService; - @MockBean private IngestRequestValidator ingestRequestValidator; - @MockBean private AssetModelValidator assetModelValidator; + @MockitoBean private JobService jobService; + @MockitoBean private SnapshotService snapshotService; + @MockitoBean private IamService iamService; + @MockitoBean private FileService fileService; + @MockitoBean private ApplicationConfiguration applicationConfiguration; + @MockitoBean private AuthenticatedUserRequestFactory authenticatedUserRequestFactory; + @MockitoBean private SnapshotBuilderService snapshotBuilderService; + @MockitoBean private IngestRequestValidator ingestRequestValidator; + @MockitoBean private AssetModelValidator assetModelValidator; @BeforeEach void setup() { diff --git a/src/test/java/bio/terra/service/snapshot/SnapshotScaleConnectedTest.java b/src/test/java/bio/terra/service/snapshot/SnapshotScaleConnectedTest.java index c241775a52..353e02eecd 100644 --- a/src/test/java/bio/terra/service/snapshot/SnapshotScaleConnectedTest.java +++ b/src/test/java/bio/terra/service/snapshot/SnapshotScaleConnectedTest.java @@ -24,10 +24,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @@ -46,7 +46,7 @@ public class SnapshotScaleConnectedTest { @Autowired private ConfigurationService configService; @Autowired private ConnectedTestConfiguration testConfig; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private final Storage storage = StorageOptions.getDefaultInstance().getService(); private DatasetSummaryModel datasetSummary; diff --git a/src/test/java/bio/terra/service/snapshot/SnapshotStorageAccountDaoTest.java b/src/test/java/bio/terra/service/snapshot/SnapshotStorageAccountDaoTest.java index ec830c0fb0..6d72807329 100644 --- a/src/test/java/bio/terra/service/snapshot/SnapshotStorageAccountDaoTest.java +++ b/src/test/java/bio/terra/service/snapshot/SnapshotStorageAccountDaoTest.java @@ -28,8 +28,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -40,9 +40,9 @@ @EmbeddedDatabaseTest public class SnapshotStorageAccountDaoTest { - @MockBean private SnapshotStorageAccountDao snapshotStorageAccountDao; - @MockBean private AzureStorageAccountService storageAccountService; - @MockBean private AzureApplicationDeploymentService applicationDeploymentService; + @MockitoBean private SnapshotStorageAccountDao snapshotStorageAccountDao; + @MockitoBean private AzureStorageAccountService storageAccountService; + @MockitoBean private AzureApplicationDeploymentService applicationDeploymentService; @Autowired private ResourceService resourceService; @Test diff --git a/src/test/java/bio/terra/service/tabulardata/google/BigQueryPdaoDatasetConnectedTest.java b/src/test/java/bio/terra/service/tabulardata/google/BigQueryPdaoDatasetConnectedTest.java index 1764c0317a..f632c07ff5 100644 --- a/src/test/java/bio/terra/service/tabulardata/google/BigQueryPdaoDatasetConnectedTest.java +++ b/src/test/java/bio/terra/service/tabulardata/google/BigQueryPdaoDatasetConnectedTest.java @@ -59,8 +59,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.stringtemplate.v4.ST; @@ -97,7 +97,7 @@ public class BigQueryPdaoDatasetConnectedTest { @Autowired private GoogleResourceManagerService resourceManagerService; @Autowired private BufferService bufferService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BillingProfileModel profileModel; diff --git a/src/test/java/bio/terra/service/tabulardata/google/BigQueryPdaoTest.java b/src/test/java/bio/terra/service/tabulardata/google/BigQueryPdaoTest.java index d932b1c7c3..7dcd2b4a11 100644 --- a/src/test/java/bio/terra/service/tabulardata/google/BigQueryPdaoTest.java +++ b/src/test/java/bio/terra/service/tabulardata/google/BigQueryPdaoTest.java @@ -103,9 +103,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MvcResult; import org.stringtemplate.v4.ST; @@ -134,7 +134,7 @@ public class BigQueryPdaoTest { @Autowired private SnapshotService snapshotService; @Autowired private SnapshotBuilderService snapshotBuilderService; @Autowired private PolicyService policyService; - @MockBean private IamProviderInterface samService; + @MockitoBean private IamProviderInterface samService; private BillingProfileModel profileModel;