PageRenderTime 34ms CodeModel.GetById 27ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): AGPL-3.0
  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 */
 17package org.exoplatform.social.client.core.service;
 18
 19import org.exoplatform.social.client.api.SocialClientLibException;
 20import org.exoplatform.social.client.api.UnsupportedMethodException;
 21import org.exoplatform.social.client.api.model.RestIdentity;
 22import org.exoplatform.social.client.api.model.RestProfile;
 23import org.exoplatform.social.client.core.AbstractClientTestV1Alpha3;
 24import org.testng.annotations.AfterMethod;
 25import org.testng.annotations.BeforeMethod;
 26import org.testng.annotations.Test;
 27
 28import static org.hamcrest.CoreMatchers.equalTo;
 29import static org.hamcrest.MatcherAssert.assertThat;
 30import static org.hamcrest.core.IsNull.notNullValue;
 31import static org.testng.Assert.fail;
 32
 33/**
 34 * Unit Test for {@link IdentityServiceImplV1Alpha1}.
 35 *
 36 * @author <a href="http://hoatle.net">hoatle (hoatlevan at gmail dot com)</a>
 37 * @since Jul 1, 2011
 38 */
 39public class IdentityServiceV1Alpha3IT extends AbstractClientTestV1Alpha3 {
 40
 41
 42  @BeforeMethod
 43  @Override
 44  public void setUp() {
 45    super.setUp();
 46  }
 47
 48  @Override
 49  public void afterSetup() {
 50    startSessionAs("root", "gtn");
 51  }
 52
 53  @AfterMethod
 54  @Override
 55  public void tearDown() {
 56    super.tearDown();
 57  }
 58
 59  /**
 60   * Test the case create a new identity.
 61   */
 62  @Test(expectedExceptions = UnsupportedMethodException.class)
 63  public void testCreate() throws SocialClientLibException {
 64    if (!canRunTest()) {
 65      throw new UnsupportedMethodException();
 66    }
 67    identityService.create(new RestIdentity());
 68  }
 69
 70  /**
 71   * Test the case update an existing identity.
 72   */
 73  @Test(expectedExceptions = UnsupportedMethodException.class)
 74  public void testUpdate() throws SocialClientLibException {
 75    if (!canRunTest()) {
 76      throw new UnsupportedMethodException();
 77    }
 78    identityService.update(identityService.get(getRootIdentity().getId()));
 79  }
 80
 81  /**
 82   * Test the case delete an existing identity.
 83   */
 84  @Test(expectedExceptions = UnsupportedMethodException.class)
 85  public void testDelete() throws SocialClientLibException {
 86    if (!canRunTest()) {
 87      throw new UnsupportedMethodException();
 88    }
 89    identityService.delete(identityService.get(getRootIdentity().getId()));
 90  }
 91
 92  /**
 93   * Test the case get an identity by its id.
 94   */
 95  @Test
 96  public void testGetIdentity() throws SocialClientLibException {
 97    if (!canRunTest()) {
 98      return;
 99    }
100    String id = getRootIdentity().getId();
101    RestIdentity identity = identityService.get(id);
102    assertThat("Identity must not be null", identity, notNullValue());
103    assertThat("Identity provider must be organization", identity.getProviderId(), equalTo("organization"));
104    assertThat("RemoteId must be demo", identity.getRemoteId(), equalTo("root"));
105
106    RestProfile profile = identity.getProfile();
107    assertThat("profile must not be null", profile, notNullValue());
108    assertThat("profile.getAvatarUrl() must not be null", profile.getAvatarUrl(), notNullValue());
109    assertThat("profile.getFullName() must return: Root Root", profile.getFullName(), equalTo("Root Root"));
110
111    try {
112      identity = identityService.get(null);
113      fail("Expecting NullPointerException from IdentityService#get(String)");
114    } catch (NullPointerException npe) {
115    }
116  }
117
118  /**
119   * Test the case get id of identity.
120   */
121  @Test
122  public void testGetIdentityId() throws SocialClientLibException {
123    if (!canRunTest()) {
124      return;
125    }
126    String expectedId = getRootIdentity().getId();
127    String resultId = identityService.getIdentityId("organization", "root");
128    assertThat("identity id must be " + expectedId, resultId, equalTo(expectedId));
129
130    try {
131      resultId = identityService.getIdentityId(null, "root");
132      fail("Expecting NullPointerException from IdentityService#getIdentityId(String, String)");
133    } catch (NullPointerException npe) {
134    }
135
136    try {
137      resultId = identityService.getIdentityId(null, null);
138      fail("Expecting NullPointerException from IdentityService#getIdentityId(String, String)");
139    } catch (NullPointerException npe) {
140    }
141  }
142
143  @Test
144  public void testGetIdentityByProviderAndRemoteId() throws Exception {
145    if (!canRunTest()) {
146      return;
147    }
148    RestIdentity restIdentity = identityService.getIdentity("organization", "root");
149    assertThat("RestIdentity must not null.", restIdentity, notNullValue());
150    assertThat("RemoteId must be root", "root", equalTo(restIdentity.getRemoteId()));
151    assertThat("Provider must be organization", "organization", equalTo(restIdentity.getProviderId()));
152    RestProfile restProfile = restIdentity.getProfile();
153    assertThat("Avatar URL must not be null", restProfile.getAvatarUrl(), notNullValue());
154    assertThat("Profile's full name must be root gtn", "Root Root", equalTo(restProfile.getFullName()));
155  }
156}