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,83 @@
/*
* 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.plugin.util;

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.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

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

/**
* @generated by Cursor
* @description <Unit Test for AutoClosableLock class>
*/
@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestAutoClosableLock {
@Test
public void test01_simpleLockUnlock() {
ReentrantLock lock = new ReentrantLock();
assertFalse(lock.isLocked());
try (AutoClosableLock ignored = new AutoClosableLock(lock)) {
assertTrue(lock.isLocked());
}
assertFalse(lock.isLocked());
}

@Test
public void test02_tryLock_withTimeout_acquired() {
ReentrantLock lock = new ReentrantLock();
try (AutoClosableLock.AutoClosableTryLock tryLock = new AutoClosableLock.AutoClosableTryLock(lock, 50,
TimeUnit.MILLISECONDS)) {
assertTrue(tryLock.isLocked());
}
assertFalse(lock.isLocked());
}

@Test
public void test03_tryWriteLock_acquiredAndReleased() {
ReentrantReadWriteLock rw = new ReentrantReadWriteLock();
try (AutoClosableLock.AutoClosableTryWriteLock tryWrite = new AutoClosableLock.AutoClosableTryWriteLock(rw)) {
assertTrue(tryWrite.isLocked());
}
assertFalse(rw.isWriteLocked());
}

@Test
public void test04_readAndWriteLock_scopes() {
ReentrantReadWriteLock rw = new ReentrantReadWriteLock();
assertFalse(rw.isWriteLocked());
try (AutoClosableLock.AutoClosableReadLock ignored = new AutoClosableLock.AutoClosableReadLock(rw)) {
assertTrue(rw.getReadLockCount() > 0);
}
assertTrue(rw.getReadLockCount() == 0);

try (AutoClosableLock.AutoClosableWriteLock ignored = new AutoClosableLock.AutoClosableWriteLock(rw)) {
assertTrue(rw.isWriteLocked());
}
assertFalse(rw.isWriteLocked());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.plugin.util;

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.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @generated by Cursor
* @description <Unit Test for DownloadTrigger class>
*/
@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestDownloadTrigger {
@Test
public void test01_waitAndSignal() throws Exception {
DownloadTrigger trigger = new DownloadTrigger();

Thread waiter = new Thread(() -> assertDoesNotThrow(() -> trigger.waitForCompletion()));
waiter.start();

Thread.sleep(50L);
trigger.signalCompletion();

waiter.join(2000L);
assertTrue(!waiter.isAlive());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.plugin.util;

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.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

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

/**
* @generated by Cursor
* @description <Unit Test for DownloaderTask class>
*/
@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestDownloaderTask {
@Test
public void test01_run_putsTriggerAndWaitsUntilSignaled() throws Exception {
LinkedBlockingQueue<DownloadTrigger> queue = new LinkedBlockingQueue<>();
DownloaderTask task = new DownloaderTask(queue);

Thread t = new Thread(task::run);
t.start();

DownloadTrigger trigger = queue.poll(2, TimeUnit.SECONDS);
assertNotNull(trigger);

Thread.sleep(50L);
trigger.signalCompletion();

t.join(2000L);
assertTrue(!t.isAlive());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.plugin.util;

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 javax.script.ScriptEngine;

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

/**
* @generated by Cursor
* @description <Unit Test for GraalScriptEngineCreator class>
*/
@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestGraalScriptEngineCreator {
@Test
public void test01_getScriptEngine_withNullClassLoader_returnsGracefully() {
GraalScriptEngineCreator creator = new GraalScriptEngineCreator();
ScriptEngine engine = creator.getScriptEngine(null);
// engine may be null if graal.js is not available; ensure no exception and type
// if present
assertTrue(engine == null || engine.getFactory() != null);
}

@Test
public void test02_getScriptEngine_withCustomClassLoader_returnsGracefully() {
ClassLoader cl = this.getClass().getClassLoader();
GraalScriptEngineCreator creator = new GraalScriptEngineCreator();
ScriptEngine engine = creator.getScriptEngine(cl);
assertTrue(engine == null || engine.getFactory() != null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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.plugin.util;

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.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

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

/**
* @generated by Cursor
* @description <Unit Test for GrantRevokeRequest class>
*/
@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestGrantRevokeRequest {
@Test
public void test01_defaultsAndSetters() {
GrantRevokeRequest req = new GrantRevokeRequest();
req.setGrantor("g");
req.setGrantorGroups(null);
req.setResource(null);
req.setUsers(null);
req.setGroups(null);
req.setRoles(null);
req.setAccessTypes(null);
req.setDelegateAdmin(null);
req.setEnableAudit(null);
req.setReplaceExistingPermissions(null);
req.setIsRecursive(null);
req.setClientIPAddress("1.1.1.1");
req.setClientType("app");
req.setRequestData("rd");
req.setSessionId("sid");
req.setClusterName("cluster");
req.setZoneName("zone");
req.setOwnerUser("owner");

assertEquals("g", req.getGrantor());
assertEquals(0, req.getGrantorGroups().size());
assertEquals(0, req.getResource().size());
assertEquals(0, req.getUsers().size());
assertEquals(0, req.getRoles().size());
assertEquals(0, req.getAccessTypes().size());
assertEquals(Boolean.FALSE, req.getDelegateAdmin());
assertEquals(Boolean.TRUE, req.getEnableAudit());
assertEquals(Boolean.FALSE, req.getReplaceExistingPermissions());
assertEquals(Boolean.FALSE, req.getIsRecursive());
assertNotNull(req.toString());
}

@Test
public void test02_constructorAssignsFields() {
Set<String> ggs = new HashSet<>(Arrays.asList("gg"));
Set<String> us = new HashSet<>(Arrays.asList("u"));
Set<String> gs = new HashSet<>(Arrays.asList("gr"));
Set<String> rs = new HashSet<>(Arrays.asList("rl"));
Set<String> ats = new HashSet<>(Arrays.asList("a"));
GrantRevokeRequest req = new GrantRevokeRequest("g", ggs, new HashMap<>(), us, gs, rs, ats, Boolean.TRUE,
Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, "ip", "cli", "rd", "sid", "cluster", "zone", "owner");
assertEquals("g", req.getGrantor());
assertEquals(Boolean.TRUE, req.getDelegateAdmin());
assertEquals(Boolean.FALSE, req.getEnableAudit());
assertEquals(Boolean.TRUE, req.getReplaceExistingPermissions());
assertEquals(Boolean.TRUE, req.getIsRecursive());
}
}
Loading
Loading