use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testTextualSort.
@Test
public void testTextualSort() throws Exception {
deleteAllIn(provider);
List<Metacard> list = new ArrayList<Metacard>();
DateTime now = new DateTime();
for (int i = 65; i < 65 + 5; i++) {
MockMetacard m = new MockMetacard(Library.getFlagstaffRecord());
m.setEffectiveDate(now.minus(5L * i).toDate());
m.setTitle((char) i + " Record ");
list.add(m);
}
create(list);
Filter filter = null;
QueryImpl query = null;
SourceResponse sourceResponse = null;
// Sort all Textual ASCENDING
filter = filterBuilder.attribute(Metacard.EFFECTIVE).before().date(now.plusMillis(1).toDate());
query = new QueryImpl(filter);
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Metacard.TITLE, SortOrder.ASCENDING.name()));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(list.size(), sourceResponse.getResults().size());
int ascii = 65;
for (int i = 0; i < list.size(); i++) {
Result r = sourceResponse.getResults().get(i);
assertEquals((char) (i + ascii) + " Record ", r.getMetacard().getTitle());
}
// Sort all Textual DESCENDING
query.setSortBy(new ddf.catalog.filter.impl.SortByImpl(Metacard.TITLE, SortOrder.DESCENDING.name()));
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(list.size(), sourceResponse.getResults().size());
int asciiE = 69;
for (int i = (list.size() - 1); i >= 0; i--) {
Result r = sourceResponse.getResults().get(i);
assertEquals((char) (asciiE - i) + " Record ", r.getMetacard().getTitle());
}
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testDeleteOperation.
/**
* Testing that if records are properly deleted.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testDeleteOperation() throws IngestException, UnsupportedQueryException {
// Single Deletion
deleteAllIn(provider);
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
CreateResponse createResponse = create(metacard);
DeleteResponse deleteResponse = delete(createResponse.getCreatedMetacards().get(0).getId());
Metacard deletedMetacard = deleteResponse.getDeletedMetacards().get(0);
verifyDeletedRecord(metacard, createResponse, deleteResponse, deletedMetacard);
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testUpdateUnknownAttribute.
/**
* Testing update operation of unknown attribute. Should return no results.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
public void testUpdateUnknownAttribute() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
UpdateResponse response = provider.update(new UpdateRequest() {
@Override
public boolean hasProperties() {
return false;
}
@Override
public Serializable getPropertyValue(String name) {
return null;
}
@Override
public Set<String> getPropertyNames() {
return null;
}
@Override
public Map<String, Serializable> getProperties() {
return null;
}
@Override
public boolean containsPropertyName(String name) {
return false;
}
@Override
public List<Entry<Serializable, Metacard>> getUpdates() {
MockMetacard newMetacard = new MockMetacard(Library.getShowLowRecord());
List<Entry<Serializable, Metacard>> updateList = new ArrayList<Entry<Serializable, Metacard>>();
updateList.add(new SimpleEntry<Serializable, Metacard>(MockMetacard.DEFAULT_TITLE, newMetacard));
return updateList;
}
@Override
public String getAttributeName() {
return "dataAccess";
}
});
assertEquals(0, response.getUpdatedMetacards().size());
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testWhitespaceTokenizedFieldWithWildcardSearch.
/**
* Testing Tokenization of the search phrase.
*
* @throws Exception
*/
@Test
public void testWhitespaceTokenizedFieldWithWildcardSearch() throws Exception {
deleteAllIn(provider);
List<Metacard> list = new ArrayList<Metacard>();
String title = "AB-12.yz_file";
MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setTitle(title);
String searchPhrase1 = "AB*12.yz_file";
String searchPhrase2 = "AB-12*yz_file";
String searchPhrase3 = "AB-12.yz*file";
String searchPhrase4 = "AB-12.*_file";
String searchPhrase5 = "Flagstaff Chamb*";
String searchPhrase6 = "Flagstaff Cmmerce";
list.add(metacard1);
create(list);
queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().like().text(searchPhrase1));
queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().like().text(searchPhrase2));
queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().like().text(searchPhrase3));
queryAndVerifyCount(1, filterBuilder.attribute(Metacard.TITLE).is().like().text(searchPhrase4));
// Matching Phrase with wildcard
queryAndVerifyCount(1, filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase5));
// Non-Matching Phrase without wildcard
queryAndVerifyCount(0, filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase6));
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testSpatialQueryWithCounterClockwiseRectangle.
@Test
public void testSpatialQueryWithCounterClockwiseRectangle() throws Exception {
deleteAllIn(provider);
MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
metacard.setLocation(FLAGSTAFF_AIRPORT_POINT_WKT);
List<Metacard> list = Arrays.asList((Metacard) metacard);
/** CREATE **/
create(list);
/** POSITIVE **/
Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(COUNTERCLOCKWISE_ARIZONA_RECTANGLE_WKT);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find Flagstaff record.", 1, sourceResponse.getResults().size());
for (Result r : sourceResponse.getResults()) {
assertTrue("Wrong record, Flagstaff keyword was not found.", ALL_RESULTS != r.getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE));
}
}
Aggregations