gt:         if (null != collection)
context: /*
   * Copyright (C) 2005-2013 Alfresco Software Limited.
   *
   * This file is part of Alfresco
   *
   * Alfresco is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * Alfresco is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
   */
  package org.alfresco.bm.api.v1;
  
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertNotNull;
  import static org.junit.Assert.assertNotSame;
  import static org.junit.Assert.assertNull;
  import static org.junit.Assert.assertTrue;
  import static org.junit.Assert.fail;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.net.UnknownHostException;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Properties;
  import java.util.Scanner;
  import java.util.Set;
  import java.util.UUID;
  
  import javax.ws.rs.WebApplicationException;
  import javax.ws.rs.core.Response.Status;
  import javax.ws.rs.core.StreamingOutput;
  
  import org.alfresco.bm.exception.ObjectNotFoundException;
  import org.alfresco.bm.log.LogService;
  import org.alfresco.bm.log.LogWatcher;
  import org.alfresco.bm.report.DataReportService;
  import org.alfresco.bm.test.TestConstants;
  import org.alfresco.bm.test.TestRun;
  import org.alfresco.bm.test.TestRunServicesCache;
  import org.alfresco.bm.test.TestRunState;
  import org.alfresco.bm.test.TestServiceImpl;
  import org.alfresco.bm.test.mongo.MongoTestDAO;
  import org.alfresco.mongo.MongoClientFactory;
  import org.alfresco.mongo.MongoDBFactory;
  import org.alfresco.mongo.MongoDBForTestsFactory;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.poi.POIXMLProperties;
  import org.apache.poi.POIXMLProperties.CoreProperties;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  import org.bson.types.ObjectId;
  import org.junit.After;
  import org.junit.Assert;
  import org.junit.Before;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.junit.runners.JUnit4;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  import org.springframework.core.env.ConfigurableEnvironment;
  import org.springframework.core.env.PropertiesPropertySource;
  
  import com.google.gson.Gson;
  import com.mongodb.DB;
  import com.mongodb.DBCursor;
  import com.mongodb.DBObject;
  import com.mongodb.MongoClient;
  import com.mongodb.MongoClientURI;
  import com.mongodb.ServerAddress;
  
  /**
   * @see TestRestAPI V1
   * 
   * @author Derek Hulley
   * @since 2.0
   */
  @RunWith(JUnit4.class)
  public class RestAPITest implements TestConstants
  {
      public static final String RELEASE = "RestAPITest";
      public static final int SCHEMA = 0;
      public static final String MONGO_TEST_DATABASE = "bm21-data";
  
      private static Log logger = LogFactory.getLog(RestAPITest.class);
  
      private Gson gson = new Gson();
      private MongoDBForTestsFactory mockDBFactory;
      private ClassPathXmlApplicationContext ctx;
  
      private MongoTestDAO dao;
      private TestRestAPI api;
      private TestRunServicesCache testRunServicesCache;
      private DB appDB;
      private String mongoHost;
  
      @Before
      public void setUp() throws Exception
      {
          gson = new Gson();
  
          // Create a mock DB to connect to
          mockDBFactory = new MongoDBForTestsFactory();
          mongoHost = mockDBFactory.getMongoHost();
          String database = mockDBFactory.getObject().getName();
  
          // Create an application context (don't start, yet)
          ctx = new ClassPathXmlApplicationContext(
                  new String[] {
                          PATH_APP_CONTEXT
                  },
                  false);
  
          // Pass our properties to the new context
          Properties ctxProperties = new Properties();
          {
              ctxProperties.put(PROP_MONGO_CONFIG_HOST, mongoHost);
              ctxProperties.put(PROP_MONGO_CONFIG_DATABASE, database);
              ctxProperties.put(PROP_MONGO_TEST_DATABASE, MONGO_TEST_DATABASE);
              ctxProperties.put(PROP_APP_RELEASE, RELEASE);
              ctxProperties.put(PROP_APP_SCHEMA, "" + SCHEMA);
              ctxProperties.put(PROP_APP_INHERITANCE, "COMMON, TEST");
              ctxProperties.put(PROP_TEST_RUN_MONITOR_PERIOD, "" + 20000);
              ctxProperties.put(PROP_SYSTEM_CAPABILITIES, "Java");
              ctxProperties.put(PROP_APP_CONTEXT_PATH, "/");
              ctxProperties.put(PROP_APP_DIR, ".");
          }
          ConfigurableEnvironment ctxEnv = ctx.getEnvironment();
          ctxEnv.getPropertySources().addFirst(
                  new PropertiesPropertySource(
                          "RestAPITest",
                          ctxProperties));
          // Override all properties with system properties
          ctxEnv.getPropertySources().addFirst(
                  new PropertiesPropertySource(
                          "system",
                          System.getProperties()));
          // Start the context now
          ctx.refresh();
  
          // Get beans
          dao = ctx.getBean(MongoTestDAO.class);
          appDB = dao.getDb();
          TestServiceImpl testService = ctx.getBean(TestServiceImpl.class);
          LogService logService = ctx.getBean(LogService.class);
          this.testRunServicesCache = ctx.getBean(TestRunServicesCache.class);
          api = new TestRestAPI(dao, testService, logService, testRunServicesCache);
      }
  
      @After
      public void tearDown() throws Exception
      {
          if (ctx != null)
          {
              try
              {
                  ctx.close();
              }
              catch (Exception e)
              {
              }
          }
          if (mockDBFactory != null)
          {
              try
              {
                  mockDBFactory.destroy();
              }
              catch (Exception e)
              {
              }
          }
      }
  
      @Test
      public void basic()
      {
          assertNotNull(appDB);
          Set<String> collectionNames = new HashSet<String>();
          collectionNames.add("test.drivers");
          collectionNames.add("test.defs");
          collectionNames.add("tests");
          collectionNames.add("test.runs");
          collectionNames.add("test.props");
  
          Set<String> dbColNames = removeSystemValues(appDB.getCollectionNames());
          assertEquals(collectionNames, dbColNames);
      }
  
      /**
       * make sure the system name is NOT contained as from 3.2 on
       * 
       * @param collection
       *        (Set<String>) collection to check
       * @return
       */
      private Set<String> removeSystemValues(Set<String> collection)
      {
  