3 * * ============LICENSE_START=======================================================
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
12 * * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.dcaegen2.platform.mod.objectmothers;
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;
34 import java.util.ArrayList;
35 import java.util.HashSet;
36 import java.util.List;
42 * Mock for AuthenticationController Test Case
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";
49 public static String asJsonString(final Object object) {
51 return new ObjectMapper().writeValueAsString(object);
52 } catch (Exception e) {
53 throw new RuntimeException(e);
57 public static LoginRequest getLoginRequest() {
58 return TestUtil.deserializeJsonFileToModel(LOGIN_REQUEST, LoginRequest.class);
61 public static SignupRequest getSignupRequest() {
62 return TestUtil.deserializeJsonFileToModel(SIGNUP_REQUEST, SignupRequest.class);
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);
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();