// -------------------------------------------------------------------------
  @Test
  public void test_search_name_noMatch() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    request.setName("FooBar");
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(0, test.getDocuments().size());
  }
  // -------------------------------------------------------------------------
  @Test
  public void test_search_configIds_none() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    request.setConfigIds(new ArrayList<ObjectIdentifier>());
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(0, test.getDocuments().size());
  }
  // -------------------------------------------------------------------------
  @Test
  public void test_search_versionAsOf_below() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    request.setVersionCorrection(
        VersionCorrection.ofVersionAsOf(_version1aInstant.minusSeconds(5)));
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(0, test.getDocuments().size());
  }
  @Test
  public void test_search_name_case() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    request.setName("TESTConfig102");
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(1, test.getDocuments().size());
    assert102(test.getDocuments().get(0));
  }
  @Test
  public void test_search_name_wildcard() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    request.setName("TestConfig1*");
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(2, test.getDocuments().size());
    assert102(test.getDocuments().get(0));
    assert101(test.getDocuments().get(1));
  }
  @Test
  public void test_search_versionAsOf_above() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    request.setVersionCorrection(VersionCorrection.ofVersionAsOf(_version2Instant.plusSeconds(5)));
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(3, test.getDocuments().size());
    assert202(test.getDocuments().get(0)); // new version
    assert102(test.getDocuments().get(1));
    assert101(test.getDocuments().get(2));
  }
  // -------------------------------------------------------------------------
  @Test
  public void test_search_all_documents() {
    ConfigSearchRequest<Object> request = new ConfigSearchRequest<Object>(Object.class);

    ConfigSearchResult<Object> test = _cfgMaster.search(request);

    assertEquals(1, test.getPaging().getFirstItem());
    assertEquals(Integer.MAX_VALUE, test.getPaging().getPagingSize());
    assertEquals(_totalConfigs, test.getPaging().getTotalItems());

    assertEquals(_totalConfigs, test.getDocuments().size());
  }
  @Test
  public void test_search_configIds() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    request.addConfigId(ObjectIdentifier.of("DbCfg", "101"));
    request.addConfigId(ObjectIdentifier.of("DbCfg", "201"));
    request.addConfigId(ObjectIdentifier.of("DbCfg", "9999"));
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(2, test.getDocuments().size());
    assert202(test.getDocuments().get(0));
    assert101(test.getDocuments().get(1));
  }
  @Test
  public void test_search_pageTwo() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    request.setPagingRequest(PagingRequest.of(2, 2));
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(3, test.getPaging().getFirstItem());
    assertEquals(2, test.getPaging().getPagingSize());
    assertEquals(_totalIdentifiers, test.getPaging().getTotalItems());

    assertEquals(1, test.getDocuments().size());
    assert101(test.getDocuments().get(0));
  }
コード例 #10
0
  /**
   * Search for configuration elements using a request object.
   *
   * @param <T> the type of configuration element
   * @param request the request object with value for search fields, not null
   * @return all configuration elements matching the request, not null
   */
  public <T> List<T> search(final ConfigSearchRequest<T> request) {
    ArgumentChecker.notNull(request, "request");
    ArgumentChecker.notNull(request.getType(), "request.type");
    request.setVersionCorrection(getVersionCorrection());

    ConfigSearchResult<T> searchResult = getMaster().search(request);
    List<ConfigDocument<T>> documents = searchResult.getDocuments();
    List<T> result = new ArrayList<T>();
    for (ConfigDocument<T> configDocument : documents) {
      result.add(configDocument.getValue());
    }
    return result;
  }
コード例 #11
0
  /**
   * Searches for a configuration document matching the specified name.
   *
   * <p>This will always return the latest correction of the version requested, ignoring any other
   * version constraints of the implementation.
   *
   * @param <T> the type of configuration element
   * @param clazz the configuration element type, not null
   * @param name the element name to search for, wildcards allowed, not null
   * @param versionAsOf the version to fetch, null means latest
   * @return the versioned configuration document matching the request, null if not found
   */
  public <T> ConfigDocument<T> getDocumentByName(
      final Class<T> clazz, final String name, final Instant versionAsOf) {
    ArgumentChecker.notNull(clazz, "clazz");
    ArgumentChecker.notNull(name, "name");

    ConfigSearchRequest<T> request = new ConfigSearchRequest<T>();
    request.setPagingRequest(PagingRequest.ONE);
    request.setVersionCorrection(VersionCorrection.ofVersionAsOf(versionAsOf));
    request.setName(name);
    request.setType(clazz);

    ConfigSearchResult<T> searchResult = getMaster().search(request);
    return searchResult.getFirstDocument();
  }
コード例 #12
0
  @Override
  public <T> Collection<? extends T> getConfigs(
      Class<T> clazz, String configName, VersionCorrection versionCorrection) {
    ArgumentChecker.notNull(clazz, "clazz");
    ArgumentChecker.notNull(configName, "configName");
    ArgumentChecker.notNull(versionCorrection, "versionCorrection");

    ConfigSearchRequest<T> request = new ConfigSearchRequest<T>();
    request.setVersionCorrection(versionCorrection);
    request.setName(configName);
    request.setType(clazz);
    ConfigSearchResult<T> searchResult = getMaster().search(request);
    return searchResult.getValues();
  }
  // -------------------------------------------------------------------------
  @Test
  public void test_search_typed_documents() {
    ConfigSearchRequest<Identifier> request = createIdentifierSearchRequest();
    ConfigSearchResult<Identifier> test = _cfgMaster.search(request);

    assertEquals(1, test.getPaging().getFirstItem());
    assertEquals(Integer.MAX_VALUE, test.getPaging().getPagingSize());
    assertEquals(_totalIdentifiers, test.getPaging().getTotalItems());

    assertEquals(_totalIdentifiers, test.getDocuments().size());
    assert202(test.getDocuments().get(0));
    assert102(test.getDocuments().get(1));
    assert101(test.getDocuments().get(2));
  }