AMBARI-7234. Admin View: Unclear error during deleting view with set permission 
for user. (jaimin)


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

Branch: refs/heads/branch-alerts-dev
Commit: e40e47f8370941cbc0d818150bd7eea6d20a6522
Parents: 3c30d91
Author: Jaimin Jetly <jai...@hortonworks.com>
Authored: Tue Sep 9 17:11:36 2014 -0700
Committer: Jaimin Jetly <jai...@hortonworks.com>
Committed: Tue Sep 9 17:11:36 2014 -0700

----------------------------------------------------------------------
 .../apache/ambari/server/view/ViewRegistry.java |  4 ++
 .../ambari/server/view/ViewRegistryTest.java    | 39 ++++++++++++++++++++
 2 files changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e40e47f8/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java 
b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
index 859ea96..509e474 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
@@ -567,6 +567,10 @@ public class ViewRegistry {
           LOG.debug("Deleting view instance " + viewName + "/" +
               version + "/" +instanceName);
         }
+        List<PrivilegeEntity> instancePrivileges = 
privilegeDAO.findByResourceId(instanceEntity.getResource().getId());
+        for (PrivilegeEntity privilegeEntity : instancePrivileges) {
+          privilegeDAO.remove(privilegeEntity);
+        }
         instanceDAO.remove(instanceEntity);
         viewEntity.removeInstanceDefinition(instanceName);
         removeInstanceDefinition(viewEntity, instanceName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/e40e47f8/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
index 7ce4699..38c2f9b 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java
@@ -33,10 +33,12 @@ import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -703,6 +705,43 @@ public class ViewRegistryTest {
   }
 
   @Test
+  public void testUninstallViewInstance() throws Exception {
+
+    ViewRegistry registry = getRegistry();
+
+    Configuration ambariConfig = new Configuration(new Properties());
+
+    ViewConfig config = ViewConfigTest.getConfig(xml_valid_instance);
+    ViewEntity viewEntity = getViewEntity(config, ambariConfig, 
getClass().getClassLoader(), "");
+    ViewInstanceEntity viewInstanceEntity = getViewInstanceEntity(viewEntity, 
config.getInstances().get(0));
+    ResourceEntity resource = new ResourceEntity();
+    resource.setId(3L);
+    viewInstanceEntity.setResource(resource);
+    PrivilegeEntity privilege1 = createNiceMock(PrivilegeEntity.class);
+    PrivilegeEntity privilege2 = createNiceMock(PrivilegeEntity.class);
+    List<PrivilegeEntity> privileges = Arrays.asList(privilege1, privilege2);
+
+    expect(privilegeDAO.findByResourceId(3L)).andReturn(privileges);
+    privilegeDAO.remove(privilege1);
+    privilegeDAO.remove(privilege2);
+    viewInstanceDAO.remove(viewInstanceEntity);
+
+    handlerList.removeViewInstance(viewInstanceEntity);
+
+    replay(viewInstanceDAO, privilegeDAO, handlerList);
+
+    registry.addDefinition(viewEntity);
+    registry.addInstanceDefinition(viewEntity, viewInstanceEntity);
+    registry.uninstallViewInstance(viewInstanceEntity);
+
+    Collection<ViewInstanceEntity> viewInstanceDefinitions = 
registry.getInstanceDefinitions(viewEntity);
+
+    Assert.assertEquals(0, viewInstanceDefinitions.size());
+
+    verify(viewInstanceDAO, privilegeDAO, handlerList);
+  }
+
+  @Test
   public void testUpdateViewInstance_invalid() throws Exception {
 
     ViewRegistry registry = getRegistry();

Reply via email to