use of org.codice.ddf.migration.MigrationMetadata in project ddf by codice.
the class MetacardsMigratable method export.
/**
* Exports all the metacards currently stored in the catalog framework.
* <p>
* {@inheritDoc}
*/
@Override
@NotNull
public MigrationMetadata export(@NotNull Path exportPath) throws MigrationException {
config.setExportPath(exportPath.resolve(this.getId()));
fileWriter.createExportDirectory(config.getExportPath());
Collection<MigrationWarning> warnings = new ArrayList<>();
Map<String, Serializable> props = createMapWithNativeQueryMode();
Filter dumpFilter = filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text("*");
QueryImpl exportQuery = new QueryImpl(dumpFilter);
exportQuery.setPageSize(config.getExportQueryPageSize());
exportQuery.setRequestsTotalResultsCount(false);
QueryRequest exportQueryRequest = new QueryRequestImpl(exportQuery, props);
try {
executeQueryLoop(exportQuery, exportQueryRequest);
} catch (Exception e) {
LOGGER.info("Internal error occurred when exporting catalog: {}", e);
throw new ExportMigrationException(DEFAULT_FAILURE_MESSAGE);
} finally {
cleanup();
}
return new MigrationMetadata(warnings);
}
use of org.codice.ddf.migration.MigrationMetadata in project ddf by codice.
the class MetacardsMigratableTest method exportWhenResultSetLargerThanExportPageSize.
@Test
public void exportWhenResultSetLargerThanExportPageSize() throws Exception {
List<Result> result1 = Arrays.asList(mock(Result.class), mock(Result.class));
List<Result> result2 = Collections.singletonList(mock(Result.class));
List<Integer> startIndices = setupProviderResponses(result1, result2);
MigrationMetadata metadata = migratable.export(EXPORT_PATH);
verify(mockTaskManager).exportMetacardQuery(result1, 1);
assertThat("Invalid start index for first query", startIndices.get(0), is(1));
verify(mockTaskManager).exportMetacardQuery(result2, 2);
assertThat("Invalid start index for second query", startIndices.get(1), is(config.getExportQueryPageSize() + 1));
verify(mockTaskManager).close();
assertThat(metadata.getMigrationWarnings(), is(empty()));
}
use of org.codice.ddf.migration.MigrationMetadata in project ddf by codice.
the class TestMigratable method exportFailsWhenMigratableThrowsMigrationException.
@Test(expected = MigrationException.class)
public void exportFailsWhenMigratableThrowsMigrationException() throws Exception {
ConfigurationMigrationManager configurationMigrationManager = createConfigurationMigrationManager();
when(configurationMigratable.export(any(Path.class))).thenThrow(new MigrationException(""));
when(dataMigratable.export(any(Path.class))).thenReturn(new MigrationMetadata(ImmutableList.of()));
try {
export(() -> configurationMigrationManager.export(exportPath));
} finally {
verify(configurationMigratable).export(exportPath);
verify(dataMigratable, never()).export(any(Path.class));
}
}
use of org.codice.ddf.migration.MigrationMetadata in project ddf by codice.
the class SecurityMigratableTest method testExportCrlIsNull.
@Test
public void testExportCrlIsNull() {
// Setup
MigratableUtil mockMigratableUtil = mock(MigratableUtil.class);
when(mockMigratableUtil.getJavaPropertyValue(SERVER_ENCRYPTION_PROPERTIES_PATH, CRL_PROP_KEY)).thenReturn(null);
SecurityMigratable securityMigratable = new SecurityMigratable(DESCRIBABLE_BEAN, mockMigratableUtil);
// Perform test
MigrationMetadata migrationMetadata = securityMigratable.export(EXPORT_DIRECTORY);
// Verify
verify(mockMigratableUtil, never()).copyFile(eq(EXPECTED_SERVER_ENCRYPTION_CRL_PATH), eq(EXPORT_DIRECTORY), anyCollectionOf(MigrationWarning.class));
assertThat(migrationMetadata.getMigrationWarnings().size(), is(0));
}
use of org.codice.ddf.migration.MigrationMetadata in project ddf by codice.
the class SecurityMigratableTest method testWarningsReturned.
@Test
public void testWarningsReturned() throws Exception {
MigratableUtil migratableUtil = mock(MigratableUtil.class);
MigrationWarning expectedWarning = new MigrationWarning("Expected Warning");
doAnswer(new MigrationWarningAnswer(expectedWarning)).when(migratableUtil).copyDirectory(eq(PDP_POLICIES_DIR_REL_PATH), eq(EXPORT_DIRECTORY), Matchers.<Collection<MigrationWarning>>any());
SecurityMigratable securityMigratable = new SecurityMigratable(DESCRIBABLE_BEAN, migratableUtil);
MigrationMetadata migrationMetadata = securityMigratable.export(EXPORT_DIRECTORY);
assertThat(migrationMetadata.getMigrationWarnings(), containsInAnyOrder(expectedWarning));
}
Aggregations