ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From me...@apache.org
Subject ranger git commit: RANGER-2138 : Add unit tests for org.apache.ranger.service package
Date Fri, 22 Jun 2018 05:28:10 GMT
Repository: ranger
Updated Branches:
  refs/heads/master ee20663d4 -> 29fedc53f


RANGER-2138 : Add unit tests for org.apache.ranger.service package

Signed-off-by: Mehul Parikh <mehul@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/29fedc53
Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/29fedc53
Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/29fedc53

Branch: refs/heads/master
Commit: 29fedc53fdc4a9df9f5857e754cf6fdcad488cef
Parents: ee20663
Author: fatimaawez <fatimakhan4689@gmail.com>
Authored: Thu Jun 21 18:26:59 2018 +0530
Committer: Mehul Parikh <mehul@apache.org>
Committed: Fri Jun 22 10:57:55 2018 +0530

----------------------------------------------------------------------
 .../ranger/service/TestAuthSessionService.java  | 100 +++++++++++++
 .../ranger/service/TestRangerAuditFields.java   |  48 +++++++
 .../service/TestRangerDataHistService.java      | 113 +++++++++++++++
 .../service/TestRangerPluginActivityLogger.java |  75 ++++++++++
 .../TestRangerServiceWithAssignedIdService.java | 107 ++++++++++++++
 .../TestRangerTagResourceMapService.java        | 140 +++++++++++++++++++
 .../ranger/service/TestRangerTagService.java    | 140 +++++++++++++++++++
 .../service/TestRangerTransactionService.java   |  61 ++++++++
 .../apache/ranger/service/TestUserService.java  |  63 +++++++++
 .../service/filter/TestRangerRESTAPIFilter.java |  48 +++++++
 10 files changed, 895 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestAuthSessionService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestAuthSessionService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestAuthSessionService.java
new file mode 100644
index 0000000..292777e
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestAuthSessionService.java
@@ -0,0 +1,100 @@
+/*
+ * 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.service;
+
+import javax.persistence.EntityManager;
+
+import org.apache.ranger.common.SearchCriteria;
+
+import org.apache.ranger.common.SearchUtil;
+
+import org.apache.ranger.common.db.BaseDao;
+import org.apache.ranger.entity.XXAuthSession;
+import org.apache.ranger.view.VXAuthSession;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestAuthSessionService {
+	@InjectMocks
+	AuthSessionService authSessionService = new AuthSessionService();
+
+	@Mock
+	VXAuthSession vXAuthSession;
+
+	@Mock
+	XXAuthSession mObj;
+
+	@Mock
+	XXAuthSession xXAuthSession;
+
+	@Mock
+	SearchCriteria searchCriteria;
+
+	@Mock
+	SearchUtil searchUtil;
+
+	@Mock
+	BaseDao entityDao;
+
+	@Test
+	public void test1GetResourceName() {
+		authSessionService.getResourceName();
+	}
+
+	@Test
+	public void test2CreateEntityObject() {
+		authSessionService.createEntityObject();
+	}
+
+	@Test
+	public void test3CreateViewObject() {
+		authSessionService.createViewObject();
+	}
+
+	@Test
+	public void test4search() {
+		SearchCriteria testSearchCriteria = createsearchCriteria();
+		EntityManager em = null;
+		Mockito.when(authSessionService.getDao().getEntityManager()).thenReturn(em);
+		authSessionService.search(testSearchCriteria);
+	}
+
+	private SearchCriteria createsearchCriteria() {
+		SearchCriteria testsearchCriteria = new SearchCriteria();
+		testsearchCriteria.setStartIndex(0);
+		testsearchCriteria.setMaxRows(Integer.MAX_VALUE);
+		testsearchCriteria.setSortBy("id");
+		testsearchCriteria.setSortType("asc");
+		testsearchCriteria.setGetCount(true);
+		testsearchCriteria.setOwnerId(null);
+		testsearchCriteria.setGetChildren(false);
+		testsearchCriteria.setDistinct(false);
+		return testsearchCriteria;
+	}
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestRangerAuditFields.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerAuditFields.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerAuditFields.java
new file mode 100644
index 0000000..1d71bc3
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerAuditFields.java
@@ -0,0 +1,48 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed 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.service;
+
+import org.apache.ranger.entity.XXDBBase;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRangerAuditFields {
+
+        @InjectMocks
+        RangerAuditFields rangerAuditFields;
+
+        @Mock
+        XXDBBase XXDBBase;
+
+        @Test
+        public void test1PopulateAuditFields() {
+                rangerAuditFields.populateAuditFields(XXDBBase, XXDBBase);
+        }
+
+        @Test
+        public void test2PopulateAuditFieldsForCreate() {
+
+                rangerAuditFields.populateAuditFieldsForCreate(XXDBBase);
+        }
+
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestRangerDataHistService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerDataHistService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerDataHistService.java
new file mode 100644
index 0000000..e1a236e
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerDataHistService.java
@@ -0,0 +1,113 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed 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.service;
+
+import java.util.Date;
+
+import org.apache.ranger.db.RangerDaoManager;
+import org.apache.ranger.entity.XXDataHist;
+import org.apache.ranger.plugin.model.RangerBaseModelObject;
+import org.apache.ranger.plugin.model.RangerPolicy;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRangerDataHistService {
+
+	@InjectMocks
+	RangerDataHistService rangerDataHistService;
+
+	@Mock
+	RangerBaseModelObject baseModelObj;
+
+	@Mock
+	RangerDaoManager daoMgr;
+	@Mock
+	org.apache.ranger.db.XXDataHistDao XXDataHistDao;
+
+	@Mock
+	ObjectMapper mapper;
+
+	@Test
+	public void test1CreateObjectDataHistory() {
+		String action = "create";
+		RangerBaseModelObject baseModelObj = new RangerBaseModelObject();
+		Mockito.when(daoMgr.getXXDataHist()).thenReturn(XXDataHistDao);
+		rangerDataHistService.createObjectDataHistory(baseModelObj, action);
+
+	}
+
+	@Test
+	public void test2WriteObjectAsString() {
+		RangerBaseModelObject testbaseModelObj = createRangerBaseModelObject();
+		rangerDataHistService.writeObjectAsString(testbaseModelObj);
+
+	}
+
+	@Test
+	public void test3WriteJsonToJavaObject() {
+		XXDataHist XXDataHist = createXXDataHistObject();
+		rangerDataHistService.writeJsonToJavaObject(XXDataHist.getContent(), RangerPolicy.class);
+	}
+
+	private XXDataHist createXXDataHistObject() {
+		XXDataHist xDataHist = new XXDataHist();
+		Date date = new Date();
+		xDataHist.setObjectId(1L);
+		xDataHist.setObjectGuid("testGuid");
+		xDataHist.setCreateTime(date);
+		xDataHist.setAction("Create");
+		xDataHist.setVersion(1L);
+		xDataHist.setUpdateTime(date);
+		xDataHist.setFromTime(date);
+
+		xDataHist.setContent("{\"id\":3,\"guid\":\"c3991965-b063-4fff-b9e5-2e0aa566af29\""
+				+ ",\"isEnabled\":true,\"createdBy\":\"Admin\",\""
+				+ "updatedBy\":\"Admin\",\"createTime\":1529044511083,\"updateTime\""
+				+ ":1529044511084,\"version\":1,\"service\":\"cl1_storm_01\",\"name\""
+				+ ":\"all - topology\",\"policyType\":0,\"description\":\"Policy for all - topology\""
+				+ ",\"resourceSignature\":\"61c9e34a1c273ed9263940cf79275e94\",\"isAuditEnabled\""
+				+ ":true,\"resources\":{\"topology\":{\"values\":[\"*\"],\"isExcludes\":false,\"isRecursive\""
+				+ ":false}},\"policyItems\":[{\"accesses\":[{\"type\":\"submitTopology\",\"isAllowed\":true}"
+				+ ",{\"type\":\"fileUpload\",\"isAllowed\":true},{\"type\":\"fileDownload\",\"isAllowed\""
+				+ ":true},{\"type\":\"killTopology\",\"isAllowed\":true},{\"type\":\"rebalance\",\"isAllowed\""
+				+ ":true},{\"type\":\"activate\",\"isAllowed\":true},{\"type\":\"deactivate\",\"isAllowed\":true},{\"type\":\"getTopologyConf\",\"isAllowed\":true},{\"type\":\"getTopology\",\"isAllowed\":true},{\"type\":\"getUserTopology\",\"isAllowed\":true},{\"type\":\"getTopologyInfo\",\"isAllowed\":true},{\"type\":\"uploadNewCredentials\",\"isAllowed\":true}],\"users\":[\"test\",\"test123\",\"HTTP123\"],\"groups\":[],\"conditions\":[],\"delegateAdmin\":true}],\"denyPolicyItems\":[],\"allowExceptions\":[],\"denyExceptions\":[],\"dataMaskPolicyItems\":[],\"rowFilterPolicyItems\":[]}
");
+
+		return xDataHist;
+	}
+
+	private RangerBaseModelObject createRangerBaseModelObject() {
+		RangerBaseModelObject baseModelObj = new RangerBaseModelObject();
+		Date date = new Date();
+		baseModelObj.setCreatedBy("admin");
+		baseModelObj.setCreateTime(date);
+		baseModelObj.setGuid("testGuid");
+		baseModelObj.setIsEnabled(true);
+		baseModelObj.setUpdatedBy("admin");
+		baseModelObj.setUpdateTime(date);
+		baseModelObj.setVersion(1L);
+		return baseModelObj;
+
+	}
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestRangerPluginActivityLogger.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerPluginActivityLogger.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerPluginActivityLogger.java
new file mode 100644
index 0000000..e501cc3
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerPluginActivityLogger.java
@@ -0,0 +1,75 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+ *
+ * Licensed 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.service;
+
+import org.apache.ranger.db.RangerDaoManager;
+import org.apache.ranger.entity.XXPolicyExportAudit;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRangerPluginActivityLogger {
+
+	@InjectMocks
+	RangerPluginActivityLogger rangerPluginActivityLogger;
+
+	@Mock
+	RangerDaoManager rangerDaoManager;
+
+	@Mock
+	XXPolicyExportAudit xXPolicyExportAudit;
+
+	@Mock
+	RangerTransactionService transactionService;
+
+	@Mock
+	Runnable commitWork;
+
+	boolean pluginActivityAuditCommitInline = false;
+
+	@Test
+	public void test1CommitAfterTransactionComplete() {
+		pluginActivityAuditCommitInline = false;
+		rangerPluginActivityLogger.commitAfterTransactionComplete(commitWork);
+
+	}
+
+	@Test
+	public void test2Init() {
+		pluginActivityAuditCommitInline = false;
+		rangerPluginActivityLogger.init();
+
+	}
+
+	@Test
+	public void test3CommitAfterTransactionComplete() {
+		pluginActivityAuditCommitInline = true;
+		rangerPluginActivityLogger.commitAfterTransactionComplete(commitWork);
+	}
+
+	@Test
+	public void test4Init() {
+		pluginActivityAuditCommitInline = true;
+		rangerPluginActivityLogger.init();
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceWithAssignedIdService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceWithAssignedIdService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceWithAssignedIdService.java
new file mode 100644
index 0000000..c5221cd
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerServiceWithAssignedIdService.java
@@ -0,0 +1,107 @@
+/*
+ * 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.service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.ranger.db.RangerDaoManager;
+import org.apache.ranger.db.XXServiceConfigMapDao;
+import org.apache.ranger.db.XXServiceDao;
+import org.apache.ranger.db.XXServiceVersionInfoDao;
+import org.apache.ranger.entity.XXService;
+import org.apache.ranger.entity.XXServiceConfigMap;
+
+import org.apache.ranger.entity.XXServiceVersionInfo;
+import org.apache.ranger.entity.XXServiceWithAssignedId;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.apache.ranger.plugin.model.RangerService;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRangerServiceWithAssignedIdService {
+
+        @InjectMocks
+        RangerServiceWithAssignedIdService rangerServiceWithAssignedIdService;
+
+        @Mock
+        RangerDaoManager daoMgr;
+        @Mock
+        XXServiceConfigMapDao xXServiceConfigMapDao;
+
+        @Mock
+        org.apache.ranger.entity.XXServiceDef xXServiceDef;
+
+        @Mock
+        org.apache.ranger.db.XXServiceDefDao xXServiceDefDao;
+
+        @Mock
+        XXServiceDao xXServiceDao;
+
+        @Mock
+        XXService xXService;
+
+        @Mock
+        RangerService RangerService;
+
+        @Mock
+        org.apache.ranger.db.XXPortalUserDao xXPortalUserDao;
+
+        @Mock
+        XXServiceVersionInfoDao xXServiceVersionInfoDao;
+
+        @Mock
+        XXServiceVersionInfo xXServiceVersionInfo;
+
+        @Test
+        public void test1GetPopulatedViewObject() {
+                XXServiceWithAssignedId xXServiceWithAssignedId = new XXServiceWithAssignedId();
+                xXServiceWithAssignedId.setId(1L);
+                Date date = new Date();
+                xXServiceWithAssignedId.setIsEnabled(true);
+                xXServiceWithAssignedId.setName("testService");
+                xXServiceWithAssignedId.setPolicyVersion(1L);
+                xXServiceWithAssignedId.setVersion(1L);
+                xXServiceWithAssignedId.setCreateTime(date);
+                xXServiceWithAssignedId.setTagService(1L);
+                xXServiceWithAssignedId.setTagVersion(1L);
+                xXServiceWithAssignedId.setUpdateTime(date);
+                xXServiceWithAssignedId.setUpdatedByUserId(1L);
+                xXServiceWithAssignedId.setAddedByUserId(1L);
+                xXServiceWithAssignedId.setType(1L);
+                List<XXServiceConfigMap> svcConfigMapList = new ArrayList<XXServiceConfigMap>();
+                Mockito.when(daoMgr.getXXPortalUser()).thenReturn(xXPortalUserDao);
+                Mockito.when(daoMgr.getXXServiceDef()).thenReturn(xXServiceDefDao);
+                Mockito.when(xXServiceDefDao.getById(1L)).thenReturn(xXServiceDef);
+                Mockito.when(daoMgr.getXXService()).thenReturn(xXServiceDao);
+                Mockito.when(xXServiceDao.getById(1L)).thenReturn(xXService);
+                Mockito.when(daoMgr.getXXServiceVersionInfo()).thenReturn(xXServiceVersionInfoDao);
+                Mockito.when(xXServiceVersionInfoDao.findByServiceId(1L)).thenReturn(xXServiceVersionInfo);
+                Mockito.when(daoMgr.getXXServiceConfigMap()).thenReturn(xXServiceConfigMapDao);
+                Mockito.when(xXServiceConfigMapDao.findByServiceId(1L)).thenReturn(svcConfigMapList);
+                rangerServiceWithAssignedIdService.getPopulatedViewObject(xXServiceWithAssignedId);
+        }
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagResourceMapService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagResourceMapService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagResourceMapService.java
new file mode 100644
index 0000000..27ec8e1
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagResourceMapService.java
@@ -0,0 +1,140 @@
+/*
+ * 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.service;
+
+import org.apache.ranger.db.RangerDaoManager;
+import org.apache.ranger.db.XXServiceVersionInfoDao;
+import org.apache.ranger.db.XXTagResourceMapDao;
+import org.apache.ranger.entity.XXTagResourceMap;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRangerTagResourceMapService {
+	@InjectMocks
+	RangerTagResourceMapService rangerTagResourceMapService;
+
+	@Mock
+	XXTagResourceMap xXTagResourceMap;
+
+	@Mock
+	RangerDaoManager daoMgr;
+
+	@Mock
+	XXServiceVersionInfoDao xXServiceVersionInfoDao;
+
+	@Mock
+	org.apache.ranger.db.XXPortalUserDao XXPortalUserDao;
+
+	@Mock
+	XXTagResourceMapDao xXTagResourceMapDao;
+
+	@Test
+	public void test1PostCreate() {
+		Mockito.when(daoMgr.getXXPortalUser()).thenReturn(XXPortalUserDao);
+		Mockito.when(daoMgr.getXXServiceVersionInfo()).thenReturn(xXServiceVersionInfoDao);
+		rangerTagResourceMapService.postCreate(xXTagResourceMap);
+
+	}
+
+	@Test
+	public void test2PostUpdate() {
+		Mockito.when(daoMgr.getXXPortalUser()).thenReturn(XXPortalUserDao);
+		Mockito.when(daoMgr.getXXServiceVersionInfo()).thenReturn(xXServiceVersionInfoDao);
+		rangerTagResourceMapService.postUpdate(xXTagResourceMap);
+
+	}
+
+	@Test
+	public void test3GetPopulatedViewObject() {
+		Mockito.when(daoMgr.getXXPortalUser()).thenReturn(XXPortalUserDao);
+		rangerTagResourceMapService.getPopulatedViewObject(xXTagResourceMap);
+
+	}
+
+	@Test
+	public void test4GetByTagId() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getByTagId(1L);
+
+	}
+
+	@Test
+	public void test5GetByTagGuid() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getByTagGuid("1");
+
+	}
+
+	@Test
+	public void test6GetByResourceId() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getByResourceId(1L);
+
+	}
+
+	@Test
+	public void test7GetTagIdsForResourceId() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getTagIdsForResourceId(1L);
+
+	}
+
+	@Test
+	public void test8GetByResourceGuid() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getByResourceGuid("1");
+
+	}
+
+	@Test
+	public void test9GetByGuid() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getByGuid("1");
+
+	}
+
+	@Test
+	public void test10GetByTagAndResourceId() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getByTagAndResourceId(1L, 1L);
+
+	}
+
+	@Test
+	public void test11GetByTagAndResourceGuid() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getByTagAndResourceGuid("1", "1");
+
+	}
+
+	@Test
+	public void test12GetTagResourceMapsByServiceId() {
+		Mockito.when(daoMgr.getXXTagResourceMap()).thenReturn(xXTagResourceMapDao);
+		rangerTagResourceMapService.getTagResourceMapsByServiceId(1L);
+
+	}
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
new file mode 100644
index 0000000..1175989
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTagService.java
@@ -0,0 +1,140 @@
+/*
+ * 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.service;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.Date;
+
+import org.apache.ranger.db.RangerDaoManager;
+import org.apache.ranger.db.XXPortalUserDao;
+import org.apache.ranger.db.XXServiceVersionInfoDao;
+import org.apache.ranger.db.XXTagAttributeDao;
+import org.apache.ranger.db.XXTagDao;
+import org.apache.ranger.db.XXTagDefDao;
+import org.apache.ranger.entity.XXTag;
+import org.apache.ranger.entity.XXTagDef;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRangerTagService {
+
+        @InjectMocks
+        RangerTagService rangerTagService;
+
+        @Mock
+        XXTag xXTag;
+
+        @Mock
+        RangerDaoManager daoMgr;
+
+        @Mock
+        XXPortalUserDao xXPortalUserDao;
+
+        @Mock
+        XXServiceVersionInfoDao xXServiceVersionInfoDao;
+
+        @Mock
+        XXTagDefDao xXTagDefDao;
+
+        @Mock
+        XXTagDef xXTagDef;
+
+        @Mock
+        XXTagAttributeDao xXTagAttributeDao;
+
+        @Mock
+        XXTagDao xXTagDao;
+
+        @Test
+        public void test1postUpdate() {
+                Mockito.when(daoMgr.getXXPortalUser()).thenReturn(xXPortalUserDao);
+                Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
+                Mockito.when(daoMgr.getXXTagAttribute()).thenReturn(xXTagAttributeDao);
+                Mockito.when(xXTagDefDao.getById(xXTag.getType())).thenReturn(xXTagDef);
+                Mockito.when(daoMgr.getXXServiceVersionInfo()).thenReturn(xXServiceVersionInfoDao);
+                rangerTagService.postUpdate(xXTag);
+
+        }
+
+        @Test
+        public void test2GetPopulatedViewObject() {
+                Mockito.when(daoMgr.getXXPortalUser()).thenReturn(xXPortalUserDao);
+                Mockito.when(daoMgr.getXXTagDef()).thenReturn(xXTagDefDao);
+                XXTag xXTag = createXXTag();
+                Mockito.when(xXTagDefDao.getById(1L)).thenReturn(xXTagDef);
+                Mockito.when(daoMgr.getXXTagAttribute()).thenReturn(xXTagAttributeDao);
+                rangerTagService.getPopulatedViewObject(xXTag);
+
+        }
+
+        @Test
+        public void test3GetTagByGuid() {
+                Mockito.when(daoMgr.getXXTag()).thenReturn(xXTagDao);
+                rangerTagService.getTagByGuid("1");
+
+        }
+
+        @Test
+        public void test4GetTagsByType() {
+                Mockito.when(daoMgr.getXXTag()).thenReturn(xXTagDao);
+                rangerTagService.getTagsByType("testTagName");
+
+        }
+
+        @Test
+        public void test5GetTagsForResourceId() {
+                Mockito.when(daoMgr.getXXTag()).thenReturn(xXTagDao);
+                rangerTagService.getTagsForResourceId(1L);
+
+        }
+
+        @Test
+        public void test6GetTagsForResourceGuid() {
+                Mockito.when(daoMgr.getXXTag()).thenReturn(xXTagDao);
+                rangerTagService.getTagsForResourceGuid("1");
+
+        }
+
+        @Test
+        public void test7getTagsByServiceId() {
+                Mockito.when(daoMgr.getXXTag()).thenReturn(xXTagDao);
+                rangerTagService.getTagsByServiceId(1L);
+        }
+
+        private XXTag createXXTag() {
+                XXTag xXTag = new XXTag();
+                xXTag.setAddedByUserId(1L);
+                Date date = new Date();
+                xXTag.setCreateTime(date);
+                xXTag.setGuid("1");
+                xXTag.setType(1L);
+                xXTag.setUpdatedByUserId(1L);
+                xXTag.setVersion(1L);
+                xXTag.setId(1L);
+                return xXTag;
+        }
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestRangerTransactionService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestRangerTransactionService.java
b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTransactionService.java
new file mode 100644
index 0000000..9ba9cf1
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestRangerTransactionService.java
@@ -0,0 +1,61 @@
+/*
+ * 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.service;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRangerTransactionService {
+
+	@InjectMocks
+	RangerTransactionService rangerTransactionService;
+
+	@Mock
+	ScheduledExecutorService scheduler;
+
+	@Mock
+	Runnable task;
+
+	@Test
+	public void test1Init() {
+		rangerTransactionService.init();
+
+	}
+
+	@Test
+	public void test2Destroy() {
+		rangerTransactionService.destroy();
+
+	}
+
+	@Test
+	public void test3ExecuteAfterTransactionComplete() {
+		rangerTransactionService.executeAfterTransactionComplete(task);
+
+	}
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/TestUserService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/TestUserService.java b/security-admin/src/test/java/org/apache/ranger/service/TestUserService.java
new file mode 100644
index 0000000..c48739b
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/TestUserService.java
@@ -0,0 +1,63 @@
+/*
+ * 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.service;
+
+import org.apache.ranger.db.RangerDaoManager;
+import org.apache.ranger.db.XXPortalUserRoleDao;
+import org.apache.ranger.entity.XXPortalUser;
+import org.apache.ranger.view.VXPortalUser;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestUserService {
+
+        @InjectMocks
+        UserService userService;
+
+        @Mock
+        XXPortalUser xXPortalUser;
+
+        @Mock
+        VXPortalUser vXPortalUser;
+
+        @Mock
+        RangerDaoManager daoManager;
+
+        @Mock
+        XXPortalUserRoleDao xXPortalUserRoleDao;
+
+        @Test
+        public void test1GetInstance() {
+                userService.getInstance();
+        }
+
+        @Test
+        public void test2GjUserToUserProfile() {
+                Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xXPortalUserRoleDao);
+                userService.gjUserToUserProfile(xXPortalUser, vXPortalUser);
+        }
+}

http://git-wip-us.apache.org/repos/asf/ranger/blob/29fedc53/security-admin/src/test/java/org/apache/ranger/service/filter/TestRangerRESTAPIFilter.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/service/filter/TestRangerRESTAPIFilter.java
b/security-admin/src/test/java/org/apache/ranger/service/filter/TestRangerRESTAPIFilter.java
new file mode 100644
index 0000000..176fcaf
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/service/filter/TestRangerRESTAPIFilter.java
@@ -0,0 +1,48 @@
+/*
+ * 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.service.filter;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import com.sun.jersey.spi.container.ContainerRequest;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRangerRESTAPIFilter {
+
+        @InjectMocks
+        RangerRESTAPIFilter rangerRESTAPIFilter = new RangerRESTAPIFilter();
+
+        @Mock
+        ContainerRequest request;
+
+        @Test
+        public void test1Filter() {
+                rangerRESTAPIFilter.filter(request);
+
+        }
+
+}


Mime
View raw message