Skip to content

Commit

Permalink
[cleanup][broker-common] Use TestNG instead of JUnit (apache#15573)
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan Liu <[email protected]>
  • Loading branch information
nodece authored May 13, 2022
1 parent cd54508 commit 952c5a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
package org.apache.pulsar.broker.authorization;

import static org.mockito.Mockito.mock;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Properties;
import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
import org.apache.pulsar.broker.authentication.utils.AuthTokenUtils;
import org.apache.pulsar.broker.resources.PulsarResources;
import org.junit.Assert;
import org.testng.annotations.Test;

import javax.crypto.SecretKey;
Expand Down Expand Up @@ -59,18 +60,18 @@ public String getHttpHeader(String name) {
}
};

Assert.assertTrue(provider.authorize(ads, role -> {
assertTrue(provider.authorize(ads, role -> {
if (role.equals(userB)) {
return CompletableFuture.completedFuture(true); // only userB has permission
}
return CompletableFuture.completedFuture(false);
}).get());

Assert.assertTrue(provider.authorize(ads, role -> {
assertTrue(provider.authorize(ads, role -> {
return CompletableFuture.completedFuture(true); // all users has permission
}).get());

Assert.assertFalse(provider.authorize(ads, role -> {
assertFalse(provider.authorize(ads, role -> {
return CompletableFuture.completedFuture(false); // all users has no permission
}).get());
}
Expand Down Expand Up @@ -98,7 +99,7 @@ public String getHttpHeader(String name) {
}
};

Assert.assertFalse(provider.authorize(ads, role -> CompletableFuture.completedFuture(false)).get());
assertFalse(provider.authorize(ads, role -> CompletableFuture.completedFuture(false)).get());
}

@Test
Expand All @@ -125,7 +126,7 @@ public String getHttpHeader(String name) {
}
};

Assert.assertTrue(provider.authorize(ads, role -> {
assertTrue(provider.authorize(ads, role -> {
if (role.equals(testRole)) {
return CompletableFuture.completedFuture(true);
}
Expand Down Expand Up @@ -155,7 +156,7 @@ public String getHttpHeader(String name) {
}
};

Assert.assertFalse(provider.authorize(ads, role -> CompletableFuture.completedFuture(false)).get());
assertFalse(provider.authorize(ads, role -> CompletableFuture.completedFuture(false)).get());
}

@Test
Expand Down Expand Up @@ -190,7 +191,7 @@ public String getHttpHeader(String name) {
}
};

Assert.assertTrue(provider.authorize(ads, role -> {
assertTrue(provider.authorize(ads, role -> {
if (role.equals(testRole)) {
return CompletableFuture.completedFuture(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

package org.apache.pulsar.broker.resources;

import org.junit.Assert;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;


public class NamespaceResourcesTest {
@Test
public void test_pathIsFromNamespace() {
Assert.assertFalse(NamespaceResources.pathIsFromNamespace("/admin/clusters"));
Assert.assertFalse(NamespaceResources.pathIsFromNamespace("/admin/policies"));
Assert.assertFalse(NamespaceResources.pathIsFromNamespace("/admin/policies/my-tenant"));
Assert.assertTrue(NamespaceResources.pathIsFromNamespace("/admin/policies/my-tenant/my-ns"));
assertFalse(NamespaceResources.pathIsFromNamespace("/admin/clusters"));
assertFalse(NamespaceResources.pathIsFromNamespace("/admin/policies"));
assertFalse(NamespaceResources.pathIsFromNamespace("/admin/policies/my-tenant"));
assertTrue(NamespaceResources.pathIsFromNamespace("/admin/policies/my-tenant/my-ns"));
}
}

0 comments on commit 952c5a9

Please sign in to comment.