ae63a61814ca76e567166b336181886c754d76cb
[so/libs.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package com.woorea.openstack.keystone.model.authentication;
22
23 import com.woorea.openstack.keystone.model.authentication.AccessKey.ApiAccessKeyCredentials;
24 import org.codehaus.jackson.map.DeserializationConfig;
25 import org.codehaus.jackson.map.ObjectMapper;
26 import org.codehaus.jackson.map.SerializationConfig;
27 import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.skyscreamer.jsonassert.JSONAssert;
31 import org.skyscreamer.jsonassert.JSONCompareMode;
32
33 public class ApiAccessKeyCredentialsTest {
34
35     private static final String EOL = System.lineSeparator();
36
37     private static final String JSON_FULL = "{" + EOL
38         + "  \"accessKey\" : \"accesskey\"," + EOL
39         + "  \"secretKey\" : \"secretkey\"" + EOL
40         + "}";
41
42     private ObjectMapper objectMapper = new ObjectMapper()
43         .setSerializationInclusion(Inclusion.NON_NULL)
44         .enable(SerializationConfig.Feature.INDENT_OUTPUT)
45         .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
46
47     @Test
48     public void testSerialization() throws Exception {
49         System.out.println("CLASS: " + ApiAccessKeyCredentials.class.getName());
50         System.out.println("TEST JSON: " + JSON_FULL);
51         ApiAccessKeyCredentials apiaccesskeycredentials = objectMapper.readValue(JSON_FULL, ApiAccessKeyCredentials.class);
52         String json = objectMapper.writeValueAsString(apiaccesskeycredentials);
53         System.out.println("RE-SERIALIZED OBJECT: " + json);
54         JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT);
55     }
56
57     @Test
58     public void testMethods() throws Exception {
59         ApiAccessKeyCredentials apiaccesskeycredentials = objectMapper.readValue(JSON_FULL, ApiAccessKeyCredentials.class);
60         apiaccesskeycredentials.toString();
61         
62         String secretKey = apiaccesskeycredentials.getSecretKey();
63         Assert.assertNotNull(secretKey);
64         apiaccesskeycredentials.setSecretKey(secretKey);
65         
66         String accessKey = apiaccesskeycredentials.getAccessKey();
67         Assert.assertNotNull(accessKey);
68         apiaccesskeycredentials.setAccessKey(accessKey);
69     }
70 }