[DCAE] INFO.yaml update
[dcaegen2/platform.git] / mod2 / auth-service / src / test / java / org / onap / dcaegen2 / platform / mod / objectmothers / AuthObjectMother.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7  *  *  ================================================================================
8  *  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  *  you may not use this file except in compliance with the License.
10  *  *  You may obtain a copy of the License at
11  *  *
12  *  *       http://www.apache.org/licenses/LICENSE-2.0
13  *  *
14  *  *  Unless required by applicable law or agreed to in writing, software
15  *  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  *  See the License for the specific language governing permissions and
18  *  *  limitations under the License.
19  *  *  ============LICENSE_END=========================================================
20  *
21  */
22
23 package org.onap.dcaegen2.platform.mod.objectmothers;
24
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import org.onap.dcaegen2.platform.mod.models.LoginRequest;
27 import org.onap.dcaegen2.platform.mod.models.ModUser;
28 import org.onap.dcaegen2.platform.mod.models.Role;
29 import org.onap.dcaegen2.platform.mod.models.SignupRequest;
30 import org.onap.dcaegen2.platform.mod.security.services.UserDetailsImpl;
31 import org.onap.dcaegen2.platform.mod.util.TestUtil;
32 import org.springframework.security.core.authority.SimpleGrantedAuthority;
33
34 import java.util.ArrayList;
35 import java.util.HashSet;
36 import java.util.List;
37 import java.util.Set;
38
39 /**
40  * @author
41  * @date 09/22/2020
42  * Mock for AuthenticationController Test Case
43  */
44
45 public class AuthObjectMother {
46     public static final String LOGIN_REQUEST = "src/test/resources/http/requests/AuthLoginRequest.json";
47     public static final String SIGNUP_REQUEST = "src/test/resources/http/requests/AuthSignupRequest.json";
48
49     public static String asJsonString(final Object object) {
50         try {
51             return new ObjectMapper().writeValueAsString(object);
52         } catch (Exception e) {
53             throw new RuntimeException(e);
54         }
55     }
56
57     public static LoginRequest getLoginRequest() {
58         return TestUtil.deserializeJsonFileToModel(LOGIN_REQUEST, LoginRequest.class);
59     }
60
61     public static SignupRequest getSignupRequest() {
62         return TestUtil.deserializeJsonFileToModel(SIGNUP_REQUEST, SignupRequest.class);
63     }
64
65     public static UserDetailsImpl getUserDetailsImpl() {
66         SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROLE_ADMIN");
67         List authorities = new ArrayList();
68         authorities.add(simpleGrantedAuthority);
69         return new UserDetailsImpl("admin123", "admin123", "admin123", "admin123", authorities);
70     }
71
72     public static ModUser getModUser() {
73         ModUser user = new ModUser();
74         user.setUsername("test");
75         user.setFullName("test");
76         user.setPassword("password");
77         Set<Role> roles = new HashSet<>();
78         Role role = new Role();
79         role.setName("test");
80         role.setId("123");
81         roles.add(role);
82         user.setRoles(roles);
83         return user;
84     }
85 }