### Question:
ConfigurationLoader { public JsonNode loadMappingRulesConfig(String serviceId, boolean loadFromOfflineCache) { String mappingRulesJson = doLoadMappingRulesConfig(serviceId, loadFromOfflineCache); try { return new ObjectMapper().readTree(mappingRulesJson).get("mapping_rules"); } catch (Exception e) { throw new ThreeScaleAdapterException(APIM_3021.pattern(), e); } } ConfigurationLoader(OfflineConfigurationCacheRepo repo,
                               EmergencyModeState emergencyModeState,
                               ThreeScaleAdminCommunicationComponent threeScaleAdminCommunicationComponent,
                               ThreeScaleBackendCommunicationComponent threeScaleBackendCommunicationComponent); Client loadPlanConfig(String serviceId, String clientId, boolean loadFromOfflineCache); JsonNode loadMappingRulesConfig(String serviceId, boolean loadFromOfflineCache); JsonNode loadMetricConfig(String serviceId, boolean loadFromOfflineCache); JsonNode loadProxyConfig(String serviceId, boolean loadFromOfflineCache);  }### Answer:
@Test public void successfulLoadMappingRulesConfiguration() { when(mockedThreeScaleAdminCommunicationComponent.loadMappingRulesConfig((eq(SERVICE_ID)))).thenReturn("{\"mapping_rules\" : {\"id\": 1}}"); JsonNode jsonNode = testee.loadMappingRulesConfig(SERVICE_ID, false); assertThat(jsonNode.get("id").asText(), is("1")); }
@Test(expected = RuntimeException.class) public void exceptionWhileloadMappingRulesConfiguration() { when(mockedThreeScaleAdminCommunicationComponent.loadMappingRulesConfig((eq(SERVICE_ID)))).thenThrow(new RuntimeException()); testee.loadMappingRulesConfig(SERVICE_ID, false); }
@Test public void exceptionWhileloadMappingRulesConfigurationWithCache() { when(mockedThreeScaleAdminCommunicationComponent.loadMappingRulesConfig((eq(SERVICE_ID)))).thenThrow(new RuntimeException()); when(mockedOfflineConfigurationCacheRepo.findMappingRulesConfig((eq(SERVICE_ID)))).thenReturn("{\"mapping_rules\" : {\"id\": 1}}"); JsonNode jsonNode = testee.loadMappingRulesConfig(SERVICE_ID, true); verify(mockedEmergencyModeState).setConfigurationSuccessfulLoaded(eq(MAPPING_RULES), eq(false)); assertThat(jsonNode.get("id").asText(), is("1")); }