2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package com.woorea.openstack.keystone.model.authentication;
23 import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
24 import com.woorea.openstack.keystone.model.authentication.UsernamePassword.PasswordCredentials;
25 import org.codehaus.jackson.map.DeserializationConfig;
26 import org.codehaus.jackson.map.ObjectMapper;
27 import org.codehaus.jackson.map.SerializationConfig;
28 import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.skyscreamer.jsonassert.JSONAssert;
32 import org.skyscreamer.jsonassert.JSONCompareMode;
34 public class UsernamePasswordTest {
36 private static final String EOL = System.lineSeparator();
38 private static final String JSON_FULL = "{" + EOL
39 + " \"auth\" : {" + EOL
40 + " \"tenantId\" : \"tenantid\"," + EOL
41 + " \"tenantName\" : \"tenantname\"," + EOL
42 + " \"passwordCredentials\" : {" + EOL
43 + " \"username\" : \"username\"," + EOL
44 + " \"password\" : \"password\"" + EOL
49 private ObjectMapper objectMapper = new ObjectMapper()
50 .setSerializationInclusion(Inclusion.NON_NULL)
51 .enable(SerializationConfig.Feature.INDENT_OUTPUT)
52 .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE)
53 .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE)
54 .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
57 public void testSerialization() throws Exception {
58 System.out.println("CLASS: " + UsernamePassword.class.getName());
59 System.out.println("TEST JSON: " + JSON_FULL);
60 UsernamePassword usernamepassword = objectMapper.readValue(JSON_FULL, UsernamePassword.class);
61 String json = objectMapper.writeValueAsString(usernamepassword);
62 System.out.println("RE-SERIALIZED OBJECT: " + json);
63 JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT);
67 public void testMethods() throws Exception {
68 UsernamePassword usernamepassword = objectMapper.readValue(JSON_FULL, UsernamePassword.class);
69 usernamepassword.toString();
71 PasswordCredentials passwordCredentials = usernamepassword.getPasswordCredentials();
72 Assert.assertNotNull(passwordCredentials);
73 usernamepassword.setPasswordCredentials(passwordCredentials);
75 String tenantId = usernamepassword.getTenantId();
76 Assert.assertNotNull(tenantId);
77 usernamepassword.setTenantId(tenantId);
79 String tenantName = usernamepassword.getTenantName();
80 Assert.assertNotNull(tenantName);
81 usernamepassword.setTenantName(tenantName);