001    package org.hackystat.sensorbase.test;
002    
003    import org.hackystat.sensorbase.resource.projects.ProjectManager;
004    import org.hackystat.sensorbase.resource.sensordata.SensorDataManager;
005    import org.hackystat.sensorbase.resource.sensordatatypes.SdtManager;
006    import org.hackystat.sensorbase.resource.users.UserManager;
007    import org.hackystat.sensorbase.server.Server;
008    import org.hackystat.sensorbase.server.ServerProperties;
009    
010    import static org.hackystat.sensorbase.server.ServerProperties.ADMIN_EMAIL_KEY;
011    import static org.hackystat.sensorbase.server.ServerProperties.ADMIN_PASSWORD_KEY;
012    import org.junit.BeforeClass;
013    
014    
015    /**
016     * Provides helpful utility methods to SensorBase test classes, which will
017     * normally want to extend this class. 
018     * @author Philip Johnson
019     *
020     */
021    public class SensorBaseRestApiHelper {
022      /** The SensorBase server used in these tests. */
023      protected static Server server;
024    
025      /** Make a Manager available to this test class. */
026      protected static SensorDataManager sensorDataManager; 
027    
028      /** Make a Manager available to this test class. */
029      protected static UserManager userManager; 
030    
031      /** Make a Manager available to this test class. */
032      protected static SdtManager sdtManager; 
033    
034      /** Make a Manager available to this test class. */
035      protected static ProjectManager projectManager; 
036      
037      /** The admin email. */
038      protected static String adminEmail;
039      /** The admin password. */
040      protected static String adminPassword;
041    
042      /**
043       * Starts the server going for these tests. 
044       * @throws Exception If problems occur setting up the server. 
045       */
046      @BeforeClass public static void setupServer() throws Exception {
047        // Create a 'testing' version of ServerProperties.
048        ServerProperties properties = new ServerProperties();
049        properties.setTestProperties();
050        // Now instantiate the server parameterized for testing purposes. 
051        SensorBaseRestApiHelper.server = Server.newInstance(properties);
052    
053        SensorBaseRestApiHelper.sensorDataManager = 
054          (SensorDataManager)server.getContext().getAttributes().get("SensorDataManager");
055        SensorBaseRestApiHelper.userManager = 
056          (UserManager)server.getContext().getAttributes().get("UserManager");
057        SensorBaseRestApiHelper.sdtManager = 
058          (SdtManager)server.getContext().getAttributes().get("SdtManager");
059        SensorBaseRestApiHelper.projectManager = 
060          (ProjectManager)server.getContext().getAttributes().get("ProjectManager");
061        SensorBaseRestApiHelper.adminEmail = server.getServerProperties().get(ADMIN_EMAIL_KEY);
062        SensorBaseRestApiHelper.adminPassword = server.getServerProperties().get(ADMIN_PASSWORD_KEY);
063      }
064    
065      /**
066       * Returns the hostname associated with this test server. 
067       * @return The host name, including the context root. 
068       */
069      protected static String getHostName() {
070        return SensorBaseRestApiHelper.server.getHostName();
071      }
072    }