|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.ranger.plugin.util; |
| 21 | + |
| 22 | +import org.apache.ranger.authorization.hadoop.config.RangerPluginConfig; |
| 23 | +import org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions; |
| 24 | +import org.apache.ranger.plugin.service.RangerBasePlugin; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 28 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 29 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 30 | + |
| 31 | +public class TestRangerRESTClient { |
| 32 | + private static final String SERVICE_TYPE = "hive"; |
| 33 | + private static final String SERVICE_NAME = "test-service"; |
| 34 | + private static final String APP_ID = "test-app"; |
| 35 | + private static final String ERR_MESSAGE = "Ranger URL is null or empty."; |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testPluginInit_WithNoUrl_ThrowsException() { |
| 39 | + RangerBasePlugin plugin = new RangerBasePlugin(SERVICE_TYPE, SERVICE_NAME, APP_ID); |
| 40 | + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, plugin::init); |
| 41 | + assertTrue(exception.getMessage().contains(ERR_MESSAGE)); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testPluginInit_WithValidUrl_Succeeds() { |
| 46 | + RangerPolicyEngineOptions peOptions = new RangerPolicyEngineOptions(); |
| 47 | + RangerPluginConfig pluginConfig = new RangerPluginConfig(SERVICE_TYPE, SERVICE_NAME, APP_ID, "cl1", "on-perm", peOptions); |
| 48 | + pluginConfig.set("ranger.plugin.hive.policy.rest.url", "http://dummy:1234"); |
| 49 | + RangerBasePlugin plugin = new RangerBasePlugin(pluginConfig); |
| 50 | + plugin.init(); |
| 51 | + assertNotNull(plugin, "RangerBasePlugin should be initialized successfully"); |
| 52 | + } |
| 53 | +} |
0 commit comments