Search in sources :

Example 46 with CreateRequestImpl

use of ddf.catalog.operation.impl.CreateRequestImpl 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));
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Example 47 with CreateRequestImpl

use of ddf.catalog.operation.impl.CreateRequestImpl 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));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Subject(ddf.security.Subject) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) Test(org.junit.Test)

Example 48 with CreateRequestImpl

use of ddf.catalog.operation.impl.CreateRequestImpl 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"));
        }
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateRequest(ddf.catalog.operation.CreateRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) RegistryObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType) Test(org.junit.Test)

Example 49 with CreateRequestImpl

use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.

the class IdentificationPluginTest method testOtherExtIds.

//test ext IDs are not set to other items
@Test
public void testOtherExtIds() throws Exception {
    //unmarshal metacard.metadata and confirm both origin and local ext id are set to metacard.getId()
    String xml = convert("/registry-extra-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.getValue(), is(testMetacard.getId()));
        }
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateRequest(ddf.catalog.operation.CreateRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) RegistryObjectType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryObjectType) Test(org.junit.Test)

Example 50 with CreateRequestImpl

use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.

the class IdentificationPluginTest method testRemoteRequest.

@Test
public void testRemoteRequest() throws Exception {
    String xml = convert("/registry-no-extid.xml");
    sampleData.setAttribute(Metacard.METADATA, xml);
    Map<String, Serializable> props = new HashMap<>();
    props.put(Constants.LOCAL_DESTINATION_KEY, false);
    CreateRequest result = identificationPlugin.process(new CreateRequestImpl(Collections.singletonList(sampleData), props));
    assertThat(result.getMetacards().get(0).getMetadata(), equalTo(xml));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Test(org.junit.Test)

Aggregations

CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)80 Test (org.junit.Test)60 Metacard (ddf.catalog.data.Metacard)53 CreateResponse (ddf.catalog.operation.CreateResponse)44 CreateRequest (ddf.catalog.operation.CreateRequest)42 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)29 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)26 Serializable (java.io.Serializable)22 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)19 IngestException (ddf.catalog.source.IngestException)19 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)17 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)17 InputStream (java.io.InputStream)17 HashSet (java.util.HashSet)16 QueryImpl (ddf.catalog.operation.impl.QueryImpl)15 Subject (ddf.security.Subject)15 QueryRequest (ddf.catalog.operation.QueryRequest)13 QueryResponse (ddf.catalog.operation.QueryResponse)13 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)12