fixture.configuration.addRawConfiguration(new RawConfiguration());
final Configuration translatedConfig = fixture.configuration.deepCopy();
translatedConfig.put(new PropertySimple("x", "y"));
final ResourceConfigurationUpdate expectedUpdate = new ResourceConfigurationUpdate(fixture.resource,
translatedConfig, fixture.subject.getName());
expectedUpdate.setId(-1);
final AgentClient agentClient = context.mock(AgentClient.class);
final ConfigurationAgentService configAgentService = context.mock(ConfigurationAgentService.class);
final ConfigurationUpdateRequest expectedUpdateRequest = new ConfigurationUpdateRequest(expectedUpdate.getId(),
expectedUpdate.getConfiguration(), expectedUpdate.getResource().getId());
final Sequence configUdpate = context.sequence("raw-config-update");
context.checking(new Expectations() {
{
oneOf(authorizationMgr).hasResourcePermission(fixture.subject, CONFIGURE_READ, fixture.resourceId);
will(returnValue(true));
oneOf(authorizationMgr).hasResourcePermission(fixture.subject, CONFIGURE_WRITE, fixture.resourceId);
will(returnValue(true));
allowing(entityMgr).find(Resource.class, fixture.resourceId);
will(returnValue(fixture.resource));
allowing(authorizationMgr).canViewResource(fixture.subject, fixture.resourceId);
will(returnValue(true));
oneOf(configAgentService).merge(fixture.configuration, fixture.resourceId, FROM_RAW);
will(returnValue(translatedConfig));
inSequence(configUdpate);
oneOf(configurationMgrLocal).persistResourceConfigurationUpdateInNewTransaction(fixture.subject,
fixture.resourceId, translatedConfig, INPROGRESS, fixture.subject.getName(),
fixture.isPartOfGroupUpdate);
will(returnValue(expectedUpdate));
inSequence(configUdpate);
allowing(agentMgr).getAgentClient(expectedUpdate.getResource().getAgent());
will(returnValue(agentClient));
allowing(agentClient).getConfigurationAgentService();
will(returnValue(configAgentService));
oneOf(configAgentService).validate(fixture.configuration, fixture.resourceId, FROM_RAW);
oneOf(configAgentService).updateResourceConfiguration(
with(matchingUpdateRequest(expectedUpdateRequest)));
inSequence(configUdpate);
}
});
ResourceConfigurationUpdate actualUpdate = configurationMgr.updateStructuredOrRawConfiguration(fixture.subject,
fixture.resourceId, fixture.configuration, FROM_RAW);
assertSame(actualUpdate, expectedUpdate, "Expected to get back the persisted configuration update");
}