Hibernate db fix
[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.onap.portal.domain.builder.FnUserBuilder;
52 import org.springframework.beans.factory.annotation.Autowired;
53 import org.springframework.boot.test.context.SpringBootTest;
54 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
55 import org.springframework.test.context.TestPropertySource;
56 import org.springframework.test.context.junit4.SpringRunner;
57 import org.springframework.transaction.annotation.Transactional;
58
59 @RunWith(SpringRunner.class)
60 @SpringBootTest
61 @TestPropertySource(locations="classpath:test.properties")
62 @Transactional
63 class FnUserServiceTest {
64        private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
65        @Autowired
66        private FnUserService fnUserService;
67        @Autowired
68        private FnLuTimezoneService fnLuTimezoneService;
69        @Autowired
70        private FnLanguageService fnLanguageService;
71
72        @Test
73        void saveUser(){
74               FnUser actual = fnUserService.getUser(1L).get();
75
76               FnUser expected = new FnUserBuilder().createFnUser();
77               expected.setUserId(123L);
78               expected.setFirstName("Demo");
79               expected.setLastName("User");
80               expected.setEmail("demo@openecomp.org");
81               expected.setOrgUserId("demo");
82               expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone()));
83               expected.setLoginId("demo");
84               expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
85               expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
86               expected.setActiveYn("Y");
87               expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
88               expected.setModifiedId(actual);
89               expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
90               expected.setIsInternalYn("N");
91               expected.setStateCd("NJ");
92               expected.setCountryCd("US");
93               expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage()));
94
95               fnUserService.saveFnUser(principal, expected);
96
97               //Clean up
98               fnUserService.deleteUser(expected);
99        }
100
101        @Test
102        void getUser() {
103               FnUser actual = fnUserService.getUser(1L).get();
104
105
106               FnUser expected = new FnUserBuilder().createFnUser();
107               expected.setUserId(1L);
108               expected.setFirstName("Demo");
109               expected.setLastName("User");
110               expected.setEmail("demo@openecomp.org");
111               expected.setOrgUserId("demo");
112               expected.setLoginId("demo");
113               expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
114               expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
115               expected.setActiveYn("Y");
116               expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
117               expected.setModifiedId(actual);
118               expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
119               expected.setIsInternalYn("N");
120               expected.setStateCd("NJ");
121               expected.setCountryCd("US");
122               expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone()));
123               expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage()));
124
125
126               assertEquals(expected.getUserId(), actual.getUserId());
127               assertEquals(expected.getOrgId(), actual.getOrgId());
128               assertEquals(expected.getManagerId(), actual.getManagerId());
129               assertEquals(expected.getFirstName(), actual.getFirstName());
130               assertEquals(expected.getMiddleName(), actual.getMiddleName());
131               assertEquals(expected.getLastName(), actual.getLastName());
132               assertEquals(expected.getPhone(), actual.getPhone());
133               assertEquals(expected.getFax(), actual.getFax());
134               assertEquals(expected.getCellular(), actual.getCellular());
135               assertEquals(expected.getEmail(), actual.getEmail());
136               assertEquals(expected.getAddressId(), actual.getAddressId());
137               assertEquals(expected.getAlertMethodCd(), actual.getAlertMethodCd());
138               assertEquals(expected.getHrid(), actual.getHrid());
139               assertEquals(expected.getOrgUserId(), actual.getOrgUserId());
140               assertEquals(expected.getOrg_code(), actual.getOrg_code());
141               assertEquals(expected.getLoginId(), actual.getLoginId());
142               assertEquals(expected.getLoginPwd(), actual.getLoginPwd());
143               assertEquals(expected.getLastLoginDate(), actual.getLastLoginDate());
144               assertEquals(expected.getActiveYn(), actual.getActiveYn());
145               assertEquals(expected.getCreatedId(), actual.getCreatedId());
146               assertEquals(expected.getCreatedDate(), actual.getCreatedDate());
147               assertEquals(expected.getModifiedId(), actual.getModifiedId());
148               assertEquals(expected.getModifiedDate(), actual.getModifiedDate());
149               assertEquals(expected.getIsInternalYn(), actual.getIsInternalYn());
150               assertEquals(expected.getAddressLine1(), actual.getAddressLine1());
151               assertEquals(expected.getAddressLine2(), actual.getAddressLine2());
152               assertEquals(expected.getCity(), actual.getCity());
153               assertEquals(expected.getStateCd(), actual.getStateCd());
154               assertEquals(expected.getZipCode(), actual.getZipCode());
155               assertEquals(expected.getCountryCd(), actual.getCountryCd());
156               assertEquals(expected.getLocationClli(), actual.getLocationClli());
157               assertEquals(expected.getOrgManagerUserId(), actual.getOrgManagerUserId());
158               assertEquals(expected.getCompany(), actual.getCompany());
159               assertEquals(expected.getDepartmentName(), actual.getDepartmentName());
160               assertEquals(expected.getJobTitle(), actual.getJobTitle());
161               assertEquals(expected.getTimezone().getTimezoneId(), actual.getTimezone().getTimezoneId());
162               assertEquals(expected.getDepartment(), actual.getDepartment());
163               assertEquals(expected.getBusinessUnit(), actual.getBusinessUnit());
164               assertEquals(expected.getBusinessUnitName(), actual.getBusinessUnitName());
165               assertEquals(expected.getCost_center(), actual.getCost_center());
166               assertEquals(expected.getFinLocCode(), actual.getFinLocCode());
167               assertEquals(expected.getSiloStatus(), actual.getSiloStatus());
168               assertEquals(expected.getLanguageId(), actual.getLanguageId());
169        }
170 }