ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject [4/5] incubator-ranger git commit: RANGER-1170 : Improvement of Unit Test coverage in Ranger
Date Wed, 28 Sep 2016 15:25:44 GMT
RANGER-1170 : Improvement of Unit Test coverage in Ranger

Signed-off-by: Velmurugan Periasamy <vel@apache.org>


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

Branch: refs/heads/master
Commit: 1c441f798e1c5da54f6bb9faf211eadb5f10b6b5
Parents: eb21ea6
Author: Ankita Sinha <ankita.sinha@freestoneinfotech.com>
Authored: Wed Sep 14 17:09:09 2016 +0530
Committer: Velmurugan Periasamy <vel@apache.org>
Committed: Wed Sep 28 11:19:17 2016 -0400

----------------------------------------------------------------------
 .../org/apache/ranger/rest/TestTagREST.java     | 1816 ++++++++++++++
 .../org/apache/ranger/rest/TestUserREST.java    |  489 ++++
 .../org/apache/ranger/rest/TestXAuditREST.java  |  219 ++
 .../org/apache/ranger/rest/TestXKeyREST.java    |  236 ++
 .../org/apache/ranger/rest/TestXUserREST.java   | 2238 ++++++++++++++++++
 .../ranger/service/TestRangerTagDefService.java |  274 +++
 .../service/TestRangerTagDefServiceBase.java    |   77 +
 7 files changed, 5349 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1c441f79/security-admin/src/test/java/org/apache/ranger/rest/TestTagREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/rest/TestTagREST.java b/security-admin/src/test/java/org/apache/ranger/rest/TestTagREST.java
new file mode 100644
index 0000000..fabd384
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/rest/TestTagREST.java
@@ -0,0 +1,1816 @@
+/*
+ * 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.rest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.apache.ranger.biz.RangerBizUtil;
+import org.apache.ranger.biz.ServiceDBStore;
+import org.apache.ranger.biz.TagDBStore;
+import org.apache.ranger.common.RESTErrorUtil;
+import org.apache.ranger.db.RangerDaoManager;
+import org.apache.ranger.db.XXServiceDao;
+import org.apache.ranger.db.XXServiceDefDao;
+import org.apache.ranger.entity.XXService;
+import org.apache.ranger.entity.XXServiceDef;
+import org.apache.ranger.plugin.model.RangerService;
+import org.apache.ranger.plugin.model.RangerServiceResource;
+import org.apache.ranger.plugin.model.RangerTag;
+import org.apache.ranger.plugin.model.RangerTagDef;
+import org.apache.ranger.plugin.model.RangerTagResourceMap;
+import org.apache.ranger.plugin.store.TagValidator;
+import org.apache.ranger.plugin.util.SearchFilter;
+import org.apache.ranger.plugin.util.ServiceTags;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+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.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestTagREST {
+	private static Long id = 1L;
+	private static String gId = "1427365526516_835_0";
+	private static String name = "test";
+	private static String serviceName = "HDFS";
+	private static String resourceSignature = "testResourceSign";
+	private static String tagGuid = "8787878787_09_1";
+	private static String resourceGuid = "9898989898_09_1";
+	private static Long lastKnownVersion = 10L;
+	private static String pluginId = "1";
+	private static String Allowed_User_List_For_Tag_Download = "tag.download.auth.users";
+
+	@InjectMocks
+	TagREST tagREST = new TagREST();
+
+	@Mock
+	TagValidator validator;
+
+	@Mock
+	TagDBStore tagStore;
+
+	@Mock
+	RESTErrorUtil restErrorUtil;
+	
+	@Mock
+	RangerBizUtil bizUtil;
+	
+	@Mock
+	RangerDaoManager daoManager;
+	
+	@Mock
+	ServiceDBStore svcStore;
+
+	@Rule
+	public ExpectedException thrown = ExpectedException.none();
+
+	@Test
+	public void test1createTagDef() {
+		RangerTagDef oldTagDef = null;
+		RangerTagDef newTagDef = new RangerTagDef();
+		newTagDef.setId(id);
+		newTagDef.setName(name);
+
+		try {
+			Mockito.when(validator.preCreateTagDef(oldTagDef, false)).thenReturn(null);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.createTagDef(oldTagDef)).thenReturn(newTagDef);
+		} catch (Exception e) {
+		}
+		RangerTagDef rangerTagDef = tagREST.createTagDef(oldTagDef, false);
+
+		Assert.assertEquals(rangerTagDef.getId(), newTagDef.getId());
+		Assert.assertNotNull(rangerTagDef);
+		Assert.assertEquals(rangerTagDef.getName(), newTagDef.getName());
+
+		try {
+			Mockito.verify(validator).preCreateTagDef(oldTagDef, false);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).createTagDef(oldTagDef);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test2createTagDef() {
+		RangerTagDef oldTagDef = new RangerTagDef();
+		RangerTagDef newTagDef = new RangerTagDef();
+		oldTagDef.setId(id);
+		newTagDef.setId(id);
+		newTagDef.setName(name);
+
+		try {
+			Mockito.when(validator.preCreateTagDef(oldTagDef, true)).thenReturn(
+					oldTagDef);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.updateTagDef(oldTagDef)).thenReturn(newTagDef);
+		} catch (Exception e) {
+		}
+
+		RangerTagDef rangerTagDef = tagREST.createTagDef(oldTagDef, true);
+		Assert.assertEquals(rangerTagDef.getName(), newTagDef.getName());
+		Assert.assertEquals(rangerTagDef.getId(), newTagDef.getId());
+		Assert.assertNotEquals(oldTagDef.getName(), rangerTagDef.getName());
+
+		try {
+			Mockito.verify(validator).preCreateTagDef(oldTagDef, true);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).updateTagDef(oldTagDef);
+		} catch (Exception e) {
+		}
+	}
+
+	@Test
+	public void test3createTagDef() {
+		RangerTagDef oldTagDef = new RangerTagDef();
+		RangerTagDef newTagDef = new RangerTagDef();
+		oldTagDef.setId(null);
+		newTagDef.setId(id);
+		newTagDef.setName(name);
+
+		try {
+			Mockito.when(validator.preCreateTagDef(oldTagDef, true)).thenReturn(oldTagDef);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.updateTagDef(oldTagDef)).thenReturn(newTagDef);
+		} catch (Exception e) {
+		}
+
+		RangerTagDef rangerTagDef = tagREST.createTagDef(oldTagDef, true);
+		
+		Assert.assertNotNull(rangerTagDef);
+		Assert.assertEquals(rangerTagDef.getId(), newTagDef.getId());
+		Assert.assertEquals(rangerTagDef.getName(), newTagDef.getName());
+		Assert.assertNotEquals(rangerTagDef.getName(), oldTagDef.getName());
+		
+		try {
+			Mockito.verify(validator).preCreateTagDef(oldTagDef, true);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).updateTagDef(oldTagDef);
+		} catch (Exception e) {
+		}
+	}
+	 
+	@Test
+	public void test4createTagDef() {
+		RangerTagDef oldtagDef = new RangerTagDef(); 
+		oldtagDef.setId(id);
+		
+		try {
+			Mockito.when(validator.preCreateTagDef(oldtagDef, false)).thenReturn(
+					oldtagDef);
+		} catch (Exception e) {
+		}
+		Mockito.when(
+				restErrorUtil.createRESTException(Mockito.anyInt(),
+						Mockito.anyString(), Mockito.anyBoolean())).thenThrow(
+				new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		tagREST.createTagDef(oldtagDef, false);
+
+		try {
+			Mockito.verify(validator).preCreateTagDef(oldtagDef, false);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(),
+				Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test5deleteTagDef(){
+		try {
+			Mockito.doNothing().when(tagStore).deleteTagDef(id);
+		} catch (Exception e) {
+		}
+		tagREST.deleteTagDef(id);
+		try {
+			Mockito.verify(tagStore).deleteTagDef(id);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test6deleteTagDefByGuid() {
+		RangerTagDef oldTagDef = new RangerTagDef();
+		oldTagDef.setId(id);
+		oldTagDef.setGuid(gId);
+		
+		try {
+			Mockito.when(tagStore.getTagDefByGuid(oldTagDef.getGuid())).thenReturn(oldTagDef);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(tagStore).deleteTagDef(oldTagDef.getId());
+		} catch (Exception e) {
+		}
+		
+		tagREST.deleteTagDefByGuid(oldTagDef.getGuid());
+		Assert.assertNotNull(oldTagDef.getId());
+		Assert.assertNotNull(oldTagDef.getGuid());
+		
+		try {
+			Mockito.verify(tagStore).getTagDefByGuid(oldTagDef.getGuid());
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).deleteTagDef(oldTagDef.getId());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test7deleteTagDefByGuid() {
+		try {
+			Mockito.when(tagStore.getTagDefByGuid(gId)).thenReturn(null);
+		} catch (Exception e) {
+		}
+		tagREST.deleteTagDefByGuid(gId);
+		try {
+			Mockito.verify(tagStore).getTagDefByGuid(gId);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test8getTagDef() {
+		RangerTagDef oldTagDef = new RangerTagDef();
+		oldTagDef.setId(id);
+		oldTagDef.setName(name);
+		
+		try {
+			Mockito.when(tagStore.getTagDef(id)).thenReturn(oldTagDef);
+		} catch (Exception e) {
+		}
+		
+		RangerTagDef rangerTagDef = tagREST.getTagDef(id);
+		Assert.assertNotNull(rangerTagDef.getId());
+		Assert.assertEquals(rangerTagDef.getId(), oldTagDef.getId());
+		Assert.assertEquals(rangerTagDef.getName(), oldTagDef.getName());
+		
+		try {
+			Mockito.verify(tagStore).getTagDef(id);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test9getTagDef() {
+		try {
+			Mockito.when(tagStore.getTagDef(id)).thenReturn(null);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		tagREST.getTagDef(id);
+		
+		try {
+			Mockito.verify(tagStore).getTagDef(id);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(),
+				Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test10getTagDefByGuid() {
+		RangerTagDef oldTagDef = new RangerTagDef();
+		oldTagDef.setId(id);
+		oldTagDef.setGuid(gId);
+		
+		try {
+			Mockito.when(tagStore.getTagDefByGuid(gId)).thenReturn(oldTagDef);
+		} catch (Exception e) {
+		}
+		
+		RangerTagDef rangerTagDef = tagREST.getTagDefByGuid(gId);
+		Assert.assertNotNull(oldTagDef.getGuid());
+		Assert.assertEquals(rangerTagDef.getGuid(), oldTagDef.getGuid());
+		Assert.assertEquals(rangerTagDef.getId(), oldTagDef.getId());
+		
+		try {
+			Mockito.verify(tagStore).getTagDefByGuid(gId);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test11getTagDefByGuid() {
+		try {
+			Mockito.when(tagStore.getTagDefByGuid(gId)).thenReturn(null);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		tagREST.getTagDefByGuid(gId);
+		
+		try {
+			Mockito.verify(tagStore).getTagDefByGuid(gId);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(),
+				Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test12getTagDefByName() {
+		RangerTagDef oldTagDef = new RangerTagDef();
+		oldTagDef.setId(id);
+		oldTagDef.setName(name);
+		
+		try {
+			Mockito.when(tagStore.getTagDefByName(name)).thenReturn(oldTagDef);
+		} catch (Exception e) {
+		}
+		
+		RangerTagDef rangerTagDef = tagREST.getTagDefByName(name);
+		Assert.assertNotNull(rangerTagDef.getName());
+		Assert.assertEquals(rangerTagDef.getName(), oldTagDef.getName());
+		Assert.assertEquals(rangerTagDef.getId(), oldTagDef.getId());
+		
+		try {
+			Mockito.verify(tagStore).getTagDefByName(name);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test13getTagDefByName() {
+		try {
+			Mockito.when(tagStore.getTagDefByName(name)).thenReturn(null);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		tagREST.getTagDefByName(name);
+		
+		try {
+			Mockito.verify(tagStore).getTagDefByName(name);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(),
+				Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test14getAllTagDefs() {
+		List<RangerTagDef> ret = new ArrayList<RangerTagDef>();
+		RangerTagDef rangerTagDef = new RangerTagDef();
+		rangerTagDef.setId(id);
+		rangerTagDef.setVersion(5L);
+		ret.add(rangerTagDef);
+		
+		try {
+			Mockito.when(tagStore.getTagDefs((SearchFilter)Mockito.anyObject())).thenReturn(ret);
+		} catch (Exception e) {
+		}
+		List<RangerTagDef> result = tagREST.getAllTagDefs();
+		
+		Assert.assertNotNull(result);
+		Assert.assertEquals(result.get(0).getId(), ret.get(0).getId());
+		Assert.assertEquals(result.get(0).getVersion(), ret.get(0).getVersion());
+		
+		try {
+			Mockito.verify(tagStore).getTagDefs((SearchFilter)Mockito.anyObject());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test15getAllTagDefs() {
+		try {
+			Mockito.when(tagStore.getTagDefs((SearchFilter)Mockito.anyObject())).thenReturn(null);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		tagREST.getAllTagDefs();
+		
+		try {
+			Mockito.verify(tagStore).getTagDefs((SearchFilter)Mockito.anyObject());
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(),
+				Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test16getTagTypes(){
+		List<String> ret = new ArrayList<String>();
+		ret.add(name);
+		
+		try {
+			Mockito.when(tagStore.getTagTypes()).thenReturn(ret);
+		} catch (Exception e) {
+		}
+		List<String> result = tagREST.getTagTypes();
+		Assert.assertNotNull(result);
+		
+		try {
+			Mockito.verify(tagStore).getTagTypes();
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test17createTag() {
+		RangerTag oldTag = null; 
+		RangerTag newTag = new RangerTag();
+		newTag.setId(id);
+		newTag.setGuid(gId);
+		
+		try {
+			Mockito.when(validator.preCreateTag(oldTag)).thenReturn(oldTag);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.createTag(oldTag)).thenReturn(newTag);
+		} catch (Exception e) {
+		}
+		RangerTag rangerTag = tagREST.createTag(oldTag, false);
+		
+		Assert.assertEquals(rangerTag.getId(),newTag.getId());
+		Assert.assertEquals(rangerTag.getGuid(), newTag.getGuid());
+		
+		try {
+			Mockito.verify(validator).preCreateTag(oldTag);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).createTag(oldTag);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test18createTag(){
+		RangerTag oldTag = new RangerTag();
+		RangerTag newTag = new RangerTag();
+		oldTag.setId(id);
+		newTag.setId(id);
+		newTag.setVersion(5L);
+
+		try {
+			Mockito.when(validator.preCreateTag(oldTag)).thenReturn(oldTag);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(validator).preUpdateTag(oldTag.getId(), oldTag);
+		} catch (Exception e1) {
+		}
+		try {
+			Mockito.when(tagStore.updateTag(oldTag)).thenReturn(newTag);
+		} catch (Exception e) {
+		}
+		
+		RangerTag rangerTag = tagREST.createTag(oldTag,true);
+		Assert.assertEquals(rangerTag.getVersion(), newTag.getVersion());
+		Assert.assertNotNull(newTag.getVersion());
+		Assert.assertNotEquals(oldTag.getVersion(), newTag.getVersion());
+		Assert.assertEquals(oldTag.getId(), newTag.getId());
+		
+		try {
+			Mockito.verify(validator).preCreateTag(oldTag);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(validator).preUpdateTag(oldTag.getId(), oldTag);
+		} catch (Exception e1) {
+		}
+		try {
+			Mockito.verify(tagStore).updateTag(oldTag);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test19createTag(){
+		RangerTag oldTag = new RangerTag();
+		oldTag.setId(id);	
+		
+		try {
+			Mockito.when(validator.preCreateTag(oldTag)).thenReturn(oldTag);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		tagREST.createTag(oldTag,false);
+		
+		try {
+			Mockito.verify(validator).preCreateTag(oldTag);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test20updateTagByGuid() {
+		RangerTag oldTag = new RangerTag();
+		RangerTag newTag = new RangerTag();
+		oldTag.setGuid(gId);
+		newTag.setGuid(gId);
+		newTag.setVersion(5L);
+		
+		try {
+			Mockito.doNothing().when(validator).preUpdateTagByGuid(gId, oldTag);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.updateTag(oldTag)).thenReturn(newTag);
+		} catch (Exception e) {
+		}
+				
+		RangerTag rangerTag = tagREST.updateTagByGuid(gId, oldTag);
+		Assert.assertEquals(oldTag.getGuid(), newTag.getGuid());
+		Assert.assertNotEquals(rangerTag.getVersion(), oldTag.getVersion());
+		Assert.assertEquals(rangerTag.getVersion(), newTag.getVersion());
+		
+		try {
+			Mockito.verify(validator).preUpdateTagByGuid(gId, oldTag);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).updateTag(oldTag);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test21deleteTag() {
+		RangerTag oldTag = new RangerTag();
+		oldTag.setId(id);
+		
+		try {
+			Mockito.when(validator.preDeleteTag(id)).thenReturn(oldTag);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(tagStore).deleteTag(id);
+		} catch (Exception e) {
+		}
+		
+		tagREST.deleteTag(id);
+		Assert.assertNotNull(oldTag.getId());
+		
+		try {
+			Mockito.verify(validator).preDeleteTag(id);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).deleteTag(id);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test22deleteTagByGuid() {
+		RangerTag oldTag = new RangerTag();
+		oldTag.setId(id);
+		oldTag.setGuid(gId);
+		
+		try {
+			Mockito.when(validator.preDeleteTagByGuid(gId)).thenReturn(oldTag);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(tagStore).deleteTag(oldTag.getId());
+		} catch (Exception e) {
+		}
+		
+		tagREST.deleteTagByGuid(gId);
+		Assert.assertNotNull(oldTag.getId());
+		Assert.assertNotNull(oldTag.getGuid());
+		
+		try {
+			Mockito.verify(validator).preDeleteTagByGuid(gId);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).deleteTag(oldTag.getId());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test23getTag() {
+		RangerTag oldTag = new RangerTag();
+		oldTag.setId(id);
+		oldTag.setGuid(gId);
+		
+		try {
+			Mockito.when(tagStore.getTag(id)).thenReturn(oldTag);
+		} catch (Exception e) {
+		}
+		RangerTag rangerTag = tagREST.getTag(id);
+		Assert.assertNotNull(oldTag.getId());
+		Assert.assertEquals(rangerTag.getId(), oldTag.getId());
+		Assert.assertEquals(rangerTag.getGuid(), oldTag.getGuid());
+		
+		try {
+			Mockito.verify(tagStore).getTag(id);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test24getTagByGuid() {
+		RangerTag oldTag = new RangerTag();
+		oldTag.setId(id);
+		oldTag.setGuid(gId);
+		
+		try {
+			Mockito.when(tagStore.getTagByGuid(gId)).thenReturn(oldTag);
+		} catch (Exception e) {
+		}
+		RangerTag rangerTag = tagREST.getTagByGuid(gId);
+		Assert.assertNotNull(oldTag.getGuid());
+		Assert.assertEquals(rangerTag.getGuid(), oldTag.getGuid());
+		Assert.assertEquals(rangerTag.getId(), oldTag.getId());
+		Assert.assertNotNull(rangerTag.getId());
+		
+		try {
+			Mockito.verify(tagStore).getTagByGuid(gId);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test25getTagsByType() {
+		String type = "file";
+		List<RangerTag> tag = new ArrayList<RangerTag>();
+		RangerTag rTag = new RangerTag();
+		rTag.setType(type);
+		tag.add(rTag);
+		
+		try {
+			Mockito.when(tagStore.getTagsByType(type)).thenReturn(tag);
+		} catch (Exception e) {
+		}
+		List<RangerTag> rangerTag = tagREST.getTagsByType(type);
+		Assert.assertEquals(rangerTag.get(0).getType(), tag.get(0).getType());
+		
+		try {
+			Mockito.verify(tagStore).getTagsByType(type);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test26getAllTags() {
+		List<RangerTag> ret = new ArrayList<RangerTag>();
+		RangerTag rangerTag = new RangerTag();
+		rangerTag.setId(id);
+		rangerTag.setGuid(gId);
+		ret.add(rangerTag);
+		
+		try {
+			Mockito.when(tagStore.getTags((SearchFilter)Mockito.anyObject())).thenReturn(ret);
+		} catch (Exception e) {
+		}
+		
+		List<RangerTag> result = tagREST.getAllTags();
+		Assert.assertEquals(result.get(0).getId(), ret.get(0).getId());
+		Assert.assertEquals(result.get(0).getVersion(), ret.get(0).getVersion());
+		Assert.assertNotNull(result.get(0).getId());
+		
+		try {
+			Mockito.verify(tagStore).getTags((SearchFilter)Mockito.anyObject());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test60getAllTags() {
+		List<RangerTag> ret = new ArrayList<RangerTag>();
+		
+		try {
+			Mockito.when(tagStore.getTags((SearchFilter)Mockito.anyObject())).thenReturn(ret);
+		} catch (Exception e) {
+		}
+		
+		List<RangerTag> result = tagREST.getAllTags();
+		Assert.assertNotNull(result);
+		
+		try {
+			Mockito.verify(tagStore).getTags((SearchFilter)Mockito.anyObject());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test27createServiceResource() {
+		RangerServiceResource oldRSR = null;
+		RangerServiceResource newRSR = new RangerServiceResource();
+		newRSR.setId(id);
+		newRSR.setGuid(gId);
+		
+		try {
+			Mockito.when(validator.preCreateServiceResource(oldRSR)).thenReturn(oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.createServiceResource(oldRSR)).thenReturn(newRSR);
+		} catch (Exception e) {
+		}
+		
+		RangerServiceResource rangerServiceResource = tagREST.createServiceResource(oldRSR, false);
+		Assert.assertNotNull(rangerServiceResource.getId());
+		Assert.assertEquals(rangerServiceResource.getId(), newRSR.getId());
+		Assert.assertEquals(rangerServiceResource.getGuid(), newRSR.getGuid());
+		
+		try {
+			Mockito.verify(validator).preCreateServiceResource(oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).createServiceResource(oldRSR);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test28createServiceResource() {
+		RangerServiceResource oldRSR = new RangerServiceResource();
+		RangerServiceResource newRSR = new RangerServiceResource();
+		oldRSR.setId(id);
+		newRSR.setId(id);
+		newRSR.setVersion(5L);
+		
+		try {
+			Mockito.when(validator.preCreateServiceResource(oldRSR)).thenReturn(oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(validator).preUpdateServiceResource(oldRSR.getId(), oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.updateServiceResource(oldRSR)).thenReturn(newRSR);
+		} catch (Exception e) {
+		}
+		
+		RangerServiceResource rangerServiceResource = tagREST.createServiceResource(oldRSR, true);
+		Assert.assertNotEquals(oldRSR.getVersion(), newRSR.getVersion());
+		Assert.assertEquals(rangerServiceResource.getId(), newRSR.getId());
+		Assert.assertEquals(rangerServiceResource.getId(), oldRSR.getId());
+		
+		try {
+			Mockito.verify(validator).preCreateServiceResource(oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(validator).preUpdateServiceResource(oldRSR.getId(), oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).updateServiceResource(oldRSR);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test29createServiceResource(){
+		RangerServiceResource oldRSR = new RangerServiceResource();
+		
+		try {
+			Mockito.when(validator.preCreateServiceResource(oldRSR)).thenReturn(oldRSR);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		tagREST.createServiceResource(oldRSR, false);
+		
+		try {
+			Mockito.verify(validator).preCreateServiceResource(oldRSR);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test30updateServiceResourceByGuid() {
+		RangerServiceResource oldSRS = new RangerServiceResource();
+		RangerServiceResource newSRS = new RangerServiceResource();
+		oldSRS.setId(id);
+		oldSRS.setGuid(gId);
+		newSRS.setId(id);
+		newSRS.setGuid(gId);
+		newSRS.setVersion(5L);
+		
+		try {
+			Mockito.doNothing().when(validator).preUpdateServiceResourceByGuid(gId, oldSRS);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.updateServiceResource(oldSRS)).thenReturn(newSRS);
+		} catch (Exception e) {
+		}
+		
+		RangerServiceResource rangerServiceResource = tagREST.updateServiceResourceByGuid(gId, oldSRS);
+		Assert.assertEquals(oldSRS.getId(), newSRS.getId());
+		Assert.assertEquals(oldSRS.getGuid(), newSRS.getGuid());
+		Assert.assertNotEquals(oldSRS.getVersion(), newSRS.getVersion());
+		Assert.assertEquals(rangerServiceResource.getVersion(), newSRS.getVersion());
+		
+		try {
+			Mockito.verify(validator).preUpdateServiceResourceByGuid(gId, oldSRS);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).updateServiceResource(oldSRS);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test31deleteServiceResource() {
+		RangerServiceResource oldSRS = new RangerServiceResource();
+		oldSRS.setId(id);
+		
+		try {
+			Mockito.when(validator.preDeleteServiceResource(id)).thenReturn(oldSRS);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(tagStore).deleteServiceResource(id);
+		} catch (Exception e) {
+		}
+		
+		tagREST.deleteServiceResource(id);
+		Assert.assertNotNull(oldSRS.getId());
+		
+		try {
+			Mockito.verify(validator).preDeleteServiceResource(id);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).deleteServiceResource(id);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test32getServiceResource() {
+		RangerServiceResource oldSRS = new RangerServiceResource();
+		oldSRS.setId(id);
+		oldSRS.setGuid(gId);
+		
+		try {
+			Mockito.when(tagStore.getServiceResource(id)).thenReturn(oldSRS);
+		} catch (Exception e) {
+		}
+		RangerServiceResource rangerServiceResource = tagREST.getServiceResource(id);
+		
+		Assert.assertNotNull(rangerServiceResource);
+		Assert.assertEquals(rangerServiceResource.getId(), oldSRS.getId());
+		Assert.assertEquals(rangerServiceResource.getGuid(), oldSRS.getGuid());
+		try {
+			Mockito.verify(tagStore).getServiceResource(id);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test33getServiceResourceByGuid() {
+		RangerServiceResource oldSRS = new RangerServiceResource();
+		oldSRS.setId(id);
+		oldSRS.setGuid(gId);
+		
+		try {
+			Mockito.when(tagStore.getServiceResourceByGuid(gId)).thenReturn(oldSRS);
+		} catch (Exception e) {
+		}
+		RangerServiceResource rangerServiceResource = tagREST.getServiceResourceByGuid(gId);
+		
+		Assert.assertNotNull(rangerServiceResource);
+		Assert.assertEquals(rangerServiceResource.getGuid(), oldSRS.getGuid());
+		Assert.assertEquals(rangerServiceResource.getId(), oldSRS.getId());
+		try {
+			Mockito.verify(tagStore).getServiceResourceByGuid(gId);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test34getServiceResourcesByService() {
+		List<RangerServiceResource> ret = new ArrayList<RangerServiceResource>();
+		RangerServiceResource rangerServiceResource = new RangerServiceResource();
+		rangerServiceResource.setId(id);
+		rangerServiceResource.setServiceName(serviceName);
+		ret.add(rangerServiceResource);
+		
+		try {
+			Mockito.when(tagStore.getServiceResourcesByService(serviceName)).thenReturn(ret);
+		} catch (Exception e) {
+		}
+		
+		List<RangerServiceResource> reslut = tagREST.getServiceResourcesByService(serviceName);
+		Assert.assertNotNull(reslut.get(0).getId());
+		Assert.assertEquals(reslut.get(0).getId(), ret.get(0).getId());
+		Assert.assertEquals(reslut.get(0).getServiceName(), ret.get(0).getServiceName());
+	
+		try {
+			Mockito.verify(tagStore).getServiceResourcesByService(serviceName);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test 
+	public void test35getServiceResourcesByService() {
+		List<RangerServiceResource> oldSRS = new ArrayList<RangerServiceResource>();
+		RangerServiceResource rangerServiceResource = new RangerServiceResource();
+		rangerServiceResource.setId(id);
+		rangerServiceResource.setServiceName(serviceName);
+		oldSRS.add(rangerServiceResource);		
+		
+		try {
+			Mockito.when(tagStore.getServiceResourcesByService(serviceName)).thenReturn(oldSRS);
+		} catch (Exception e) {
+		}
+		
+		List<RangerServiceResource> result = tagREST.getServiceResourcesByService(serviceName);
+		Assert.assertNotNull(result);
+		Assert.assertEquals(result.size(), 1);
+		Assert.assertEquals(result.get(0).getId(), id);
+		Assert.assertEquals(result.get(0).getServiceName(), serviceName);
+	
+		try {
+			Mockito.verify(tagStore).getServiceResourcesByService(serviceName);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test 
+	public void test59getServiceResourcesByService() {
+		List<RangerServiceResource> oldSRS = new ArrayList<RangerServiceResource>();		
+		
+		try {
+			Mockito.when(tagStore.getServiceResourcesByService(serviceName)).thenReturn(oldSRS);
+		} catch (Exception e) {
+		}
+		
+		List<RangerServiceResource> result = tagREST.getServiceResourcesByService(serviceName);
+		Assert.assertNotNull(result);
+	
+		try {
+			Mockito.verify(tagStore).getServiceResourcesByService(serviceName);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test36getServiceResourceByServiceAndResourceSignature() {
+		RangerServiceResource oldSRS = new RangerServiceResource();
+		oldSRS.setId(id);
+		oldSRS.setResourceSignature(resourceSignature);
+		oldSRS.setServiceName(serviceName);
+		
+		try {
+			Mockito.when(tagStore.getServiceResourceByServiceAndResourceSignature(serviceName, resourceSignature)).thenReturn(oldSRS);
+		} catch (Exception e) {
+		}
+		
+		RangerServiceResource rangerServiceResource = tagREST.getServiceResourceByServiceAndResourceSignature(serviceName, resourceSignature);
+		Assert.assertEquals(rangerServiceResource.getId(), oldSRS.getId());
+		Assert.assertEquals(rangerServiceResource.getServiceName(), oldSRS.getServiceName());
+		Assert.assertEquals(rangerServiceResource.getResourceSignature(), oldSRS.getResourceSignature());
+		
+		try {
+			Mockito.verify(tagStore).getServiceResourceByServiceAndResourceSignature(serviceName, resourceSignature);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test37getAllServiceResources() {
+		List<RangerServiceResource> ret = new ArrayList<RangerServiceResource>();
+		RangerServiceResource rangerServiceResource =  new RangerServiceResource();
+		rangerServiceResource.setId(id);
+		rangerServiceResource.setServiceName(serviceName);
+		ret.add(rangerServiceResource);
+		
+		try {
+			Mockito.when(tagStore.getServiceResources((SearchFilter)Mockito.anyObject())).thenReturn(ret);
+		} catch (Exception e) {
+		}
+		List<RangerServiceResource> result = tagREST.getAllServiceResources();
+		Assert.assertNotNull(result.get(0).getId());
+		Assert.assertEquals(result.get(0).getId(), ret.get(0).getId());
+		Assert.assertEquals(result.get(0).getServiceName(), ret.get(0).getServiceName());
+		
+		try {
+			Mockito.verify(tagStore).getServiceResources((SearchFilter)Mockito.anyObject());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test38createTagResourceMap() {
+		RangerTagResourceMap oldTagResourceMap = null;
+		RangerTagResourceMap newTagResourceMap = new RangerTagResourceMap();
+		newTagResourceMap.setTagId(id);
+		newTagResourceMap.setResourceId(id);
+		
+		try {
+			Mockito.when(tagStore.getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(validator.preCreateTagResourceMap(tagGuid, resourceGuid)).thenReturn(newTagResourceMap);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.createTagResourceMap(newTagResourceMap)).thenReturn(newTagResourceMap);
+		} catch (Exception e) {
+		}
+		
+		RangerTagResourceMap rangerTagResourceMap = tagREST.createTagResourceMap(tagGuid, resourceGuid, false);
+		Assert.assertEquals(rangerTagResourceMap.getTagId(), newTagResourceMap.getTagId());
+		Assert.assertEquals(rangerTagResourceMap.getResourceId(), newTagResourceMap.getResourceId());
+		
+		try {
+			Mockito.verify(tagStore).getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(validator).preCreateTagResourceMap(tagGuid, resourceGuid);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).createTagResourceMap(newTagResourceMap);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test39createTagResourceMap() {
+		RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
+		
+		try {
+			Mockito.when(tagStore.getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(),Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		tagREST.createTagResourceMap(tagGuid, resourceGuid, false);
+		
+		try {
+			Mockito.verify(tagStore).getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(),Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test40createTagResourceMap() {
+		RangerTagResourceMap oldTagResourceMap = null;
+		RangerTagResourceMap newTagResourceMap = new RangerTagResourceMap();
+		newTagResourceMap.setId(id);
+		newTagResourceMap.setGuid(gId);
+		RangerTagResourceMap finalTagResourceMap = new RangerTagResourceMap();
+		finalTagResourceMap.setId(id);
+		finalTagResourceMap.setGuid(gId);
+		finalTagResourceMap.setVersion(5L);
+		
+		try {
+			Mockito.when(tagStore.getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(validator.preCreateTagResourceMap(tagGuid, resourceGuid)).thenReturn(newTagResourceMap);
+		} catch (Exception e1) {
+		}
+		try {
+			Mockito.when(tagStore.createTagResourceMap(newTagResourceMap)).thenReturn(finalTagResourceMap);
+		} catch (Exception e1) {
+		}
+		RangerTagResourceMap result = tagREST.createTagResourceMap(tagGuid, resourceGuid, true);
+		Assert.assertNotNull(result.getId());
+		Assert.assertEquals(result.getGuid(), finalTagResourceMap.getGuid());
+		Assert.assertEquals(result.getId(), finalTagResourceMap.getId());
+		Assert.assertEquals(result.getVersion(), finalTagResourceMap.getVersion());
+		
+		try {
+			Mockito.verify(tagStore).getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(validator).preCreateTagResourceMap(tagGuid, resourceGuid);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).createTagResourceMap(newTagResourceMap);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test41deleteTagResourceMap() {
+		RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
+		oldTagResourceMap.setId(id);
+		try {
+			Mockito.when(validator.preDeleteTagResourceMap(id)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(tagStore).deleteTagResourceMap(id);
+		} catch (Exception e) {
+		}
+		
+		tagREST.deleteTagResourceMap(id);
+		Assert.assertNotNull(oldTagResourceMap.getId());
+		try {
+			Mockito.verify(validator).preDeleteTagResourceMap(id);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).deleteTagResourceMap(id);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test42deleteTagResourceMapByGuid() {
+		RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
+		oldTagResourceMap.setId(id);
+		oldTagResourceMap.setGuid(gId);
+		try {
+			Mockito.when(validator.preDeleteTagResourceMapByGuid(gId)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(tagStore).deleteServiceResource(oldTagResourceMap.getId());
+		} catch (Exception e) {
+		}
+		
+		tagREST.deleteTagResourceMapByGuid(gId);
+		Assert.assertNotNull(oldTagResourceMap.getId());
+		Assert.assertNotNull(oldTagResourceMap.getGuid());
+		
+		try {
+			Mockito.verify(validator).preDeleteTagResourceMapByGuid(gId);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).deleteServiceResource(oldTagResourceMap.getId());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test43deleteTagResourceMap() {
+		RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
+		oldTagResourceMap.setId(id);
+		
+		try {
+			Mockito.when(validator.preDeleteTagResourceMap(tagGuid, resourceGuid)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(tagStore).deleteTagResourceMap(oldTagResourceMap.getId());
+		} catch (Exception e) {
+		}
+		
+		tagREST.deleteTagResourceMap(tagGuid, resourceGuid);
+		try {
+			Mockito.verify(validator).preDeleteTagResourceMap(tagGuid, resourceGuid);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test44getTagResourceMap() {
+		RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
+		oldTagResourceMap.setId(id);
+		oldTagResourceMap.setGuid(gId);
+		
+		try {
+			Mockito.when(tagStore.getTagResourceMap(id)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		
+		RangerTagResourceMap rangerTagResourceMap = tagREST.getTagResourceMap(id);
+		Assert.assertNotNull(rangerTagResourceMap.getId());
+		Assert.assertEquals(rangerTagResourceMap.getId(), oldTagResourceMap.getId());
+		Assert.assertEquals(rangerTagResourceMap.getGuid(), oldTagResourceMap.getGuid());
+		try {
+			Mockito.verify(tagStore).getTagResourceMap(id);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test45getTagResourceMapByGuid() {
+		RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
+		oldTagResourceMap.setId(id);
+		oldTagResourceMap.setGuid(gId);
+		
+		try {
+			Mockito.when(tagStore.getTagResourceMapByGuid(gId)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		
+		RangerTagResourceMap rangerTagResourceMap = tagREST.getTagResourceMapByGuid(gId);
+		Assert.assertNotNull(rangerTagResourceMap.getId());
+		Assert.assertEquals(rangerTagResourceMap.getId(), oldTagResourceMap.getId());
+		Assert.assertEquals(rangerTagResourceMap.getGuid(), oldTagResourceMap.getGuid());
+		try {
+			Mockito.verify(tagStore).getTagResourceMapByGuid(gId);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test46getTagResourceMap() {
+		RangerTagResourceMap oldTagResourceMap = new RangerTagResourceMap();
+		oldTagResourceMap.setId(id);
+		oldTagResourceMap.setTagId(id);
+		
+		try {
+			Mockito.when(tagStore.getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid)).thenReturn(oldTagResourceMap);
+		} catch (Exception e) {
+		}
+		RangerTagResourceMap rangerTagResourceMap = tagREST.getTagResourceMap(tagGuid, resourceGuid);
+		Assert.assertNotNull(rangerTagResourceMap.getId());
+		Assert.assertEquals(rangerTagResourceMap.getId(), oldTagResourceMap.getId());
+		Assert.assertEquals(rangerTagResourceMap.getTagId(), oldTagResourceMap.getTagId());
+		try {
+			Mockito.verify(tagStore).getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test47getAllTagResourceMaps() {
+		List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
+		RangerTagResourceMap rangerTagResourceMap = new RangerTagResourceMap();
+		rangerTagResourceMap.setId(id);
+		rangerTagResourceMap.setTagId(id);
+		ret.add(rangerTagResourceMap);
+		
+		try {
+			Mockito.when(tagStore.getTagResourceMaps((SearchFilter)Mockito.anyObject())).thenReturn(ret);
+		} catch (Exception e) {
+		}
+		
+		List<RangerTagResourceMap> result = tagREST.getAllTagResourceMaps();
+		Assert.assertNotNull(result.get(0).getId());
+		Assert.assertEquals(result.get(0).getId(), ret.get(0).getId());
+		Assert.assertEquals(result.get(0).getTagId(), ret.get(0).getTagId());
+		
+		try {
+			Mockito.verify(tagStore).getTagResourceMaps((SearchFilter)Mockito.anyObject());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test58getAllTagResourceMaps() {
+		List<RangerTagResourceMap> ret = new ArrayList<RangerTagResourceMap>();
+		
+		try {
+			Mockito.when(tagStore.getTagResourceMaps((SearchFilter)Mockito.anyObject())).thenReturn(ret);
+		} catch (Exception e) {
+		}
+		
+		List<RangerTagResourceMap> result = tagREST.getAllTagResourceMaps();
+		Assert.assertNotNull(result);
+		
+		try {
+			Mockito.verify(tagStore).getTagResourceMaps((SearchFilter)Mockito.anyObject());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test48deleteServiceResourceByGuid() {
+		RangerServiceResource oldRSR = new RangerServiceResource();
+		oldRSR.setId(id);
+		oldRSR.setGuid(gId);
+		List<RangerTagResourceMap> tagResourceMaps = new ArrayList<RangerTagResourceMap>();
+		RangerTagResourceMap rangerTagResourceMap = new RangerTagResourceMap();
+		rangerTagResourceMap.setId(id);
+		rangerTagResourceMap.setTagId(id);
+		tagResourceMaps.add(rangerTagResourceMap);
+		
+		try {
+			Mockito.when(validator.preDeleteServiceResourceByGuid(gId, true)).thenReturn(oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.getTagResourceMapsForResourceGuid(oldRSR.getGuid())).thenReturn(tagResourceMaps);
+		} catch (Exception e) {
+		}
+		tagREST.deleteServiceResourceByGuid(gId, true);
+		
+		try {
+			Mockito.verify(validator).preDeleteServiceResourceByGuid(gId, true);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).getTagResourceMapsForResourceGuid(oldRSR.getGuid());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test49deleteServiceResourceByGuid() {
+		RangerServiceResource oldRSR = new RangerServiceResource();
+		oldRSR.setId(id);
+		oldRSR.setGuid(gId);
+		
+		try {
+			Mockito.when(validator.preDeleteServiceResourceByGuid(gId, false)).thenReturn(oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.doNothing().when(tagStore).deleteServiceResource(oldRSR.getId());
+		} catch (Exception e) {
+		}
+		
+		tagREST.deleteServiceResourceByGuid(gId, false);
+		
+		try {
+			Mockito.verify(validator).preDeleteServiceResourceByGuid(gId, false);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test61deleteServiceResourceByGuid() {
+		RangerServiceResource oldRSR = new RangerServiceResource();
+		oldRSR.setId(id);
+		oldRSR.setGuid(gId);
+		List<RangerTagResourceMap> tagResourceMaps = new ArrayList<RangerTagResourceMap>();
+		
+		try {
+			Mockito.when(validator.preDeleteServiceResourceByGuid(gId, true)).thenReturn(oldRSR);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.when(tagStore.getTagResourceMapsForResourceGuid(oldRSR.getGuid())).thenReturn(tagResourceMaps);
+		} catch (Exception e) {
+		}
+		tagREST.deleteServiceResourceByGuid(gId, true);
+		
+		try {
+			Mockito.verify(validator).preDeleteServiceResourceByGuid(gId, true);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).getTagResourceMapsForResourceGuid(oldRSR.getGuid());
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test50getServiceTagsIfUpdated() {
+		ServiceTags oldServiceTag = null;
+		
+		try {
+			Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(),Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		
+		tagREST.getServiceTagsIfUpdated(serviceName, lastKnownVersion, pluginId);
+		
+		try {
+			Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(),Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test51getServiceTagsIfUpdated() {
+		ServiceTags oldServiceTag = new ServiceTags();
+		oldServiceTag.setServiceName(serviceName);
+		oldServiceTag.setTagVersion(5L);
+		
+		try {
+			Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
+		} catch (Exception e) {
+		}
+		
+		ServiceTags serviceTags = tagREST.getServiceTagsIfUpdated(serviceName, lastKnownVersion, pluginId);
+		Assert.assertEquals(serviceTags.getServiceName(), oldServiceTag.getServiceName());
+		Assert.assertEquals(serviceTags.getTagVersion(), oldServiceTag.getTagVersion());
+		
+		try {
+			Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test52getSecureServiceTagsIfUpdatedIsKeyAdminTrue() {
+		boolean isAdmin = false;
+		boolean isKeyAdmin = true;
+		ServiceTags oldServiceTag = new ServiceTags();
+		oldServiceTag.setServiceName(serviceName);
+		oldServiceTag.setTagVersion(5L);
+		
+		XXService xService = new XXService();
+		xService.setId(id);
+		xService.setName(serviceName);
+		xService.setType(5L);
+		
+		XXServiceDef xServiceDef = new XXServiceDef();
+		xServiceDef.setId(id);
+		xServiceDef.setVersion(5L);
+		xServiceDef.setImplclassname("org.apache.ranger.services.kms.RangerServiceKMS");
+		
+		RangerService rangerService = new RangerService();
+		rangerService.setId(id);
+		rangerService.setName(serviceName);
+		
+		XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
+		XXServiceDefDao xXServiceDefDao  = Mockito.mock(XXServiceDefDao.class);
+		
+		Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
+		Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
+
+		Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
+		Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
+		Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
+		Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
+		try {
+			Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
+		} catch (Exception e) {
+		}
+		
+		try {
+			Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
+		} catch (Exception e) {
+		}
+		
+		ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, pluginId);
+		Assert.assertNotNull(result.getServiceName());
+		Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
+		Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
+		
+		Mockito.verify(bizUtil).isAdmin();
+		Mockito.verify(bizUtil).isKeyAdmin();
+		Mockito.verify(daoManager).getXXService();
+		Mockito.verify(xXServiceDao).findByName(serviceName);
+		Mockito.verify(daoManager).getXXServiceDef();
+		Mockito.verify(xXServiceDefDao).getById(xService.getType());
+		try {
+			Mockito.verify(svcStore).getServiceByName(serviceName);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test53getSecureServiceTagsIfUpdatedIsAdminTrue() {
+		boolean isAdmin = true;
+		boolean isKeyAdmin = false;
+		ServiceTags oldServiceTag = new ServiceTags();
+		oldServiceTag.setServiceName(serviceName);
+		oldServiceTag.setTagVersion(5L);
+		
+		XXService xService = new XXService();
+		xService.setId(id);
+		xService.setName(serviceName);
+		xService.setType(5L);
+		
+		XXServiceDef xServiceDef = new XXServiceDef();
+		xServiceDef.setId(id);
+		xServiceDef.setVersion(5L);
+		
+		RangerService rangerService = new RangerService();
+		rangerService.setId(id);
+		rangerService.setName(serviceName);
+		
+		XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
+		XXServiceDefDao xXServiceDefDao  = Mockito.mock(XXServiceDefDao.class);
+		
+		Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
+		Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
+
+		Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
+		Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
+		Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
+		Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
+		try {
+			Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
+		} catch (Exception e) {
+		}
+		
+		try {
+			Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
+		} catch (Exception e) {
+		}
+		
+		ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, pluginId);
+		Assert.assertNotNull(result.getServiceName());
+		Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
+		Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
+		
+		Mockito.verify(bizUtil).isAdmin();
+		Mockito.verify(bizUtil).isKeyAdmin();
+		Mockito.verify(daoManager).getXXService();
+		Mockito.verify(xXServiceDao).findByName(serviceName);
+		Mockito.verify(daoManager).getXXServiceDef();
+		Mockito.verify(xXServiceDefDao).getById(xService.getType());
+		try {
+			Mockito.verify(svcStore).getServiceByName(serviceName);
+		} catch (Exception e) {
+		}
+		try {
+			Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test54getSecureServiceTagsIfUpdatedIsKeyAdminFalse() {
+		boolean isAdmin = false;
+		boolean isKeyAdmin = false;
+		boolean isAllowed = true;
+		ServiceTags oldServiceTag = new ServiceTags();
+		oldServiceTag.setServiceName(serviceName);
+		oldServiceTag.setTagVersion(5L);
+		
+		XXService xService = new XXService();
+		xService.setId(id);
+		xService.setName(serviceName);
+		xService.setType(5L);
+		
+		XXServiceDef xServiceDef = new XXServiceDef();
+		xServiceDef.setId(id);
+		xServiceDef.setVersion(5L);
+		xServiceDef.setImplclassname("org.apache.ranger.services.kms.RangerServiceKMS");
+		
+		RangerService rangerService = new RangerService();
+		rangerService.setId(id);
+		rangerService.setName(serviceName);
+		
+		XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
+		XXServiceDefDao xXServiceDefDao  = Mockito.mock(XXServiceDefDao.class);
+		
+		Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
+		Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
+
+		Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
+		Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
+		Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
+		Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
+		try {
+			Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
+		} catch (Exception e) {
+		}
+		
+		Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
+		try {
+			Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
+		} catch (Exception e) {
+		}
+		
+		ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, pluginId);
+		Assert.assertNotNull(result.getServiceName());
+		Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
+		Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
+		
+		Mockito.verify(bizUtil).isAdmin();
+		Mockito.verify(bizUtil).isKeyAdmin();
+		Mockito.verify(daoManager).getXXService();
+		Mockito.verify(xXServiceDao).findByName(serviceName);
+		Mockito.verify(daoManager).getXXServiceDef();
+		Mockito.verify(xXServiceDefDao).getById(xService.getType());
+		try {
+			Mockito.verify(svcStore).getServiceByName(serviceName);
+		} catch (Exception e) {
+		}
+		Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
+		try {
+			Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test55getSecureServiceTagsIfUpdatedIsAdminFalse() {
+		boolean isAdmin = false;
+		boolean isKeyAdmin = false;
+		boolean isAllowed = true;
+		ServiceTags oldServiceTag = new ServiceTags();
+		oldServiceTag.setServiceName(serviceName);
+		oldServiceTag.setTagVersion(5L);
+		
+		XXService xService = new XXService();
+		xService.setId(id);
+		xService.setName(serviceName);
+		xService.setType(5L);
+		
+		XXServiceDef xServiceDef = new XXServiceDef();
+		xServiceDef.setId(id);
+		xServiceDef.setVersion(5L);
+		
+		RangerService rangerService = new RangerService();
+		rangerService.setId(id);
+		rangerService.setName(serviceName);
+		
+		XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
+		XXServiceDefDao xXServiceDefDao  = Mockito.mock(XXServiceDefDao.class);
+		
+		Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
+		Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
+
+		Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
+		Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
+		Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
+		Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
+		try {
+			Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
+		} catch (Exception e) {
+		}
+		
+		Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
+		try {
+			Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
+		} catch (Exception e) {
+		}
+		
+		ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, pluginId);
+		Assert.assertNotNull(result.getServiceName());
+		Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
+		Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
+		
+		Mockito.verify(bizUtil).isAdmin();
+		Mockito.verify(bizUtil).isKeyAdmin();
+		Mockito.verify(daoManager).getXXService();
+		Mockito.verify(xXServiceDao).findByName(serviceName);
+		Mockito.verify(daoManager).getXXServiceDef();
+		Mockito.verify(xXServiceDefDao).getById(xService.getType());
+		try {
+			Mockito.verify(svcStore).getServiceByName(serviceName);
+		} catch (Exception e) {
+		}
+		Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
+		try {
+			Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
+		} catch (Exception e) {
+		}
+	}
+	
+	@Test
+	public void test56getSecureServiceTagsIfUpdatedIsAllowedFalse() {
+		boolean isAdmin = false;
+		boolean isKeyAdmin = false;
+		boolean isAllowed = false;
+		ServiceTags oldServiceTag = new ServiceTags();
+		oldServiceTag.setServiceName(serviceName);
+		oldServiceTag.setTagVersion(5L);
+		
+		XXService xService = new XXService();
+		xService.setId(id);
+		xService.setName(serviceName);
+		xService.setType(5L);
+		
+		XXServiceDef xServiceDef = new XXServiceDef();
+		xServiceDef.setId(id);
+		xServiceDef.setVersion(5L);
+		
+		RangerService rangerService = new RangerService();
+		rangerService.setId(id);
+		rangerService.setName(serviceName);
+		
+		XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
+		XXServiceDefDao xXServiceDefDao  = Mockito.mock(XXServiceDefDao.class);
+		
+		Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
+		Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
+
+		Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
+		Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
+		Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
+		Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
+		try {
+			Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
+		} catch (Exception e) {
+		}
+		
+		Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		
+		tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, pluginId);
+		
+		Mockito.verify(bizUtil).isAdmin();
+		Mockito.verify(bizUtil).isKeyAdmin();
+		Mockito.verify(daoManager).getXXService();
+		Mockito.verify(xXServiceDao).findByName(serviceName);
+		Mockito.verify(daoManager).getXXServiceDef();
+		Mockito.verify(xXServiceDefDao).getById(xService.getType());
+		try {
+			Mockito.verify(svcStore).getServiceByName(serviceName);
+		} catch (Exception e) {
+		}
+		Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
+	}
+	
+	@Test
+	public void test57getSecureServiceTagsIfUpdated() {
+		boolean isAdmin = false;
+		boolean isKeyAdmin = false;
+		boolean isAllowed = true;
+		ServiceTags oldServiceTag = null;
+		
+		XXService xService = new XXService();
+		xService.setId(id);
+		xService.setName(serviceName);
+		xService.setType(5L);
+		
+		XXServiceDef xServiceDef = new XXServiceDef();
+		xServiceDef.setId(id);
+		xServiceDef.setVersion(5L);
+		
+		RangerService rangerService = new RangerService();
+		rangerService.setId(id);
+		rangerService.setName(serviceName);
+		
+		XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
+		XXServiceDefDao xXServiceDefDao  = Mockito.mock(XXServiceDefDao.class);
+		
+		Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
+		Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
+
+		Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
+		Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
+		Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
+		Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
+		try {
+			Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
+		} catch (Exception e) {
+		}
+		
+		Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
+		try {
+			Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
+		} catch (Exception e) {
+		}
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+		
+		tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, pluginId);
+		
+		Mockito.verify(bizUtil).isAdmin();
+		Mockito.verify(bizUtil).isKeyAdmin();
+		Mockito.verify(daoManager).getXXService();
+		Mockito.verify(xXServiceDao).findByName(serviceName);
+		Mockito.verify(daoManager).getXXServiceDef();
+		Mockito.verify(xXServiceDefDao).getById(xService.getType());
+		try {
+			Mockito.verify(svcStore).getServiceByName(serviceName);
+		} catch (Exception e) {
+		}
+		Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
+		try {
+			Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
+		} catch (Exception e) {
+		}
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/1c441f79/security-admin/src/test/java/org/apache/ranger/rest/TestUserREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/rest/TestUserREST.java b/security-admin/src/test/java/org/apache/ranger/rest/TestUserREST.java
new file mode 100644
index 0000000..a5ed33c
--- /dev/null
+++ b/security-admin/src/test/java/org/apache/ranger/rest/TestUserREST.java
@@ -0,0 +1,489 @@
+/*
+ * 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.rest;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.WebApplicationException;
+
+import org.apache.ranger.biz.UserMgr;
+import org.apache.ranger.biz.XUserMgr;
+import org.apache.ranger.common.MessageEnums;
+import org.apache.ranger.common.RESTErrorUtil;
+import org.apache.ranger.common.RangerConfigUtil;
+import org.apache.ranger.common.RangerConstants;
+import org.apache.ranger.common.SearchCriteria;
+import org.apache.ranger.common.SearchUtil;
+import org.apache.ranger.common.StringUtil;
+import org.apache.ranger.db.RangerDaoManager;
+import org.apache.ranger.db.XXPortalUserDao;
+import org.apache.ranger.entity.XXPortalUser;
+import org.apache.ranger.util.RangerRestUtil;
+import org.apache.ranger.view.VXPasswordChange;
+import org.apache.ranger.view.VXPortalUser;
+import org.apache.ranger.view.VXPortalUserList;
+import org.apache.ranger.view.VXResponse;
+import org.apache.ranger.view.VXStringList;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+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.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestUserREST {
+
+	@InjectMocks
+	UserREST userREST = new UserREST();
+
+	@Mock
+	HttpServletRequest request;
+
+	@Mock
+	SearchUtil searchUtil;
+
+	@Mock
+	RangerConfigUtil configUtil;
+
+	@Mock
+	UserMgr userManager;
+
+	@Mock
+	RangerDaoManager daoManager;
+
+	@Mock
+	XUserMgr xUserMgr;
+
+	@Mock
+	RESTErrorUtil restErrorUtil;
+
+	@Mock
+	VXPortalUserList vXPUserExpList;
+
+	@Mock
+	RangerRestUtil msRestUtil;
+
+	@Mock
+	VXPortalUser vxPUserAct;
+
+	@Mock
+	VXPasswordChange changePassword;
+
+	@Mock
+	VXResponse responseExp;
+
+	@Rule
+	public ExpectedException thrown = ExpectedException.none();
+
+	Long userId = 10l;
+	int pageSize = 100;
+	String firstName = "abc";
+	String lastName = "xyz";
+	String loginId = "xyzId";
+	String emailId = "abc@Example.com";
+
+	@SuppressWarnings("deprecation")
+	@Test
+	public void test1SearchUsers() {
+		SearchCriteria searchCriteria = new SearchCriteria();
+		vXPUserExpList = new VXPortalUserList();
+		vXPUserExpList.setPageSize(pageSize);
+		List<Integer> status = new ArrayList<Integer>();
+		String publicScreenName = "nrp";
+		List<String> roles = new ArrayList<String>();
+		String[] approvedSortByParams = new String[] { "requestDate", "approvedDate", "activationDate", "emailAddress",
+				"firstName", "lastName" };
+
+		Mockito.when(searchUtil.extractCommonCriterias(request, approvedSortByParams)).thenReturn(searchCriteria);
+		Mockito.when(searchUtil.extractLong(request, searchCriteria, "userId", "User Id")).thenReturn(userId);
+		Mockito.when(searchUtil.extractString(request, searchCriteria, "loginId", "Login Id", null))
+				.thenReturn(loginId);
+		Mockito.when(searchUtil.extractString(request, searchCriteria, "emailAddress", "Email Address", null))
+				.thenReturn(emailId);
+		Mockito.when(searchUtil.extractString(request, searchCriteria, "firstName", "First Name",
+				StringUtil.VALIDATION_NAME)).thenReturn(firstName);
+		Mockito.when(
+				searchUtil.extractString(request, searchCriteria, "lastName", "Last Name", StringUtil.VALIDATION_NAME))
+				.thenReturn(lastName);
+		Mockito.when(searchUtil.extractEnum(request, searchCriteria, "status", "Status", "statusList",
+				RangerConstants.ActivationStatus_MAX)).thenReturn(status);
+		Mockito.when(searchUtil.extractString(request, searchCriteria, "publicScreenName", "Public Screen Name",
+				StringUtil.VALIDATION_NAME)).thenReturn(publicScreenName);
+		Mockito.when(searchUtil.extractStringList(request, searchCriteria, "role", "Role", "roleList",
+				configUtil.getRoles(), StringUtil.VALIDATION_NAME)).thenReturn(roles);
+		Mockito.when(userManager.searchUsers(searchCriteria)).thenReturn(vXPUserExpList);
+
+		VXPortalUserList vXPUserListAct = userREST.searchUsers(request);
+
+		Assert.assertNotNull(vXPUserListAct);
+		Assert.assertEquals(vXPUserExpList, vXPUserListAct);
+		Assert.assertEquals(vXPUserExpList.getPageSize(), vXPUserListAct.getPageSize());
+
+		Mockito.verify(searchUtil).extractCommonCriterias(request, approvedSortByParams);
+		Mockito.verify(searchUtil).extractLong(request, searchCriteria, "userId", "User Id");
+		Mockito.verify(searchUtil).extractString(request, searchCriteria, "loginId", "Login Id", null);
+		Mockito.verify(searchUtil).extractString(request, searchCriteria, "emailAddress", "Email Address", null);
+		Mockito.verify(searchUtil).extractString(request, searchCriteria, "firstName", "First Name",
+				StringUtil.VALIDATION_NAME);
+		Mockito.verify(searchUtil).extractString(request, searchCriteria, "lastName", "Last Name",
+				StringUtil.VALIDATION_NAME);
+		Mockito.verify(searchUtil).extractEnum(request, searchCriteria, "status", "Status", "statusList",
+				RangerConstants.ActivationStatus_MAX);
+		Mockito.verify(searchUtil).extractString(request, searchCriteria, "publicScreenName", "Public Screen Name",
+				StringUtil.VALIDATION_NAME);
+		Mockito.verify(searchUtil).extractStringList(request, searchCriteria, "role", "Role", "roleList",
+				configUtil.getRoles(), StringUtil.VALIDATION_NAME);
+		Mockito.verify(userManager).searchUsers(searchCriteria);
+	}
+
+	@Test
+	public void test2GetUserProfileForUser() {
+		VXPortalUser vxPUserExp = CreateVXPortalUser();
+
+		Mockito.when(userManager.getUserProfile(userId)).thenReturn(vxPUserExp);
+
+		VXPortalUser VXPUserAct = userREST.getUserProfileForUser(userId);
+
+		Assert.assertNotNull(VXPUserAct);
+		Assert.assertEquals(vxPUserExp, VXPUserAct);
+		Assert.assertEquals(vxPUserExp.getLoginId(), VXPUserAct.getLoginId());
+		Assert.assertEquals(vxPUserExp.getFirstName(), VXPUserAct.getFirstName());
+		Assert.assertEquals(vxPUserExp.getEmailAddress(), VXPUserAct.getEmailAddress());
+		Assert.assertEquals(vxPUserExp.getId(), VXPUserAct.getId());
+
+		Mockito.verify(userManager).getUserProfile(userId);
+	}
+
+	@Test
+	public void test3GetUserProfileForUser() {
+		VXPortalUser vxPUserExp = new VXPortalUser();
+		vxPUserExp = null;
+
+		Mockito.when(userManager.getUserProfile(userId)).thenReturn(vxPUserExp);
+
+		VXPortalUser VXPUserAct = userREST.getUserProfileForUser(userId);
+
+		Assert.assertEquals(vxPUserExp, VXPUserAct);
+
+		Mockito.verify(userManager).getUserProfile(userId);
+	}
+
+	@Test
+	public void test6Create() {
+		VXPortalUser vxPUserExp = CreateVXPortalUser();
+
+		Mockito.when(userManager.createUser(vxPUserExp)).thenReturn(vxPUserExp);
+
+		VXPortalUser VXPUserAct = userREST.create(vxPUserExp, request);
+
+		Assert.assertNotNull(VXPUserAct);
+		Assert.assertEquals(vxPUserExp.getLoginId(), VXPUserAct.getLoginId());
+		Assert.assertEquals(vxPUserExp.getFirstName(), VXPUserAct.getFirstName());
+		Assert.assertEquals(vxPUserExp.getLastName(), VXPUserAct.getLastName());
+		Assert.assertEquals(vxPUserExp.getEmailAddress(), VXPUserAct.getEmailAddress());
+
+		Mockito.verify(userManager).createUser(vxPUserExp);
+	}
+
+	@Test
+	public void test7CreateDefaultAccountUser() {
+		VXPortalUser vxPUserExp = new VXPortalUser();
+		vxPUserExp = null;
+		Mockito.when(userManager.createDefaultAccountUser(vxPUserExp)).thenReturn(vxPUserExp);
+
+		VXPortalUser VXPUserAct = userREST.createDefaultAccountUser(vxPUserExp, request);
+
+		Assert.assertNull(VXPUserAct);
+
+		Mockito.verify(userManager).createDefaultAccountUser(vxPUserExp);
+	}
+
+	@Test
+	public void test8CreateDefaultAccountUser() {
+		VXPortalUser vxPUserExp = CreateVXPortalUser();
+
+		Mockito.when(userManager.createDefaultAccountUser(vxPUserExp)).thenReturn(vxPUserExp);
+		Mockito.doNothing().when(xUserMgr).assignPermissionToUser(vxPUserExp, true);
+
+		VXPortalUser VXPUserAct = userREST.createDefaultAccountUser(vxPUserExp, request);
+
+		Assert.assertNotNull(VXPUserAct);
+		Assert.assertEquals(vxPUserExp, VXPUserAct);
+		Assert.assertEquals(vxPUserExp.getLoginId(), VXPUserAct.getLoginId());
+		Assert.assertEquals(vxPUserExp.getFirstName(), VXPUserAct.getFirstName());
+		Assert.assertEquals(vxPUserExp.getLastName(), VXPUserAct.getLastName());
+		Assert.assertEquals(vxPUserExp.getEmailAddress(), VXPUserAct.getEmailAddress());
+
+		Mockito.verify(userManager).createDefaultAccountUser(vxPUserExp);
+		Mockito.verify(xUserMgr).assignPermissionToUser(vxPUserExp, true);
+	}
+
+	@Test
+	public void test8Update() {
+		VXPortalUser vxPUserExp = CreateVXPortalUser();
+		vxPUserExp.setLoginId(loginId);
+		XXPortalUser xxPUserExp = new XXPortalUser();
+		xxPUserExp.setLoginId(loginId);
+		XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
+
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
+		Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPUserExp);
+		Mockito.doNothing().when(userManager).checkAccess(xxPUserExp);
+		Mockito.doNothing().when(msRestUtil).validateVUserProfileForUpdate(xxPUserExp, vxPUserExp);
+		Mockito.when(userManager.updateUser(vxPUserExp)).thenReturn(xxPUserExp);
+		Mockito.when(userManager.mapXXPortalUserVXPortalUser(xxPUserExp)).thenReturn(vxPUserExp);
+
+		VXPortalUser vxPUserAct = userREST.update(vxPUserExp, request);
+
+		Assert.assertNotNull(vxPUserAct);
+		Assert.assertEquals(xxPUserExp.getLoginId(), vxPUserAct.getLoginId());
+		Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
+		Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
+
+		Mockito.verify(daoManager).getXXPortalUser();
+		Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
+		Mockito.verify(userManager).checkAccess(xxPUserExp);
+		Mockito.verify(msRestUtil).validateVUserProfileForUpdate(xxPUserExp, vxPUserExp);
+		Mockito.verify(userManager).updateUser(vxPUserExp);
+		Mockito.verify(userManager).mapXXPortalUserVXPortalUser(xxPUserExp);
+	}
+
+	@Test
+	public void test9Update() {
+		VXPortalUser vxPUserExp = new VXPortalUser();
+		XXPortalUser xxPUserExp = new XXPortalUser();
+		xxPUserExp = null;
+		XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
+
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
+		Mockito.when(xxPortalUserDao.getById(Mockito.anyLong())).thenReturn(xxPUserExp);
+		Mockito.doNothing().when(userManager).checkAccess(xxPUserExp);
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.anyObject(),
+				Mockito.anyLong(), Mockito.anyString(), Mockito.anyString())).thenReturn(new WebApplicationException());
+
+		thrown.expect(WebApplicationException.class);
+
+		userREST.update(vxPUserExp, request);
+
+		Mockito.verify(daoManager).getXXPortalUser();
+		Mockito.verify(xxPortalUserDao).getById(Mockito.anyLong());
+		Mockito.verify(userManager).checkAccess(xxPUserExp);
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.anyObject(),
+				Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
+	}
+
+	@Test
+	public void test10SetUserRoles() {
+		Long userId = 10L;
+		VXResponse responseExp = new VXResponse();
+		VXStringList roleList = new VXStringList();
+		Mockito.doNothing().when(userManager).checkAccess(userId);
+		Mockito.doNothing().when(userManager).setUserRoles(userId, roleList.getVXStrings());
+
+		VXResponse responseAct = userREST.setUserRoles(userId, roleList);
+
+		Assert.assertNotNull(responseAct);
+		Assert.assertEquals(responseExp.getStatusCode(), responseAct.getStatusCode());
+
+		Mockito.verify(userManager).checkAccess(userId);
+		Mockito.verify(userManager).setUserRoles(userId, roleList.getVXStrings());
+	}
+
+	@Test
+	public void test11DeactivateUser() {
+		VXPortalUser vxPUserExp = CreateVXPortalUser();
+		XXPortalUser xxPUserExp = new XXPortalUser();
+		xxPUserExp.setLoginId(loginId);
+		xxPUserExp.setStatus(1);
+		vxPUserExp.setStatus(5);
+
+		XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
+
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
+		Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUserExp);
+		Mockito.when(userManager.deactivateUser(xxPUserExp)).thenReturn(vxPUserExp);
+
+		VXPortalUser vxPUserAct = userREST.deactivateUser(userId);
+		Assert.assertNotNull(vxPUserAct);
+		Assert.assertEquals(xxPUserExp.getLoginId(), vxPUserAct.getLoginId());
+		Assert.assertEquals(vxPUserExp.getStatus(), vxPUserAct.getStatus());
+		Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
+		Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
+
+		Mockito.verify(daoManager).getXXPortalUser();
+		Mockito.verify(xxPortalUserDao).getById(userId);
+		Mockito.verify(userManager).deactivateUser(xxPUserExp);
+	}
+
+	@Test
+	public void test12DeactivateUser() {
+		XXPortalUser xxPUserExp = new XXPortalUser();
+		xxPUserExp = null;
+		XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
+
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
+		Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUserExp);
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.anyObject(),
+				Mockito.anyLong(), Mockito.anyString(), Mockito.anyString())).thenReturn(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+
+		userREST.deactivateUser(userId);
+
+		Mockito.verify(daoManager).getXXPortalUser();
+		Mockito.verify(xxPortalUserDao).getById(userId);
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.anyObject(),
+				Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
+	}
+
+	@Test
+	public void test13GetUserProfile() {
+		HttpSession hs = Mockito.mock(HttpSession.class);
+		VXPortalUser vxPUserExp = CreateVXPortalUser();
+		Mockito.when(userManager.getUserProfileByLoginId()).thenReturn(vxPUserExp);
+		Mockito.when(request.getSession()).thenReturn(hs);
+		Mockito.when(hs.getId()).thenReturn("id");
+
+		VXPortalUser vxPUserAct = userREST.getUserProfile(request);
+
+		Assert.assertNotNull(vxPUserAct);
+		Assert.assertEquals(vxPUserExp, vxPUserAct);
+		Assert.assertEquals(vxPUserExp.getId(), vxPUserAct.getId());
+		Assert.assertEquals(vxPUserExp.getFirstName(), vxPUserAct.getFirstName());
+
+		Mockito.verify(userManager).getUserProfileByLoginId();
+	}
+
+	@Test
+	public void test15SuggestUserFirstName() {
+		String op = userREST.suggestUserFirstName(firstName, request);
+		Assert.assertNull(op);
+	}
+
+	@Test
+	public void test16ChangePassword() {
+		XXPortalUser xxPUser = new XXPortalUser();
+		VXResponse vxResponseExp = new VXResponse();
+		vxResponseExp.setStatusCode(10);
+		XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
+
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
+		Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUser);
+		Mockito.doNothing().when(userManager).checkAccess(xxPUser);
+		Mockito.doNothing().when(changePassword).setId(userId);
+		Mockito.when(userManager.changePassword(changePassword)).thenReturn(vxResponseExp);
+		VXResponse vxResponseAct = userREST.changePassword(userId, changePassword);
+
+		Assert.assertNotNull(vxResponseAct);
+		Assert.assertEquals(vxResponseExp, vxResponseAct);
+		Assert.assertEquals(vxResponseExp.getStatusCode(), vxResponseAct.getStatusCode());
+
+		Mockito.verify(daoManager).getXXPortalUser();
+		Mockito.verify(xxPortalUserDao).getById(userId);
+		Mockito.verify(userManager).checkAccess(xxPUser);
+		Mockito.verify(changePassword).setId(userId);
+		Mockito.verify(userManager).changePassword(changePassword);
+	}
+
+	@Test
+	public void test17ChangePassword() {
+		XXPortalUser xxPUser = new XXPortalUser();
+		xxPUser = null;
+		XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
+
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
+		Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUser);
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.anyObject(),
+				Mockito.anyLong(), Mockito.anyString(), Mockito.anyString())).thenReturn(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+
+		userREST.changePassword(userId, changePassword);
+
+		Mockito.verify(daoManager).getXXPortalUser();
+		Mockito.verify(xxPortalUserDao).getById(userId);
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.anyObject(),
+				Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
+	}
+
+	@Test
+	public void test18ChangeEmailAddress() {
+		XXPortalUser xxPUser = new XXPortalUser();
+		VXPortalUser vxPUserExp = CreateVXPortalUser();
+
+		XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
+
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
+		Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUser);
+		Mockito.doNothing().when(userManager).checkAccess(xxPUser);
+		Mockito.doNothing().when(changePassword).setId(userId);
+		Mockito.when(userManager.changeEmailAddress(xxPUser, changePassword)).thenReturn(vxPUserExp);
+
+		VXPortalUser vxPortalUserAct = userREST.changeEmailAddress(userId, changePassword);
+
+		Assert.assertNotNull(vxPortalUserAct);
+		Assert.assertEquals(vxPUserExp, vxPortalUserAct);
+		Assert.assertEquals(vxPUserExp.getId(), vxPortalUserAct.getId());
+		Assert.assertEquals(vxPUserExp.getFirstName(), vxPortalUserAct.getFirstName());
+
+		Mockito.verify(daoManager).getXXPortalUser();
+		Mockito.verify(xxPortalUserDao).getById(userId);
+		Mockito.verify(userManager).checkAccess(xxPUser);
+		Mockito.verify(changePassword).setId(userId);
+		Mockito.verify(userManager).changeEmailAddress(xxPUser, changePassword);
+	}
+
+	@Test
+	public void test19ChangeEmailAddress() {
+		XXPortalUser xxPUser = new XXPortalUser();
+		xxPUser = null;
+		XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class);
+
+		Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao);
+		Mockito.when(xxPortalUserDao.getById(userId)).thenReturn(xxPUser);
+		Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.anyObject(),
+				Mockito.anyLong(), Mockito.anyString(), Mockito.anyString())).thenReturn(new WebApplicationException());
+		thrown.expect(WebApplicationException.class);
+
+		userREST.changeEmailAddress(userId, changePassword);
+
+		Mockito.verify(daoManager).getXXPortalUser();
+		Mockito.verify(xxPortalUserDao).getById(userId);
+		Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.anyObject(),
+				Mockito.anyLong(), Mockito.anyString(), Mockito.anyString());
+	}
+
+	private VXPortalUser CreateVXPortalUser() {
+
+		VXPortalUser vxPUserExp = new VXPortalUser();
+		vxPUserExp.setId(userId);
+		vxPUserExp.setFirstName(firstName);
+		vxPUserExp.setLastName(lastName);
+		vxPUserExp.setEmailAddress(emailId);
+		vxPUserExp.setLoginId(loginId);
+		return vxPUserExp;
+	}
+}
\ No newline at end of file


Mime
View raw message