Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,9 @@ private void validateReferencingComponents(final String parameterName, final Par

final ControllerServiceState serviceState = serviceNode.getState();
if (serviceState != ControllerServiceState.DISABLED && enforceReferencingState) {
throw new IllegalStateException("Cannot " + action + " parameter '" + parameterName + "' because it is referenced by "
+ serviceNode + ", which currently has a state of " + serviceState);
throw new IllegalStateException("Cannot " + action + " parameter '" + parameterName + "' because it is referenced by controller service '" + serviceNode.getName()
+ "' (" + serviceNode.getComponentType() + ", id=" + serviceNode.getIdentifier() + "), which has state " + serviceState
+ " instead of " + ControllerServiceState.DISABLED);
}

if (parameter != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ public void testChangingParameterForEnabledControllerService() {
final ParameterContext context = createStandardParameterContext(referenceManager);
final ControllerServiceNode serviceNode = mock(ControllerServiceNode.class);
enableControllerService(serviceNode);
when(serviceNode.getName()).thenReturn("My Service");
when(serviceNode.getComponentType()).thenReturn("MyService");
when(serviceNode.getIdentifier()).thenReturn("service-id");

final ParameterDescriptor abcDescriptor = new ParameterDescriptor.Builder().name("abc").sensitive(true).build();
final Map<String, Parameter> parameters = new HashMap<>();
Expand All @@ -629,24 +632,29 @@ public void testChangingParameterForEnabledControllerService() {
for (final ControllerServiceState state : EnumSet.of(ControllerServiceState.ENABLED, ControllerServiceState.ENABLING, ControllerServiceState.DISABLING)) {
setControllerServiceState(serviceNode, state);

try {
context.setParameters(parameters);
fail("Was able to update parameter being referenced by Controller Service that is " + state);
} catch (final IllegalStateException expected) {
}
final IllegalStateException exception = assertThrows(IllegalStateException.class, () -> context.setParameters(parameters));
assertControllerServiceReferenceMessage(exception.getMessage(), "update", state);

assertEquals("123", context.getParameter("abc").get().getValue());
}

setControllerServiceState(serviceNode, ControllerServiceState.DISABLING);
parameters.clear();
context.setParameters(parameters);
parameters.put("abc", null);
final IllegalStateException exception = assertThrows(IllegalStateException.class, () -> context.setParameters(parameters));
assertControllerServiceReferenceMessage(exception.getMessage(), "remove", ControllerServiceState.DISABLING);
}

parameters.put("abc", createParameter(abcDescriptor, null));
try {
context.setParameters(parameters);
fail("Was able to remove parameter being referenced by Controller Service that is DISABLING");
} catch (final IllegalStateException expected) {
}
private static void assertControllerServiceReferenceMessage(final String message, final String action, final ControllerServiceState state) {
assertTrue(message.contains("Cannot " + action + " parameter"));
assertTrue(message.contains("abc"));
assertTrue(message.contains("controller service"));
assertTrue(message.contains("My Service"));
assertTrue(message.contains("MyService"));
assertTrue(message.contains("service-id"));
assertTrue(message.contains(state.name()));
assertTrue(message.contains(ControllerServiceState.DISABLED.name()));
assertFalse(message.contains("StandardControllerServiceNode"));
}

private ParameterContext createStandardParameterContext(final ParameterReferenceManager referenceManager) {
Expand Down
Loading