@Test public void when_endpoint_contains_two_variables_replace_them_all() throws Exception { // GIVEN ConfigLoader.loadMappingsConfig(false); // WHEN MappingEndpoint endpoint = ConfigLoader.getConfig().get(0).getMappingEndpoint("/v0.1/contacts/mobile/support", "GET"); // THEN assertEquals(endpoint.getInternalEndpoint(), "/contacts/mobile/support"); }
@Test public void when_endpoint_contains_RE_return_it_from_RE_mappings() throws Exception { // GIVEN ConfigLoader.loadMappingsConfig(false); // WHEN MappingEndpoint endpoint = ConfigLoader.getConfig().get(0).getMappingEndpoint("/v0.1/payments/12345", "GET"); // THEN assertEquals(endpoint.getInternalEndpoint(), "/payments/12345"); }
@Test public void when_mapping_list_contains_method_and_uri_return_that_mapping_endpoint() throws Exception { // GIVEN ConfigLoader.loadMappingsConfig(false); // WHEN MappingEndpoint meEndpoint = ConfigLoader.getConfig().get(0).getMappingEndpoint("/v0.1/me", "GET"); // THEN assertEquals(meEndpoint.getExternalEndpoint(), "/v0.1/me"); assertEquals(meEndpoint.getMethod(), "GET"); }
@Test public void when_load_read_mapping() throws Exception { // WHEN ConfigLoader.loadMappingsConfig(false); // THEN List<MappingConfig> config = ConfigLoader.getConfig(); Map<String, String> actions = config.get(0).getActions(); assertEquals(actions.get("ReplaceCustomerId"), "com.apifest.example.ReplaceCustomerIdAction"); assertEquals(actions.get("AddSenderIdInBody"), "com.apifest.example.AddSenderIdInBody"); MappingEndpoint endpoint = config.get(0).getMappingEndpoint("/v0.1/me", "GET"); assertEquals(endpoint.getInternalEndpoint(), "/customer/{customerId}"); assertEquals(endpoint.getAction().getName(), "ReplaceCustomerId"); }
@Test public void when_action_class_is_not_null_do_not_invoke_getAction_from_actions_map() throws Exception { // GIVEN ConfigLoader.loadMappingsConfig(false); MappingAction action = new MappingAction(); action.setName("testAction"); action.setActionClassName("com.apifest.example.AddSenderIdInBodyAction"); ConfigLoader.jarClassLoader = mock(URLClassLoader.class); doReturn(AddSenderIdInBodyAction.class) .when(ConfigLoader.jarClassLoader) .loadClass(action.getActionClassName()); // WHEN BasicAction actionClass = ConfigLoader.getConfig().get(0).getAction(action); // THEN assertTrue(actionClass instanceof AddSenderIdInBodyAction); }
@Test public void when_actionClassname_is_null_get_className_from_actions_config() throws Exception { // GIVEN ConfigLoader.loadMappingsConfig(false); MappingAction mappingAction = new MappingAction(); mappingAction.setName("ReplaceCustomerId"); MappingEndpoint endpoint = new MappingEndpoint(); endpoint.setAction(mappingAction); ConfigLoader.jarClassLoader = mock(URLClassLoader.class); doReturn(ReplaceCustomerIdAction.class) .when(ConfigLoader.jarClassLoader) .loadClass(ReplaceCustomerIdAction.class.getCanonicalName()); // WHEN BasicAction action = ConfigLoader.getConfig().get(0).getAction(mappingAction); // THEN assertTrue(action instanceof ReplaceCustomerIdAction); }