Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3e1a7431fcda6e0be6657c5cd70e361a1117343e (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
 * 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.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.eclipse.osee.account.rest.model.AccountPreferencesData;
import org.eclipse.osee.account.rest.model.AccountPreferencesInput;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

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

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

   //@formatter:off
   @Mock private AccountOps accountOps;
   @Mock private AccountPreferencesData preferences;
   @Mock private AccountPreferencesInput input;
   //@formatter:on

   private AccountPreferencesResource resource;

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

      resource = new AccountPreferencesResource(accountOps, ACCOUNT_ID);
   }

   @Test
   public void testGetAccountPreferences() {
      when(accountOps.getAccountPreferencesData(ACCOUNT_ID)).thenReturn(preferences);

      AccountPreferencesData actual = resource.getAccountPreferences();

      assertEquals(preferences, actual);
      verify(accountOps).getAccountPreferencesData(ACCOUNT_ID);
   }

   @Test
   public void testSetAccountPreferences() {
      Map<String, String> map = new HashMap<String, String>();
      map.put("a", "1");
      map.put("b", "2");
      map.put("c", "3");

      when(input.getMap()).thenReturn(map);
      when(accountOps.setAccountPreferences(ACCOUNT_ID, input)).thenReturn(true);

      Response actual = resource.setAccountPreferences(input);

      assertEquals(Status.OK.getStatusCode(), actual.getStatus());
      verify(accountOps).setAccountPreferences(ACCOUNT_ID, input);
   }

   @Test
   public void testSetAccountPreferencesNotModified() {
      Map<String, String> map = new HashMap<String, String>();
      map.put("a", "1");
      map.put("b", "2");
      map.put("c", "3");

      when(input.getMap()).thenReturn(map);
      when(accountOps.setAccountPreferences(ACCOUNT_ID, input)).thenReturn(false);

      Response actual = resource.setAccountPreferences(input);

      assertEquals(Status.NOT_MODIFIED.getStatusCode(), actual.getStatus());
      verify(accountOps).setAccountPreferences(ACCOUNT_ID, input);
   }

}

Back to the top