ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [08/50] [abbrv] git commit: AMBARI-6897. View Unit Test Failure. (mahadev)
Date Wed, 20 Aug 2014 15:30:09 GMT
AMBARI-6897. View Unit Test Failure. (mahadev)


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

Branch: refs/heads/branch-alerts-dev
Commit: 50e798395a1ca97ce0d0f2eb4979bed657227ea4
Parents: 32caa43
Author: Mahadev Konar <mahadev@apache.org>
Authored: Mon Aug 18 10:49:53 2014 -0700
Committer: Mahadev Konar <mahadev@apache.org>
Committed: Mon Aug 18 10:49:57 2014 -0700

----------------------------------------------------------------------
 .../apache/ambari/server/view/ViewRegistry.java | 20 ++++++++---------
 .../ambari/server/view/ViewRegistryTest.java    | 23 +++++++++++---------
 2 files changed, 22 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/50e79839/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 82d84f6..65a48b4 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
@@ -1053,15 +1053,6 @@ public class ViewRegistry {
       throws Exception {
     String viewName = view.getName();
 
-    // get or create an admin resource type to represent this view
-    ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findByName(viewName);
-    if (resourceTypeEntity == null) {
-      resourceTypeEntity = new ResourceTypeEntity();
-      resourceTypeEntity.setName(view.getName());
-      resourceTypeDAO.create(resourceTypeEntity);
-    }
-    view.setResourceType(resourceTypeEntity);
-
     ViewEntity persistedView = viewDAO.findByName(viewName);
 
     // if the view is not yet persisted ...
@@ -1070,11 +1061,18 @@ public class ViewRegistry {
         LOG.debug("Creating View " + viewName + ".");
       }
 
+      // get or create an admin resource type to represent this view
+      ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findByName(viewName);
+      if (resourceTypeEntity == null) {
+        resourceTypeEntity = view.getResourceType();
+        resourceTypeDAO.create(resourceTypeEntity);
+      }
+
       for( ViewInstanceEntity instance : view.getInstances()) {
 
         // create an admin resource to represent this view instance
         ResourceEntity resourceEntity = new ResourceEntity();
-        resourceEntity.setResourceType(resourceTypeEntity);
+        resourceEntity.setResourceType(view.getResourceType());
         resourceDAO.create(resourceEntity);
 
         instance.setResource(resourceEntity);
@@ -1146,7 +1144,7 @@ public class ViewRegistry {
     for (ViewInstanceEntity instance : xmlInstanceEntityMap.values()) {
       // create an admin resource to represent this view instance
       ResourceEntity resourceEntity = new ResourceEntity();
-      resourceEntity.setResourceType(resourceTypeEntity);
+      resourceEntity.setResourceType(view.getResourceType());
       resourceDAO.create(resourceEntity);
       instance.setResource(resourceEntity);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/50e79839/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 77990a7..21a00ed 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
@@ -173,12 +173,10 @@ public class ViewRegistryTest {
 
     ViewDAO vDAO = createMock(ViewDAO.class);
     ResourceDAO rDAO = createNiceMock(ResourceDAO.class);
-    ResourceTypeDAO rtDAO = createNiceMock(ResourceTypeDAO.class);
     ViewInstanceDAO viDAO = createNiceMock(ViewInstanceDAO.class);
 
     ViewRegistry.setViewDAO(vDAO);
     ViewRegistry.setResourceDAO(rDAO);
-    ViewRegistry.setResourceTypeDAO(rtDAO);
     ViewRegistry.setInstanceDAO(viDAO);
 
     ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
@@ -261,15 +259,11 @@ public class ViewRegistryTest {
 
     expect(vDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList());
 
-    expect(rtDAO.findByName("MY_VIEW{1.0.0}")).andReturn(null);
-    rtDAO.create(EasyMock.anyObject(ResourceTypeEntity.class));
-    EasyMock.expectLastCall().anyTimes();
-
     expect(viDAO.merge(EasyMock.anyObject(ViewInstanceEntity.class))).andReturn(null).times(2);
 
     // replay mocks
     replay(configuration, viewDir, extractedArchiveDir, viewArchive, archiveDir, entryFile,
classesDir,
-        libDir, fileEntry, viewJarFile, enumeration, jarEntry, is, fos, rDAO, rtDAO, vDAO,
viDAO);
+        libDir, fileEntry, viewJarFile, enumeration, jarEntry, is, fos, rDAO, vDAO, viDAO);
 
     ViewRegistry registry = ViewRegistry.getInstance();
     registry.setHelper(new TestViewRegistryHelper(viewConfigs, files, outputStreams, jarFiles));
@@ -280,7 +274,7 @@ public class ViewRegistryTest {
 
     // verify mocks
     verify(configuration, viewDir, extractedArchiveDir, viewArchive, archiveDir, entryFile,
classesDir,
-        libDir, fileEntry, viewJarFile, enumeration, jarEntry, is, fos, rDAO, rtDAO, vDAO,
viDAO);
+        libDir, fileEntry, viewJarFile, enumeration, jarEntry, is, fos, rDAO, vDAO, viDAO);
   }
 
   @Test
@@ -386,6 +380,7 @@ public class ViewRegistryTest {
     expect(fileEntry.toURI()).andReturn(new URI("file:./"));
 
     expect(vDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList());
+    expect(vDAO.findByName("MY_VIEW{1.0.0}")).andReturn(viewDefinition);
 
     // replay mocks
     replay(configuration, viewDir, extractedArchiveDir, viewArchive, archiveDir, entryFile,
classesDir,
@@ -578,7 +573,7 @@ public class ViewRegistryTest {
     ViewEntity viewEntity = getViewEntity(config, ambariConfig, getClass().getClassLoader(),
"");
     ViewInstanceEntity viewInstanceEntity = getViewInstanceEntity(viewEntity, config.getInstances().get(0));
 
-    replay(viewDAO, viewInstanceDAO, securityHelper);
+    replay(viewDAO, viewInstanceDAO, securityHelper, rtDAO);
 
     registry.addDefinition(viewEntity);
     try {
@@ -616,7 +611,7 @@ public class ViewRegistryTest {
     ViewInstanceEntity viewInstanceEntity = getViewInstanceEntity(viewEntity, config.getInstances().get(0));
     viewInstanceEntity.setViewName("BOGUS_VIEW");
 
-    replay(viewDAO, viewInstanceDAO, securityHelper);
+    replay(viewDAO, viewInstanceDAO, securityHelper, rtDAO);
 
     registry.addDefinition(viewEntity);
     try {
@@ -844,6 +839,14 @@ public class ViewRegistryTest {
 
   public static void clear() {
     ViewRegistry.getInstance().clear();
+
+    ViewRegistry.setInstanceDAO(null);
+    ViewRegistry.setMemberDAO(null);
+    ViewRegistry.setPrivilegeDAO(null);
+    ViewRegistry.setResourceDAO(null);
+    ViewRegistry.setResourceTypeDAO(null);
+    ViewRegistry.setSecurityHelper(null);
+    ViewRegistry.setUserDAO(null);
     ViewRegistry.setViewDAO(null);
   }
 


Mime
View raw message