StubConfiguration extends AbstractConfiguration { public boolean dropAllStubConfig() { LOG.debug("Call drop all stub configuration."); boolean droppedAllStubConfig = true; JSONObject stubConfig = getStubConfigInformation(); if ((stubConfig != null) && (stubConfig.length() > 0)) { try { LOG.debug("Gets stub configs array from all stub configuration JSON."); JSONArray configs = stubConfig.getJSONArray("configs"); for (int i = 0; i < configs.length(); i++) { LOG.debug("Get the stub group name."); String groupName = configs.getJSONObject(i).getString("groupname"); droppedAllStubConfig &= dropStubConfig(groupName); LOG.info("Dropped stub configuration: {}", groupName); } } catch (JSONException e) { LOG.error("Error occurred while dropping sub configuration. ", e); droppedAllStubConfig = false; } } else { droppedAllStubConfig = false; } return droppedAllStubConfig; } StubConfiguration(WilmaServiceConfig config);  StubConfiguration(WilmaServiceConfig config, WilmaHttpClient client); JSONObject getStubConfigInformation(); boolean setStubConfigStatus(String groupName, StubConfigStatus status); boolean setStubConfigOrder(String groupName, StubConfigOrder order); boolean dropStubConfig(String groupName); boolean dropAllStubConfig(); boolean persistActualStubConfig();  }
@Test public void shouldReturnTrueForDropAllStubConfigIfTheGivenJSONIsCorrect() { when(client.sendGetterRequest(STUB_STATUS_URL)).thenReturn(Optional.<String>of(validNotEmptyJson())); when(client.sendSetterRequest(DROP_STUB_URL1)).thenReturn(true); when(client.sendSetterRequest(DROP_STUB_URL2)).thenReturn(true); ArgumentCaptor<String> url = ArgumentCaptor.forClass(String.class); boolean result = stubConfiguration.dropAllStubConfig(); assertTrue(result); verify(client, times(2)).sendSetterRequest(url.capture()); assertEquals(url.getAllValues().get(0), DROP_STUB_URL1); assertEquals(url.getAllValues().get(1), DROP_STUB_URL2); }
@Test public void shouldReturnTrueForDropAllStubConfigIfTheGivenJSONIsCorrectEvenIfEmpty() { when(client.sendGetterRequest(STUB_STATUS_URL)).thenReturn(Optional.<String>of(validEmptyJson())); ArgumentCaptor<String> url = ArgumentCaptor.forClass(String.class); boolean result = stubConfiguration.dropAllStubConfig(); assertTrue(result); verify(client, times(0)).sendSetterRequest(url.capture()); }
@Test public void shouldReturnFalseForDropAllStubConfigIfTheConfigIsMissing() { when(client.sendGetterRequest(STUB_STATUS_URL)).thenReturn(Optional.<String>absent()); assertFalse(stubConfiguration.dropAllStubConfig()); }
@Test(dataProvider = "testdata") public void shouldReturnFalseForDropAllStubConfigIfTheGivenJSONIsIncorrect(String jsonString) { when(client.sendGetterRequest(STUB_STATUS_URL)).thenReturn(Optional.<String>of(jsonString)); assertFalse(stubConfiguration.dropAllStubConfig()); }