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.fasterxml.jackson.annotation.JsonInclude.Include;
24 import com.fasterxml.jackson.databind.DeserializationFeature;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.databind.SerializationFeature;
27 import com.woorea.openstack.keystone.model.authentication.AccessKey.ApiAccessKeyCredentials;
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 ApiAccessKeyCredentialsTest {
36 private static final String EOL = System.lineSeparator();
38 private static final String JSON_FULL = "{" + EOL
39 + " \"accessKey\" : \"accesskey\"," + EOL
40 + " \"secretKey\" : \"secretkey\"" + EOL
43 private ObjectMapper objectMapper = new ObjectMapper()
44 .setSerializationInclusion(Include.NON_NULL)
45 .enable(SerializationFeature.INDENT_OUTPUT)
46 .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
47 .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
50 public void testSerialization() throws Exception {
51 System.out.println("CLASS: " + ApiAccessKeyCredentials.class.getName());
52 System.out.println("TEST JSON: " + JSON_FULL);
53 ApiAccessKeyCredentials apiaccesskeycredentials = objectMapper.readValue(JSON_FULL, ApiAccessKeyCredentials.class);
54 String json = objectMapper.writeValueAsString(apiaccesskeycredentials);
55 System.out.println("RE-SERIALIZED OBJECT: " + json);
56 JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT);
60 public void testMethods() throws Exception {
61 ApiAccessKeyCredentials apiaccesskeycredentials = objectMapper.readValue(JSON_FULL, ApiAccessKeyCredentials.class);
62 apiaccesskeycredentials.toString();
64 String secretKey = apiaccesskeycredentials.getSecretKey();
65 Assert.assertNotNull(secretKey);
66 apiaccesskeycredentials.setSecretKey(secretKey);
68 String accessKey = apiaccesskeycredentials.getAccessKey();
69 Assert.assertNotNull(accessKey);
70 apiaccesskeycredentials.setAccessKey(accessKey);