airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramin...@apache.org
Subject [2/3] git commit: Fixed experiment data model and helper classes for unit testing. AIRAVATA-1025
Date Thu, 20 Feb 2014 20:56:36 GMT
Fixed experiment data model and helper classes for unit testing. AIRAVATA-1025


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

Branch: refs/heads/master
Commit: afddb4cb46f78c0174bc827643e45bb5c2309b55
Parents: ca3f8c4 59c77d3
Author: raminder <raminder@apache.org>
Authored: Thu Feb 20 15:53:31 2014 -0500
Committer: raminder <raminder@apache.org>
Committed: Thu Feb 20 15:53:31 2014 -0500

----------------------------------------------------------------------
 .../persistance/registry/jpa/ResourceUtils.java |  65 +--
 .../registry/jpa/impl/ExperimentRegistry.java   | 398 ++++++++++---------
 .../registry/jpa/impl/RegistryImpl.java         |  37 +-
 .../persistance/registry/jpa/impl/UserReg.java  |   6 +-
 .../resources/DataTransferDetailResource.java   |  12 +
 .../jpa/resources/ExperimentResource.java       |  16 +
 .../registry/jpa/resources/GatewayResource.java |   8 +-
 .../registry/jpa/resources/UserResource.java    |  34 --
 .../jpa/utils/ThriftDataModelConversion.java    | 108 +++--
 .../registry/jpa/AbstractResourceTest.java      |   6 +-
 .../jpa/ExperimentInputResourceTest.java        |  10 +-
 .../registry/jpa/ProjectResourceTest.java       |  81 ----
 .../registry/jpa/util/Initialize.java           |   9 +-
 .../apache/airavata/registry/cpi/Registry.java  |  20 +-
 .../airavata/registry/cpi/utils/Constants.java  |   1 -
 15 files changed, 416 insertions(+), 395 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/afddb4cb/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
----------------------------------------------------------------------
diff --cc modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
index 97ed481,7562d37..18a7e90
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
@@@ -103,7 -103,26 +103,37 @@@ public class ResourceUtils 
  
      }
  
-     public static Resource getWorker(String gatewayName, String userName){
+     public static void addUser (String userName, String password){
+         UserResource resource = new UserResource();
+         resource.setUserName(userName);
+         resource.setPassword(password);
+         resource.save();
+     }
+ 
+     public static boolean isUserExist (String username){
+         EntityManager em = getEntityManager();
+         em.getTransaction().begin();
+         QueryGenerator generator = new QueryGenerator(AbstractResource.USERS);
+         generator.setParameter(AbstractResource.UserConstants.USERNAME, username);
+         Query q = generator.selectQuery(em);
+         int size = q.getResultList().size();
+         em.getTransaction().commit();
+         em.close();
+         return size>0;
+     }
++    public static Resource getUser(String userName){
++        if (isUserExist(userName)) {
++            EntityManager em = getEntityManager();
++            Users user =  em.find(Users.class, userName);
++            UserResource userResource = (UserResource)Utils.getResource(ResourceType.USER,
user);
++            em.close();
++            return userResource;
++        }
++        return null;
++
++    }
+ 
+     public static Resource getWorker(String gatewayName, String userName) {
          EntityManager em = getEntityManager();
          Gateway_Worker gatewayWorker = em.find(Gateway_Worker.class, new Gateway_Worker_PK(gatewayName,
userName));
          WorkerResource workerResource = (WorkerResource) Utils.getResource(ResourceType.GATEWAY_WORKER,
gatewayWorker);

http://git-wip-us.apache.org/repos/asf/airavata/blob/afddb4cb/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/AbstractResourceTest.java
----------------------------------------------------------------------
diff --cc modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/AbstractResourceTest.java
index 5d356e4,da36d85..160e1fc
--- a/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/AbstractResourceTest.java
+++ b/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/AbstractResourceTest.java
@@@ -28,6 -26,6 +28,7 @@@ import org.apache.airavata.persistance.
  import org.apache.airavata.persistance.registry.jpa.resources.UserResource;
  import org.apache.airavata.persistance.registry.jpa.resources.WorkerResource;
  import org.apache.airavata.persistance.registry.jpa.util.Initialize;
++import org.apache.airavata.registry.api.util.RegistrySettings;
  
  import java.sql.Timestamp;
  import java.util.Calendar;
@@@ -46,15 -43,9 +47,12 @@@ public abstract class AbstractResourceT
          initialize.initializeDB();
          gatewayResource = (GatewayResource)ResourceUtils.getGateway("default");
          workerResource = (WorkerResource)ResourceUtils.getWorker(gatewayResource.getGatewayName(),
"admin");
 -        userResource = (UserResource)gatewayResource.create(ResourceType.USER);
 -        userResource.setUserName("admin");
 -        userResource.setPassword("admin");
++        userResource = (UserResource)ResourceUtils.getUser(RegistrySettings.getSetting("default.registry.user"));
 +        projectResource = (ProjectResource)workerResource.create(ResourceType.PROJECT);
 +        projectResource.setGateway(gatewayResource);
 +        projectResource.setName("default");
 +        projectResource.setWorker(workerResource);
 +        projectResource.save();
-         userResource = (UserResource)gatewayResource.create(ResourceType.USER);
-         userResource.setUserName("admin");
-         userResource.setPassword("admin");
-         userResource.save();
      }
  
      public Timestamp getCurrentTimestamp() {

http://git-wip-us.apache.org/repos/asf/airavata/blob/afddb4cb/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/ExperimentInputResourceTest.java
----------------------------------------------------------------------
diff --cc modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/ExperimentInputResourceTest.java
index e3e0212,da0806d..e9bda26
--- a/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/ExperimentInputResourceTest.java
+++ b/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/ExperimentInputResourceTest.java
@@@ -1,53 -1,61 +1,61 @@@
 -/*
 - *
 - * Licensed to the Apache Software Foundation (ASF) under one
 - * or more contributor license agreements.  See the NOTICE file
 - * distributed with this work for additional information
 - * regarding copyright ownership.  The ASF licenses this file
 - * to you under the Apache License, Version 2.0 (the
 - * "License"); you may not use this file except in compliance
 - * with the License.  You may obtain a copy of the License at
 - *
 - *   http://www.apache.org/licenses/LICENSE-2.0
 - *
 - * Unless required by applicable law or agreed to in writing,
 - * software distributed under the License is distributed on an
 - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 - * KIND, either express or implied.  See the License for the
 - * specific language governing permissions and limitations
 - * under the License.
 - *
 - */
 -
 -package org.apache.airavata.persistance.registry.jpa;
 -
 -import org.apache.airavata.persistance.registry.jpa.resources.*;
 -
 -import java.util.Map;
 -
 -public class ExperimentInputResourceTest extends AbstractResourceTest  {
 -    private ExperimentMetadataResource experimentResource;
 -    @Override
 -    public void setUp() throws Exception {
 -        super.setUp();
 -        super.setUp();
 -        GatewayResource gatewayResource = super.getGatewayResource();
 -        WorkerResource workerResource = super.getWorkerResource();
 -        ProjectResource projectResource = new ProjectResource(workerResource, gatewayResource,
"testProject");
 -        projectResource.save();
 -
 -        experimentResource = (ExperimentMetadataResource) gatewayResource.create(ResourceType.EXPERIMENT_METADATA);
 -        experimentResource.setExpID("testExpID");
 -        experimentResource.setExperimentName("testExpID");
 -        experimentResource.setExecutionUser(workerResource.getUser());
 -        experimentResource.setProject(projectResource);
 -        experimentResource.save();
 -    }
 -
 -    public void testSave() throws Exception {
 -        ExperimentInputResource experimentInputResource = new ExperimentInputResource();
 -        experimentInputResource.setExperimentMetadataResource(experimentResource);
 -        experimentInputResource.setExperimentKey("testKey");
 -        experimentInputResource.setValue("testValue");
 -        experimentInputResource.save();
 -
 -        assertTrue("Experiment input saved successfully", experimentResource.isExists(ResourceType.EXPERIMENT_INPUT,
"testExpID"));
 -    }
 -
 -    @Override
 -    public void tearDown() throws Exception {
 -        super.tearDown();
 -    }
 -}
 +///*
 +// *
 +// * 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.airavata.persistance.registry.jpa;
 +//
 +//import org.apache.airavata.persistance.registry.jpa.resources.*;
 +//
 +//import java.util.Map;
 +//
 +//public class ExperimentInputResourceTest extends AbstractResourceTest  {
++//    private ExperimentMetadataResource experimentResource;
 +//    @Override
 +//    public void setUp() throws Exception {
 +//        super.setUp();
++//        super.setUp();
 +//        GatewayResource gatewayResource = super.getGatewayResource();
 +//        WorkerResource workerResource = super.getWorkerResource();
 +//        ProjectResource projectResource = new ProjectResource(workerResource, gatewayResource,
"testProject");
 +//        projectResource.save();
 +//
 +//        experimentResource = (ExperimentMetadataResource) gatewayResource.create(ResourceType.EXPERIMENT_METADATA);
 +//        experimentResource.setExpID("testExpID");
 +//        experimentResource.setExperimentName("testExpID");
 +//        experimentResource.setExecutionUser(workerResource.getUser());
 +//        experimentResource.setProject(projectResource);
 +//        experimentResource.save();
 +//    }
 +//
 +//    public void testSave() throws Exception {
- //     
++//        ExperimentInputResource experimentInputResource = new ExperimentInputResource();
++//        experimentInputResource.setExperimentMetadataResource(experimentResource);
++//        experimentInputResource.setExperimentKey("testKey");
++//        experimentInputResource.setValue("testValue");
++//        experimentInputResource.save();
++//
++//        assertTrue("Experiment input saved successfully", experimentResource.isExists(ResourceType.EXPERIMENT_INPUT,
"testExpID"));
 +//    }
 +//
 +//    @Override
 +//    public void tearDown() throws Exception {
 +//        super.tearDown();
 +//    }
 +//}

http://git-wip-us.apache.org/repos/asf/airavata/blob/afddb4cb/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/util/Initialize.java
----------------------------------------------------------------------
diff --cc modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/util/Initialize.java
index e811e2e,f2a2987..6dd0697
--- a/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/util/Initialize.java
+++ b/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/util/Initialize.java
@@@ -22,7 -22,7 +22,9 @@@
  package org.apache.airavata.persistance.registry.jpa.util;
  
  import org.apache.airavata.persistance.registry.jpa.ResourceType;
++import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
  import org.apache.airavata.persistance.registry.jpa.resources.GatewayResource;
++import org.apache.airavata.persistance.registry.jpa.resources.ProjectResource;
  import org.apache.airavata.persistance.registry.jpa.resources.UserResource;
  import org.apache.airavata.persistance.registry.jpa.resources.Utils;
  import org.apache.airavata.persistance.registry.jpa.resources.WorkerResource;
@@@ -146,8 -146,8 +148,8 @@@ public class Initialize 
              gatewayResource.setGatewayName(RegistrySettings.getSetting("default.registry.gateway"));
              gatewayResource.setOwner(RegistrySettings.getSetting("default.registry.gateway"));
              gatewayResource.save();
--
--            UserResource userResource = (UserResource) gatewayResource.create(ResourceType.USER);
++            
++            UserResource userResource = new UserResource();
              userResource.setUserName(RegistrySettings.getSetting("default.registry.user"));
              userResource.setPassword(RegistrySettings.getSetting("default.registry.password"));
              userResource.save();
@@@ -155,6 -155,6 +157,7 @@@
              WorkerResource workerResource = (WorkerResource) gatewayResource.create(ResourceType.GATEWAY_WORKER);
              workerResource.setUser(userResource.getUserName());
              workerResource.save();
++          
          } catch (RegistrySettingsException e) {
              logger.error("Unable to read properties", e);
          }


Mime
View raw message