<commit_before>/**
 * Copyright (C) 2009 - 2010 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.financial.batch.db;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.time.calendar.OffsetTime;

import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.Sets;
import com.opengamma.engine.ComputationTargetSpecification;
import com.opengamma.engine.ComputationTargetType;
import com.opengamma.engine.view.ViewTestUtils;
import com.opengamma.financial.batch.BatchJob;
import com.opengamma.financial.batch.LiveDataValue;
import com.opengamma.id.Identifier;
import com.opengamma.id.UniqueIdentifier;
import com.opengamma.util.test.TransactionalHibernateTest;
import com.opengamma.util.time.DateUtil;

/**
 * 
 */
public class BatchDbManagerImplTest extends TransactionalHibernateTest {
    
    private BatchDbManagerImpl _dbManager;
    private BatchJob _batchJob;
    
    public BatchDbManagerImplTest(String databaseType, final String databaseVersion) {
      super(databaseType, databaseVersion);
    }
    
    @Override
    public Class<?>[] getHibernateMappingClasses() {
      return BatchDbManagerImpl.getHibernateMappingClasses();
    }

    @Before
    public void setUp() throws Exception {
      super.setUp();
      
      _dbManager = new BatchDbManagerImpl();
      _dbManager.setSessionFactory(getSessionFactory());
      
      _batchJob = new BatchJob();
      _batchJob.setBatchDbManager(_dbManager);
      _batchJob.setViewName("test_view");
      _batchJob.setView(ViewTestUtils.getMockView());
      _batchJob.init();
   }
    
    @Test
    public void getVersion() {
      // create
      OpenGammaVersion version1 = _dbManager.getOpenGammaVersion(_batchJob);
      assertNotNull(version1);
      assertEquals(_batchJob.getOpenGammaVersion(), version1.getVersion());
      assertEquals(_batchJob.getOpenGammaVersionHash(), version1.getHash());
      
      // get
      OpenGammaVersion version2 = _dbManager.getOpenGammaVersion(_batchJob);
      assertEquals(version1, version2);
    }
    
    @Test
    public void getObservationTime() {
      // create
      ObservationTime time1 = _dbManager.getObservationTime(_batchJob);
      assertNotNull(time1);<commit_msg>Test fixed<commit_after>/**
 * Copyright (C) 2009 - 2010 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.financial.batch.db;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.time.calendar.OffsetTime;

import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.Sets;
import com.opengamma.engine.ComputationTargetSpecification;
import com.opengamma.engine.ComputationTargetType;
import com.opengamma.engine.view.ViewTestUtils;
import com.opengamma.financial.batch.BatchJob;
import com.opengamma.financial.batch.LiveDataValue;
import com.opengamma.id.Identifier;
import com.opengamma.id.UniqueIdentifier;
import com.opengamma.util.test.TransactionalHibernateTest;
import com.opengamma.util.time.DateUtil;

/**
 * 
 */
public class BatchDbManagerImplTest extends TransactionalHibernateTest {
    
    private BatchDbManagerImpl _dbManager;
    private BatchJob _batchJob;
    
    public BatchDbManagerImplTest(String databaseType, final String databaseVersion) {
      super(databaseType, databaseVersion);
    }
    
    @Override
    public Class<?>[] getHibernateMappingClasses() {
      return BatchDbManagerImpl.getHibernateMappingClasses();
    }

    @Before
    public void setUp() throws Exception {
      super.setUp();
      
      _dbManager = new BatchDbManagerImpl();
      _dbManager.initialize(getDbTool(), getSessionFactory());
      
      _batchJob = new BatchJob();
      _batchJob.setBatchDbManager(_dbManager);
      _batchJob.setViewName("test_view");
      _batchJob.setView(ViewTestUtils.getMockView());
      _batchJob.init();
   }
    
    @Test
    public void getVersion() {
      // create
      OpenGammaVersion version1 = _dbManager.getOpenGammaVersion(_batchJob);
      assertNotNull(version1);
      assertEquals(_batchJob.getOpenGammaVersion(), version1.getVersion());
      assertEquals(_batchJob.getOpenGammaVersionHash(), version1.getHash());
      
      // get
      OpenGammaVersion version2 = _dbManager.getOpenGammaVersion(_batchJob);
      assertEquals(version1, version2);
    }
    
    @Test
    public void getObservationTime() {
      // create
      ObservationTime time1 = _dbManager.getObservationTime(_batchJob);
      assertNotNull(time1);
{'fraction_non_alphanumeric': 0.09657441455389974, 'fraction_numerical': 0.006580220630927037, 'mean_word_length': 4.081612586037365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4825390', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1493, 'n_words': 275}