From 9e0219abc61b28b94d88fefbf8cc4a13d1683a67 Mon Sep 17 00:00:00 2001 From: Rob Daugherty Date: Mon, 10 Sep 2018 17:45:52 -0400 Subject: Functional so/libs unit tests Unit tests to prepare for migration from the codehaus to the fasterxml implementation of jackson. Iincreases the code coverage metric from 51% to 70%. Change-Id: I6338214f3de9df95956b46d4e313d00052eb8692 Issue-ID: SO-1011 Signed-off-by: Rob Daugherty --- .../openstack/keystone/model/AccessTest.java | 154 ++++++++++++++++++--- .../openstack/keystone/model/EndpointTest.java | 126 +++++++++-------- .../openstack/keystone/model/EndpointsTest.java | 71 ++++++++-- .../woorea/openstack/keystone/model/ErrorTest.java | 61 ++++++-- .../woorea/openstack/keystone/model/LinkTest.java | 57 ++++++-- .../woorea/openstack/keystone/model/RoleTest.java | 86 +++++++----- .../woorea/openstack/keystone/model/RolesTest.java | 67 +++++++-- .../openstack/keystone/model/ServiceTest.java | 86 +++++++----- .../openstack/keystone/model/ServicesTest.java | 67 +++++++-- .../openstack/keystone/model/TenantTest.java | 91 +++++++----- .../openstack/keystone/model/TenantsTest.java | 84 +++++++++-- .../woorea/openstack/keystone/model/TokenTest.java | 71 +++++++--- .../woorea/openstack/keystone/model/UserTest.java | 142 +++++++++---------- .../woorea/openstack/keystone/model/UsersTest.java | 73 ++++++++-- .../model/authentication/AccessKeyTest.java | 83 +++++++++++ .../ApiAccessKeyCredentialsTest.java | 70 ++++++++++ .../authentication/PasswordCredentialsTest.java | 70 ++++++++++ .../keystone/model/authentication/TokenTest.java | 65 +++++++++ .../model/authentication/UsernamePasswordTest.java | 83 +++++++++++ 19 files changed, 1250 insertions(+), 357 deletions(-) create mode 100644 keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/AccessKeyTest.java create mode 100644 keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/ApiAccessKeyCredentialsTest.java create mode 100644 keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/PasswordCredentialsTest.java create mode 100644 keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/TokenTest.java create mode 100644 keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/UsernamePasswordTest.java (limited to 'keystone-model/src/test/java/com/woorea/openstack/keystone/model') diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/AccessTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/AccessTest.java index cd4e80f..c6c3ec5 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/AccessTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/AccessTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,30 +20,147 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Access; +import com.woorea.openstack.keystone.model.Access.Service; +import com.woorea.openstack.keystone.model.Access.User; +import com.woorea.openstack.keystone.model.Token; +import java.util.List; +import java.util.Map; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class AccessTest { - Access access = new Access(); + private static final String EOL = System.lineSeparator(); - @Test - public void getTokenTest() throws Exception { - access.getToken(); - } + private static final String JSON_FULL = "{" + EOL + + " \"access\" : {" + EOL + + " \"token\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"issued_at\" : 1488024000000," + EOL + + " \"expires\" : 1488628800000," + EOL + + " \"tenant\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : false" + EOL + + " }" + EOL + + " }," + EOL + + " \"serviceCatalog\" : [ {" + EOL + + " \"type\" : \"type\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"endpoints\" : [ {" + EOL + + " \"region\" : \"region\"," + EOL + + " \"publicURL\" : \"publicurl\"," + EOL + + " \"internalURL\" : \"internalurl\"," + EOL + + " \"adminURL\" : \"adminurl\"" + EOL + + " }, {" + EOL + + " \"region\" : \"region\"," + EOL + + " \"publicURL\" : \"publicurl\"," + EOL + + " \"internalURL\" : \"internalurl\"," + EOL + + " \"adminURL\" : \"adminurl\"" + EOL + + " } ]," + EOL + + " \"endpoints_links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " }, {" + EOL + + " \"type\" : \"type\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"endpoints\" : [ {" + EOL + + " \"region\" : \"region\"," + EOL + + " \"publicURL\" : \"publicurl\"," + EOL + + " \"internalURL\" : \"internalurl\"," + EOL + + " \"adminURL\" : \"adminurl\"" + EOL + + " }, {" + EOL + + " \"region\" : \"region\"," + EOL + + " \"publicURL\" : \"publicurl\"," + EOL + + " \"internalURL\" : \"internalurl\"," + EOL + + " \"adminURL\" : \"adminurl\"" + EOL + + " } ]," + EOL + + " \"endpoints_links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " } ]," + EOL + + " \"user\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"username\" : \"username\"," + EOL + + " \"roles\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " } ]," + EOL + + " \"roles_links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + " }," + EOL + + " \"metadata\" : {" + EOL + + " \"metadata-k1\" : \"metadata-v1\"," + EOL + + " \"metadata-k2\" : \"metadata-v2\"" + EOL + + " }" + EOL + + " }" + EOL + + "}"; - @Test - public void getServiceCatalogTest() throws Exception { - access.getServiceCatalog(); - } + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getUserTest() throws Exception { - access.getUser(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Access.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Access access = objectMapper.readValue(JSON_FULL, Access.class); + String json = objectMapper.writeValueAsString(access); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getMetadataTest() throws Exception { - access.getMetadata(); + public void testMethods() throws Exception { + Access access = objectMapper.readValue(JSON_FULL, Access.class); + access.toString(); + + List serviceCatalog = access.getServiceCatalog(); + Assert.assertNotNull(serviceCatalog); + Assert.assertEquals(2, serviceCatalog.size()); + + Map metadata = access.getMetadata(); + Assert.assertNotNull(metadata); + Assert.assertEquals(2, metadata.size()); + + User user = access.getUser(); + Assert.assertNotNull(user); + + Token token = access.getToken(); + Assert.assertNotNull(token); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/EndpointTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/EndpointTest.java index b832da3..a379617 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/EndpointTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/EndpointTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,70 +20,75 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Endpoint; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class EndpointTest { - Endpoint endpoint = new Endpoint(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"endpoint\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"service_id\" : \"serviceid\"," + EOL + + " \"publicurl\" : \"publicurl\"," + EOL + + " \"internalurl\" : \"internalurl\"," + EOL + + " \"adminurl\" : \"adminurl\"" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getId() throws Exception { - endpoint.getId(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Endpoint.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Endpoint endpoint = objectMapper.readValue(JSON_FULL, Endpoint.class); + String json = objectMapper.writeValueAsString(endpoint); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setId() throws Exception { - endpoint.setId("test"); + public void testMethods() throws Exception { + Endpoint endpoint = objectMapper.readValue(JSON_FULL, Endpoint.class); + endpoint.toString(); + + String publicURL = endpoint.getPublicURL(); + Assert.assertNotNull(publicURL); + endpoint.setPublicURL(publicURL); + + String internalURL = endpoint.getInternalURL(); + Assert.assertNotNull(internalURL); + endpoint.setInternalURL(internalURL); + + String id = endpoint.getId(); + Assert.assertNotNull(id); + endpoint.setId(id); + + String region = endpoint.getRegion(); + Assert.assertNotNull(region); + endpoint.setRegion(region); + + String serviceId = endpoint.getServiceId(); + Assert.assertNotNull(serviceId); + endpoint.setServiceId(serviceId); + + String adminURL = endpoint.getAdminURL(); + Assert.assertNotNull(adminURL); + endpoint.setAdminURL(adminURL); } - - @Test - public void getServiceId() throws Exception { - endpoint.getServiceId(); - } - - @Test - public void setServiceId() throws Exception { - endpoint.setServiceId("test"); - } - - @Test - public void getRegion() throws Exception { - endpoint.getRegion(); - } - - @Test - public void setRegion() throws Exception { - endpoint.setRegion("region"); - } - - @Test - public void getPublicURL() throws Exception { - endpoint.getPublicURL(); - } - - @Test - public void setPublicURL() throws Exception { - endpoint.setPublicURL("url"); - } - - @Test - public void getInternalURL() throws Exception { - endpoint.getInternalURL(); - } - - @Test - public void setInternalURL() throws Exception { - endpoint.setInternalURL("test"); - } - - @Test - public void getAdminURL() throws Exception { - endpoint.getAdminURL(); - } - - @Test - public void setAdminURL() throws Exception { - endpoint.setAdminURL("admin url"); - } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/EndpointsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/EndpointsTest.java index 8bc2870..a566f0f 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/EndpointsTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/EndpointsTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,20 +20,68 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Endpoint; +import com.woorea.openstack.keystone.model.Endpoints; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class EndpointsTest { - Endpoints endpoints = new Endpoints(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"endpoints\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"service_id\" : \"serviceid\"," + EOL + + " \"publicurl\" : \"publicurl\"," + EOL + + " \"internalurl\" : \"internalurl\"," + EOL + + " \"adminurl\" : \"adminurl\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"service_id\" : \"serviceid\"," + EOL + + " \"publicurl\" : \"publicurl\"," + EOL + + " \"internalurl\" : \"internalurl\"," + EOL + + " \"adminurl\" : \"adminurl\"" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getList() throws Exception { - endpoints.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Endpoints.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Endpoints endpoints = objectMapper.readValue(JSON_FULL, Endpoints.class); + String json = objectMapper.writeValueAsString(endpoints); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - endpoints.iterator(); + @Test + public void testMethods() throws Exception { + Endpoints endpoints = objectMapper.readValue(JSON_FULL, Endpoints.class); + endpoints.toString(); + + List list = endpoints.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Endpoint x : endpoints) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ErrorTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ErrorTest.java index 33c0726..357f9c6 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ErrorTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ErrorTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,25 +20,57 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Error; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class ErrorTest { - Error error = new Error(); + private static final String EOL = System.lineSeparator(); - @Test - public void getCode() throws Exception { - error.getCode(); - } + private static final String JSON_FULL = "{" + EOL + + " \"error\" : {" + EOL + + " \"code\" : 29," + EOL + + " \"title\" : \"title\"," + EOL + + " \"message\" : \"message\"" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getTitle() throws Exception { - error.getTitle(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Error.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Error error = objectMapper.readValue(JSON_FULL, Error.class); + String json = objectMapper.writeValueAsString(error); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getMessage() throws Exception { - error.getMessage(); + public void testMethods() throws Exception { + Error error = objectMapper.readValue(JSON_FULL, Error.class); + error.toString(); + + Integer code = error.getCode(); + Assert.assertNotNull(code); + + String title = error.getTitle(); + Assert.assertNotNull(title); + + String message = error.getMessage(); + Assert.assertNotNull(message); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/LinkTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/LinkTest.java index 521ad09..a7a20b9 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/LinkTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/LinkTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,25 +20,53 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Link; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class LinkTest { - Link link = new Link(); + private static final String EOL = System.lineSeparator(); - @Test - public void getRel() throws Exception { - link.getRel(); - } + private static final String JSON_FULL = "{" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getHref() throws Exception { - link.getHref(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Link.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Link link = objectMapper.readValue(JSON_FULL, Link.class); + String json = objectMapper.writeValueAsString(link); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getType() throws Exception { - link.getType(); + public void testMethods() throws Exception { + Link link = objectMapper.readValue(JSON_FULL, Link.class); + link.toString(); + + String rel = link.getRel(); + Assert.assertNotNull(rel); + + String href = link.getHref(); + Assert.assertNotNull(href); + + String type = link.getType(); + Assert.assertNotNull(type); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/RoleTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/RoleTest.java index 0f7f7f3..b93532c 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/RoleTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/RoleTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,45 +20,64 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Role; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class RoleTest { - Role role = new Role(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() throws Exception { - role.getId(); - } - - @Test - public void getName() throws Exception { - role.getName(); - } - - @Test - public void setName() throws Exception { - role.setName("name"); - } + private static final String JSON_FULL = "{" + EOL + + " \"role\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : \"enabled\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getDescription() throws Exception { - role.getDescription(); - } + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void setDescription() throws Exception { - role.setDescription("desc"); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Role.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Role role = objectMapper.readValue(JSON_FULL, Role.class); + String json = objectMapper.writeValueAsString(role); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getEnabled() throws Exception { - role.getEnabled(); + public void testMethods() throws Exception { + Role role = objectMapper.readValue(JSON_FULL, Role.class); + role.toString(); + + String name = role.getName(); + Assert.assertNotNull(name); + role.setName(name); + + String description = role.getDescription(); + Assert.assertNotNull(description); + role.setDescription(description); + + String id = role.getId(); + Assert.assertNotNull(id); + + String enabled = role.getEnabled(); + Assert.assertNotNull(enabled); + role.setEnabled(enabled); } - - @Test - public void setEnabled() throws Exception { - role.setEnabled("test"); - } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/RolesTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/RolesTest.java index 7656dd6..98a7c79 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/RolesTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/RolesTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,20 +20,64 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Role; +import com.woorea.openstack.keystone.model.Roles; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class RolesTest { - Roles roles = new Roles(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"roles\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : \"enabled\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : \"enabled\"" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getList() throws Exception { - roles.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Roles.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Roles roles = objectMapper.readValue(JSON_FULL, Roles.class); + String json = objectMapper.writeValueAsString(roles); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - roles.iterator(); + @Test + public void testMethods() throws Exception { + Roles roles = objectMapper.readValue(JSON_FULL, Roles.class); + roles.toString(); + + List list = roles.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Role x : roles) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ServiceTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ServiceTest.java index 03c4f98..e6c8a28 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ServiceTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ServiceTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,45 +20,64 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Service; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class ServiceTest { - Service service = new Service(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() throws Exception { - service.getId(); - } - - @Test - public void getType() throws Exception { - service.getType(); - } - - @Test - public void setType() throws Exception { - service.setType("type"); - } + private static final String JSON_FULL = "{" + EOL + + " \"OS-KSADM:service\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"" + EOL + + " }" + EOL + + "}"; - @Test - public void getName() throws Exception { - service.getName(); - } + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void setName() throws Exception { - service.setName("name"); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Service.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Service service = objectMapper.readValue(JSON_FULL, Service.class); + String json = objectMapper.writeValueAsString(service); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getDescription() throws Exception { - service.getDescription(); + public void testMethods() throws Exception { + Service service = objectMapper.readValue(JSON_FULL, Service.class); + service.toString(); + + String name = service.getName(); + Assert.assertNotNull(name); + service.setName(name); + + String description = service.getDescription(); + Assert.assertNotNull(description); + service.setDescription(description); + + String id = service.getId(); + Assert.assertNotNull(id); + + String type = service.getType(); + Assert.assertNotNull(type); + service.setType(type); } - - @Test - public void setDescription() throws Exception { - service.setDescription("desc"); - } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ServicesTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ServicesTest.java index c095e66..28b7517 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ServicesTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/ServicesTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,20 +20,64 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Service; +import com.woorea.openstack.keystone.model.Services; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class ServicesTest { - Services services = new Services(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"OS-KSADM:services\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getList() throws Exception { - services.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Services.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Services services = objectMapper.readValue(JSON_FULL, Services.class); + String json = objectMapper.writeValueAsString(services); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - services.iterator(); + @Test + public void testMethods() throws Exception { + Services services = objectMapper.readValue(JSON_FULL, Services.class); + services.toString(); + + List list = services.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Service x : services) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TenantTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TenantTest.java index 9c5b02e..6ce4a11 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TenantTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TenantTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,49 +20,65 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Tenant; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class TenantTest { - Tenant tenant = new Tenant(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() throws Exception { - tenant.getId(); - } - - @Test - public void setId() throws Exception { - tenant.setId("tenantid"); - } - - @Test - public void getName() throws Exception { - tenant.getName(); - } + private static final String JSON_FULL = "{" + EOL + + " \"tenant\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : false" + EOL + + " }" + EOL + + "}"; - @Test - public void setName() throws Exception { - tenant.setName("test"); - } - - @Test - public void getDescription() throws Exception { - tenant.getDescription(); - } - - @Test - public void setDescription() throws Exception { - tenant.setDescription("desc"); - } + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getEnabled() throws Exception { - tenant.getEnabled(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Tenant.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Tenant tenant = objectMapper.readValue(JSON_FULL, Tenant.class); + String json = objectMapper.writeValueAsString(tenant); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setEnabled() throws Exception { - tenant.setEnabled(true); + public void testMethods() throws Exception { + Tenant tenant = objectMapper.readValue(JSON_FULL, Tenant.class); + tenant.toString(); + + String name = tenant.getName(); + Assert.assertNotNull(name); + tenant.setName(name); + + String description = tenant.getDescription(); + Assert.assertNotNull(description); + tenant.setDescription(description); + + String id = tenant.getId(); + Assert.assertNotNull(id); + tenant.setId(id); + + Boolean enabled = tenant.getEnabled(); + Assert.assertNotNull(enabled); + tenant.setEnabled(enabled); } -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TenantsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TenantsTest.java index eb4c2ee..f3d10e3 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TenantsTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TenantsTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,25 +20,78 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Link; +import com.woorea.openstack.keystone.model.Tenant; +import com.woorea.openstack.keystone.model.Tenants; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class TenantsTest { - Tenants tenants= new Tenants(); + private static final String EOL = System.lineSeparator(); - @Test - public void getList() throws Exception { - tenants.getList(); - } + private static final String JSON_FULL = "{" + EOL + + " \"tenants\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : false" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : false" + EOL + + " } ]," + EOL + + " \"tenants_links\" : [ {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " }, {" + EOL + + " \"rel\" : \"rel\"," + EOL + + " \"href\" : \"href\"," + EOL + + " \"type\" : \"type\"" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getLinks() throws Exception { - tenants.getLinks(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Tenants.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Tenants tenants = objectMapper.readValue(JSON_FULL, Tenants.class); + String json = objectMapper.writeValueAsString(tenants); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - tenants.iterator(); + @Test + public void testMethods() throws Exception { + Tenants tenants = objectMapper.readValue(JSON_FULL, Tenants.class); + tenants.toString(); + + List links = tenants.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(2, links.size()); + + List list = tenants.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Tenant x : tenants) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TokenTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TokenTest.java index a9c0d7c..65308b9 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TokenTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/TokenTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,30 +20,64 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.Tenant; +import com.woorea.openstack.keystone.model.Token; +import java.util.Calendar; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class TokenTest { - Token token = new Token(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() throws Exception { - token.getId(); - } + private static final String JSON_FULL = "{" + EOL + + " \"id\" : \"id\"," + EOL + + " \"issued_at\" : 1488024000000," + EOL + + " \"expires\" : 1488628800000," + EOL + + " \"tenant\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : false" + EOL + + " }" + EOL + + "}"; - @Test - public void getIssued_at() throws Exception { - token.getIssued_at(); - } + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getExpires() throws Exception { - token.getExpires(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Token.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Token token = objectMapper.readValue(JSON_FULL, Token.class); + String json = objectMapper.writeValueAsString(token); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void getTenant() throws Exception { - token.getTenant(); + public void testMethods() throws Exception { + Token token = objectMapper.readValue(JSON_FULL, Token.class); + token.toString(); + + Calendar expires = token.getExpires(); + Assert.assertNotNull(expires); + + String id = token.getId(); + Assert.assertNotNull(id); + + Calendar issued_at = token.getIssued_at(); + Assert.assertNotNull(issued_at); + + Tenant tenant = token.getTenant(); + Assert.assertNotNull(tenant); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/UserTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/UserTest.java index 7898a76..5669dab 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/UserTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/UserTest.java @@ -1,9 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== - * + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,80 +20,80 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.User; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class UserTest { - User user = new User(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"user\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"username\" : \"username\"," + EOL + + " \"password\" : \"password\"," + EOL + + " \"tenantId\" : \"tenantid\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"email\" : \"email\"," + EOL + + " \"enabled\" : false" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getId() throws Exception { - user.getId(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + User.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + User user = objectMapper.readValue(JSON_FULL, User.class); + String json = objectMapper.writeValueAsString(user); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setId() throws Exception { - user.setId("test"); + public void testMethods() throws Exception { + User user = objectMapper.readValue(JSON_FULL, User.class); + user.toString(); + + String password = user.getPassword(); + Assert.assertNotNull(password); + user.setPassword(password); + + String name = user.getName(); + Assert.assertNotNull(name); + user.setName(name); + + String tenantId = user.getTenantId(); + Assert.assertNotNull(tenantId); + user.setTenantId(tenantId); + + String id = user.getId(); + Assert.assertNotNull(id); + user.setId(id); + + String email = user.getEmail(); + Assert.assertNotNull(email); + user.setEmail(email); + + Boolean enabled = user.getEnabled(); + Assert.assertNotNull(enabled); + user.setEnabled(enabled); + + String username = user.getUsername(); + Assert.assertNotNull(username); + user.setUsername(username); } - - @Test - public void getUsername() throws Exception { - user.getUsername(); - } - - @Test - public void setUsername() throws Exception { - user.setUsername("test"); - } - - @Test - public void getPassword() throws Exception { - user.getPassword(); - } - - @Test - public void setPassword() throws Exception { - user.setPassword("test"); - } - - @Test - public void getTenantId() throws Exception { - user.getTenantId(); - } - - @Test - public void setTenantId() throws Exception { - user.setTenantId("test"); - } - - @Test - public void getName() throws Exception { - user.getName(); - } - - @Test - public void setName() throws Exception { - user.setName("test"); - } - - @Test - public void getEmail() throws Exception { - user.getEmail(); - } - - @Test - public void setEmail() throws Exception { - user.setEmail("test"); - } - - @Test - public void getEnabled() throws Exception { - user.getEnabled(); - } - - @Test - public void setEnabled() throws Exception { - user.setEnabled(true); - } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/UsersTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/UsersTest.java index 8a3f16d..acb96a3 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/UsersTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/UsersTest.java @@ -1,8 +1,9 @@ /*- - * ONAP-SO * ============LICENSE_START======================================================= - * Copyright 2018 Huawei Intellectual Property. All rights reserved. - * =================================================================== + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,20 +20,70 @@ package com.woorea.openstack.keystone.model; +import com.woorea.openstack.keystone.model.User; +import com.woorea.openstack.keystone.model.Users; +import java.util.List; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class UsersTest { - Users users = new Users(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"users\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"username\" : \"username\"," + EOL + + " \"password\" : \"password\"," + EOL + + " \"tenantId\" : \"tenantid\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"email\" : \"email\"," + EOL + + " \"enabled\" : false" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"username\" : \"username\"," + EOL + + " \"password\" : \"password\"," + EOL + + " \"tenantId\" : \"tenantid\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"email\" : \"email\"," + EOL + + " \"enabled\" : false" + EOL + + " } ]" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); @Test - public void getList() throws Exception { - users.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Users.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Users users = objectMapper.readValue(JSON_FULL, Users.class); + String json = objectMapper.writeValueAsString(users); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - users.iterator(); + @Test + public void testMethods() throws Exception { + Users users = objectMapper.readValue(JSON_FULL, Users.class); + users.toString(); + + List list = users.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") User x : users) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -} \ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/AccessKeyTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/AccessKeyTest.java new file mode 100644 index 0000000..413097f --- /dev/null +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/AccessKeyTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.keystone.model.authentication; + +import com.woorea.openstack.keystone.model.authentication.AccessKey; +import com.woorea.openstack.keystone.model.authentication.AccessKey.ApiAccessKeyCredentials; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class AccessKeyTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"auth\" : {" + EOL + + " \"tenantId\" : \"tenantid\"," + EOL + + " \"tenantName\" : \"tenantname\"," + EOL + + " \"apiAccessKeyCredentials\" : {" + EOL + + " \"accessKey\" : \"accesskey\"," + EOL + + " \"secretKey\" : \"secretkey\"" + EOL + + " }" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + AccessKey.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + AccessKey accesskey = objectMapper.readValue(JSON_FULL, AccessKey.class); + String json = objectMapper.writeValueAsString(accesskey); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + AccessKey accesskey = objectMapper.readValue(JSON_FULL, AccessKey.class); + accesskey.toString(); + + ApiAccessKeyCredentials apiAccessKeyCredentials = accesskey.getApiAccessKeyCredentials(); + Assert.assertNotNull(apiAccessKeyCredentials); + accesskey.setApiAccessKeyCredentials(apiAccessKeyCredentials); + + String tenantId = accesskey.getTenantId(); + Assert.assertNotNull(tenantId); + accesskey.setTenantId(tenantId); + + String tenantName = accesskey.getTenantName(); + Assert.assertNotNull(tenantName); + accesskey.setTenantName(tenantName); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/ApiAccessKeyCredentialsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/ApiAccessKeyCredentialsTest.java new file mode 100644 index 0000000..ae63a61 --- /dev/null +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/ApiAccessKeyCredentialsTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.keystone.model.authentication; + +import com.woorea.openstack.keystone.model.authentication.AccessKey.ApiAccessKeyCredentials; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class ApiAccessKeyCredentialsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"accessKey\" : \"accesskey\"," + EOL + + " \"secretKey\" : \"secretkey\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + ApiAccessKeyCredentials.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + ApiAccessKeyCredentials apiaccesskeycredentials = objectMapper.readValue(JSON_FULL, ApiAccessKeyCredentials.class); + String json = objectMapper.writeValueAsString(apiaccesskeycredentials); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + ApiAccessKeyCredentials apiaccesskeycredentials = objectMapper.readValue(JSON_FULL, ApiAccessKeyCredentials.class); + apiaccesskeycredentials.toString(); + + String secretKey = apiaccesskeycredentials.getSecretKey(); + Assert.assertNotNull(secretKey); + apiaccesskeycredentials.setSecretKey(secretKey); + + String accessKey = apiaccesskeycredentials.getAccessKey(); + Assert.assertNotNull(accessKey); + apiaccesskeycredentials.setAccessKey(accessKey); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/PasswordCredentialsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/PasswordCredentialsTest.java new file mode 100644 index 0000000..4c71e1c --- /dev/null +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/PasswordCredentialsTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.keystone.model.authentication; + +import com.woorea.openstack.keystone.model.authentication.UsernamePassword.PasswordCredentials; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class PasswordCredentialsTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"username\" : \"username\"," + EOL + + " \"password\" : \"password\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + PasswordCredentials.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + PasswordCredentials passwordcredentials = objectMapper.readValue(JSON_FULL, PasswordCredentials.class); + String json = objectMapper.writeValueAsString(passwordcredentials); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + PasswordCredentials passwordcredentials = objectMapper.readValue(JSON_FULL, PasswordCredentials.class); + passwordcredentials.toString(); + + String password = passwordcredentials.getPassword(); + Assert.assertNotNull(password); + passwordcredentials.setPassword(password); + + String username = passwordcredentials.getUsername(); + Assert.assertNotNull(username); + passwordcredentials.setUsername(username); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/TokenTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/TokenTest.java new file mode 100644 index 0000000..170f0b4 --- /dev/null +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/TokenTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.keystone.model.authentication; + +import com.woorea.openstack.keystone.model.authentication.TokenAuthentication.Token; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class TokenTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"id\" : \"id\"" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Token.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Token token = objectMapper.readValue(JSON_FULL, Token.class); + String json = objectMapper.writeValueAsString(token); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Token token = objectMapper.readValue(JSON_FULL, Token.class); + token.toString(); + + String id = token.getId(); + Assert.assertNotNull(id); + token.setId(id); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/UsernamePasswordTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/UsernamePasswordTest.java new file mode 100644 index 0000000..ee98274 --- /dev/null +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/model/authentication/UsernamePasswordTest.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package com.woorea.openstack.keystone.model.authentication; + +import com.woorea.openstack.keystone.model.authentication.UsernamePassword; +import com.woorea.openstack.keystone.model.authentication.UsernamePassword.PasswordCredentials; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; +import org.junit.Assert; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +public class UsernamePasswordTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"auth\" : {" + EOL + + " \"tenantId\" : \"tenantid\"," + EOL + + " \"tenantName\" : \"tenantname\"," + EOL + + " \"passwordCredentials\" : {" + EOL + + " \"username\" : \"username\"," + EOL + + " \"password\" : \"password\"" + EOL + + " }" + EOL + + " }" + EOL + + "}"; + + private ObjectMapper objectMapper = new ObjectMapper() + .setSerializationInclusion(Inclusion.NON_NULL) + .enable(SerializationConfig.Feature.INDENT_OUTPUT) + .enable(SerializationConfig.Feature.WRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE) + .enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + @Test + public void testSerialization() throws Exception { + System.out.println("CLASS: " + UsernamePassword.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + UsernamePassword usernamepassword = objectMapper.readValue(JSON_FULL, UsernamePassword.class); + String json = objectMapper.writeValueAsString(usernamepassword); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + UsernamePassword usernamepassword = objectMapper.readValue(JSON_FULL, UsernamePassword.class); + usernamepassword.toString(); + + PasswordCredentials passwordCredentials = usernamepassword.getPasswordCredentials(); + Assert.assertNotNull(passwordCredentials); + usernamepassword.setPasswordCredentials(passwordCredentials); + + String tenantId = usernamepassword.getTenantId(); + Assert.assertNotNull(tenantId); + usernamepassword.setTenantId(tenantId); + + String tenantName = usernamepassword.getTenantName(); + Assert.assertNotNull(tenantName); + usernamepassword.setTenantName(tenantName); + } +} -- cgit 1.2.3-korg