public void getHistoricalTimeSeriesByExternalIdWithoutMetaData() throws Exception {
    ManageableHistoricalTimeSeries hts = new ManageableHistoricalTimeSeries();
    hts.setUniqueId(UID);
    hts.setTimeSeries(randomTimeSeries());
    when(_mockMaster.getTimeSeries(UID, HistoricalTimeSeriesGetFilter.ofRange(null, null)))
        .thenReturn(hts);
    ManageableHistoricalTimeSeriesInfo tsInfo = new ManageableHistoricalTimeSeriesInfo();
    tsInfo.setUniqueId(UID);
    when(_mockResolver.resolve(
            IDENTIFIERS, LocalDate.now(), null, null, CLOSE_DATA_FIELD, TEST_CONFIG))
        .thenReturn(new HistoricalTimeSeriesResolutionResult(tsInfo));

    HistoricalTimeSeries test =
        _tsSource.getHistoricalTimeSeries(CLOSE_DATA_FIELD, IDENTIFIERS, TEST_CONFIG);
    verify(_mockMaster, times(1))
        .getTimeSeries(UID, HistoricalTimeSeriesGetFilter.ofRange(null, null));

    assertEquals(UID, test.getUniqueId());
    assertEquals(hts.getTimeSeries().times(), test.getTimeSeries().times());
    assertEquals(hts.getTimeSeries().values(), test.getTimeSeries().values());
  }
  /**
   * Adds or updates a time-series in the master. Can be a sub-set of the data points present and
   * will not 'erase' points that are missing, only supplement them.
   *
   * @param description a description of the time-series for display purposes, not null
   * @param dataSource the data source, not null
   * @param dataProvider the data provider, not null
   * @param dataField the data field, not null
   * @param observationTime the descriptive observation time key, e.g. LONDON_CLOSE, not null
   * @param externalIdBundle the external identifiers with which the time-series is associated, not
   *     null
   * @param externalIdSearchType the external identifier search type for matching an existing
   *     time-series, null to use the default
   * @param timeSeries the time-series, not null
   * @return the unique identifier of the time-series
   */
  public UniqueId writeTimeSeries(
      String description,
      String dataSource,
      String dataProvider,
      String dataField,
      String observationTime,
      ExternalIdBundle externalIdBundle,
      ExternalIdSearchType externalIdSearchType,
      LocalDateDoubleTimeSeries timeSeries) {
    ArgumentChecker.notNull(description, "description");
    ArgumentChecker.notNull(dataSource, "dataSource");
    ArgumentChecker.notNull(dataProvider, "dataProvider");
    ArgumentChecker.notNull(dataField, "dataField");
    ArgumentChecker.notNull(observationTime, "observationTime");
    ArgumentChecker.notNull(externalIdBundle, "externalIdBundle");
    ArgumentChecker.notNull(timeSeries, "timeSeries");

    HistoricalTimeSeriesInfoSearchRequest htsSearchReq =
        new HistoricalTimeSeriesInfoSearchRequest();
    ExternalIdSearch idSearch = ExternalIdSearch.of(externalIdBundle);
    if (externalIdSearchType != null) {
      idSearch = idSearch.withSearchType(externalIdSearchType);
    }
    htsSearchReq.setExternalIdSearch(idSearch);
    htsSearchReq.setDataSource(dataSource);
    htsSearchReq.setDataProvider(dataProvider);
    htsSearchReq.setDataField(dataField);
    htsSearchReq.setObservationTime(observationTime);
    HistoricalTimeSeriesInfoSearchResult searchResult = _htsMaster.search(htsSearchReq);
    if (searchResult.getDocuments().size() > 0) {
      if (searchResult.getDocuments().size() > 1) {
        s_logger.warn(
            "Found multiple time-series matching search. Will only update the first. Search {} returned {}",
            htsSearchReq,
            searchResult.getInfoList());
      }
      // update existing time series
      HistoricalTimeSeriesInfoDocument existingTsDoc = searchResult.getFirstDocument();
      return writeTimeSeries(
          description,
          dataSource,
          dataProvider,
          dataField,
          observationTime,
          existingTsDoc.getObjectId(),
          timeSeries);
    } else {
      // add new time series
      ManageableHistoricalTimeSeriesInfo info = new ManageableHistoricalTimeSeriesInfo();
      info.setDataField(dataField);
      info.setDataSource(dataSource);
      info.setDataProvider(dataProvider);
      info.setObservationTime(observationTime);
      info.setExternalIdBundle(ExternalIdBundleWithDates.of(externalIdBundle));
      info.setName(description);
      HistoricalTimeSeriesInfoDocument htsInfoDoc = new HistoricalTimeSeriesInfoDocument();
      htsInfoDoc.setInfo(info);

      HistoricalTimeSeriesInfoDocument addedInfoDoc = _htsMaster.add(htsInfoDoc);
      s_logger.debug(
          "Adding time series "
              + externalIdBundle
              + " from "
              + timeSeries.getEarliestTime()
              + " to "
              + timeSeries.getLatestTime());
      return _htsMaster.updateTimeSeriesDataPoints(
          addedInfoDoc.getInfo().getTimeSeriesObjectId(), timeSeries);
    }
  }