Search in sources :

Example 1 with MetacardMarshaller

use of org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller in project ddf by codice.

the class TestRegistryStore method testInit.

@Test
public void testInit() throws Exception {
    RegistryStoreImpl registryStore = spy(new RegistryStoreImpl(context, cswSourceConfiguration, provider, factory, encryptionService) {

        @Override
        protected void validateOperation() {
        }

        @Override
        public boolean isAvailable() {
            return availability;
        }

        @Override
        protected SourceResponse query(QueryRequest queryRequest, ElementSetType elementSetName, List<QName> elementNames, Csw csw) throws UnsupportedQueryException {
            if (queryResults == null) {
                throw new UnsupportedQueryException("Test - Bad Query");
            }
            return new SourceResponseImpl(queryRequest, queryResults);
        }

        @Override
        public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
            return new SourceResponseImpl(request, Collections.singletonList(new Result() {

                @Override
                public Metacard getMetacard() {
                    MetacardImpl metacard = new MetacardImpl();
                    metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "registryId");
                    metacard.setAttribute(Metacard.TITLE, "title");
                    return metacard;
                }

                @Override
                public Double getRelevanceScore() {
                    return null;
                }

                @Override
                public Double getDistanceInMeters() {
                    return null;
                }
            }));
        }

        @Override
        protected CapabilitiesType getCapabilities() {
            return mock(CapabilitiesType.class);
        }

        @Override
        public void configureCswSource() {
        }

        ;

        @Override
        protected Subject getSystemSubject() {
            return subject;
        }

        @Override
        BundleContext getBundleContext() {
            return context;
        }
    });
    registryStore.setFilterBuilder(filterBuilder);
    registryStore.setFilterAdapter(filterAdapter);
    registryStore.setConfigAdmin(configAdmin);
    registryStore.setMetacardMarshaller(new MetacardMarshaller(parser));
    registryStore.setSchemaTransformerManager(transformer);
    registryStore.setAutoPush(true);
    registryStore.setRegistryUrl("http://test.url:0101/example");
    properties = new Hashtable<>();
    properties.put(RegistryStoreImpl.ID, "registryId");
    registryStore.setMetacardMarshaller(marshaller);
    Csw csw = mock(Csw.class);
    when(factory.getClientForSubject(any())).thenReturn(csw);
    cswSourceConfiguration.setCswUrl("https://localhost");
    cswSourceConfiguration.setPollIntervalMinutes(1);
    queryResults.add(new ResultImpl(getDefaultMetacard()));
    registryStore.init();
    assertThat(registryStore.getRegistryId(), is("registryId"));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) QName(javax.xml.namespace.QName) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Subject(ddf.security.Subject) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 2 with MetacardMarshaller

use of org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller in project ddf by codice.

the class FederationAdminServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    when(parser.configureParser(anyList(), any(ClassLoader.class))).thenReturn(configurator);
    federationAdminServiceImpl = Mockito.spy(new FederationAdminServiceImpl(security));
    federationAdminServiceImpl.setRegistryTransformer(registryTransformer);
    federationAdminServiceImpl.setCatalogFramework(catalogFramework);
    federationAdminServiceImpl.setMetacardMarshaller(new MetacardMarshaller(parser));
    federationAdminServiceImpl.setFilterBuilder(filterBuilder);
    System.setProperty(SystemInfo.SITE_NAME, TEST_SITE_NAME);
    System.setProperty(SystemInfo.VERSION, TEST_VERSION);
    testMetacard = getPopulatedTestRegistryMetacard();
    when(deleteResponse.getProcessingErrors()).thenReturn(new HashSet<ProcessingDetails>());
    when(createResponse.getProcessingErrors()).thenReturn(new HashSet<ProcessingDetails>());
    when(updateResponse.getProcessingErrors()).thenReturn(new HashSet<ProcessingDetails>());
    when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(updateResponse);
    when(catalogFramework.delete(any(DeleteRequest.class))).thenReturn(deleteResponse);
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    when(security.runWithSubjectOrElevate(any(Callable.class))).thenAnswer(invocation -> {
        try {
            return ((Callable) invocation.getArguments()[0]).call();
        } catch (Exception e) {
            throw new InvocationTargetException(e.getCause());
        }
    });
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) UpdateRequest(ddf.catalog.operation.UpdateRequest) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) CreateRequest(ddf.catalog.operation.CreateRequest) DeleteRequest(ddf.catalog.operation.DeleteRequest) Callable(java.util.concurrent.Callable) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) ParserException(org.codice.ddf.parser.ParserException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) IngestException(ddf.catalog.source.IngestException) FederationException(ddf.catalog.federation.FederationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Before(org.junit.Before)

Example 3 with MetacardMarshaller

use of org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller in project ddf by codice.

the class TestRegistryStore method setup.

@Before
public void setup() throws Exception {
    parser = new XmlParser();
    marshaller = new MetacardMarshaller(new XmlParser());
    context = mock(BundleContext.class);
    provider = mock(Converter.class);
    cswSourceConfiguration = new CswSourceConfiguration();
    factory = mock(SecureCxfClientFactory.class);
    transformer = mock(TransformerManager.class);
    encryptionService = mock(EncryptionService.class);
    configAdmin = mock(ConfigurationAdmin.class);
    configuration = mock(Configuration.class);
    subject = mock(Subject.class);
    queryResults = new ArrayList<>();
    registryStore = spy(new RegistryStoreImpl(context, cswSourceConfiguration, provider, factory, encryptionService) {

        @Override
        protected void validateOperation() {
        }

        @Override
        public boolean isAvailable() {
            return availability;
        }

        @Override
        protected SourceResponse query(QueryRequest queryRequest, ElementSetType elementSetName, List<QName> elementNames, Csw csw) throws UnsupportedQueryException {
            if (queryResults == null) {
                throw new UnsupportedQueryException("Test - Bad Query");
            }
            return new SourceResponseImpl(queryRequest, queryResults);
        }

        @Override
        protected CapabilitiesType getCapabilities() {
            return mock(CapabilitiesType.class);
        }

        @Override
        public void configureCswSource() {
        }

        ;

        @Override
        protected Subject getSystemSubject() {
            return subject;
        }

        @Override
        BundleContext getBundleContext() {
            return context;
        }
    });
    registryStore.setFilterBuilder(filterBuilder);
    registryStore.setFilterAdapter(filterAdapter);
    registryStore.setConfigAdmin(configAdmin);
    registryStore.setMetacardMarshaller(new MetacardMarshaller(parser));
    registryStore.setSchemaTransformerManager(transformer);
    registryStore.setAutoPush(true);
    registryStore.setRegistryUrl("http://test.url:0101/example");
    properties = new Hashtable<>();
    properties.put(RegistryStoreImpl.ID, "registryId");
    registryStore.setMetacardMarshaller(marshaller);
    when(configAdmin.getConfiguration(any())).thenReturn(configuration);
    when(configuration.getProperties()).thenReturn(properties);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) XmlParser(org.codice.ddf.parser.xml.XmlParser) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) Configuration(org.osgi.service.cm.Configuration) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) QueryRequest(ddf.catalog.operation.QueryRequest) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Subject(ddf.security.Subject) EncryptionService(ddf.security.encryption.EncryptionService) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) Converter(com.thoughtworks.xstream.converters.Converter) List(java.util.List) ArrayList(java.util.ArrayList) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 4 with MetacardMarshaller

use of org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller in project ddf by codice.

the class FederationAdminTest method setup.

@Before
public void setup() throws Exception {
    parser = new XmlParser();
    configurator = parser.configureParser(Arrays.asList(RegistryObjectType.class.getPackage().getName(), EbrimConstants.OGC_FACTORY.getClass().getPackage().getName(), EbrimConstants.GML_FACTORY.getClass().getPackage().getName()), this.getClass().getClassLoader());
    federationAdmin = new FederationAdmin(helper) {

        @Override
        public BundleContext getContext() {
            return context;
        }
    };
    federationAdmin.setFederationAdminService(federationAdminService);
    federationAdmin.setRegistryTransformer(registryTransformer);
    federationAdmin.setMetacardMarshaller(new MetacardMarshaller(parser));
    federationAdmin.setSlotHelper(new SlotTypeHelper());
    federationAdmin.setRegistryMapConverter(new RegistryPackageWebConverter());
    federationAdmin.setRegistryTypeConverter(new RegistryPackageTypeConverter());
    federationAdmin.setSourceConfigRefresh(sourceConfiguration);
    mcard = new MetacardImpl(new RegistryObjectMetacardType());
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "myId");
    mcard.setAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, new ArrayList<>());
    mcard.setId("someUUID");
    when(queryResponse.getResults()).thenReturn(Collections.singletonList(new ResultImpl(mcard)));
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse);
    catalogStoreMap.put("myDest", store);
}
Also used : XmlParser(org.codice.ddf.parser.xml.XmlParser) QueryRequest(ddf.catalog.operation.QueryRequest) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) SlotTypeHelper(org.codice.ddf.registry.schemabindings.helper.SlotTypeHelper) RegistryPackageWebConverter(org.codice.ddf.registry.schemabindings.converter.web.RegistryPackageWebConverter) ResultImpl(ddf.catalog.data.impl.ResultImpl) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) RegistryPackageTypeConverter(org.codice.ddf.registry.schemabindings.converter.type.RegistryPackageTypeConverter) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 5 with MetacardMarshaller

use of org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller in project ddf by codice.

the class SourceConfigurationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    parser = new XmlParser();
    adminService = mock(FederationAdminService.class);
    configAdmin = mock(ConfigurationAdmin.class);
    metaTypeService = mock(MetaTypeService.class);
    bundleContext = mock(BundleContext.class);
    executorService = mock(ExecutorService.class);
    sch = new SourceConfigurationHandler(adminService, executorService) {

        @Override
        protected BundleContext getBundleContext() {
            return bundleContext;
        }
    };
    sch.setMetacardMarshaller(new MetacardMarshaller(parser));
    sch.setConfigurationAdmin(configAdmin);
    sch.setMetaTypeService(metaTypeService);
    sch.setSlotHelper(new SlotTypeHelper());
    sch.setRegistryTypeHelper(new RegistryPackageTypeHelper());
    sch.setActivateConfigurations(false);
    sch.setPreserveActiveConfigurations(true);
    sch.setUrlBindingName("urlBindingName");
    sch.setBindingTypeFactoryPid(Collections.singletonList("CSW_2.0.2=Csw_Federated_Source"));
    sch.setSourceActivationPriorityOrder(Collections.singletonList("CSW_2.0.2"));
    sch.setCleanUpOnDelete(false);
    Bundle bundle = mock(Bundle.class);
    mti = mock(MetaTypeInformation.class);
    ocd = mock(ObjectClassDefinition.class);
    config = mock(Configuration.class);
    AttributeDefinition adi = new AttributeDefinitionImpl("attId", "attName", "attDesc", "attValue");
    when(adminService.getRegistryMetacards()).thenReturn(new ArrayList());
    when(bundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
    when(configAdmin.listConfigurations("(id=TestRegNode")).thenReturn(null);
    when(configAdmin.listConfigurations("(registry-id=urn:uuid:2014ca7f59ac46f495e32b4a67a51276")).thenReturn(null);
    when(metaTypeService.getMetaTypeInformation(any(Bundle.class))).thenReturn(mti);
    when(mti.getObjectClassDefinition(anyString(), anyString())).thenReturn(ocd);
    when(ocd.getAttributeDefinitions(anyInt())).thenReturn(new AttributeDefinition[] { adi });
    when(configAdmin.createFactoryConfiguration(anyString(), anyString())).thenReturn(config);
    mcard = new MetacardImpl(new RegistryObjectMetacardType());
    mcard.setTags(Collections.singleton(RegistryConstants.REGISTRY_TAG));
    mcard.setId("2014ca7f59ac46f495e32b4a67a51276");
    mcard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "urn:uuid:2014ca7f59ac46f495e32b4a67a51276");
    mcard.setMetadata(getMetadata("/csw-rim-node-csw-binding.xml"));
    mcard.setTitle("TestRegNode");
    Dictionary<String, Object> eventProperties = new Hashtable<>();
    eventProperties.put("ddf.catalog.event.metacard", mcard);
    createEvent = new Event("ddf/catalog/event/CREATED", eventProperties);
    updateEvent = new Event("ddf/catalog/event/UPDATED", eventProperties);
    deleteEvent = new Event("ddf/catalog/event/DELETED", eventProperties);
    System.setProperty(RegistryConstants.REGISTRY_ID_PROPERTY, "myRegId");
}
Also used : MetaTypeService(org.osgi.service.metatype.MetaTypeService) Configuration(org.osgi.service.cm.Configuration) SlotTypeHelper(org.codice.ddf.registry.schemabindings.helper.SlotTypeHelper) ArrayList(java.util.ArrayList) AttributeDefinition(org.osgi.service.metatype.AttributeDefinition) Matchers.anyString(org.mockito.Matchers.anyString) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition) XmlParser(org.codice.ddf.parser.xml.XmlParser) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ExecutorService(java.util.concurrent.ExecutorService) Event(org.osgi.service.event.Event) RegistryPackageTypeHelper(org.codice.ddf.registry.schemabindings.helper.RegistryPackageTypeHelper) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Aggregations

MetacardMarshaller (org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller)7 Before (org.junit.Before)6 XmlParser (org.codice.ddf.parser.xml.XmlParser)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 BundleContext (org.osgi.framework.BundleContext)4 QueryRequest (ddf.catalog.operation.QueryRequest)3 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)3 RegistryObjectMetacardType (org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType)3 ResultImpl (ddf.catalog.data.impl.ResultImpl)2 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)2 Subject (ddf.security.Subject)2 ArrayList (java.util.ArrayList)2 ElementSetType (net.opengis.cat.csw.v_2_0_2.ElementSetType)2 SlotTypeHelper (org.codice.ddf.registry.schemabindings.helper.SlotTypeHelper)2 Csw (org.codice.ddf.spatial.ogc.csw.catalog.common.Csw)2 Configuration (org.osgi.service.cm.Configuration)2 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)2 Converter (com.thoughtworks.xstream.converters.Converter)1 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1