use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class ReplicateCommandTest method setUp.
@Before
public void setUp() throws Exception {
catalogFramework = mock(CatalogFramework.class);
replicateCommand = new ReplicateCommand();
final Session session = mock(Session.class);
when(session.readLine(anyString(), isNull())).thenReturn("sourceId1");
replicateCommand.session = session;
replicateCommand.catalogFramework = catalogFramework;
replicateCommand.filterBuilder = new GeotoolsFilterBuilder();
when(mockSession.getKeyboard()).thenReturn(mockIS);
when(catalogFramework.getSourceIds()).thenReturn(SOURCE_IDS);
when(catalogFramework.query(isA(QueryRequest.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
QueryRequest request = (QueryRequest) args[0];
QueryResponse mockQueryResponse = mock(QueryResponse.class);
when(mockQueryResponse.getHits()).thenReturn(Long.valueOf(HITS));
when(mockQueryResponse.getResults()).thenReturn(getResultList(Math.min(replicateCommand.batchSize, HITS - request.getQuery().getStartIndex() + 1)));
return mockQueryResponse;
});
when(catalogFramework.create(isA(CreateRequest.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
CreateRequest request = (CreateRequest) args[0];
when(mockCreateResponse.getCreatedMetacards()).thenReturn(request.getMetacards());
return mockCreateResponse;
});
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class TestRegistryStore method testCreateWithExistingMetacard.
@Test
public void testCreateWithExistingMetacard() throws Exception {
Metacard mcard = getDefaultMetacard();
queryResults.add(new ResultImpl(mcard));
CreateRequest request = new CreateRequestImpl(mcard);
CreateResponse response = registryStore.create(request);
assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class TestMetacardGroomerPlugin method testCreateWithNullRecords.
@Test
public void testCreateWithNullRecords() throws PluginExecutionException, StopProcessingException {
CreateRequest request = mock(CreateRequest.class);
when(request.getMetacards()).thenReturn(null);
CreateRequest returnedRequest = plugin.process(request);
assertThat(returnedRequest, not(nullValue()));
assertThat(returnedRequest.getMetacards(), nullValue());
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class FederationAdminServiceImplTest method testAddRegistryEntryString.
@Test
public void testAddRegistryEntryString() throws Exception {
Metacard metacard = testMetacard;
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, Collections.singletonList(RegistryConstants.REGISTRY_TAG)));
Metacard createdMetacard = testMetacard;
Subject systemSubject = security.getSystemSubject();
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);
CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard), properties, null);
CreateResponse response = new CreateResponseImpl(request, null, Collections.singletonList(createdMetacard));
when(registryTransformer.transform(any(InputStream.class))).thenReturn(metacard);
when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);
String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(TEST_XML_STRING);
assertThat(createdMetacardId, is(equalTo(RegistryObjectMetacardType.REGISTRY_ID)));
verify(registryTransformer).transform(any(InputStream.class));
verify(catalogFramework).create(any(CreateRequest.class));
}
use of ddf.catalog.operation.CreateRequest in project ddf by codice.
the class IdentificationPluginTest method testIdsAlreadySet.
//test both ids are already set
@Test
public void testIdsAlreadySet() throws Exception {
//unmarshal metacard.metadata and confirm only local ext id are set to metacard.getId()
String xml = convert("/registry-both-extid.xml");
sampleData.setAttribute(Metacard.METADATA, xml);
CreateRequest result = identificationPlugin.process(new CreateRequestImpl(sampleData));
Metacard testMetacard = result.getMetacards().get(0);
String metadata = testMetacard.getMetadata();
InputStream inputStream = new ByteArrayInputStream(metadata.getBytes(Charsets.UTF_8));
JAXBElement<RegistryObjectType> registryObjectTypeJAXBElement = parser.unmarshal(configurator, JAXBElement.class, inputStream);
RegistryObjectType registryObjectType = registryObjectTypeJAXBElement.getValue();
List<ExternalIdentifierType> extIdList = registryObjectType.getExternalIdentifier();
for (ExternalIdentifierType singleExtId : extIdList) {
if (singleExtId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_LOCAL)) {
assertThat(singleExtId.getValue(), is(testMetacard.getId()));
} else if (singleExtId.getId().equals(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN)) {
assertThat(singleExtId.getId(), is(RegistryConstants.REGISTRY_MCARD_ID_ORIGIN));
assertThat(singleExtId.getValue(), is("registryPresetOriginValue"));
}
}
}
Aggregations