### Question:
StructuredAndRawConfigManagement extends ConfigManagementSupport { public void executeUpdate(int resourceId, Configuration configuration) throws PluginContainerException { ResourceConfigurationFacet facet = loadResourceConfigFacetWithWriteLock(resourceId); StringBuilder errors = new StringBuilder(); try { facet.validateStructuredConfiguration(configuration); facet.persistStructuredConfiguration(configuration); } catch (Throwable t) { errors.append(t.getMessage()); } for (RawConfiguration rawConfig : configuration.getRawConfigurations()) { try { facet.validateRawConfiguration(rawConfig); facet.persistRawConfiguration(rawConfig); } catch (Throwable t) { errors.append(t.getMessage()).append("\n\n"); } } if (errors.length() > 0) { throw new ConfigurationUpdateException(errors.toString()); } }  Configuration executeLoad(int resourceId); void executeUpdate(int resourceId, Configuration configuration);  }### Answer:
@Test public void facetShouldBeCalledToUpdateStructuredAndRaw() throws Exception { final RawConfiguration raw1 = createRawConfiguration("/tmp/raw1.txt"); final RawConfiguration raw2 = createRawConfiguration("/tmp/raw2.txt"); final Configuration config = new Configuration(); config.addRawConfiguration(raw1); config.addRawConfiguration(raw2); addDefaultExpectationsForUpdate(); context.checking(new Expectations() {{ oneOf(configFacet).validateStructuredConfiguration(config); oneOf(configFacet).persistStructuredConfiguration(config); oneOf(configFacet).validateRawConfiguration(raw1); oneOf(configFacet).persistRawConfiguration(raw1); oneOf(configFacet).validateRawConfiguration(raw2); oneOf(configFacet).persistRawConfiguration(raw2); }}); structuredAndRawConfigManagement.executeUpdate(resourceId, config); }
@Test(expectedExceptions = {ConfigurationUpdateException.class}) public void exceptionShouldBeThrownWhenStructuredValidationFails() throws Exception { final RawConfiguration raw = createRawConfiguration("/tmp/raw.txt"); final Configuration config = new Configuration(); config.addRawConfiguration(raw); addDefaultExpectationsForUpdate(); context.checking(new Expectations() {{ oneOf(configFacet).validateStructuredConfiguration(config); will(throwException(new RuntimeException())); oneOf(configFacet).validateRawConfiguration(raw); oneOf(configFacet).persistRawConfiguration(raw); }}); structuredAndRawConfigManagement.executeUpdate(resourceId, config); }
@Test(expectedExceptions = {ConfigurationUpdateException.class}) public void exceptionShouldBeThrownWhenStructuredUpdateFails() throws Exception { final RawConfiguration raw = createRawConfiguration("/tmp/raw.txt"); final Configuration config = new Configuration(); config.addRawConfiguration(raw); addDefaultExpectationsForUpdate(); context.checking(new Expectations() {{ oneOf(configFacet).validateStructuredConfiguration(config); oneOf(configFacet).persistStructuredConfiguration(config); will(throwException(new RuntimeException())); oneOf(configFacet).validateRawConfiguration(raw); oneOf(configFacet).persistRawConfiguration(raw); }}); structuredAndRawConfigManagement.executeUpdate(resourceId, config); }
@Test(expectedExceptions = {ConfigurationUpdateException.class}) public void structuredAndSecondRawShouldStillGetUpdatedWhenFirstRawValidationFails() throws Exception { final RawConfiguration raw1 = createRawConfiguration("/tmp/raw1.txt"); final RawConfiguration raw2 = createRawConfiguration("/tmp/raw2.txt"); final Configuration config = new Configuration(); config.addRawConfiguration(raw1); config.addRawConfiguration(raw2); addDefaultExpectationsForUpdate(); context.checking(new Expectations() {{ oneOf(configFacet).validateStructuredConfiguration(config); oneOf(configFacet).persistStructuredConfiguration(config); oneOf(configFacet).validateRawConfiguration(raw1); will(throwException(new RuntimeException())); oneOf(configFacet).validateRawConfiguration(raw2); oneOf(configFacet).persistRawConfiguration(raw2); }}); structuredAndRawConfigManagement.executeUpdate(resourceId, config); }