PageRenderTime 814ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://gbif-ecat.googlecode.com/
Java | 131 lines | 103 code | 16 blank | 12 comment | 0 complexity | f8205a016bb104db450ce3869ff7b0d8 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.Description;
  17. import org.gbif.checklistbank.api.model.Distribution;
  18. import org.gbif.checklistbank.api.model.Identifier;
  19. import org.gbif.checklistbank.api.model.Image;
  20. import org.gbif.checklistbank.api.model.Reference;
  21. import org.gbif.checklistbank.api.model.SpeciesProfile;
  22. import org.gbif.checklistbank.api.model.TypeSpecimen;
  23. import org.gbif.checklistbank.api.model.VernacularName;
  24. import org.gbif.checklistbank.api.service.DescriptionService;
  25. import org.gbif.checklistbank.api.service.DistributionService;
  26. import org.gbif.checklistbank.api.service.IdentifierService;
  27. import org.gbif.checklistbank.api.service.ImageService;
  28. import org.gbif.checklistbank.api.service.NameUsageComponentService;
  29. import org.gbif.checklistbank.api.service.ReferenceService;
  30. import org.gbif.checklistbank.api.service.SpeciesProfileService;
  31. import org.gbif.checklistbank.api.service.TypeSpecimenService;
  32. import org.gbif.checklistbank.api.service.VernacularNameService;
  33. import org.gbif.checklistbank.ws.client.guice.ChecklistBankWsClientModule;
  34. import org.gbif.checklistbank.ws.guice.ChecklistBankWsModule;
  35. import com.google.inject.Guice;
  36. import com.google.inject.Injector;
  37. import junit.framework.Assert;
  38. import org.junit.Before;
  39. import org.junit.Test;
  40. public class NameUsageComponentTestIT extends BaseResourceTest {
  41. private Injector clientInjector;
  42. public NameUsageComponentTestIT() {
  43. super("org.gbif.checklistbank.ws", "clb", ChecklistBankWsModule.class, "/name_usage/");
  44. }
  45. @Before
  46. public void init() {
  47. clientInjector =
  48. Guice
  49. .createInjector(new UrlBindingModule(this.getBaseURI(), "clb"), new ChecklistBankWsClientModule(false, true));
  50. }
  51. @Test
  52. public void testListDescriptions() {
  53. NameUsageComponentService<Description, Description> wsClient;
  54. wsClient = clientInjector.getInstance(DescriptionService.class);
  55. PagingResponse<Description> descriptions = wsClient.listByUsage(100026167, new PagingRequest(0, 20));
  56. Assert.assertNotNull(descriptions);
  57. Assert.assertEquals(descriptions.getResults().size(), 1);
  58. }
  59. @Test
  60. public void testListDistributions() {
  61. NameUsageComponentService<Distribution, Distribution> wsClient;
  62. wsClient = clientInjector.getInstance(DistributionService.class);
  63. PagingResponse<Distribution> distributions = wsClient.listByUsage(100425637, new PagingRequest(0, 20));
  64. Assert.assertNotNull(distributions);
  65. Assert.assertEquals(distributions.getResults().size(), 20);
  66. }
  67. @Test
  68. public void testListIdentifiers() {
  69. NameUsageComponentService<Identifier, Identifier> wsClient;
  70. wsClient = clientInjector.getInstance(IdentifierService.class);
  71. PagingResponse<Identifier> identifiers = wsClient.listByUsage(100026088, new PagingRequest(0, 20));
  72. Assert.assertNotNull(identifiers);
  73. Assert.assertEquals(identifiers.getResults().size(), 1);
  74. }
  75. @Test
  76. public void testListImages() {
  77. NameUsageComponentService<Image, Image> wsClient;
  78. wsClient = clientInjector.getInstance(ImageService.class);
  79. PagingResponse<Image> images = wsClient.listByUsage(100027553, new PagingRequest(0, 20));
  80. Assert.assertNotNull(images);
  81. Assert.assertEquals(images.getResults().size(), 1);
  82. }
  83. @Test
  84. public void testListReferences() {
  85. NameUsageComponentService<Reference, Reference> wsClient;
  86. wsClient = clientInjector.getInstance(ReferenceService.class);
  87. PagingResponse<Reference> references = wsClient.listByUsage(100027553, new PagingRequest(0, 20));
  88. Assert.assertNotNull(references);
  89. Assert.assertEquals(references.getResults().size(), 4);
  90. }
  91. @Test
  92. public void testListSpeciesProfiles() {
  93. NameUsageComponentService<SpeciesProfile, SpeciesProfile> wsClient;
  94. wsClient = clientInjector.getInstance(SpeciesProfileService.class);
  95. PagingResponse<SpeciesProfile> speciesProfiles = wsClient.listByUsage(100027553, new PagingRequest(0, 20));
  96. Assert.assertNotNull(speciesProfiles);
  97. Assert.assertEquals(speciesProfiles.getResults().size(), 1);
  98. }
  99. @Test
  100. public void testListTypeSpecimens() {
  101. NameUsageComponentService<TypeSpecimen, TypeSpecimen> wsClient;
  102. wsClient = clientInjector.getInstance(TypeSpecimenService.class);
  103. PagingResponse<TypeSpecimen> typesSpecimens = wsClient.listByUsage(100026699, new PagingRequest(0, 20));
  104. Assert.assertNotNull(typesSpecimens);
  105. Assert.assertEquals(typesSpecimens.getResults().size(), 1);
  106. }
  107. @Test
  108. public void testListVernacularNames() {
  109. NameUsageComponentService<VernacularName, VernacularName> wsClient;
  110. wsClient = clientInjector.getInstance(VernacularNameService.class);
  111. PagingResponse<VernacularName> vernacularNames = wsClient.listByUsage(6, new PagingRequest(0, 20));
  112. Assert.assertNotNull(vernacularNames);
  113. Assert.assertEquals(vernacularNames.getResults().size(), 6);
  114. }
  115. }