Search in sources :

Example 1 with FederationAdminService

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService in project ddf by codice.

the class RegistryPublicationServiceImplTest method setup.

@Before
public void setup() {
    federationAdminService = mock(FederationAdminService.class);
    registryPublicationService = Mockito.spy(new RegistryPublicationServiceImpl());
    registryPublicationService.setFederationAdminService(federationAdminService);
    metacard = new MetacardImpl(new RegistryObjectMetacardType());
    metacard.setId("mcardId");
    metacard.setTags(Collections.singleton(RegistryConstants.REGISTRY_TAG));
    when(registryPublicationService.getBundleContext()).thenReturn(bundleContext);
    when(bundleContext.getService(serviceReference)).thenReturn(registryStore);
    doReturn(REGISTRY_STORE_REGISTRY_ID).when(registryStore).getRegistryId();
    doReturn(REGISTRY_STORE_ID).when(registryStore).getId();
    registryPublicationService.bindRegistryStore(serviceReference);
}
Also used : FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Before(org.junit.Before)

Example 2 with FederationAdminService

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService in project ddf by codice.

the class TestRegistry method createRegistryEntry.

private String createRegistryEntry(String id, String regId) throws Exception {
    Response response = given().auth().preemptive().basic(ADMIN, ADMIN).body(getCswRegistryInsert(id, regId)).header("Content-Type", "text/xml").expect().log().all().statusCode(200).when().post(CSW_PATH.getUrl());
    ValidatableResponse validatableResponse = response.then();
    validatableResponse.body(hasXPath("//TransactionResponse/TransactionSummary/totalInserted", CoreMatchers.is("1")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", CoreMatchers.is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", CoreMatchers.is("0")));
    String idPath = "//*[local-name()='identifier']/text()";
    String mcardId = XmlSearch.evaluate(idPath, response.getBody().asString());
    boolean foundMetacard = false;
    long startTime = System.currentTimeMillis();
    long metacardLookupTimeout = TimeUnit.MINUTES.toMillis(20);
    while (!foundMetacard) {
        LOGGER.info("Waiting for metacard to be created");
        List entries = SECURITY.runAsAdminWithException(() -> {
            FederationAdminService federationAdminServiceImpl = getServiceManager().getService(FederationAdminService.class);
            return federationAdminServiceImpl.getRegistryMetacardsByRegistryIds(Collections.singletonList(regId));
        });
        if (!entries.isEmpty()) {
            foundMetacard = true;
        } else if (System.currentTimeMillis() - startTime > metacardLookupTimeout) {
            fail("Registry Metacard was not created in the allowed time");
        }
        Thread.sleep(SLEEP_TIME);
    }
    return mcardId;
}
Also used : Response(com.jayway.restassured.response.Response) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with FederationAdminService

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService in project ddf by codice.

the class TestRegistry method testCswRegistryStoreDelete.

@Test
public void testCswRegistryStoreDelete() throws Exception {
    String regID = "urn:uuid:2014ca7f59ac46f495e32b4a67a51291";
    String remoteMetacardResponse = getRegistryQueryResponse(REMOTE_METACARD_ID, regID, REMOTE_REGISTRY_ID, "NodeName", "2016-01-26T17:16:34.996Z");
    try {
        createRegistryEntry(METACARD_ID, regID);
        cswServer.whenHttp().match(post("/services/csw"), withPostBodyContaining("GetRecords"), withPostBodyContaining(RegistryConstants.REGISTRY_TAG_INTERNAL)).then(ok(), contentType("text/xml"), bytesContent(remoteMetacardResponse.getBytes()));
        cswServer.whenHttp().match(post("/services/csw"), withPostBodyContaining("GetRecords"), not(withPostBodyContaining(RegistryConstants.REGISTRY_TAG_INTERNAL)), withPostBodyContaining(REMOTE_METACARD_ID)).then(ok(), contentType("text/xml"), bytesContent(remoteMetacardResponse.getBytes()));
        SECURITY.runAsAdminWithException(() -> {
            FederationAdminService federationAdminServiceImpl = getServiceManager().getService(FederationAdminService.class);
            List<String> toBeDeletedIDs = new ArrayList<>();
            toBeDeletedIDs.add(regID);
            federationAdminServiceImpl.deleteRegistryEntriesByRegistryIds(toBeDeletedIDs, new HashSet(destinations));
            cswServer.verifyHttp().times(1, withPostBodyContaining("Transaction"), withPostBodyContaining("Delete"));
            cswServer.verifyHttp().atLeast(3);
            return null;
        });
    } catch (Exception e) {
        String message = "There was an error deleting the remote registry metacard.";
        LOGGER.error(message, e);
        throw new Exception(message, e);
    }
}
Also used : FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HashSet(java.util.HashSet) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with FederationAdminService

use of org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService in project ddf by codice.

the class TestRegistry method testCswRegistryStoreUpdate.

@Test
public void testCswRegistryStoreUpdate() throws Exception {
    String regID = "urn:uuid:2014ca7f59ac46f495e32b4a67a51290";
    String remoteMetacardResponse = getRegistryQueryResponse(REMOTE_METACARD_ID, regID, REMOTE_REGISTRY_ID, "NodeName", "2016-01-26T17:16:34.996Z");
    String remoteUpdatedMetacardResponse = getRegistryQueryResponse(REMOTE_METACARD_ID, regID, REMOTE_REGISTRY_ID, "New Node Name", "2016-01-26T17:16:34.996Z");
    cswServer.whenHttp().match(post("/services/csw"), withPostBodyContaining("GetRecords"), withPostBodyContaining(RegistryConstants.REGISTRY_TAG_INTERNAL), withPostBodyContaining(METACARD_ID)).then(ok(), contentType("text/xml"), bytesContent(remoteMetacardResponse.getBytes()));
    cswServer.whenHttp().match(post("/services/csw"), withPostBodyContaining("GetRecords"), not(withPostBodyContaining(RegistryConstants.REGISTRY_TAG_INTERNAL)), withPostBodyContaining(METACARD_ID)).then(ok(), contentType("text/xml"), bytesContent(remoteMetacardResponse.getBytes()));
    cswServer.whenHttp().match(post("/services/csw"), withPostBodyContaining("GetRecords"), not(withPostBodyContaining(RegistryConstants.REGISTRY_TAG_INTERNAL)), withPostBodyContaining(REMOTE_METACARD_ID)).then(ok(), contentType("text/xml"), bytesContent(remoteUpdatedMetacardResponse.getBytes()));
    try {
        SECURITY.runAsAdminWithException(() -> {
            FederationAdminService federationAdminServiceImpl = getServiceManager().getService(FederationAdminService.class);
            federationAdminServiceImpl.updateRegistryEntry(getRegistryNode(METACARD_ID, regID, regID, "New Node Name", "2016-02-26T17:16:34.996Z"), new HashSet(destinations));
            cswServer.verifyHttp().times(1, withPostBodyContaining("Transaction"), withPostBodyContaining("Update"));
            cswServer.verifyHttp().atLeast(4);
            return null;
        });
    } catch (Exception e) {
        String message = "There was an error updating the remote registry metacard.";
        LOGGER.error(message, e);
        throw new Exception(message, e);
    }
}
Also used : FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) IOException(java.io.IOException) HashSet(java.util.HashSet) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

FederationAdminService (org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 Test (org.junit.Test)2 Response (com.jayway.restassured.response.Response)1 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 List (java.util.List)1 RegistryObjectMetacardType (org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType)1 Before (org.junit.Before)1