|
| 1 | +// Copyright © 2020 Sovren Group, Inc. All rights reserved. |
| 2 | +// This file is provided for use by, or on behalf of, Sovren licensees |
| 3 | +// within the terms of their license of Sovren products or Sovren customers |
| 4 | +// within the Terms of Service pertaining to the Sovren SaaS products. |
| 5 | + |
| 6 | +package com.sovren; |
| 7 | + |
| 8 | +import com.sovren.exceptions.SovrenException; |
| 9 | +import com.sovren.models.api.matching.request.FilterCriteria; |
| 10 | +import java.util.ArrayList; |
| 11 | +import static org.junit.jupiter.api.Assertions.*; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | + |
| 14 | +public class SDKTests extends TestBase { |
| 15 | + |
| 16 | + @Test |
| 17 | + public void test404Message(){ |
| 18 | + DataCenter fakeDC = new DataCenter("https://rest.resumeparsing.com/v9/fake"); |
| 19 | + SovrenClient client = new SovrenClient("1234", "1234", fakeDC); |
| 20 | + |
| 21 | + try { |
| 22 | + client.getAccountInfo(); |
| 23 | + } |
| 24 | + catch (SovrenException e){ |
| 25 | + assertEquals(404, e.HttpStatusCode); |
| 26 | + assertEquals("404 - Not Found", e.getMessage()); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void test500Message(){ |
| 32 | + DataCenter fakeDC = new DataCenter("https://thisisnotarealurlatall-akmeaoiaefoij.com/"); |
| 33 | + SovrenClient client = new SovrenClient("1234", "1234", fakeDC); |
| 34 | + |
| 35 | + try { |
| 36 | + client.getAccountInfo(); |
| 37 | + } |
| 38 | + catch (SovrenException e){ |
| 39 | + assertEquals(500, e.HttpStatusCode); |
| 40 | + assertEquals("connect timed out", e.getMessage().toLowerCase()); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testSelfHostedDataCenter(){ |
| 46 | + String url = "https://selfhosted.customer.com"; |
| 47 | + DataCenter fakeDC = new DataCenter(url); |
| 48 | + ApiEndpoints endpoints = new ApiEndpoints(fakeDC); |
| 49 | + |
| 50 | + assertEquals(url + "/account", endpoints.account()); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testDebugRequestBody(){ |
| 55 | + DataCenter fakeDC = new DataCenter("https://thisisnotarealurlatall-akmeaoiaefoij.com/"); |
| 56 | + SovrenClient client = new SovrenClient("1234", "1234", fakeDC); |
| 57 | + client.ShowFullRequestBodyInExceptions = true; |
| 58 | + |
| 59 | + try { |
| 60 | + ArrayList<String> index = new ArrayList<>(); |
| 61 | + index.add("testIndex"); |
| 62 | + client.search(index, new FilterCriteria(), null, null); |
| 63 | + } |
| 64 | + catch (SovrenException e){ |
| 65 | + String expectedRequest = "{\"IndexIdsToSearchInto\":[\"testIndex\"],\"FilterCriteria\":{\"UserDefinedTagsMustAllExist\":false,\"HasPatents\":false,\"HasSecurityCredentials\":false,\"IsAuthor\":false,\"IsPublicSpeaker\":false,\"IsMilitary\":false,\"EmployersMustAllBeCurrentEmployer\":false,\"SkillsMustAllExist\":false,\"IsTopStudent\":false,\"IsCurrentStudent\":false,\"IsRecentGraduate\":false,\"LanguagesKnownMustAllExist\":false}}"; |
| 66 | + assertEquals(expectedRequest, e.RequestBody); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments