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
12 changes: 12 additions & 0 deletions tagsync/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,17 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
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.tagsync.ha;

import org.apache.ranger.tagsync.process.TagSyncConfig;
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.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestTagSyncHAInitializerImpl {
@Test
public void test01GetInstanceReturnsSingleton() {
TagSyncConfig config = TagSyncConfig.getInstance();
TagSyncHAInitializerImpl instance1 = TagSyncHAInitializerImpl.getInstance(config);
TagSyncHAInitializerImpl instance2 = TagSyncHAInitializerImpl.getInstance(config);

assertNotNull(instance1);
assertNotNull(instance2);
assertTrue(instance1 == instance2);
}

@Test
public void test02GetInstanceWithNullConfig() {
TagSyncHAInitializerImpl instance = TagSyncHAInitializerImpl.getInstance(null);
assertNotNull(instance);
}

@Test
public void test03IsActiveDefaultBehavior() {
TagSyncConfig config = TagSyncConfig.getInstance();
TagSyncHAInitializerImpl instance = TagSyncHAInitializerImpl.getInstance(config);

assertNotNull(instance);
assertTrue(instance.isActive());
}

@Test
public void test04GetInstanceMultipleCalls() {
TagSyncConfig config = TagSyncConfig.getInstance();

for (int i = 0; i < 5; i++) {
TagSyncHAInitializerImpl instance = TagSyncHAInitializerImpl.getInstance(config);
assertNotNull(instance);
}
}

@Test
public void test05InstanceInitialization() {
TagSyncConfig config = TagSyncConfig.getInstance();
TagSyncHAInitializerImpl instance = TagSyncHAInitializerImpl.getInstance(config);

assertNotNull(instance);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* 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.tagsync.model;

import org.apache.ranger.plugin.util.ServiceTags;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.Properties;

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

public class TestAbstractTagSource {
@Mock
private TagSink mockTagSink;
private ConcreteTagSource tagSource;

@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);
tagSource = new ConcreteTagSource();
}

@Test
public void test01SetTagSinkStoresCorrectly() {
tagSource.setTagSink(mockTagSink);
assertEquals(mockTagSink, tagSource.getStoredSink());
}

@Test
public void test02InitializeWithValidProperties() {
Properties props = new Properties();
props.setProperty("test.property", "value");
assertTrue(tagSource.initialize(props));
}

@Test
public void test03InitializeWithNullProperties() {
assertFalse(tagSource.initialize(null));
}

@Test
public void test04StartReturnsTrue() {
assertTrue(tagSource.start());
}

@Test
public void test05StopDoesNotThrowException() {
tagSource.stop();
assertNotNull(tagSource);
}

@Test
public void test06UpdateSinkWithValidServiceTags() throws Exception {
tagSource.setTagSink(mockTagSink);
ServiceTags serviceTags = new ServiceTags();
serviceTags.setServiceName("test_service");

tagSource.updateSink(serviceTags);
assertNotNull(serviceTags);
}

@Test
public void test07UpdateSinkHandlesNullServiceTags() throws Exception {
tagSource.setTagSink(mockTagSink);
tagSource.updateSink(null);
assertNotNull(tagSource);
}

@Test
public void test08GetNameReturnsSetName() {
String testName = "TestSource";
tagSource.setName(testName);
assertEquals(testName, tagSource.getName());
}

public static class ConcreteTagSource extends AbstractTagSource {
private TagSink storedSink;

@Override
public boolean initialize(Properties properties) {
return properties != null;
}

@Override
public boolean start() {
return true;
}

@Override
public void stop() {
}

@Override
public void setTagSink(TagSink sink) {
this.storedSink = sink;
super.setTagSink(sink);
}

public TagSink getStoredSink() {
return storedSink;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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.tagsync.process;

import org.junit.jupiter.api.BeforeEach;
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.Properties;

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

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

@ExtendWith(MockitoExtension.class)
@TestMethodOrder(MethodOrderer.MethodName.class)
public class TestTagSyncConfig {
private Properties properties;

@BeforeEach
public void setUp() {
properties = new Properties();
}

@Test
public void test01GetInstanceReturnsSingleton() {
TagSyncConfig config1 = TagSyncConfig.getInstance();
TagSyncConfig config2 = TagSyncConfig.getInstance();

assertNotNull(config1);
assertNotNull(config2);
assertTrue(config1 == config2);
}

@Test
public void test02GetPropertiesReturnsNonNull() {
TagSyncConfig config = TagSyncConfig.getInstance();
Properties props = config.getProperties();
assertNotNull(props);
}

@Test
public void test03GetTagSinkClassNameWithValidProperty() {
properties.setProperty("ranger.tagsync.dest.ranger.impl.class", "org.apache.ranger.tagsync.sink.tagadmin.TagAdminRESTSink");
String className = TagSyncConfig.getTagSinkClassName(properties);
assertEquals("org.apache.ranger.tagsync.sink.tagadmin.TagAdminRESTSink", className);
}

@Test
public void test04GetTagSourceFileNameFromProperties() {
properties.setProperty("ranger.tagsync.source.file.filename", "/tmp/tags.json");
String filename = TagSyncConfig.getTagSourceFileName(properties);
assertEquals("/tmp/tags.json", filename);
}

@Test
public void test05IsTagSyncEnabledDefaultValue() {
boolean enabled = TagSyncConfig.isTagSyncEnabled(properties);
assertTrue(enabled);
}

@Test
public void test06GetTagAdminRESTUrlWithValidProperty() {
properties.setProperty("ranger.tagsync.dest.ranger.endpoint", "http://localhost:6080");
String url = TagSyncConfig.getTagAdminRESTUrl(properties);
assertEquals("http://localhost:6080", url);
}

@Test
public void test07IsTagSyncServiceActiveByDefault() {
boolean isActive = TagSyncConfig.isTagSyncServiceActive();
assertTrue(isActive);
}

@Test
public void test08GetTagAdminConnectionCheckInterval() {
properties.setProperty("ranger.tagsync.dest.ranger.connection.check.interval", "20000");
long interval = TagSyncConfig.getTagAdminConnectionCheckInterval(properties);
assertEquals(20000L, interval);
}

@Test
public void test09GetFileCheckIntervalInMillisDefaultValue() {
long interval = TagSyncConfig.getTagSourceFileModTimeCheckIntervalInMillis(properties);
assertTrue(interval > 0);
}

@Test
public void test10GetFileCheckIntervalDefaultValue() {
long interval = TagSyncConfig.getTagSourceFileModTimeCheckIntervalInMillis(properties);
assertTrue(interval == 60000L);
}

@Test
public void test11GetTagAdminUserNameFromProperties() {
properties.setProperty("ranger.tagsync.dest.ranger.username", "testuser");
String username = TagSyncConfig.getTagAdminUserName(properties);
assertEquals("testuser", username);
}

@Test
public void test12GetTagAdminPasswordFromProperties() {
properties.setProperty("ranger.tagsync.dest.ranger.password", "testpass");
String password = TagSyncConfig.getTagAdminPassword(properties);
assertEquals("testpass", password);
}
}
Loading