/src/test/java/org/exoplatform/social/client/core/service/IdentityServiceV1Alpha3IT.java

http://github.com/exosocial/exo.social.client · Java · 156 lines · 102 code · 17 blank · 37 comment · 6 complexity · 7bba9ec0432139402ad1a1dce5d1e5f7 MD5 · raw file

  1. /*
  2. * Copyright (C) 2003-2011 eXo Platform SAS.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Affero General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package org.exoplatform.social.client.core.service;
  18. import org.exoplatform.social.client.api.SocialClientLibException;
  19. import org.exoplatform.social.client.api.UnsupportedMethodException;
  20. import org.exoplatform.social.client.api.model.RestIdentity;
  21. import org.exoplatform.social.client.api.model.RestProfile;
  22. import org.exoplatform.social.client.core.AbstractClientTestV1Alpha3;
  23. import org.testng.annotations.AfterMethod;
  24. import org.testng.annotations.BeforeMethod;
  25. import org.testng.annotations.Test;
  26. import static org.hamcrest.CoreMatchers.equalTo;
  27. import static org.hamcrest.MatcherAssert.assertThat;
  28. import static org.hamcrest.core.IsNull.notNullValue;
  29. import static org.testng.Assert.fail;
  30. /**
  31. * Unit Test for {@link IdentityServiceImplV1Alpha1}.
  32. *
  33. * @author <a href="http://hoatle.net">hoatle (hoatlevan at gmail dot com)</a>
  34. * @since Jul 1, 2011
  35. */
  36. public class IdentityServiceV1Alpha3IT extends AbstractClientTestV1Alpha3 {
  37. @BeforeMethod
  38. @Override
  39. public void setUp() {
  40. super.setUp();
  41. }
  42. @Override
  43. public void afterSetup() {
  44. startSessionAs("root", "gtn");
  45. }
  46. @AfterMethod
  47. @Override
  48. public void tearDown() {
  49. super.tearDown();
  50. }
  51. /**
  52. * Test the case create a new identity.
  53. */
  54. @Test(expectedExceptions = UnsupportedMethodException.class)
  55. public void testCreate() throws SocialClientLibException {
  56. if (!canRunTest()) {
  57. throw new UnsupportedMethodException();
  58. }
  59. identityService.create(new RestIdentity());
  60. }
  61. /**
  62. * Test the case update an existing identity.
  63. */
  64. @Test(expectedExceptions = UnsupportedMethodException.class)
  65. public void testUpdate() throws SocialClientLibException {
  66. if (!canRunTest()) {
  67. throw new UnsupportedMethodException();
  68. }
  69. identityService.update(identityService.get(getRootIdentity().getId()));
  70. }
  71. /**
  72. * Test the case delete an existing identity.
  73. */
  74. @Test(expectedExceptions = UnsupportedMethodException.class)
  75. public void testDelete() throws SocialClientLibException {
  76. if (!canRunTest()) {
  77. throw new UnsupportedMethodException();
  78. }
  79. identityService.delete(identityService.get(getRootIdentity().getId()));
  80. }
  81. /**
  82. * Test the case get an identity by its id.
  83. */
  84. @Test
  85. public void testGetIdentity() throws SocialClientLibException {
  86. if (!canRunTest()) {
  87. return;
  88. }
  89. String id = getRootIdentity().getId();
  90. RestIdentity identity = identityService.get(id);
  91. assertThat("Identity must not be null", identity, notNullValue());
  92. assertThat("Identity provider must be organization", identity.getProviderId(), equalTo("organization"));
  93. assertThat("RemoteId must be demo", identity.getRemoteId(), equalTo("root"));
  94. RestProfile profile = identity.getProfile();
  95. assertThat("profile must not be null", profile, notNullValue());
  96. assertThat("profile.getAvatarUrl() must not be null", profile.getAvatarUrl(), notNullValue());
  97. assertThat("profile.getFullName() must return: Root Root", profile.getFullName(), equalTo("Root Root"));
  98. try {
  99. identity = identityService.get(null);
  100. fail("Expecting NullPointerException from IdentityService#get(String)");
  101. } catch (NullPointerException npe) {
  102. }
  103. }
  104. /**
  105. * Test the case get id of identity.
  106. */
  107. @Test
  108. public void testGetIdentityId() throws SocialClientLibException {
  109. if (!canRunTest()) {
  110. return;
  111. }
  112. String expectedId = getRootIdentity().getId();
  113. String resultId = identityService.getIdentityId("organization", "root");
  114. assertThat("identity id must be " + expectedId, resultId, equalTo(expectedId));
  115. try {
  116. resultId = identityService.getIdentityId(null, "root");
  117. fail("Expecting NullPointerException from IdentityService#getIdentityId(String, String)");
  118. } catch (NullPointerException npe) {
  119. }
  120. try {
  121. resultId = identityService.getIdentityId(null, null);
  122. fail("Expecting NullPointerException from IdentityService#getIdentityId(String, String)");
  123. } catch (NullPointerException npe) {
  124. }
  125. }
  126. @Test
  127. public void testGetIdentityByProviderAndRemoteId() throws Exception {
  128. if (!canRunTest()) {
  129. return;
  130. }
  131. RestIdentity restIdentity = identityService.getIdentity("organization", "root");
  132. assertThat("RestIdentity must not null.", restIdentity, notNullValue());
  133. assertThat("RemoteId must be root", "root", equalTo(restIdentity.getRemoteId()));
  134. assertThat("Provider must be organization", "organization", equalTo(restIdentity.getProviderId()));
  135. RestProfile restProfile = restIdentity.getProfile();
  136. assertThat("Avatar URL must not be null", restProfile.getAvatarUrl(), notNullValue());
  137. assertThat("Profile's full name must be root gtn", "Root Root", equalTo(restProfile.getFullName()));
  138. }
  139. }