/checklistbank-ws-test/src/test/java/org/gbif/checklistbank/ws/NameUsageTestIT.java

http://gbif-ecat.googlecode.com/ · Java · 92 lines · 63 code · 17 blank · 12 comment · 0 complexity · 517400ec7a1facece30cf34b2ebf0356 MD5 · raw file

  1. /*
  2. * Copyright 2011 Global Biodiversity Information Facility (GBIF)
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. package org.gbif.checklistbank.ws;
  14. import org.gbif.api.paging.PagingRequest;
  15. import org.gbif.api.paging.PagingResponse;
  16. import org.gbif.checklistbank.api.model.NameUsage;
  17. import org.gbif.checklistbank.api.service.NameUsageService;
  18. import org.gbif.checklistbank.ws.client.guice.ChecklistBankWsClientModule;
  19. import org.gbif.checklistbank.ws.guice.ChecklistBankWsModule;
  20. import java.util.List;
  21. import java.util.Locale;
  22. import java.util.UUID;
  23. import com.google.inject.Guice;
  24. import com.google.inject.Injector;
  25. import junit.framework.Assert;
  26. import org.junit.Before;
  27. import org.junit.Test;
  28. public class NameUsageTestIT extends BaseResourceTest {
  29. private Injector clientInjector;
  30. private NameUsageService wsClient;
  31. public NameUsageTestIT() {
  32. super("org.gbif.checklistbank.ws", "clb", ChecklistBankWsModule.class, "/name_usage/");
  33. }
  34. @Before
  35. public void init() {
  36. clientInjector =
  37. Guice
  38. .createInjector(new UrlBindingModule(this.getBaseURI(), "clb"), new ChecklistBankWsClientModule(false, true));
  39. wsClient = clientInjector.getInstance(NameUsageService.class);
  40. }
  41. @Test
  42. public void testGet() {
  43. NameUsage nameUsage = this.wsClient.get(1, new Locale("en"));
  44. Assert.assertNotNull(nameUsage);
  45. }
  46. @Test
  47. public void testListChildren() {
  48. PagingResponse<NameUsage> children = this.wsClient.listChildren(6, new Locale("en"), new PagingRequest(0, 20));
  49. Assert.assertNotNull(children);
  50. Assert.assertEquals(children.getResults().size(), 20);
  51. }
  52. @Test
  53. public void testListDatasets() {
  54. List<UUID> datasets = this.wsClient.listRelatedOccurrenceDatasets(6);
  55. Assert.assertNotNull(datasets);
  56. }
  57. @Test
  58. public void testListParents() {
  59. List<NameUsage> parents = this.wsClient.listParents(13, new Locale("en"));
  60. Assert.assertNotNull(parents);
  61. Assert.assertEquals(parents.size(), 1);
  62. }
  63. @Test
  64. public void testListRelated() {
  65. PagingResponse<NameUsage> related = this.wsClient.listRelated(6, new Locale("en"), new PagingRequest(0, 20));
  66. Assert.assertNotNull(related);
  67. Assert.assertEquals(related.getResults().size(), 16);
  68. }
  69. @Test
  70. public void testListSynonyms() {
  71. PagingResponse<NameUsage> synonyms = this.wsClient.listSynonyms(6, new Locale("en"), new PagingRequest(0, 20));
  72. Assert.assertNotNull(synonyms);
  73. Assert.assertEquals(synonyms.getResults().size(), 1);
  74. }
  75. }