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);
}
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;
}
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);
}
}
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);
}
}
Aggregations