blob: 5a041b52c67e980992f0a8b393f135937c6b9d47 (
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/*******************************************************************************
* 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.junit.Assert.assertNotNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import java.net.URI;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.eclipse.osee.account.rest.model.AccountDetailsData;
import org.eclipse.osee.account.rest.model.AccountInfoData;
import org.eclipse.osee.account.rest.model.AccountInput;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
/**
* Test Case for {@link AccountResource}
*
* @author Roberto E. Escobar
*/
public class AccountResourceTest {
private static final String NEW_USERNAME = "helloWorld";
private static final ArtifactId ACCOUNT_ID = TokenFactory.createArtifactId(93253L);
//@formatter:off
@Mock private AccountOps accountOps;
@Mock private AccountInput accountInput;
@Mock private AccountInfoData accountInfoData;
@Mock private AccountDetailsData details;
@Mock private UriInfo uriInfo;
//@formatter:on
private AccountResource resource;
@Before
public void setUp() {
initMocks(this);
resource = new AccountResource(accountOps, ACCOUNT_ID);
}
@Test
public void testDeleteAccount() {
when(accountOps.deleteAccount(ACCOUNT_ID)).thenReturn(true);
Response actual = resource.deleteAccount();
assertEquals(Status.OK.getStatusCode(), actual.getStatus());
verify(accountOps).deleteAccount(ACCOUNT_ID);
}
@Test
public void testDeleteAccountNotModified() {
when(accountOps.deleteAccount(ACCOUNT_ID)).thenReturn(false);
Response actual = resource.deleteAccount();
assertEquals(Status.NOT_MODIFIED.getStatusCode(), actual.getStatus());
verify(accountOps).deleteAccount(ACCOUNT_ID);
}
@Test
public void testGetAccountDetailsData() {
when(accountOps.getAccountDetailsData(ACCOUNT_ID)).thenReturn(details);
AccountDetailsData actual = resource.getAccountDetailsData();
assertEquals(details, actual);
verify(accountOps).getAccountDetailsData(ACCOUNT_ID);
}
@Test
public void testAccountSettingsData() {
AccountPreferencesResource actual = resource.getAccountSettingsData();
assertNotNull(actual);
// Ensure resource constructed correctly;
actual.getAccountPreferences();
verify(accountOps).getAccountPreferencesDataById(ACCOUNT_ID);
}
@Test
public void testActive() {
AccountActiveResource actual = resource.active();
assertNotNull(actual);
// Ensure resource constructed correctly;
actual.isActive();
verify(accountOps).isActive(ACCOUNT_ID);
}
@Test
public void testGetSessions() {
AccountSessionsResource actual = resource.sessions();
assertNotNull(actual);
// Ensure resource constructed correctly;
actual.getAccountSessions();
verify(accountOps).getAccountSessionById(ACCOUNT_ID);
}
@Test
public void testGetSubscriptions() {
URI uri = UriBuilder.fromPath("http://localhost:8089/oseex/accounts/{account-id}/subscriptions").build(
ACCOUNT_ID.getUuid());
when(uriInfo.getRequestUri()).thenReturn(uri);
Response response = resource.getSubscriptions(uriInfo);
int status = response.getStatus();
assertEquals(Status.SEE_OTHER.getStatusCode(), status);
URI location = (URI) response.getMetadata().getFirst(HttpHeaders.LOCATION);
URI expectedLocation =
UriBuilder.fromUri(uri).path("..").path("..").path("..").path("subscriptions").path("for-account").path(
"{account-id}").build(ACCOUNT_ID.getUuid());
assertEquals(expectedLocation, location);
}
}
|