|
29 | 29 | import org.apache.pulsar.client.admin.PulsarAdminException; |
30 | 30 | import org.apache.pulsar.common.policies.data.ClusterData; |
31 | 31 | import org.apache.pulsar.common.policies.data.TenantInfo; |
| 32 | +import org.apache.pulsar.common.policies.data.TenantInfoImpl; |
32 | 33 | import org.testng.annotations.AfterClass; |
33 | 34 | import org.testng.annotations.BeforeClass; |
34 | 35 | import org.testng.annotations.Test; |
@@ -73,4 +74,49 @@ public void testDeleteNonExistTenant() { |
73 | 74 | String tenant = "test-non-exist-tenant-" + UUID.randomUUID(); |
74 | 75 | assertThrows(PulsarAdminException.NotFoundException.class, () -> admin.tenants().deleteTenant(tenant)); |
75 | 76 | } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void testCreateTenantWithNull() { |
| 80 | + String tenant = "test-create-tenant-with-null-value-" + UUID.randomUUID(); |
| 81 | + // Put doesn't allow null value |
| 82 | + assertThrows(PulsarAdminException.class, |
| 83 | + () -> admin.tenants().createTenant(tenant, null)); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void testCreateTenantWithInvalidCluster() { |
| 88 | + String tenant = "test-create-tenant-with-invalid-cluster-" + UUID.randomUUID(); |
| 89 | + // clusters is empty |
| 90 | + assertThrows(PulsarAdminException.PreconditionFailedException.class, |
| 91 | + () -> admin.tenants().createTenant(tenant, TenantInfo.builder().build())); |
| 92 | + |
| 93 | + // clusters is null |
| 94 | + assertThrows(PulsarAdminException.PreconditionFailedException.class, |
| 95 | + () -> { |
| 96 | + TenantInfoImpl tenantInfo = new TenantInfoImpl(); |
| 97 | + tenantInfo.setAdminRoles(null); |
| 98 | + tenantInfo.setAllowedClusters(null); |
| 99 | + admin.tenants().createTenant(tenant, tenantInfo); |
| 100 | + }); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testUpdateTenantWithInvalidCluster() throws PulsarAdminException { |
| 105 | + String tenant = "test-update-tenant-with-invalid-cluster-" + UUID.randomUUID(); |
| 106 | + admin.tenants().createTenant(tenant, |
| 107 | + TenantInfo.builder().allowedClusters(Collections.singleton(CLUSTER)).build()); |
| 108 | + |
| 109 | + // clusters is empty |
| 110 | + assertThrows(PulsarAdminException.PreconditionFailedException.class, |
| 111 | + () -> admin.tenants().updateTenant(tenant, TenantInfo.builder().build())); |
| 112 | + |
| 113 | + // clusters is null |
| 114 | + assertThrows(PulsarAdminException.PreconditionFailedException.class, |
| 115 | + () -> { |
| 116 | + TenantInfoImpl tenantInfo = new TenantInfoImpl(); |
| 117 | + tenantInfo.setAdminRoles(null); |
| 118 | + tenantInfo.setAllowedClusters(null); |
| 119 | + admin.tenants().updateTenant(tenant, tenantInfo); |
| 120 | + }); |
| 121 | + } |
76 | 122 | } |
0 commit comments