LanguageController tests up
[portal.git] / portal-BE / src / test / java / org / onap / portal / service / fn / FnUserServiceTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ===================================================================
9  *
10  * Unless otherwise specified, all software contained herein is licensed
11  * under the Apache License, Version 2.0 (the "License");
12  * you may not use this software except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * Unless otherwise specified, all documentation contained herein is licensed
24  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25  * you may not use this documentation except in compliance with the License.
26  * You may obtain a copy of the License at
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
30  * Unless required by applicable law or agreed to in writing, documentation
31  * distributed under the License is distributed on an "AS IS" BASIS,
32  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  * See the License for the specific language governing permissions and
34  * limitations under the License.
35  *
36  * ============LICENSE_END============================================
37  *
38  *
39  */
40
41 package org.onap.portal.service.fn;
42
43 import static org.junit.jupiter.api.Assertions.*;
44
45 import java.time.LocalDateTime;
46 import org.junit.jupiter.api.Test;
47 import org.junit.runner.RunWith;
48 import org.onap.portal.domain.db.fn.FnLanguage;
49 import org.onap.portal.domain.db.fn.FnLuTimezone;
50 import org.onap.portal.domain.db.fn.FnUser;
51 import org.springframework.beans.factory.annotation.Autowired;
52 import org.springframework.boot.test.context.SpringBootTest;
53 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
54 import org.springframework.test.context.TestPropertySource;
55 import org.springframework.test.context.junit4.SpringRunner;
56 import org.springframework.transaction.annotation.Transactional;
57
58 @RunWith(SpringRunner.class)
59 @SpringBootTest
60 @TestPropertySource(locations="classpath:test.properties")
61 @Transactional
62 class FnUserServiceTest {
63        private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
64        @Autowired
65        private FnUserService fnUserService;
66        @Autowired
67        private FnLuTimezoneService fnLuTimezoneService;
68        @Autowired
69        private FnLanguageService fnLanguageService;
70
71        @Test
72        void saveUser(){
73               FnUser actual = fnUserService.getUser(1L).get();
74
75               FnUser expected = new FnUser();
76               expected.setUserId(123L);
77               expected.setFirstName("Demo");
78               expected.setLastName("User");
79               expected.setEmail("demo@openecomp.org");
80               expected.setOrgUserId("demo");
81               expected.setTimezone(fnLuTimezoneService.getById(10).orElse(new FnLuTimezone()));
82               expected.setLoginId("demo");
83               expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
84               expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
85               expected.setActiveYn("Y");
86               expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
87               expected.setModifiedId(actual);
88               expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
89               expected.setIsInternalYn("N");
90               expected.setStateCd("NJ");
91               expected.setCountryCd("US");
92               expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage()));
93
94               fnUserService.saveFnUser(principal, expected);
95
96               //Clean up
97               fnUserService.deleteUser(expected);
98        }
99
100        @Test
101        void getUser() {
102               FnUser actual = fnUserService.getUser(1L).get();
103
104
105               FnUser expected = new FnUser();
106               expected.setUserId(1L);
107               expected.setFirstName("Demo");
108               expected.setLastName("User");
109               expected.setEmail("demo@openecomp.org");
110               expected.setOrgUserId("demo");
111               expected.setLoginId("demo");
112               expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
113               expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
114               expected.setActiveYn("Y");
115               expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
116               expected.setModifiedId(actual);
117               expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
118               expected.setIsInternalYn("N");
119               expected.setStateCd("NJ");
120               expected.setCountryCd("US");
121               expected.setTimezone(fnLuTimezoneService.getById(10).orElse(new FnLuTimezone()));
122               expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage()));
123
124
125               assertEquals(expected.getUserId(), actual.getUserId());
126               assertEquals(expected.getOrgId(), actual.getOrgId());
127               assertEquals(expected.getManagerId(), actual.getManagerId());
128               assertEquals(expected.getFirstName(), actual.getFirstName());
129               assertEquals(expected.getMiddleName(), actual.getMiddleName());
130               assertEquals(expected.getLastName(), actual.getLastName());
131               assertEquals(expected.getPhone(), actual.getPhone());
132               assertEquals(expected.getFax(), actual.getFax());
133               assertEquals(expected.getCellular(), actual.getCellular());
134               assertEquals(expected.getEmail(), actual.getEmail());
135               assertEquals(expected.getAddressId(), actual.getAddressId());
136               assertEquals(expected.getAlertMethodCd(), actual.getAlertMethodCd());
137               assertEquals(expected.getHrid(), actual.getHrid());
138               assertEquals(expected.getOrgUserId(), actual.getOrgUserId());
139               assertEquals(expected.getOrg_code(), actual.getOrg_code());
140               assertEquals(expected.getLoginId(), actual.getLoginId());
141               assertEquals(expected.getLoginPwd(), actual.getLoginPwd());
142               assertEquals(expected.getLastLoginDate(), actual.getLastLoginDate());
143               assertEquals(expected.getActiveYn(), actual.getActiveYn());
144               assertEquals(expected.getCreatedId(), actual.getCreatedId());
145               assertEquals(expected.getCreatedDate(), actual.getCreatedDate());
146               assertEquals(expected.getModifiedId(), actual.getModifiedId());
147               assertEquals(expected.getModifiedDate(), actual.getModifiedDate());
148               assertEquals(expected.getIsInternalYn(), actual.getIsInternalYn());
149               assertEquals(expected.getAddressLine1(), actual.getAddressLine1());
150               assertEquals(expected.getAddressLine2(), actual.getAddressLine2());
151               assertEquals(expected.getCity(), actual.getCity());
152               assertEquals(expected.getStateCd(), actual.getStateCd());
153               assertEquals(expected.getZipCode(), actual.getZipCode());
154               assertEquals(expected.getCountryCd(), actual.getCountryCd());
155               assertEquals(expected.getLocationClli(), actual.getLocationClli());
156               assertEquals(expected.getOrgManagerUserId(), actual.getOrgManagerUserId());
157               assertEquals(expected.getCompany(), actual.getCompany());
158               assertEquals(expected.getDepartmentName(), actual.getDepartmentName());
159               assertEquals(expected.getJobTitle(), actual.getJobTitle());
160               assertEquals(expected.getTimezone().getTimezoneId(), actual.getTimezone().getTimezoneId());
161               assertEquals(expected.getDepartment(), actual.getDepartment());
162               assertEquals(expected.getBusinessUnit(), actual.getBusinessUnit());
163               assertEquals(expected.getBusinessUnitName(), actual.getBusinessUnitName());
164               assertEquals(expected.getCost_center(), actual.getCost_center());
165               assertEquals(expected.getFinLocCode(), actual.getFinLocCode());
166               assertEquals(expected.getSiloStatus(), actual.getSiloStatus());
167               assertEquals(expected.getLanguageId(), actual.getLanguageId());
168        }
169 }