SystemManagerLocal systemManager = LookupUtil.getSystemManager();
SystemSettings settings = systemManager.getUnmaskedSystemSettings(false);
String originalBaseUrl = settings.get(SystemSetting.BASE_URL);
MeasurementDefinitionManagerLocal measurementDefinitionManager = LookupUtil
.getMeasurementDefinitionManager();
MeasurementDefinitionCriteria crit = new MeasurementDefinitionCriteria();
crit.addFilterResourceTypeName(RESOURCE_TYPE_NAME);
crit.addFilterName(METRIC_NAME);
MeasurementDefinition distroNameDef = measurementDefinitionManager.findMeasurementDefinitionsByCriteria(
freshUser(), crit).get(0);
long originalInterval = distroNameDef.getDefaultInterval();
//now modify the default configuration in the export file
String exportXML = getExportData();
exportXML = updateSystemSettingsImportConfiguration(exportXML);
exportXML = updateMetricTemplatesImportConfiguration(exportXML);
InputStream exportData = createCompressedStream(exportXML);
//let's just use the default configs so that we don't apply the changes suggested in
//the changed default configs created above
ImportConfiguration systemSettingsConfiguration = new ImportConfiguration(
SystemSettingsSynchronizer.class.getName(), new SystemSettingsSynchronizer().getImporter()
.getImportConfigurationDefinition().getDefaultTemplate().createConfiguration());
ImportConfiguration metricTemplatesConfiguration = new ImportConfiguration(
MetricTemplateSynchronizer.class.getName(), new MetricTemplateSynchronizer().getImporter()
.getImportConfigurationDefinition().getDefaultTemplate().createConfiguration());
try {
synchronizationManager.importAllSubsystems(freshUser(), exportData,
Arrays.asList(systemSettingsConfiguration, metricTemplatesConfiguration));
} finally {
exportData.close();
}
//now check that we import using the manually create configurations, not the inlined ones
settings = systemManager.getUnmaskedSystemSettings(false);
assertEquals(settings.get(SystemSetting.BASE_URL), originalBaseUrl);
measurementDefinitionManager = LookupUtil.getMeasurementDefinitionManager();
distroNameDef = measurementDefinitionManager.findMeasurementDefinitionsByCriteria(freshUser(), crit).get(0);
//the definition should have been updated by the data from the export file
assertEquals("The " + METRIC_NAME + " metric shouldn't have changed its default interval", 30000,
distroNameDef.getDefaultInterval());