Skip to content
Snippets Groups Projects
Commit 36ed344a authored by Zhibin Mai's avatar Zhibin Mai
Browse files

Add unit test

parent 5df40bab
No related branches found
No related tags found
1 merge request!571Catch the generic exception that might be thrown from FetchServiceHttpRequest.sendRequest(...) API
Pipeline #195403 failed
Pipeline: Indexer

#195404

    ......@@ -7,12 +7,15 @@ import org.mockito.InjectMocks;
    import org.mockito.Mock;
    import org.opengroup.osdu.core.common.http.IUrlFetchService;
    import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
    import org.opengroup.osdu.core.common.model.http.AppException;
    import org.opengroup.osdu.core.common.model.http.HttpResponse;
    import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo;
    import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties;
    import org.opengroup.osdu.indexer.model.SearchRequest;
    import org.opengroup.osdu.indexer.model.SearchResponse;
    import org.powermock.modules.junit4.PowerMockRunner;
    import static org.junit.jupiter.api.Assertions.assertThrows;
    import static org.mockito.ArgumentMatchers.any;
    import java.net.URISyntaxException;
    ......@@ -143,4 +146,11 @@ public class SearchServiceImplTest {
    Assert.assertNotNull(searchResponse);
    Assert.assertNull(searchResponse.getResults());
    }
    @Test
    public void query_with_exception() throws URISyntaxException {
    when(this.configurationProperties.getSearchHost()).thenReturn(searchHost);
    when(this.urlFetchService.sendRequest(any())).thenThrow(new AppException(415, "upstream server responded with unsupported media type: text/plain", "Unsupported media type" ));
    assertThrows(URISyntaxException.class, () -> sut.query(new SearchRequest()));
    }
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment