fix: update VendorTenantServiceTest for async provisioning
Tests now mock tenantRepository.findById() since provisionAsync re-loads the tenant entity, and assert on the entity directly rather than the return value of createAndProvision(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -135,13 +135,15 @@ class VendorTenantServiceTest {
|
||||
when(licenseService.generateLicense(eq(tenant), any(Duration.class), eq(actorId))).thenReturn(license);
|
||||
when(tenantProvisioner.isAvailable()).thenReturn(true);
|
||||
when(tenantProvisioner.provision(any())).thenReturn(ProvisionResult.ok("http://server:8080"));
|
||||
when(tenantRepository.findById(tenant.getId())).thenReturn(Optional.of(tenant));
|
||||
when(tenantRepository.save(any(TenantEntity.class))).thenAnswer(inv -> inv.getArgument(0));
|
||||
|
||||
var result = vendorTenantService.createAndProvision(request, actorId);
|
||||
vendorTenantService.createAndProvision(request, actorId);
|
||||
|
||||
assertThat(result.getStatus()).isEqualTo(TenantStatus.ACTIVE);
|
||||
assertThat(result.getServerEndpoint()).isEqualTo("http://server:8080");
|
||||
assertThat(result.getProvisionError()).isNull();
|
||||
// provisionAsync modifies the tenant entity in-place (runs synchronously in unit tests)
|
||||
assertThat(tenant.getStatus()).isEqualTo(TenantStatus.ACTIVE);
|
||||
assertThat(tenant.getServerEndpoint()).isEqualTo("http://server:8080");
|
||||
assertThat(tenant.getProvisionError()).isNull();
|
||||
verify(tenantRepository).save(tenant);
|
||||
}
|
||||
|
||||
@@ -156,12 +158,14 @@ class VendorTenantServiceTest {
|
||||
when(licenseService.generateLicense(eq(tenant), any(Duration.class), eq(actorId))).thenReturn(license);
|
||||
when(tenantProvisioner.isAvailable()).thenReturn(true);
|
||||
when(tenantProvisioner.provision(any())).thenReturn(ProvisionResult.fail("Docker failure"));
|
||||
when(tenantRepository.findById(tenant.getId())).thenReturn(Optional.of(tenant));
|
||||
when(tenantRepository.save(any(TenantEntity.class))).thenAnswer(inv -> inv.getArgument(0));
|
||||
|
||||
var result = vendorTenantService.createAndProvision(request, actorId);
|
||||
vendorTenantService.createAndProvision(request, actorId);
|
||||
|
||||
assertThat(result.getProvisionError()).isEqualTo("Docker failure");
|
||||
assertThat(result.getStatus()).isEqualTo(TenantStatus.PROVISIONING);
|
||||
// provisionAsync modifies the tenant entity in-place (runs synchronously in unit tests)
|
||||
assertThat(tenant.getProvisionError()).isEqualTo("Docker failure");
|
||||
assertThat(tenant.getStatus()).isEqualTo(TenantStatus.PROVISIONING);
|
||||
verify(tenantRepository).save(tenant);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user