@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_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)); }
// ------------------------------------------------------------------------- @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)); }
// ------------------------------------------------------------------------- @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_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_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_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()); }
/** * 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; }