Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package javax.ws.rs.core;

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;

/**
* @generated by Cursor
* @description : Unit Test cases for NoContentException
*/

@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestNoContentException {
@Test
public void test1_ctor_withMessage() {
NoContentException e = new NoContentException("m");
assertNotNull(e);
assertEquals("m", e.getMessage());
}

@Test
public void test2_ctor_withMessageAndCause() {
Throwable cause = new RuntimeException("c");
NoContentException e = new NoContentException("m", cause);
assertNotNull(e);
assertEquals("m", e.getMessage());
assertSame(cause, e.getCause());
}

@Test
public void test3_ctor_withCauseOnly() {
Throwable cause = new RuntimeException("c");
NoContentException e = new NoContentException(cause);
assertNotNull(e);
assertSame(cause, e.getCause());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ranger.authentication.unix.jaas;

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.security.Principal;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @generated by Cursor
* @description : Unit Test cases for RoleUserAuthorityGranter
*/

@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestRoleUserAuthorityGranter {
@Test
public void test1_grant_returnsGroupName_forUnixGroupPrincipal() {
RoleUserAuthorityGranter g = new RoleUserAuthorityGranter();
UnixGroupPrincipal grp = new UnixGroupPrincipal("hadoop");
Set<String> auths = g.grant(grp);
assertEquals(1, auths.size());
assertTrue(auths.contains("hadoop"));
}

@Test
public void test2_grant_returnsROLE_USER_forNonGroupPrincipal() {
RoleUserAuthorityGranter g = new RoleUserAuthorityGranter();
Principal p = () -> "someone"; // lambda Principal
Set<String> auths = g.grant(p);
assertEquals(1, auths.size());
assertTrue(auths.contains("ROLE_USER"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public void test04_constructor_separateThreadInitialization() throws Exception {
when(tagDefDao.findByServiceId(9L)).thenReturn(new ArrayList<XXTagDef>());

RangerTagDBRetriever r = newRetriever(daoMgr, txMgr, service);
// After separate thread initialization, collections should be non-null (possibly empty)
Assertions.assertNotNull(r.getServiceResources());
Assertions.assertNotNull(r.getTagDefs());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public void test() throws InterruptedException {
* - at least 3 and no more than 5 tasks must get rejected.
* - at least 3 and no more than 5 tasks must get timed out
*/
int successCount = results.get("success").get();
int timeoutCount = results.get("java.util.concurrent.TimeoutException").get();
int rejectedCount = results.get("java.util.concurrent.RejectedExecutionException").get();
int successCount = results.getOrDefault("success", new AtomicInteger(0)).get();
int timeoutCount = results.getOrDefault("java.util.concurrent.TimeoutException", new AtomicInteger(0)).get();
int rejectedCount = results.getOrDefault("java.util.concurrent.RejectedExecutionException", new AtomicInteger(0)).get();
assertEquals(2, successCount, "success count");
assertTrue(timeoutCount >= 3 && timeoutCount <= 5, "timeout[" + timeoutCount + "]: 3 <= count(timeout) <= 5");
assertTrue(rejectedCount >= 3 && rejectedCount <= 5, "rejected[" + rejectedCount + "]: 3 <= count(timeout) <= 5");
Expand All @@ -134,8 +134,8 @@ public void test() throws InterruptedException {
@Test
public void testLocalUncaughtExceptionHandlerDoesNotThrow() {
UncaughtExceptionHandler h = new TimedExecutor.LocalUncaughtExceptionHandler();
// Should not throw despite nulls; but pass a dummy thread and exception
h.uncaughtException(new Thread("t1"), new RuntimeException("boom"));
// Should not throw; pass a dummy thread and exception
h.uncaughtException(Thread.currentThread(), new RuntimeException("boom"));
}

@Test
Expand All @@ -144,7 +144,7 @@ public void testTimedTaskSuccess() throws Exception {
TimedExecutor exec = new TimedExecutor();
exec.initialize(cfg);
try {
String v = exec.timedTask(() -> "ok", 1, TimeUnit.SECONDS);
String v = exec.timedTask(() -> "ok", 2, TimeUnit.SECONDS);
Assertions.assertEquals("ok", v);
} finally {
exec.shutdown();
Expand Down
Loading