2a2cfed07a2136401adae7e2a87231e99fde1516
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalsdk.rnotebookintegration.service;
39
40 import java.util.Date;
41 import java.util.HashMap;
42 import java.util.Map;
43
44 import org.junit.Assert;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
47 import org.mockito.InjectMocks;
48 import org.mockito.Mock;
49 import org.mockito.Mockito;
50 import org.onap.portalsdk.core.restful.domain.EcompUser;
51 import org.onap.portalsdk.core.service.DataAccessService;
52 import org.onap.portalsdk.rnotebookintegration.domain.RNoteBookCredentials;
53 import org.onap.portalsdk.rnotebookintegration.exception.RNotebookIntegrationException;
54 import org.powermock.modules.junit4.PowerMockRunner;
55
56 @RunWith(PowerMockRunner.class)
57 public class RNoteBookIntegrationServiceImplTest {
58
59         @InjectMocks
60         private RNoteBookIntegrationServiceImpl rnoteBookIntgrServiceImpl;
61         
62         @Mock
63         private DataAccessService dataAccessService;
64         
65         @Test(expected = RNotebookIntegrationException.class)
66         public void getRNotebookCredentialsNullTokenTest() throws Exception {
67                 String token = "Token";
68                 RNoteBookCredentials rnoteBookCredentials = new RNoteBookCredentials();
69                 Mockito.when(dataAccessService.getDomainObject(RNoteBookCredentials.class, token, new HashMap<String, String>())).thenReturn(rnoteBookCredentials);
70                 rnoteBookIntgrServiceImpl.getRNotebookCredentials(token);
71         }
72         
73         @Test(expected = RNotebookIntegrationException.class)
74         public void getRNotebookCredentialsEmptyTokenTest() throws Exception {
75                 String token = "Token";
76                 RNoteBookCredentials rnoteBookCredentials = new RNoteBookCredentials();
77                 rnoteBookCredentials.setToken("");
78                 Mockito.when(dataAccessService.getDomainObject(RNoteBookCredentials.class, token, new HashMap<String, String>())).thenReturn(rnoteBookCredentials);
79                 rnoteBookIntgrServiceImpl.getRNotebookCredentials(token);
80         }
81         
82         @Test(expected = RNotebookIntegrationException.class)
83         public void getRNotebookCredentialsDateTest() throws Exception {
84                 String token = "Token";
85                 RNoteBookCredentials rnoteBookCredentials = new RNoteBookCredentials();
86                 rnoteBookCredentials.setToken("123");
87                 rnoteBookCredentials.setCreatedDate(new Date());
88                 rnoteBookCredentials.setTokenReadDate(new Date());
89                 Mockito.when(dataAccessService.getDomainObject(RNoteBookCredentials.class, token, new HashMap<String, String>())).thenReturn(rnoteBookCredentials);
90                 rnoteBookIntgrServiceImpl.getRNotebookCredentials(token);
91         }
92         
93         @Test
94         public void getRNotebookCredentialsTest() throws Exception {
95                 String token = "Token";
96                 RNoteBookCredentials rnoteBookCredentials = new RNoteBookCredentials();
97                 String json = " { \"managerId\": \"123\", \"firstName\": \"FNAME\" }";
98                 rnoteBookCredentials.setToken("123");
99                 rnoteBookCredentials.setCreatedDate(new Date());
100                 rnoteBookCredentials.setUserString(json);
101                 
102                 String mapJson = " { \"managerId\": \"123\", \"firstName\": \"FNAME\" }";
103                 rnoteBookCredentials.setParametersString(mapJson);
104                 Mockito.when(dataAccessService.getDomainObject(RNoteBookCredentials.class, token, new HashMap<String, String>())).thenReturn(rnoteBookCredentials);
105                 String response = rnoteBookIntgrServiceImpl.getRNotebookCredentials(token);
106                 Assert.assertNotNull(response);
107         }
108         
109         @Test
110         public void getRNotebookCredentialsJsonTest() throws Exception {
111                 String token = "Token";
112                 RNoteBookCredentials rnoteBookCredentials = new RNoteBookCredentials();
113                 String json = " { \"managerId\": \"123\", test }";
114                 rnoteBookCredentials.setToken("123");
115                 rnoteBookCredentials.setCreatedDate(new Date());
116                 rnoteBookCredentials.setUserString(json);
117                 
118                 rnoteBookCredentials.setParametersString(json);
119                 Mockito.when(dataAccessService.getDomainObject(RNoteBookCredentials.class, token, new HashMap<String, String>())).thenReturn(rnoteBookCredentials);
120                 String response = rnoteBookIntgrServiceImpl.getRNotebookCredentials(token);
121                 Assert.assertNotNull(response);
122         }
123         
124         @Test(expected = RNotebookIntegrationException.class)
125         public void getRNotebookCredentialsExpTest() throws Exception {
126                 String token = "Token";
127                 Mockito.when(dataAccessService.getDomainObject(RNoteBookCredentials.class, token, new HashMap<String, String>())).thenReturn(null);
128                 rnoteBookIntgrServiceImpl.getRNotebookCredentials(token);
129         }
130         
131         @Test
132         public void saveRNotebookCredentialsTest() throws Exception {
133                 String notebookId = "123";
134                 EcompUser user = new EcompUser();
135                 Map<String, String> params = new HashMap<>();
136                 params.put("Key","VALUE");
137                 String token = rnoteBookIntgrServiceImpl.saveRNotebookCredentials(notebookId, user, params);
138                 Assert.assertNotNull(token);
139         }
140         
141 }