@Test(expectedExceptions = IllegalArgumentException.class)
 public void test_update_noConfigId() {
   ConfigDocument<Identifier> doc = new ConfigDocument<Identifier>(Identifier.class);
   doc.setName("Name");
   doc.setValue(Identifier.of("A", "B"));
   _cfgMaster.update(doc);
 }
  @Test
  public void test_update_rollback() {
    DbConfigWorker w =
        new DbConfigWorker(_cfgMaster.getDbSource(), _cfgMaster.getIdentifierScheme()) {
          @Override
          protected String sqlInsertConfig() {
            return "INSERT"; // bad sql
          }
        };
    final ConfigDocument<Identifier> base =
        _cfgMaster.get(UniqueIdentifier.of("DbCfg", "101", "0"), Identifier.class);
    UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "101", "0");
    ConfigDocument<Identifier> input = new ConfigDocument<Identifier>(Identifier.class);
    input.setUniqueId(uid);
    input.setName("Name");
    input.setValue(Identifier.of("A", "B"));
    try {
      w.update(input);
      Assert.fail();
    } catch (BadSqlGrammarException ex) {
      // expected
    }
    final ConfigDocument<Identifier> test =
        _cfgMaster.get(UniqueIdentifier.of("DbCfg", "101", "0"), Identifier.class);

    assertEquals(base, test);
  }
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void test_update_notLatestVersion() {
   UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "201", "0");
   ConfigDocument<Identifier> doc = new ConfigDocument<Identifier>(Identifier.class);
   doc.setUniqueId(uid);
   doc.setName("Name");
   doc.setValue(Identifier.of("A", "B"));
   _cfgMaster.update(doc);
 }
 @Test(expectedExceptions = DataNotFoundException.class)
 public void test_update_notFound() {
   UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "0", "0");
   ConfigDocument<Identifier> doc = new ConfigDocument<Identifier>(Identifier.class);
   doc.setUniqueId(uid);
   doc.setName("Name");
   doc.setValue(Identifier.of("A", "B"));
   _cfgMaster.update(doc);
 }
  @Test
  public void test_update_getUpdateGet() {
    Instant now = Instant.now(_cfgMaster.getTimeSource());

    UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "101", "0");
    ConfigDocument<Identifier> base = _cfgMaster.get(uid, Identifier.class);
    ConfigDocument<Identifier> input = new ConfigDocument<Identifier>(Identifier.class);
    input.setUniqueId(uid);
    input.setName("NewName");
    input.setValue(Identifier.of("A", "B"));

    ConfigDocument<Identifier> updated = _cfgMaster.update(input);
    assertEquals(false, base.getUniqueId().equals(updated.getUniqueId()));
    assertEquals(now, updated.getVersionFromInstant());
    assertEquals(null, updated.getVersionToInstant());
    assertEquals(now, updated.getCorrectionFromInstant());
    assertEquals(null, updated.getCorrectionToInstant());
    assertEquals("NewName", updated.getName());
    assertEquals(Identifier.of("A", "B"), updated.getValue());

    ConfigDocument<Identifier> old = _cfgMaster.get(uid, Identifier.class);
    assertEquals(base.getUniqueId(), old.getUniqueId());
    assertEquals(base.getVersionFromInstant(), old.getVersionFromInstant());
    assertEquals(now, old.getVersionToInstant()); // old version ended
    assertEquals(base.getCorrectionFromInstant(), old.getCorrectionFromInstant());
    assertEquals(base.getCorrectionToInstant(), old.getCorrectionToInstant());
    assertEquals(base.getName(), old.getName());
    assertEquals(base.getValue(), old.getValue());

    ConfigHistoryRequest<Identifier> search =
        new ConfigHistoryRequest<Identifier>(base.getUniqueId(), null, now);
    search.setType(Identifier.class);

    ConfigHistoryResult<Identifier> searchResult = _cfgMaster.history(search);
    assertEquals(2, searchResult.getDocuments().size());
  }
 public static Set<ValueRequirement> buildRequirements(
     final InterpolatedYieldCurveSpecification specification,
     final FunctionCompilationContext context) {
   final Set<ValueRequirement> result = new HashSet<ValueRequirement>();
   for (final FixedIncomeStripWithIdentifier strip : specification.getStrips()) {
     result.add(
         new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, strip.getSecurity()));
   }
   final ConventionBundleSource conventionBundleSource =
       OpenGammaCompilationContext.getConventionBundleSource(context);
   final ConventionBundle conventionBundle =
       conventionBundleSource.getConventionBundle(
           Identifier.of(
               InMemoryConventionBundleMaster.SIMPLE_NAME_SCHEME,
               specification.getCurrency().getCode() + "_SWAP"));
   final ConventionBundle referenceRateConvention =
       conventionBundleSource.getConventionBundle(
           IdentifierBundle.of(conventionBundle.getSwapFloatingLegInitialRate()));
   final Identifier initialRefRateId =
       SecurityUtils.bloombergTickerSecurityId(
           referenceRateConvention.getIdentifiers().getIdentifier(SecurityUtils.BLOOMBERG_TICKER));
   result.add(new ValueRequirement(MarketDataRequirementNames.MARKET_VALUE, initialRefRateId));
   return Collections.unmodifiableSet(result);
 }