use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testFederatedQueryPermissions.
@Test
public void testFederatedQueryPermissions() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
List<CatalogStore> storeList = new ArrayList<>();
List<FederatedSource> sourceList = new ArrayList<>();
Map<String, Set<String>> securityAttributes = new HashMap<>();
securityAttributes.put("role", Collections.singleton("myRole"));
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true, securityAttributes);
storeList.add(store);
sourceList.add(store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeList, sourceList, eventAdmin);
List<Metacard> metacards = new ArrayList<>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setContentTypeName("someType");
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
// ==== test writing to store and not local ====
destinations.add("catalogStoreId-1");
framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
FilterBuilder builder = new GeotoolsFilterBuilder();
Subject subject = mock(Subject.class);
when(subject.isPermitted(any(KeyValueCollectionPermission.class))).thenReturn(true);
HashMap<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().like().text("someType"));
QueryRequestImpl request = new QueryRequestImpl(query, false, Collections.singletonList("catalogStoreId-1"), properties);
QueryResponse response = framework.query(request);
assertThat(response.getResults().size(), is(1));
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnCreate.
@Test
public void testInjectsAttributesOnCreate() throws Exception {
final String title = "Create";
final String injectAttributeName = "new attribute";
final double injectAttributeValue = 2;
final MetacardImpl originalMetacard = new MetacardImpl();
originalMetacard.setTitle(title);
originalMetacard.setAttribute(injectAttributeName, injectAttributeValue);
final List<Metacard> metacards = Collections.singletonList(originalMetacard);
final CreateRequest request = new CreateRequestImpl(metacards, null);
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final CreateResponse response = framework.create(request);
final Metacard createdMetacard = response.getCreatedMetacards().get(0);
final MetacardType createdMetacardType = createdMetacard.getMetacardType();
final MetacardType originalMetacardType = originalMetacard.getMetacardType();
assertThat(createdMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(createdMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(createdMetacard.getTitle(), is(title));
assertThat(createdMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdate.
/**
* Tests that the framework properly passes an update request to the local provider.
*/
@Test
public void testUpdate() throws Exception {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
// create the entry manually in the provider
CreateResponse response = provider.create(new CreateRequestImpl(metacards, null));
Metacard insertedCard = response.getCreatedMetacards().get(0);
Result mockFederationResult = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId(insertedCard.getId());
when(mockFederationResult.getMetacard()).thenReturn(metacard);
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), Collections.singletonList(mockFederationResult), 1);
when(mockFederationStrategy.federate(anyList(), any())).thenReturn(queryResponse);
List<Entry<Serializable, Metacard>> updatedEntries = new ArrayList<Entry<Serializable, Metacard>>();
updatedEntries.add(new SimpleEntry<Serializable, Metacard>(insertedCard.getId(), insertedCard));
UpdateRequest request = new UpdateRequestImpl(updatedEntries, Metacard.ID, null);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
for (Update curCard : returnedCards) {
assertNotNull(curCard.getNewMetacard().getId());
}
// make sure that the event was posted correctly
assertTrue(eventAdmin.wasEventPosted());
assertEquals(eventAdmin.getLastEvent().getId(), returnedCards.get(returnedCards.size() - 1).getOldMetacard().getId());
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class FanoutCatalogFrameworkTest method testBlacklistedTagCreateRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagCreateRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
CreateRequest request = new CreateRequestImpl(metacard);
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
framework.create(request);
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class CatalogFrameworkQueryTest method testAfterQuery.
@Test
public void testAfterQuery() throws Exception {
Calendar afterCal = Calendar.getInstance();
Calendar card1Exp = Calendar.getInstance();
card1Exp.add(Calendar.YEAR, 1);
Calendar card2Exp = Calendar.getInstance();
card2Exp.add(Calendar.YEAR, 3);
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard1 = new MetacardImpl();
newCard1.setId(null);
newCard1.setExpirationDate(card1Exp.getTime());
metacards.add(newCard1);
MetacardImpl newCard2 = new MetacardImpl();
newCard2.setId(null);
newCard2.setExpirationDate(card2Exp.getTime());
metacards.add(newCard2);
String mcId1 = null;
String mcId2 = null;
CreateResponse createResponse = null;
createResponse = framework.create(new CreateRequestImpl(metacards, null));
assertEquals(createResponse.getCreatedMetacards().size(), metacards.size());
for (Metacard curCard : createResponse.getCreatedMetacards()) {
if (curCard.getExpirationDate().equals(card1Exp.getTime())) {
mcId1 = curCard.getId();
} else {
mcId2 = curCard.getId();
}
assertNotNull(curCard.getId());
}
FilterFactory filterFactory = new FilterFactoryImpl();
Instant afterInstant = new DefaultInstant(new DefaultPosition(afterCal.getTime()));
QueryImpl query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
QueryRequest queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
LOGGER.info("Response:{}", response);
assertEquals("Expecting return 2 results.", 2, response.getHits());
} catch (UnsupportedQueryException e) {
LOGGER.error("Failure!!!", e);
fail();
} catch (FederationException e) {
fail();
}
afterInstant = new DefaultInstant(new DefaultPosition(card1Exp.getTime()));
query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
assertEquals("After filter should return 1 result", 1, response.getHits());
assertEquals("After filter should return metacard[" + mcId2 + "]", mcId2, response.getResults().get(0).getMetacard().getId());
} catch (UnsupportedQueryException e) {
fail();
} catch (FederationException e) {
fail();
}
afterInstant = new DefaultInstant(new DefaultPosition(card2Exp.getTime()));
query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
assertEquals("After filter should return 0 results.", 0, response.getHits());
} catch (UnsupportedQueryException e) {
fail();
} catch (FederationException e) {
fail();
}
}
Aggregations