@Override public Resource create(XingApi api) { return new JobsResource(api); } };
@Test public void getJobsRecommendations() throws Exception { server.enqueue(new MockResponse().setBody(file("recommended_jobs.json"))); Response<List<PartialJob>, HttpError> response = resource.getJobsRecommendationsForUser("some_id").execute(); // If no exception was thrown then the spec is build correctly. assertThat(response.body().get(0).id()).isEqualTo("61723_4cae01"); assertThat(response.body().get(0).contact().jobCompany().name()).isEqualTo("Rails Heroes"); }
/** * Returns a list of {@linkplain PartialJob} postings that match the given criteria. * * A minimal job posting consists of the fields id, title, company, location, contact, published_at and links. * If you want to return the full job posting, that contains for example the description, you need to use {@link * #getJobById(String)}. You can also follow the links.self URL, that will also lead you to the full job posting. */ public CallSpec<List<PartialJob>, HttpError> getJobsByCriteria(String criteria) { return Resource.<List<PartialJob>, HttpError>newGetSpec(api, "/v1/jobs/find") .queryParam("query", criteria) .responseAs(list(PartialJob.class, "jobs", "items")) .build(); }
/** * Returns a full {@linkplain Job} posting. * * Full job postings contain the following fields in addition to minimal job postings (returned by jobs * recommendations and jobs search ): level, job_type, industry, skills, tags, description. * When the contact field is present, it contains either a company or a user. * Warning: The company field does not contain a XING company profile in all cases. This means that the company, * that posted the job, does not have a XING company profile. In this case the id field is null and the links field * contains an empty object. */ public CallSpec<Job, HttpError> getJobById(String jobId) { return Resource.<Job, HttpError>newGetSpec(api, "/v1/jobs/{id}") .pathParam("id", jobId) .responseAs(single(Job.class, "job")) .build(); }
@Test public void getJobsByCriteria() throws Exception { server.enqueue(new MockResponse().setBody(file("list_of_jobs.json"))); Response<List<PartialJob>, HttpError> response = resource.getJobsByCriteria("some_criteria").execute(); // If no exception was thrown then the spec is build correctly. assertThat(response.body().get(0).id()).isEqualTo("61723_4cae01"); assertThat(response.body().get(0).contact().jobCompany().name()).isEqualTo("Rails Heroes"); }
@Test public void getJobById() throws Exception { server.enqueue(new MockResponse().setBody(file("jobs.json"))); Response<Job, HttpError> response = resource.getJobById("some_id").execute(); // If no exception was thrown then the spec is build correctly. assertThat(response.body().id()).isEqualTo("61723_4cae01"); assertThat(response.body().contact().jobCompany().name()).isEqualTo("Mr. Recruiter"); assertThat(response.body().contact().user().id()).isEqualTo("3456gt_35345"); assertThat(response.body().location().zipCode()).isEqualTo("20354"); }
@Test public void getJobsRecommendationsWithPagination() throws Exception { server.enqueue(new MockResponse().setBody(file("recommended_jobs.json"))); server.enqueue(new MockResponse().setBody(file("recommended_jobs.json"))); CallSpec<List<PartialJob>, HttpError> spec = resource.getJobsRecommendationsForUser("some_id"); spec.execute(); CallSpec<List<PartialJob>, HttpError> clonedSpec = spec.clone(); Response<List<PartialJob>, HttpError> response = clonedSpec.queryParam("limit", 10) .queryParam("offset", 1) .execute(); assertThat(response.body().get(0).id()).isEqualTo("61723_4cae01"); }
/** * Returns a list of recommended {@linkplain PartialJob} postings for the specified user. * * A minimal job posting consists of the fields id, title, company, location, contact, published_at and links. * If you want to return the full job posting, that contains for example the description, you need to use * {@link #getJobById(String)}. You can also follow the links.self URL, that will also lead you to the full job * posting. */ public CallSpec<List<PartialJob>, HttpError> getJobsRecommendationsForUser(String userId) { return Resource.<List<PartialJob>, HttpError>newGetSpec(api, "/v1/users/{user_id}/jobs/recommendations") .pathParam("user_id", userId) .responseAs(list(PartialJob.class, "job_recommendations", "items")) .build(); } }
@Test(expected = IllegalStateException.class) public void getJobsRecommendationsReusingCallSpecShouldThrowException() throws Exception { server.enqueue(new MockResponse().setBody(file("recommended_jobs.json"))); CallSpec<List<PartialJob>, HttpError> spec = resource.getJobsRecommendationsForUser("some_id"); spec.execute(); spec.execute(); } }