blob: 924b796dfe1c7b6ed8a1b8efd9d43016059748cc (
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
|
/*******************************************************************************
* 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.disposition.rest.resources;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.List;
import javax.ws.rs.core.Response;
import org.eclipse.osee.disposition.model.DispoProgram;
import org.eclipse.osee.disposition.rest.DispoApi;
import org.eclipse.osee.disposition.rest.util.DispoFactory;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* @author Angel Avila
*/
public class DispoProgramResourceTest {
@Mock
private DispoApi dispoApi;
@Mock
private DispoProgram id1;
@Mock
private DispoProgram id2;
@Mock
private DispoFactory dispoFactory;
private DispoProgramResource resource;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
resource = new DispoProgramResource(dispoApi, dispoFactory);
when(id1.getUuid()).thenReturn(23L);
when(id2.getUuid()).thenReturn(25L);
}
@Test
public void testGetAll() throws JSONException {
// No Sets
List<IOseeBranch> emptyResultSet = Collections.emptyList();
when(dispoApi.getDispoPrograms()).thenReturn(emptyResultSet);
Response noProgramsResponse = resource.getAllPrograms();
String messageActual = (String) noProgramsResponse.getEntity();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), noProgramsResponse.getStatus());
assertEquals("[]", messageActual);
IOseeBranch branch = TokenFactory.createBranch(id1.getUuid());
List<IOseeBranch> branchList = Collections.singletonList(branch);
when(dispoApi.getDispoPrograms()).thenReturn(branchList);
Response oneSetResponse = resource.getAllPrograms();
JSONArray entity = new JSONArray((String) oneSetResponse.getEntity());
JSONObject programFromEntity = entity.getJSONObject(0);
assertEquals(Response.Status.OK.getStatusCode(), oneSetResponse.getStatus());
assertEquals(String.valueOf(id1.getUuid()), programFromEntity.getString("value"));
}
}
|