Skip to main content
summaryrefslogtreecommitdiffstats
blob: 928b80d17de4c3016d7d18adcb7cf19e283a03a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.account.rest.internal;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.osee.account.rest.model.AccountInfoData;
import org.eclipse.osee.account.rest.model.AccountInput;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

/**
 * Test Case for {@link AccountsResource}
 * 
 * @author Roberto E. Escobar
 */
public class AccountsResourceTest {

   private static final String ACCOUNT_ID = "hello@hello.com";

   //@formatter:off
   @Mock private AccountOps accountOps;
   @Mock private AccountInfoData account;
   @Mock private AccountInput input;
   //@formatter:on

   private AccountsResource resource;

   @Before
   public void setUp() {
      initMocks(this);

      resource = new AccountsResource(accountOps);
   }

   @Test
   public void testGetAccounts() {
      List<AccountInfoData> accesses = new ArrayList<AccountInfoData>();
      accesses.add(account);
      AccountInfoData[] expected = accesses.toArray(new AccountInfoData[] {});
      when(accountOps.getAllAccounts()).thenReturn(accesses);

      AccountInfoData[] actual = resource.getAccounts();

      assertArrayEquals(expected, actual);
      verify(accountOps).getAllAccounts();
   }

   @Test
   public void testGetAccount() {
      AccountResource actual = resource.getAccount(ACCOUNT_ID);
      assertNotNull(actual);

      // Ensure resource constructed correctly;
      actual.createAccount(input);
      verify(accountOps).createAccount(ACCOUNT_ID, input);
   }

   @Test
   public void testGetLoginResource() {
      AccountLoginResource actual = resource.getLoginResource();
      assertNotNull(actual);
   }

}

Back to the top