{"action":"created","comment":{"url":"https://api.github.com/repos/codice/ddf/pulls/comments/65427407","id":65427407,"diff_hunk":"@@ -13,6 +13,1727 @@\n  **/\n package org.codice.ddf.registry.federationadmin.service.impl;\n \n+import static org.codice.ddf.registry.schemabindings.RegistryPackageUtils.RIM_FACTORY;\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.empty;\n+import static org.hamcrest.Matchers.equalTo;\n+import static org.hamcrest.Matchers.hasSize;\n+import static org.hamcrest.Matchers.is;\n+import static org.hamcrest.Matchers.notNullValue;\n+import static org.hamcrest.Matchers.nullValue;\n+import static org.mockito.Matchers.any;\n+import static org.mockito.Matchers.anyList;\n+import static org.mockito.Matchers.eq;\n+import static org.mockito.Mockito.doReturn;\n+import static org.mockito.Mockito.doThrow;\n+import static org.mockito.Mockito.never;\n+import static org.mockito.Mockito.spy;\n+import static org.mockito.Mockito.times;\n+import static org.mockito.Mockito.verify;\n+import static org.mockito.Mockito.when;\n+\n+import java.io.InputStream;\n+import java.io.OutputStream;\n+import java.io.Serializable;\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.Date;\n+import java.util.HashMap;\n+import java.util.HashSet;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Set;\n+\n+import javax.xml.bind.JAXBElement;\n+\n+import org.codice.ddf.configuration.SystemInfo;\n+import org.codice.ddf.parser.Parser;\n+import org.codice.ddf.parser.ParserConfigurator;\n+import org.codice.ddf.parser.ParserException;\n+import org.codice.ddf.registry.api.RegistryStore;\n+import org.codice.ddf.registry.common.RegistryConstants;\n+import org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType;\n+import org.codice.ddf.registry.federationadmin.service.FederationAdminException;\n+import org.codice.ddf.registry.transformer.RegistryTransformer;\n+import org.codice.ddf.security.common.Security;\n+import org.geotools.filter.FilterFactoryImpl;\n+import org.junit.Before;\n+import org.junit.Test;\n+import org.junit.runner.RunWith;\n+import org.mockito.Mock;\n+import org.mockito.runners.MockitoJUnitRunner;\n+import org.opengis.filter.Filter;\n+import org.opengis.filter.FilterFactory;\n+import org.opengis.filter.sort.SortBy;\n+import org.opengis.filter.sort.SortOrder;\n+import org.osgi.framework.BundleContext;\n+import org.osgi.framework.ServiceReference;\n+\n+import ddf.catalog.CatalogFramework;\n+import ddf.catalog.data.Attribute;\n+import ddf.catalog.data.Metacard;\n+import ddf.catalog.data.Result;\n+import ddf.catalog.data.impl.AttributeImpl;\n+import ddf.catalog.data.impl.MetacardImpl;\n+import ddf.catalog.data.impl.ResultImpl;\n+import ddf.catalog.federation.FederationException;\n+import ddf.catalog.filter.AttributeBuilder;\n+import ddf.catalog.filter.ExpressionBuilder;\n+import ddf.catalog.filter.FilterBuilder;\n+import ddf.catalog.operation.CreateRequest;\n+import ddf.catalog.operation.CreateResponse;\n+import ddf.catalog.operation.DeleteRequest;\n+import ddf.catalog.operation.Query;\n+import ddf.catalog.operation.QueryRequest;\n+import ddf.catalog.operation.QueryResponse;\n+import ddf.catalog.operation.UpdateRequest;\n+import ddf.catalog.operation.impl.CreateRequestImpl;\n+import ddf.catalog.operation.impl.CreateResponseImpl;\n+import ddf.catalog.operation.impl.QueryImpl;\n+import ddf.catalog.operation.impl.QueryRequestImpl;\n+import ddf.catalog.operation.impl.QueryResponseImpl;\n+import ddf.catalog.source.IngestException;\n+import ddf.catalog.source.SourceUnavailableException;\n+import ddf.catalog.source.UnsupportedQueryException;\n+import ddf.catalog.transform.CatalogTransformerException;\n+import ddf.security.SecurityConstants;\n+import ddf.security.Subject;\n+import oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType;\n+\n+@RunWith(MockitoJUnitRunner.class)\n public class FederationAdminServiceImplTest {\n \n+    private static final FilterFactory FILTER_FACTORY = new FilterFactoryImpl();\n+\n+    private static final String TEST_SITE_NAME = \"Slate Rock and Gravel Company\";\n+\n+    private static final String TEST_VERSION = \"FF 2.0\";\n+\n+    private static final String TEST_DESTINATION = \"Destination\";\n+\n+    private static final String TEST_METACARD_ID = \"MetacardId\";\n+\n+    private static final String TEST_ID = \"TestId\";\n+\n+    private static final String TEST_XML_STRING = \"SomeValidStringVersionOfXml\";\n+\n+    private FederationAdminServiceImpl federationAdminServiceImpl;\n+\n+    @Mock\n+    private ParserConfigurator configurator;\n+\n+    @Mock\n+    private CatalogFramework catalogFramework;\n+\n+    @Mock\n+    private Parser parser;\n+\n+    @Mock\n+    private RegistryTransformer registryTransformer;\n+\n+    @Mock\n+    private Security security;\n+\n+    @Mock\n+    private FilterBuilder filterBuilder;\n+\n+    @Mock\n+    private AttributeBuilder attributeBuilder;\n+\n+    @Mock\n+    private ExpressionBuilder expressionBuilder;\n+\n+    @Mock\n+    private Subject subject;\n+\n+    @Mock\n+    private BundleContext bundleContext;\n+\n+    @Mock\n+    private ServiceReference serviceReference;\n+\n+    @Mock\n+    private RegistryStore registryStore;\n+\n+    @Before\n+    public void setUp() throws Exception {\n+        when(parser.configureParser(anyList(), any(ClassLoader.class))).thenReturn(configurator);\n+        when(filterBuilder.attribute(any(String.class))).thenReturn(attributeBuilder);\n+        when(attributeBuilder.is()).thenReturn(expressionBuilder);\n+        when(expressionBuilder.bool(any(Boolean.class))).thenReturn(getTestFilter());\n+\n+        federationAdminServiceImpl = spy(new FederationAdminServiceImpl(security));\n+        federationAdminServiceImpl.setRegistryTransformer(registryTransformer);\n+        federationAdminServiceImpl.setCatalogFramework(catalogFramework);\n+        federationAdminServiceImpl.setParser(parser);\n+        federationAdminServiceImpl.setFilterBuilder(filterBuilder);\n+        System.setProperty(SystemInfo.SITE_NAME, TEST_SITE_NAME);\n+        System.setProperty(SystemInfo.VERSION, TEST_VERSION);\n+\n+    }\n+\n+    @Test\n+    public void testGetRegistryObjectByMetacardId() throws Exception {\n+        String metacardId = TEST_METACARD_ID;\n+        Metacard metacard = getTestMetacard();\n+        metacard.setAttribute(new AttributeImpl(Metacard.ID, metacardId));\n+        metacard.setAttribute(new AttributeImpl(Metacard.METADATA, TEST_XML_STRING));\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request, metacard);\n+        JAXBElement<RegistryPackageType> jaxbRegistryPackage = RIM_FACTORY.createRegistryPackage(\n+                getTestRegistryPackage());\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(parser.unmarshal(any(ParserConfigurator.class),\n+                eq(JAXBElement.class),\n+                any(InputStream.class))).thenReturn(jaxbRegistryPackage);\n+        RegistryPackageType registryPackage =\n+                federationAdminServiceImpl.getRegistryObjectByMetacardId(metacardId, null);\n+        assertThat(registryPackage, notNullValue());\n+        verify(federationAdminServiceImpl).getRegistryObjectByMetacardId(metacardId, null);\n+    }\n+\n+    @Test(expected = FederationAdminException.class)\n+    public void getRegistryObjectByMetacardIdEmptyString() throws FederationAdminException {\n+        assertThat(federationAdminServiceImpl.getRegistryObjectByMetacardId(\"\"), is(nullValue()));\n+    }\n+\n+    @Test\n+    public void getRegistryObjectByMetacardIdThatDoesNotExist() throws Exception {\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request);\n+        Metacard metacard = getTestMetacard();\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(registryTransformer.transform(any(InputStream.class))).thenReturn(metacard);\n+        assertThat(federationAdminServiceImpl.getRegistryObjectByMetacardId(\"Not a metacard\"),\n+                is(nullValue()));\n+    }\n+\n+    @Test(expected = FederationAdminException.class)\n+    public void getRegistryObjectByMetacardIdDuplicateMetacards() throws Exception {\n+        String metacardId = TEST_METACARD_ID;\n+        Metacard metacard = getTestMetacard();\n+        metacard.setAttribute(new AttributeImpl(Metacard.ID, metacardId));\n+        metacard.setAttribute(new AttributeImpl(Metacard.METADATA, TEST_XML_STRING));\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request, metacard, metacard);\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        federationAdminServiceImpl.getRegistryObjectByMetacardId(metacardId);\n+        verify(federationAdminServiceImpl).getRegistryObjectByMetacardId(metacardId);\n+        verify(catalogFramework).query(any(QueryRequest.class));\n+        verify(parser, never()).unmarshal(any(ParserConfigurator.class),\n+                eq(JAXBElement.class),\n+                any(InputStream.class));\n+    }\n+\n+    @Test\n+    public void testRefreshRegistrySubscriptionsWhenPollableSourceIdsIAreEmpty() throws Exception {\n+        federationAdminServiceImpl.refreshRegistrySubscriptions();\n+        verify(federationAdminServiceImpl).refreshRegistrySubscriptions();\n+    }\n+\n+    @Test\n+    public void testcreateRemoteEntries() throws Exception {\n+        Metacard firstMetacard = getTestMetacard();\n+        Metacard secondMetacard = getTestMetacard();\n+        Metacard thirdMetacard = getTestMetacard();\n+        String registryId = RegistryObjectMetacardType.REGISTRY_ID;\n+        firstMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId));\n+        secondMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId));\n+        thirdMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId + \"1\"));\n+        firstMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date()));\n+        secondMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date()));\n+        thirdMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date()));\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request,\n+                firstMetacard,\n+                secondMetacard);\n+        List<Metacard> localMetacards = new ArrayList<>();\n+        localMetacards.add(firstMetacard);\n+        localMetacards.add(secondMetacard);\n+        doReturn(localMetacards).when(federationAdminServiceImpl)\n+                .getRegistryMetacards();\n+        QueryRequest request1 = getTestQueryRequest();\n+        QueryResponse response1 = getPopulatedTestQueryResponse(request1, thirdMetacard);\n+        when(federationAdminServiceImpl.getBundleContext()).thenReturn(bundleContext);\n+        when(bundleContext.getService(serviceReference)).thenReturn(registryStore);\n+        when(registryStore.isPullAllowed()).thenReturn(true);\n+        when(registryStore.getId()).thenReturn(TEST_ID);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response, response1);\n+        federationAdminServiceImpl.bindRegistryStore(serviceReference);\n+        federationAdminServiceImpl.refreshRegistrySubscriptions();\n+        verify(catalogFramework).create(any(CreateRequest.class));\n+    }\n+\n+    @Test(expected = FederationAdminException.class)\n+    public void testcreateRemoteEntriesSourceUnavailable() throws Exception {\n+        Metacard firstMetacard = getTestMetacard();\n+        Metacard secondMetacard = getTestMetacard();\n+        Metacard thirdMetacard = getTestMetacard();\n+        String registryId = RegistryObjectMetacardType.REGISTRY_ID;\n+        firstMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId));\n+        secondMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId));\n+        thirdMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId + \"1\"));\n+        firstMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date()));\n+        secondMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date()));\n+        thirdMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date()));\n+        List<Metacard> localMetacards = new ArrayList<>();\n+        localMetacards.add(firstMetacard);\n+        localMetacards.add(secondMetacard);\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response1 = getPopulatedTestQueryResponse(request,\n+                firstMetacard,\n+                secondMetacard);\n+        doReturn(localMetacards).when(federationAdminServiceImpl)\n+                .getRegistryMetacards();\n+        QueryRequest request1 = getTestQueryRequest();\n+        QueryResponse response2 = getPopulatedTestQueryResponse(request1, thirdMetacard);\n+        when(federationAdminServiceImpl.getBundleContext()).thenReturn(bundleContext);\n+        when(bundleContext.getService(serviceReference)).thenReturn(registryStore);\n+        when(registryStore.isPullAllowed()).thenReturn(true);\n+        when(registryStore.getId()).thenReturn(TEST_ID);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response1, response2);\n+        when(catalogFramework.create(any(CreateRequest.class))).thenThrow(SourceUnavailableException.class);\n+        federationAdminServiceImpl.bindRegistryStore(serviceReference);\n+        federationAdminServiceImpl.refreshRegistrySubscriptions();\n+    }\n+\n+    @Test\n+    public void testWriteRemoteUpdates() throws Exception {\n+        Metacard firstMetacard = getTestMetacard();\n+        Metacard secondMetacard = getTestMetacard();\n+        Metacard diffDateMetacard = getTestMetacard();\n+        String registryId = RegistryObjectMetacardType.REGISTRY_ID;\n+        firstMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId + \"1\"));\n+        secondMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId + \"2\"));\n+        //Assign diffDateMetacard sameId as firstMetacard but with a different modified date\n+        diffDateMetacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId + \"1\"));\n+        firstMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date()));\n+        secondMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED, new Date()));\n+        //Date set 1000ms in the future to avoid timing issues\n+        diffDateMetacard.setAttribute(new AttributeImpl(Metacard.MODIFIED,\n+                new Date(new Date().getTime() + 1000)));\n+        //Add only first two metacarsds to localMetacards, in order to compare them against response containing diffDateMetacard\n+        List<Metacard> localMetacards = new ArrayList<>();\n+        localMetacards.add(firstMetacard);\n+        localMetacards.add(secondMetacard);\n+        doReturn(localMetacards).when(federationAdminServiceImpl)\n+                .getRegistryMetacards();\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request, diffDateMetacard);\n+        when(federationAdminServiceImpl.getBundleContext()).thenReturn(bundleContext);\n+        when(bundleContext.getService(serviceReference)).thenReturn(registryStore);\n+        when(registryStore.isPullAllowed()).thenReturn(true);\n+        when(registryStore.getId()).thenReturn(TEST_ID);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(null);\n+        //bindRegistryStore calls the method being tested: writeRemoteUpdates()\n+        federationAdminServiceImpl.bindRegistryStore(serviceReference);\n+        verify(catalogFramework).query(any(QueryRequest.class));\n+        verify(catalogFramework).update(any(UpdateRequest.class));\n+    }\n+\n+    @Test\n+    public void initWithNoPreviousEntry() throws Exception {\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request);\n+        Metacard metacard = getTestMetacard();\n+\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(registryTransformer.transform(any(InputStream.class))).thenReturn(metacard);\n+\n+        federationAdminServiceImpl.init();\n+\n+        verify(federationAdminServiceImpl).addRegistryEntry(metacard);\n+    }\n+\n+    @Test\n+    public void initWithPreviousNonPrimaryEntry() throws Exception {\n+        Metacard addThisMetacard = getTestMetacard();\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request);\n+\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(registryTransformer.transform(any(InputStream.class))).thenReturn(addThisMetacard);\n+\n+        federationAdminServiceImpl.init();\n+\n+        verify(federationAdminServiceImpl).addRegistryEntry(addThisMetacard);\n+    }\n+\n+    @Test\n+    public void initWithPreviousWithEmptyMetacard() throws Exception {\n+        Metacard addThisMetacard = getTestMetacard();\n+        QueryRequest request = getTestQueryRequest();\n+        Result result = new ResultImpl();\n+        QueryResponse response = getTestQueryResponse(request, Collections.singletonList(result));\n+\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(registryTransformer.transform(any(InputStream.class))).thenReturn(addThisMetacard);\n+\n+        federationAdminServiceImpl.init();\n+\n+        verify(federationAdminServiceImpl).addRegistryEntry(addThisMetacard);\n+    }\n+\n+    @Test\n+    public void initWithPreviousPrimaryEntry() throws Exception {\n+        Metacard addThisMetacard = getTestMetacard();\n+        Metacard findThisMetacard = getTestMetacard();\n+        Attribute regNodeStatus =\n+                new AttributeImpl(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, true);\n+        findThisMetacard.setAttribute(regNodeStatus);\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request, findThisMetacard);\n+\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(registryTransformer.transform(any(InputStream.class))).thenReturn(addThisMetacard);\n+\n+        federationAdminServiceImpl.init();\n+\n+        verify(federationAdminServiceImpl, never()).addRegistryEntry(addThisMetacard);\n+    }\n+\n+    @Test\n+    public void initWithDuplicatePreviousPrimaryEntry() throws Exception {\n+        Metacard addThisMetacard = getTestMetacard();\n+        Metacard findThisMetacard = getTestMetacard();\n+        Attribute regNodeStatus =\n+                new AttributeImpl(RegistryObjectMetacardType.REGISTRY_IDENTITY_NODE, true);\n+        findThisMetacard.setAttribute(regNodeStatus);\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request,\n+                findThisMetacard,\n+                findThisMetacard);\n+\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(registryTransformer.transform(any(InputStream.class))).thenReturn(addThisMetacard);\n+\n+        federationAdminServiceImpl.init();\n+\n+        verify(federationAdminServiceImpl, never()).addRegistryEntry(addThisMetacard);\n+    }\n+\n+    @Test\n+    public void initWithQueryException() throws Exception {\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        doThrow(SourceUnavailableException.class).when(catalogFramework)\n+                .query(any(QueryRequest.class));\n+\n+        federationAdminServiceImpl.init();\n+        verify(federationAdminServiceImpl, never()).addRegistryEntry(any(Metacard.class));\n+    }\n+\n+    @Test\n+    public void initWithIngestException() throws Exception {\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request);\n+\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(registryTransformer.transform(any(InputStream.class))).thenReturn(getTestMetacard());\n+        doThrow(IngestException.class).when(catalogFramework)\n+                .create(any(CreateRequest.class));\n+\n+        federationAdminServiceImpl.init();\n+        verify(federationAdminServiceImpl).addRegistryEntry(any(Metacard.class));\n+    }\n+\n+    @Test\n+    public void initWithMarshalException() throws Exception {\n+        QueryRequest request = getTestQueryRequest();\n+        QueryResponse response = getPopulatedTestQueryResponse(request);\n+        when(security.getSystemSubject()).thenReturn(subject);\n+        when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);\n+        doThrow(ParserException.class).when(parser)\n+                .marshal(any(ParserConfigurator.class), any(Object.class), any(OutputStream.class));\n+\n+        federationAdminServiceImpl.init();\n+        verify(federationAdminServiceImpl, never()).addRegistryEntry(any(Metacard.class));\n+    }\n+\n+    @Test\n+    public void testAddRegistryEntry() throws Exception {\n+        String destination = TEST_DESTINATION;\n+        String metacardId = TEST_METACARD_ID;\n+        Metacard metacard = getTestMetacard();\n+        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                RegistryObjectMetacardType.REGISTRY_ID));\n+\n+        metacard.setAttribute(new AttributeImpl(Metacard.TAGS,\n+                Collections.singletonList(RegistryConstants.REGISTRY_TAG)));\n+\n+        Metacard createdMetacard = metacard;\n+        createdMetacard.setAttribute(new AttributeImpl(Metacard.ID, metacardId));\n+\n+        Set<String> destinations = new HashSet<>();\n+        destinations.add(destination);\n+\n+        Subject systemSubject = security.getSystemSubject();\n+        Map<String, Serializable> properties = new HashMap<>();\n+        properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);\n+        CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard),\n+                properties,\n+                destinations);\n+        CreateResponse response = new CreateResponseImpl(request,\n+                null,\n+                Collections.singletonList(createdMetacard));\n+\n+        when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);\n+\n+        String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(metacard,\n+                destinations);\n+\n+        assertThat(createdMetacardId, is(equalTo(metacardId)));\n+        verify(catalogFramework).create(any(CreateRequest.class));\n+    }\n+\n+    @Test\n+    public void testAddRegistryEntryWithNullDestinations() throws Exception {\n+        String metacardId = TEST_METACARD_ID;\n+        Metacard metacard = getTestMetacard();\n+        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                RegistryObjectMetacardType.REGISTRY_ID));\n+\n+        metacard.setAttribute(new AttributeImpl(Metacard.TAGS,\n+                Collections.singletonList(RegistryConstants.REGISTRY_TAG)));\n+\n+        Metacard createdMetacard = metacard;\n+        createdMetacard.setAttribute(new AttributeImpl(Metacard.ID, metacardId));\n+\n+        Set<String> destinations = null;\n+\n+        Subject systemSubject = security.getSystemSubject();\n+        Map<String, Serializable> properties = new HashMap<>();\n+        properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);\n+        CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard),\n+                properties,\n+                destinations);\n+        CreateResponse response = new CreateResponseImpl(request,\n+                null,\n+                Collections.singletonList(createdMetacard));\n+\n+        when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);\n+\n+        String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(metacard,\n+                destinations);\n+\n+        assertThat(createdMetacardId, is(equalTo(metacardId)));\n+        verify(catalogFramework).create(any(CreateRequest.class));\n+    }\n+\n+    @Test(expected = FederationAdminException.class)\n+    public void testAddRegistryEntryWithNullMetacard() throws Exception {\n+        String destination = TEST_DESTINATION;\n+        Metacard metacard = null;\n+\n+        Set<String> destinations = new HashSet<>();\n+        destinations.add(destination);\n+\n+        federationAdminServiceImpl.addRegistryEntry(metacard, destinations);\n+\n+        verify(catalogFramework, never()).create(any(CreateRequest.class));\n+    }\n+\n+    @Test(expected = FederationAdminException.class)\n+    public void testAddRegistryEntryWithInvalidMetacardNoRegistryId() throws Exception {\n+        String destination = TEST_DESTINATION;\n+        Metacard metacard = getTestMetacard();\n+\n+        metacard.setAttribute(new AttributeImpl(Metacard.TAGS,\n+                Collections.singletonList(RegistryConstants.REGISTRY_TAG)));\n+\n+        Set<String> destinations = new HashSet<>();\n+        destinations.add(destination);\n+\n+        federationAdminServiceImpl.addRegistryEntry(metacard, destinations);\n+\n+        verify(catalogFramework, never()).create(any(CreateRequest.class));\n+    }\n+\n+    @Test(expected = FederationAdminException.class)\n+    public void testAddRegistryEntryWithInvalidMetacardNoRegistryTag() throws Exception {\n+        String registryId = RegistryObjectMetacardType.REGISTRY_ID;\n+        String destination = TEST_DESTINATION;\n+        Metacard metacard = getTestMetacard();\n+        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId));\n+\n+        Set<String> destinations = new HashSet<>();\n+        destinations.add(destination);\n+\n+        federationAdminServiceImpl.addRegistryEntry(metacard, destinations);\n+\n+        verify(catalogFramework, never()).create(any(CreateRequest.class));\n+    }\n+\n+    @Test(expected = FederationAdminException.class)\n+    public void testAddRegistryEntryWithIngestException() throws Exception {\n+        String registryId = RegistryObjectMetacardType.REGISTRY_ID;\n+        String destination = TEST_DESTINATION;\n+        Metacard metacard = getTestMetacard();\n+        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId));\n+\n+        Set<String> destinations = new HashSet<>();\n+        destinations.add(destination);\n+\n+        when(catalogFramework.create(any(CreateRequest.class))).thenThrow(IngestException.class);\n+\n+        federationAdminServiceImpl.addRegistryEntry(metacard, destinations);\n+\n+        verify(catalogFramework, never()).create(any(CreateRequest.class));\n+    }\n+\n+    @Test(expected = FederationAdminException.class)\n+    public void testAddRegistryEntryWithSourceUnavailableException() throws Exception {\n+        String registryId = RegistryObjectMetacardType.REGISTRY_ID;\n+        String destination = TEST_DESTINATION;\n+        Metacard metacard = getTestMetacard();\n+        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId));\n+\n+        Set<String> destinations = new HashSet<>();\n+        destinations.add(destination);\n+\n+        when(catalogFramework.create(any(CreateRequest.class))).thenThrow(SourceUnavailableException.class);\n+\n+        federationAdminServiceImpl.addRegistryEntry(metacard, destinations);\n+\n+        verify(catalogFramework, never()).create(any(CreateRequest.class));\n+    }\n+\n+    @Test\n+    public void testAddRegistryEntryMetacard() throws Exception {\n+        String registryId = RegistryObjectMetacardType.REGISTRY_ID;\n+        String metacardId = TEST_METACARD_ID;\n+        Metacard metacard = getTestMetacard();\n+        metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID,\n+                registryId));\n+\n+        metacard.setAttribute(new AttributeImpl(Metacard.TAGS,\n+                Collections.singletonList(RegistryConstants.REGISTRY_TAG)));\n+\n+        Metacard createdMetacard = metacard;\n+        createdMetacard.setAttribute(new AttributeImpl(Metacard.ID, metacardId));\n+\n+        Subject systemSubject = security.getSystemSubject();","path":"catalog/spatial/registry/registry-federation-admin-service-impl/src/test/java/org/codice/ddf/registry/federationadmin/service/impl/FederationAdminServiceImplTest.java","position":623,"original_position":623,"commit_id":"04fee2148e750e2a6863ba45d8aa8b1fdf09a462","original_commit_id":"04fee2148e750e2a6863ba45d8aa8b1fdf09a462","user":{"login":"pklinef","id":700518,"avatar_url":"https://avatars.githubusercontent.com/u/700518?v=3","gravatar_id":"","url":"https://api.github.com/users/pklinef","html_url":"https://github.com/pklinef","followers_url":"https://api.github.com/users/pklinef/followers","following_url":"https://api.github.com/users/pklinef/following{/other_user}","gists_url":"https://api.github.com/users/pklinef/gists{/gist_id}","starred_url":"https://api.github.com/users/pklinef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pklinef/subscriptions","organizations_url":"https://api.github.com/users/pklinef/orgs","repos_url":"https://api.github.com/users/pklinef/repos","events_url":"https://api.github.com/users/pklinef/events{/privacy}","received_events_url":"https://api.github.com/users/pklinef/received_events","type":"User","site_admin":false},"body":"There also seems to be a lot of duplication of mocking a catalog create response.  Consider extracting a helper method.","created_at":"2016-06-01T19:35:15Z","updated_at":"2016-06-01T19:35:15Z","html_url":"https://github.com/codice/ddf/pull/817#discussion_r65427407","pull_request_url":"https://api.github.com/repos/codice/ddf/pulls/817","_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments/65427407"},"html":{"href":"https://github.com/codice/ddf/pull/817#discussion_r65427407"},"pull_request":{"href":"https://api.github.com/repos/codice/ddf/pulls/817"}}},"pull_request":{"url":"https://api.github.com/repos/codice/ddf/pulls/817","id":71430424,"html_url":"https://github.com/codice/ddf/pull/817","diff_url":"https://github.com/codice/ddf/pull/817.diff","patch_url":"https://github.com/codice/ddf/pull/817.patch","issue_url":"https://api.github.com/repos/codice/ddf/issues/817","number":817,"state":"open","locked":false,"title":"DDF-2102: Updated registry-federation-admin-service-impl and added unit tests","user":{"login":"brianfelix","id":12402520,"avatar_url":"https://avatars.githubusercontent.com/u/12402520?v=3","gravatar_id":"","url":"https://api.github.com/users/brianfelix","html_url":"https://github.com/brianfelix","followers_url":"https://api.github.com/users/brianfelix/followers","following_url":"https://api.github.com/users/brianfelix/following{/other_user}","gists_url":"https://api.github.com/users/brianfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/brianfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianfelix/subscriptions","organizations_url":"https://api.github.com/users/brianfelix/orgs","repos_url":"https://api.github.com/users/brianfelix/repos","events_url":"https://api.github.com/users/brianfelix/events{/privacy}","received_events_url":"https://api.github.com/users/brianfelix/received_events","type":"User","site_admin":false},"body":"#### What does this PR do? Updated registry-federation-admin-service-impl and added unit tests. This is an initial pr and cannot be heroed or built right now because it requires registry PR's to be merged first.\r\n#### Who is reviewing it (please choose AT LEAST two reviewers that need to approve the PR before it can get merged; if a component team is listed, at least one of its members needs to approve)?\r\n#### Choose 2 committers to review/merge the PR (please choose ONLY two committers from below, delete the rest).\r\n@pklinef \r\n@shaundmorris \r\n#### How should this be tested? Unit tests should be run\r\n#### Any background context you want to provide?\r\n#### What are the relevant tickets? DDF-2102\r\n#### Screenshots (if appropriate)\r\n#### Checklist:\r\n- [ ] Documentation Updated\r\n- [X] Update / Add Unit Tests\r\n- [ ] Update / Add Integration Tests\r\n","created_at":"2016-05-25T17:22:06Z","updated_at":"2016-06-01T19:35:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1382069ba4ae2d78fe843b6e8931ea5875dc828","assignee":{"login":"shaundmorris","id":4359166,"avatar_url":"https://avatars.githubusercontent.com/u/4359166?v=3","gravatar_id":"","url":"https://api.github.com/users/shaundmorris","html_url":"https://github.com/shaundmorris","followers_url":"https://api.github.com/users/shaundmorris/followers","following_url":"https://api.github.com/users/shaundmorris/following{/other_user}","gists_url":"https://api.github.com/users/shaundmorris/gists{/gist_id}","starred_url":"https://api.github.com/users/shaundmorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shaundmorris/subscriptions","organizations_url":"https://api.github.com/users/shaundmorris/orgs","repos_url":"https://api.github.com/users/shaundmorris/repos","events_url":"https://api.github.com/users/shaundmorris/events{/privacy}","received_events_url":"https://api.github.com/users/shaundmorris/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/codice/ddf/pulls/817/commits","review_comments_url":"https://api.github.com/repos/codice/ddf/pulls/817/comments","review_comment_url":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codice/ddf/issues/817/comments","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/04fee2148e750e2a6863ba45d8aa8b1fdf09a462","head":{"label":"brianfelix:DDF-2102","ref":"DDF-2102","sha":"04fee2148e750e2a6863ba45d8aa8b1fdf09a462","user":{"login":"brianfelix","id":12402520,"avatar_url":"https://avatars.githubusercontent.com/u/12402520?v=3","gravatar_id":"","url":"https://api.github.com/users/brianfelix","html_url":"https://github.com/brianfelix","followers_url":"https://api.github.com/users/brianfelix/followers","following_url":"https://api.github.com/users/brianfelix/following{/other_user}","gists_url":"https://api.github.com/users/brianfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/brianfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianfelix/subscriptions","organizations_url":"https://api.github.com/users/brianfelix/orgs","repos_url":"https://api.github.com/users/brianfelix/repos","events_url":"https://api.github.com/users/brianfelix/events{/privacy}","received_events_url":"https://api.github.com/users/brianfelix/received_events","type":"User","site_admin":false},"repo":{"id":36394348,"name":"ddf","full_name":"brianfelix/ddf","owner":{"login":"brianfelix","id":12402520,"avatar_url":"https://avatars.githubusercontent.com/u/12402520?v=3","gravatar_id":"","url":"https://api.github.com/users/brianfelix","html_url":"https://github.com/brianfelix","followers_url":"https://api.github.com/users/brianfelix/followers","following_url":"https://api.github.com/users/brianfelix/following{/other_user}","gists_url":"https://api.github.com/users/brianfelix/gists{/gist_id}","starred_url":"https://api.github.com/users/brianfelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianfelix/subscriptions","organizations_url":"https://api.github.com/users/brianfelix/orgs","repos_url":"https://api.github.com/users/brianfelix/repos","events_url":"https://api.github.com/users/brianfelix/events{/privacy}","received_events_url":"https://api.github.com/users/brianfelix/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brianfelix/ddf","description":"The Distributed Data Framework - Distribution, SDK, and Test","fork":true,"url":"https://api.github.com/repos/brianfelix/ddf","forks_url":"https://api.github.com/repos/brianfelix/ddf/forks","keys_url":"https://api.github.com/repos/brianfelix/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brianfelix/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brianfelix/ddf/teams","hooks_url":"https://api.github.com/repos/brianfelix/ddf/hooks","issue_events_url":"https://api.github.com/repos/brianfelix/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/brianfelix/ddf/events","assignees_url":"https://api.github.com/repos/brianfelix/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/brianfelix/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/brianfelix/ddf/tags","blobs_url":"https://api.github.com/repos/brianfelix/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brianfelix/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brianfelix/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/brianfelix/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brianfelix/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/brianfelix/ddf/languages","stargazers_url":"https://api.github.com/repos/brianfelix/ddf/stargazers","contributors_url":"https://api.github.com/repos/brianfelix/ddf/contributors","subscribers_url":"https://api.github.com/repos/brianfelix/ddf/subscribers","subscription_url":"https://api.github.com/repos/brianfelix/ddf/subscription","commits_url":"https://api.github.com/repos/brianfelix/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/brianfelix/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/brianfelix/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/brianfelix/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/brianfelix/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/brianfelix/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brianfelix/ddf/merges","archive_url":"https://api.github.com/repos/brianfelix/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brianfelix/ddf/downloads","issues_url":"https://api.github.com/repos/brianfelix/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/brianfelix/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/brianfelix/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/brianfelix/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brianfelix/ddf/labels{/name}","releases_url":"https://api.github.com/repos/brianfelix/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/brianfelix/ddf/deployments","created_at":"2015-05-27T20:37:45Z","updated_at":"2016-02-19T17:30:08Z","pushed_at":"2016-05-25T20:28:57Z","git_url":"git://github.com/brianfelix/ddf.git","ssh_url":"git@github.com:brianfelix/ddf.git","clone_url":"https://github.com/brianfelix/ddf.git","svn_url":"https://github.com/brianfelix/ddf","homepage":"","size":142914,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"codice:master","ref":"master","sha":"7892ed10ade7c35ecf432f38722df0876fdf9a42","user":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"repo":{"id":15173563,"name":"ddf","full_name":"codice/ddf","owner":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codice/ddf","description":"Distributed Data Framework - an open source, modular integration framework.","fork":false,"url":"https://api.github.com/repos/codice/ddf","forks_url":"https://api.github.com/repos/codice/ddf/forks","keys_url":"https://api.github.com/repos/codice/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codice/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codice/ddf/teams","hooks_url":"https://api.github.com/repos/codice/ddf/hooks","issue_events_url":"https://api.github.com/repos/codice/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/codice/ddf/events","assignees_url":"https://api.github.com/repos/codice/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/codice/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/codice/ddf/tags","blobs_url":"https://api.github.com/repos/codice/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codice/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codice/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/codice/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/codice/ddf/languages","stargazers_url":"https://api.github.com/repos/codice/ddf/stargazers","contributors_url":"https://api.github.com/repos/codice/ddf/contributors","subscribers_url":"https://api.github.com/repos/codice/ddf/subscribers","subscription_url":"https://api.github.com/repos/codice/ddf/subscription","commits_url":"https://api.github.com/repos/codice/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/codice/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/codice/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/codice/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/codice/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/codice/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codice/ddf/merges","archive_url":"https://api.github.com/repos/codice/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codice/ddf/downloads","issues_url":"https://api.github.com/repos/codice/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/codice/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/codice/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/codice/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codice/ddf/labels{/name}","releases_url":"https://api.github.com/repos/codice/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/codice/ddf/deployments","created_at":"2013-12-13T20:38:28Z","updated_at":"2016-06-01T06:07:12Z","pushed_at":"2016-06-01T19:14:09Z","git_url":"git://github.com/codice/ddf.git","ssh_url":"git@github.com:codice/ddf.git","clone_url":"https://github.com/codice/ddf.git","svn_url":"https://github.com/codice/ddf","homepage":"http://ddf.codice.org","size":164458,"stargazers_count":37,"watchers_count":37,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":77,"mirror_url":null,"open_issues_count":28,"forks":77,"open_issues":28,"watchers":37,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/817"},"html":{"href":"https://github.com/codice/ddf/pull/817"},"issue":{"href":"https://api.github.com/repos/codice/ddf/issues/817"},"comments":{"href":"https://api.github.com/repos/codice/ddf/issues/817/comments"},"review_comments":{"href":"https://api.github.com/repos/codice/ddf/pulls/817/comments"},"review_comment":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codice/ddf/pulls/817/commits"},"statuses":{"href":"https://api.github.com/repos/codice/ddf/statuses/04fee2148e750e2a6863ba45d8aa8b1fdf09a462"}}}}
{"actor":{"display_login":"pklinef"}}