@Before public void setup() { initMocks(this); extension = new TaskExtension(pluginManager); pluginId = "plugin-id"; when(pluginManager.resolveExtensionVersion(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), any(List.class))).thenReturn("1.0"); pluginSettingsConfiguration = new PluginSettingsConfiguration(); requestArgumentCaptor = ArgumentCaptor.forClass(GoPluginApiRequest.class); }
@Before public void setUp() { initMocks(this); PluginManagerReference.reference().setPluginManager(pluginManager); when(pluggableTask.getPluginConfiguration()).thenReturn(new PluginConfiguration(TEST_PLUGIN_ID, "1.0")); HashMap<String, Map<String, String>> pluginConfig = new HashMap<>(); when(pluggableTask.configAsMap()).thenReturn(pluginConfig); taskExtension = new TaskExtension(pluginManager); }
@Test public void shouldValidateTask() { GoPluginApiResponse response = mock(GoPluginApiResponse.class); TaskExtension jsonBasedTaskExtension = new TaskExtension(pluginManager); TaskConfig taskConfig = mock(TaskConfig.class); when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE); when(pluginManager.isPluginOfType(PLUGGABLE_TASK_EXTENSION, pluginId)).thenReturn(true); when(response.responseBody()).thenReturn("{\"errors\":{\"key\":\"error\"}}"); when(pluginManager.submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), any(GoPluginApiRequest.class))).thenReturn(response); ValidationResult validationResult = jsonBasedTaskExtension.validate(pluginId, taskConfig); verify(pluginManager).submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), any(GoPluginApiRequest.class)); assertFalse(validationResult.isSuccessful()); assertEquals(validationResult.getErrors().get(0).getKey(), "key"); assertEquals(validationResult.getErrors().get(0).getMessage(), "error"); }