### Question:
StructuredAndRawConfigManagement extends ConfigManagementSupport { public Configuration executeLoad(int resourceId) throws PluginContainerException { ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId); Configuration configuration = facet.loadStructuredConfiguration(); Set<RawConfiguration> rawConfigs = facet.loadRawConfigurations(); if (configuration == null && rawConfigs == null) { return null; } if (configuration == null) { configuration = new Configuration(); } if (rawConfigs == null) { rawConfigs = EMPTY_SET; } for (RawConfiguration rawConfig : rawConfigs) { configuration.addRawConfiguration(rawConfig); } ResourceType resourceType = componentService.getResourceType(resourceId); if (configuration.getNotes() == null) { configuration.setNotes("Resource config for " + resourceType.getName() + " Resource w/ id " + resourceId); } configUtilityService.normalizeConfiguration(configuration, resourceType.getResourceConfigurationDefinition()); List<String> errorMsgs = configUtilityService.validateConfiguration(configuration, resourceType.getResourceConfigurationDefinition()); logErrorMsgs(errorMsgs, resourceType); return configuration; }  Configuration executeLoad(int resourceId); void executeUpdate(int resourceId, Configuration configuration);  }### Answer:
@Test public void rawConfigshouldGetLoaded() throws Exception { Configuration config = new Configuration(); Set<RawConfiguration> rawConfigs = toSet( createRawConfiguration("/tmp/foo.txt"), createRawConfiguration("/tmp/bar.txt") ); addDefaultExpectationsForLoad(config, rawConfigs); Configuration loadedConfig = structuredAndRawConfigManagement.executeLoad(resourceId); assertRawsLoaded(rawConfigs, loadedConfig); }
@Test public void structuredConfigShouldGetLoaded() throws Exception { Configuration config = new Configuration(); config.put(new PropertySimple("x", "1")); config.put(new PropertySimple("y", "2")); addDefaultExpectationsForLoad(config, EMPTY_SET); Configuration loadedConfig = structuredAndRawConfigManagement.executeLoad(resourceId); assertStructuredLoaded(config, loadedConfig); }
@Test public void theConfigNotesShouldGetSet() throws Exception { Configuration config = new Configuration(); config.setNotes(null); addDefaultExpectationsForLoad(config, EMPTY_SET); Configuration loadedConfig = structuredAndRawConfigManagement.executeLoad(resourceId); assertNotesSetToDefault(loadedConfig); }
@Test public void nullStructuredShouldBeIgnored() throws Exception { Configuration config = null; Set<RawConfiguration> rawConfigs = toSet(createRawConfiguration("/tmp/foo.txt")); addDefaultExpectationsForLoad(config, rawConfigs); Configuration loadedConfig = structuredAndRawConfigManagement.executeLoad(resourceId); Configuration emptyStructured = new Configuration(); assertRawsLoaded(rawConfigs, loadedConfig); assertStructuredLoaded(emptyStructured, loadedConfig); }
@Test public void nullRawsShouldBeIgnored() throws Exception { Configuration config = new Configuration(); config.put(new PropertySimple("x", "1")); config.put(new PropertySimple("y", "2")); Set<RawConfiguration> rawConfigs = null; addDefaultExpectationsForLoad(config, rawConfigs); Configuration loadedConfig = structuredAndRawConfigManagement.executeLoad(resourceId); assertRawsLoaded(EMPTY_SET, loadedConfig); assertStructuredLoaded(config, loadedConfig); }
@Test public void nullShouldBeReturnedWhenStructuredAndRawAreNull() throws Exception { context.checking(new Expectations() {{ atLeast(1).of(componentService).getComponent(resourceId, ResourceConfigurationFacet.class, FacetLockType.READ, ConfigManagement.FACET_METHOD_TIMEOUT, daemonThread, onlyIfStarted); will(returnValue(configFacet)); allowing(componentService).getResourceType(resourceId); will(returnValue(resourceType)); oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(null)); oneOf(configFacet).loadRawConfigurations(); will(returnValue(null)); }}); Configuration loadedConfig = structuredAndRawConfigManagement.executeLoad(resourceId); assertNull(loadedConfig, "Expected null to be returned when facet returns null for both structured and raw."); }