diff options
Diffstat (limited to 'keystone-model/src/test/java/com/woorea')
42 files changed, 2755 insertions, 982 deletions
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<Service> serviceCatalog = access.getServiceCatalog(); + Assert.assertNotNull(serviceCatalog); + Assert.assertEquals(2, serviceCatalog.size()); + + Map<String,Object> 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<Endpoint> 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<Role> 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<Service> 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<Link> links = tenants.getLinks(); + Assert.assertNotNull(links); + Assert.assertEquals(2, links.size()); + + List<Tenant> 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<User> 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); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/AuthenticationTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/AuthenticationTest.java index ec3d138..31a1099 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/AuthenticationTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/AuthenticationTest.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 @@ -16,32 +17,85 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Authentication; +import com.woorea.openstack.keystone.v3.model.Authentication.Identity; +import com.woorea.openstack.keystone.v3.model.Authentication.Scope; +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 AuthenticationTest { - Authentication authentication = new Authentication(); + private static final String EOL = System.lineSeparator(); - @Test - public void getIdentity() throws Exception { - authentication.getIdentity(); - } + private static final String JSON_FULL = "{" + EOL + + " \"auth\" : {" + EOL + + " \"identity\" : {" + EOL + + " \"methods\" : [ \"methods-v1\", \"methods-v2\" ]," + EOL + + " \"password\" : {" + EOL + + " \"user\" : {" + EOL + + " \"domain\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"password\" : \"password\"" + EOL + + " }" + EOL + + " }," + EOL + + " \"token\" : {" + EOL + + " \"id\" : \"id\"" + EOL + + " }" + EOL + + " }," + EOL + + " \"scope\" : {" + EOL + + " \"project\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"domain\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"name\" : \"name\"" + EOL + + " }" + EOL + + " }" + EOL + + " }" + EOL + + "}"; - @Test - public void setIdentity() throws Exception { - authentication.setIdentity(new Authentication.Identity()); - } + 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 getScope() throws Exception { - authentication.getScope(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Authentication.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Authentication authentication = objectMapper.readValue(JSON_FULL, Authentication.class); + String json = objectMapper.writeValueAsString(authentication); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setScope() throws Exception { - authentication.setScope(new Authentication.Scope()); + public void testMethods() throws Exception { + Authentication authentication = objectMapper.readValue(JSON_FULL, Authentication.class); + authentication.toString(); + + Identity identity = authentication.getIdentity(); + Assert.assertNotNull(identity); + authentication.setIdentity(identity); + + Scope scope = authentication.getScope(); + Assert.assertNotNull(scope); + authentication.setScope(scope); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/CredentialTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/CredentialTest.java index be5740f..b0c75b2 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/CredentialTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/CredentialTest.java @@ -1,7 +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 @@ -15,64 +17,78 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Credential; +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 java.util.HashMap; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class CredentialTest { - Credential credential = new Credential(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() throws Exception { - credential.getId(); - } + private static final String JSON_FULL = "{" + EOL + + " \"credential\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"userId\" : \"userid\"," + EOL + + " \"blob\" : {" + EOL + + " \"blob-k1\" : \"blob-v1\"," + EOL + + " \"blob-k2\" : \"blob-v2\"" + EOL + + " }" + EOL + + " }" + EOL + + "}"; - @Test - public void setId() throws Exception { - credential.setId("test"); - } + 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 getProjectId() throws Exception { - credential.getProjectId(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Credential.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Credential credential = objectMapper.readValue(JSON_FULL, Credential.class); + String json = objectMapper.writeValueAsString(credential); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setProjectId() throws Exception { - credential.setProjectId("test"); + public void testMethods() throws Exception { + Credential credential = objectMapper.readValue(JSON_FULL, Credential.class); + credential.toString(); + + Map<String,String> blob = credential.getBlob(); + Assert.assertNotNull(blob); + Assert.assertEquals(2, blob.size()); + credential.setBlob(blob); + + String id = credential.getId(); + Assert.assertNotNull(id); + credential.setId(id); + + String type = credential.getType(); + Assert.assertNotNull(type); + credential.setType(type); + + String userId = credential.getUserId(); + Assert.assertNotNull(userId); + credential.setUserId(userId); + + String projectId = credential.getProjectId(); + Assert.assertNotNull(projectId); + credential.setProjectId(projectId); } - - @Test - public void getType() throws Exception { - credential.getType(); - } - - @Test - public void setType() throws Exception { - credential.setType("test"); - } - - @Test - public void getUserId() throws Exception { - credential.getUserId(); - } - - @Test - public void setUserId() throws Exception { - credential.setUserId("test"); - } - - @Test - public void getBlob() throws Exception { - credential.getBlob(); - } - - @Test - public void setBlob() throws Exception { - credential.setBlob(new HashMap<String, String>()); - } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/CredentialsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/CredentialsTest.java index a14ab9b..a158efb 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/CredentialsTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/CredentialsTest.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 @@ -16,21 +17,75 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Credential; +import com.woorea.openstack.keystone.v3.model.Credentials; +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 CredentialsTest { - Credentials credentials = new Credentials(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"credentials\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"userId\" : \"userid\"," + EOL + + " \"blob\" : {" + EOL + + " \"blob-k1\" : \"blob-v1\"," + EOL + + " \"blob-k2\" : \"blob-v2\"" + EOL + + " }" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"userId\" : \"userid\"," + EOL + + " \"blob\" : {" + EOL + + " \"blob-k1\" : \"blob-v1\"," + EOL + + " \"blob-k2\" : \"blob-v2\"" + EOL + + " }" + 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 { - credentials.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Credentials.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Credentials credentials = objectMapper.readValue(JSON_FULL, Credentials.class); + String json = objectMapper.writeValueAsString(credentials); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - credentials.iterator(); + @Test + public void testMethods() throws Exception { + Credentials credentials = objectMapper.readValue(JSON_FULL, Credentials.class); + credentials.toString(); + + List<Credential> list = credentials.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Credential x : credentials) { + ++cnt; + } + Assert.assertEquals(2, cnt); } -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/DomainTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/DomainTest.java index 7741a41..f4e75c3 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/DomainTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/DomainTest.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 @@ -16,52 +17,54 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Token.Domain; +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 DomainTest { - Domain domain = new Domain(); - - @Test - public void getId() throws Exception { - domain.getId(); - } - - @Test - public void setId() throws Exception { - domain.setId("test"); - } - - @Test - public void getName() throws Exception { - domain.getName(); - } - - @Test - public void setName() throws Exception { - domain.setName("test"); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getDescription() throws Exception { - domain.getDescription(); - } + private static final String JSON_FULL = "{" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + "}"; - @Test - public void setDescription() throws Exception { - domain.setDescription("test"); - } + 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 getEnabled() throws Exception { - domain.getEnabled(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Domain.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Domain domain = objectMapper.readValue(JSON_FULL, Domain.class); + String json = objectMapper.writeValueAsString(domain); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setEnabled() throws Exception { - domain.setEnabled(true); + public void testMethods() throws Exception { + Domain domain = objectMapper.readValue(JSON_FULL, Domain.class); + domain.toString(); + + String name = domain.getName(); + Assert.assertNotNull(name); + domain.setName(name); + + String id = domain.getId(); + Assert.assertNotNull(id); + domain.setId(id); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/DomainsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/DomainsTest.java index aa8ff41..ee694d5 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/DomainsTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/DomainsTest.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 @@ -16,22 +17,67 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Domain; +import com.woorea.openstack.keystone.v3.model.Domains; +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 DomainsTest { - Domains domains = new Domains(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"domains\" : [ {" + 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 + + "}"; + + 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 { - domains.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Domains.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Domains domains = objectMapper.readValue(JSON_FULL, Domains.class); + String json = objectMapper.writeValueAsString(domains); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - domains.iterator(); + @Test + public void testMethods() throws Exception { + Domains domains = objectMapper.readValue(JSON_FULL, Domains.class); + domains.toString(); + + List<Domain> list = domains.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Domain x : domains) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/EndpointTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/EndpointTest.java index 9a52223..75a4441 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/EndpointTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/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 @@ -16,52 +17,74 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Token.Service.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(); - - @Test - public void getId() throws Exception { - endpoint.getId(); - } - - @Test - public void setId() throws Exception { - endpoint.setId("test"); - } - - @Test - public void getInterface() throws Exception { - endpoint.getInterface(); - } - - @Test - public void setInterface() throws Exception { - endpoint.setInterface("test"); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getName() throws Exception { - endpoint.getName(); - } + private static final String JSON_FULL = "{" + EOL + + " \"id\" : \"id\"," + EOL + + " \"url\" : \"url\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"enabled\" : false," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"legacy_endpoint_id\" : \"legacyendpointid\"" + EOL + + "}"; - @Test - public void setName() throws Exception { - endpoint.setName("test"); - } + 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 getServiceId() throws Exception { - endpoint.getServiceId(); + 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 setServiceId() throws Exception { - endpoint.setServiceId("test"); + public void testMethods() throws Exception { + Endpoint endpoint = objectMapper.readValue(JSON_FULL, Endpoint.class); + endpoint.toString(); + + String legacyEndpointId = endpoint.getLegacyEndpointId(); + Assert.assertNotNull(legacyEndpointId); + endpoint.setLegacyEndpointId(legacyEndpointId); + + String id = endpoint.getId(); + Assert.assertNotNull(id); + endpoint.setId(id); + + String region = endpoint.getRegion(); + Assert.assertNotNull(region); + endpoint.setRegion(region); + + String interfaceProperty = endpoint.getInterface(); + Assert.assertNotNull(interfaceProperty); + endpoint.setInterface(interfaceProperty); + + String url = endpoint.getUrl(); + Assert.assertNotNull(url); + endpoint.setUrl(url); + + Boolean enabled = endpoint.getEnabled(); + Assert.assertNotNull(enabled); + endpoint.setEnabled(enabled); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/EndpointsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/EndpointsTest.java index 4f6a4a9..8002b1c 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/EndpointsTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/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 @@ -16,22 +17,67 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Endpoint; +import com.woorea.openstack.keystone.v3.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 + + " \"name\" : \"name\"," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"service_id\" : \"serviceid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"service_id\" : \"serviceid\"" + 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<Endpoint> 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/v3/model/GroupTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/GroupTest.java index 76a3dd9..75fc901 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/GroupTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/GroupTest.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 @@ -16,52 +17,68 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Group; +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 GroupTest { - Group group = new Group(); - - @Test - public void getId() throws Exception { - group.getId(); - } - - @Test - public void setId() throws Exception { - group.setId("test"); - } - - @Test - public void getDomainId() throws Exception { - group.getDomainId(); - } - - @Test - public void setDomainId() throws Exception { - group.setDomainId("test"); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getName() throws Exception { - group.getName(); - } + private static final String JSON_FULL = "{" + EOL + + " \"group\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"domain_id\" : \"domainid\"" + EOL + + " }" + EOL + + "}"; - @Test - public void setName() throws Exception { - group.setName("test"); - } + 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 getDescription() throws Exception { - group.getDescription(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Group.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Group group = objectMapper.readValue(JSON_FULL, Group.class); + String json = objectMapper.writeValueAsString(group); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setDescription() throws Exception { - group.setDescription("test"); + public void testMethods() throws Exception { + Group group = objectMapper.readValue(JSON_FULL, Group.class); + group.toString(); + + String name = group.getName(); + Assert.assertNotNull(name); + group.setName(name); + + String description = group.getDescription(); + Assert.assertNotNull(description); + group.setDescription(description); + + String id = group.getId(); + Assert.assertNotNull(id); + group.setId(id); + + String domainId = group.getDomainId(); + Assert.assertNotNull(domainId); + group.setDomainId(domainId); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/GroupsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/GroupsTest.java index 3f399fd..c16c25a 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/GroupsTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/GroupsTest.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 @@ -16,21 +17,67 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Group; +import com.woorea.openstack.keystone.v3.model.Groups; +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 GroupsTest { - Groups groups = new Groups(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"groups\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"domain_id\" : \"domainid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"domain_id\" : \"domainid\"" + 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 { - groups.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Groups.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Groups groups = objectMapper.readValue(JSON_FULL, Groups.class); + String json = objectMapper.writeValueAsString(groups); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - groups.iterator(); + @Test + public void testMethods() throws Exception { + Groups groups = objectMapper.readValue(JSON_FULL, Groups.class); + groups.toString(); + + List<Group> list = groups.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Group x : groups) { + ++cnt; + } + Assert.assertEquals(2, cnt); } -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/IdentityTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/IdentityTest.java new file mode 100644 index 0000000..ba55e8b --- /dev/null +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/IdentityTest.java @@ -0,0 +1,91 @@ +/*- + * ============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.v3.model; + +import com.woorea.openstack.keystone.v3.model.Authentication.Identity; +import com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password; +import com.woorea.openstack.keystone.v3.model.Authentication.Identity.Token; +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 IdentityTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"methods\" : [ \"methods-v1\", \"methods-v2\" ]," + EOL + + " \"password\" : {" + EOL + + " \"user\" : {" + EOL + + " \"domain\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"password\" : \"password\"" + EOL + + " }" + EOL + + " }," + EOL + + " \"token\" : {" + EOL + + " \"id\" : \"id\"" + 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 testSerialization() throws Exception { + System.out.println("CLASS: " + Identity.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Identity identity = objectMapper.readValue(JSON_FULL, Identity.class); + String json = objectMapper.writeValueAsString(identity); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Identity identity = objectMapper.readValue(JSON_FULL, Identity.class); + identity.toString(); + + Password password = identity.getPassword(); + Assert.assertNotNull(password); + identity.setPassword(password); + + List<String> methods = identity.getMethods(); + Assert.assertNotNull(methods); + Assert.assertEquals(2, methods.size()); + identity.setMethods(methods); + + Token token = identity.getToken(); + Assert.assertNotNull(token); + identity.setToken(token); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PasswordTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PasswordTest.java new file mode 100644 index 0000000..d1230e2 --- /dev/null +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PasswordTest.java @@ -0,0 +1,74 @@ +/*- + * ============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.v3.model; + +import com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password; +import com.woorea.openstack.keystone.v3.model.Authentication.Identity.Password.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 PasswordTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"user\" : {" + EOL + + " \"domain\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"password\" : \"password\"" + 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 testSerialization() throws Exception { + System.out.println("CLASS: " + Password.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Password password = objectMapper.readValue(JSON_FULL, Password.class); + String json = objectMapper.writeValueAsString(password); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Password password = objectMapper.readValue(JSON_FULL, Password.class); + password.toString(); + + User user = password.getUser(); + Assert.assertNotNull(user); + password.setUser(user); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PoliciesTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PoliciesTest.java index ce0a224..a3e8a8a 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PoliciesTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PoliciesTest.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 @@ -16,22 +17,75 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Policies; +import com.woorea.openstack.keystone.v3.model.Policy; +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 PoliciesTest { - Policies policies = new Policies(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"policies\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"userId\" : \"userid\"," + EOL + + " \"blob\" : {" + EOL + + " \"blob-k1\" : \"blob-v1\"," + EOL + + " \"blob-k2\" : \"blob-v2\"" + EOL + + " }" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"userId\" : \"userid\"," + EOL + + " \"blob\" : {" + EOL + + " \"blob-k1\" : \"blob-v1\"," + EOL + + " \"blob-k2\" : \"blob-v2\"" + EOL + + " }" + 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 { - policies.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Policies.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Policies policies = objectMapper.readValue(JSON_FULL, Policies.class); + String json = objectMapper.writeValueAsString(policies); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - policies.iterator(); + @Test + public void testMethods() throws Exception { + Policies policies = objectMapper.readValue(JSON_FULL, Policies.class); + policies.toString(); + + List<Policy> list = policies.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Policy x : policies) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PolicyTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PolicyTest.java index 3062c64..2aae601 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PolicyTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/PolicyTest.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 @@ -16,64 +17,78 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Policy; +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 java.util.HashMap; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; public class PolicyTest { - Policy policy = new Policy(); + private static final String EOL = System.lineSeparator(); - @Test - public void getId() throws Exception { - policy.getId(); - } + private static final String JSON_FULL = "{" + EOL + + " \"policy\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"projectId\" : \"projectid\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"userId\" : \"userid\"," + EOL + + " \"blob\" : {" + EOL + + " \"blob-k1\" : \"blob-v1\"," + EOL + + " \"blob-k2\" : \"blob-v2\"" + EOL + + " }" + EOL + + " }" + EOL + + "}"; - @Test - public void setId() throws Exception { - policy.setId("test"); - } + 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 getProjectId() throws Exception { - policy.getProjectId(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Policy.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Policy policy = objectMapper.readValue(JSON_FULL, Policy.class); + String json = objectMapper.writeValueAsString(policy); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setProjectId() throws Exception { - policy.setProjectId("test"); + public void testMethods() throws Exception { + Policy policy = objectMapper.readValue(JSON_FULL, Policy.class); + policy.toString(); + + Map<String,String> blob = policy.getBlob(); + Assert.assertNotNull(blob); + Assert.assertEquals(2, blob.size()); + policy.setBlob(blob); + + String id = policy.getId(); + Assert.assertNotNull(id); + policy.setId(id); + + String type = policy.getType(); + Assert.assertNotNull(type); + policy.setType(type); + + String userId = policy.getUserId(); + Assert.assertNotNull(userId); + policy.setUserId(userId); + + String projectId = policy.getProjectId(); + Assert.assertNotNull(projectId); + policy.setProjectId(projectId); } - - @Test - public void getType() throws Exception { - policy.getType(); - } - - @Test - public void setType() throws Exception { - policy.setType("test"); - } - - @Test - public void getUserId() throws Exception { - policy.getUserId(); - } - - @Test - public void setUserId() throws Exception { - policy.setUserId("test"); - } - - @Test - public void getBlob() throws Exception { - policy.getBlob(); - } - - @Test - public void setBlob() throws Exception { - policy.setBlob(new HashMap<String, String>()); - } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ProjectTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ProjectTest.java index 0a9ee02..80b4122 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ProjectTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ProjectTest.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 @@ -16,52 +17,63 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Token.Domain; +import com.woorea.openstack.keystone.v3.model.Token.Project; +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 ProjectTest { - Project project = new Project(); - - @Test - public void getId() throws Exception { - project.getId(); - } - - @Test - public void setId() throws Exception { - project.setId("test"); - } - - @Test - public void getDomainId() throws Exception { - project.getDomainId(); - } - - @Test - public void setDomainId() throws Exception { - project.setDomainId("test"); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getName() throws Exception { - project.getName(); - } + private static final String JSON_FULL = "{" + EOL + + " \"domain\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + "}"; - @Test - public void setName() throws Exception { - project.setName("test"); - } + 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 getEnabled() throws Exception { - project.getEnabled(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Project.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Project project = objectMapper.readValue(JSON_FULL, Project.class); + String json = objectMapper.writeValueAsString(project); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } @Test - public void setEnabled() throws Exception { - project.setEnabled(true); + public void testMethods() throws Exception { + Project project = objectMapper.readValue(JSON_FULL, Project.class); + project.toString(); + + Domain domain = project.getDomain(); + Assert.assertNotNull(domain); + project.setDomain(domain); + + String name = project.getName(); + Assert.assertNotNull(name); + project.setName(name); + + String id = project.getId(); + Assert.assertNotNull(id); + project.setId(id); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ProjectsTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ProjectsTest.java index f4732b2..6ab1c88 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ProjectsTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ProjectsTest.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 @@ -16,22 +17,67 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Project; +import com.woorea.openstack.keystone.v3.model.Projects; +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 ProjectsTest { - Projects projects = new Projects(); + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"projects\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"enabled\" : false," + EOL + + " \"domain_id\" : \"domainid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"enabled\" : false," + EOL + + " \"domain_id\" : \"domainid\"" + 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 { - projects.getList(); + public void testSerialization() throws Exception { + System.out.println("CLASS: " + Projects.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Projects projects = objectMapper.readValue(JSON_FULL, Projects.class); + String json = objectMapper.writeValueAsString(projects); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); } - @Test(expected = NullPointerException.class) - public void iterator() throws Exception { - projects.iterator(); + @Test + public void testMethods() throws Exception { + Projects projects = objectMapper.readValue(JSON_FULL, Projects.class); + projects.toString(); + + List<Project> list = projects.getList(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + + int cnt = 0; + for (@SuppressWarnings("unused") Project x : projects) { + ++cnt; + } + Assert.assertEquals(2, cnt); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/RoleTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/RoleTest.java index d1c0c43..189205e 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/RoleTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/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 @@ -16,47 +17,43 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Token.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(); - - @Test - public void getId() throws Exception { - role.getId(); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getName() throws Exception { - role.getName(); - } + private static final String JSON_FULL = "{ }"; - @Test - public void setName() throws Exception { - role.setName("test"); - } + 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 getDescription() throws Exception { - role.getDescription(); + 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 setDescription() throws Exception { - role.setDescription("test"); + public void testMethods() throws Exception { + Role role = objectMapper.readValue(JSON_FULL, Role.class); + role.toString(); } - - @Test - public void getEnabled() throws Exception { - role.getEnabled(); - } - - @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/v3/model/RolesTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/RolesTest.java index a18efb3..6ee1b2c 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/RolesTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/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 @@ -16,22 +17,67 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Role; +import com.woorea.openstack.keystone.v3.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<Role> 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/v3/model/ScopeTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ScopeTest.java new file mode 100644 index 0000000..3f3708b --- /dev/null +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ScopeTest.java @@ -0,0 +1,73 @@ +/*- + * ============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.v3.model; + +import com.woorea.openstack.keystone.v3.model.Authentication.Scope; +import com.woorea.openstack.keystone.v3.model.Authentication.Scope.Project; +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 ScopeTest { + + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"project\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"domain\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"name\" : \"name\"" + 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 testSerialization() throws Exception { + System.out.println("CLASS: " + Scope.class.getName()); + System.out.println("TEST JSON: " + JSON_FULL); + Scope scope = objectMapper.readValue(JSON_FULL, Scope.class); + String json = objectMapper.writeValueAsString(scope); + System.out.println("RE-SERIALIZED OBJECT: " + json); + JSONAssert.assertEquals(JSON_FULL, json, JSONCompareMode.LENIENT); + } + + @Test + public void testMethods() throws Exception { + Scope scope = objectMapper.readValue(JSON_FULL, Scope.class); + scope.toString(); + + Project project = scope.getProject(); + Assert.assertNotNull(project); + scope.setProject(project); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ServiceTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ServiceTest.java index fbdc411..31430de 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ServiceTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/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 @@ -16,52 +17,76 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Token.Service; +import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint; +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 ServiceTest { - Service service = new Service(); - - @Test - public void getId() throws Exception { - service.getId(); - } - - @Test - public void setId() throws Exception { - service.setId("test"); - } - - @Test - public void getType() throws Exception { - service.getType(); - } - - @Test - public void setType() throws Exception { - service.setType("test"); - } + private static final String EOL = System.lineSeparator(); - @Test - public void getName() throws Exception { - service.getName(); - } + private static final String JSON_FULL = "{" + EOL + + " \"id\" : \"id\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"endpoints\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"url\" : \"url\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"enabled\" : false," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"legacy_endpoint_id\" : \"legacyendpointid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"url\" : \"url\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"enabled\" : false," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"legacy_endpoint_id\" : \"legacyendpointid\"" + EOL + + " } ]" + EOL + + "}"; - @Test - public void setName() throws Exception { - service.setName("test"); - } + 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 getDescription() throws Exception { - service.getDescription(); + 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 setDescription() throws Exception { - service.setDescription("test"); + public void testMethods() throws Exception { + Service service = objectMapper.readValue(JSON_FULL, Service.class); + service.toString(); + + List<Endpoint> endpoints = service.getEndpoints(); + Assert.assertNotNull(endpoints); + Assert.assertEquals(2, endpoints.size()); + service.setEndpoints(endpoints); + + String id = service.getId(); + Assert.assertNotNull(id); + service.setId(id); + + String type = service.getType(); + Assert.assertNotNull(type); + service.setType(type); } - -}
\ No newline at end of file +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ServicesTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ServicesTest.java index f9d19cd..28246c6 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/ServicesTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/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 @@ -16,22 +17,67 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.model.Service; +import com.woorea.openstack.keystone.v3.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 + + " \"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<Service> 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/v3/model/TokenTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/TokenTest.java index c8d009b..aabcfb7 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/TokenTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/TokenTest.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 @@ -17,107 +17,152 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package com.woorea.openstack.keystone.v3.model; -import org.junit.Test; +package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.model.Token; +import com.woorea.openstack.keystone.v3.model.Token.Domain; +import com.woorea.openstack.keystone.v3.model.Token.Project; +import com.woorea.openstack.keystone.v3.model.Token.Role; +import com.woorea.openstack.keystone.v3.model.Token.Service; +import com.woorea.openstack.keystone.v3.model.Token.User; import java.util.Calendar; -import java.util.Collections; -import java.util.GregorianCalendar; +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 TokenTest { - Token token = new Token(); - - @Test - public void getId() throws Exception { - token.getId(); - } - - @Test - public void setId() throws Exception { - token.setId("test"); - } - - @Test - public void getExpiresAt() throws Exception { - token.getExpiresAt(); - } - - @Test - public void setExpiresAt() throws Exception { - Calendar calendar = new GregorianCalendar(); - token.setExpiresAt(calendar); - } - - @Test - public void getIssuedAt() throws Exception { - token.getIssuedAt(); - } - - @Test - public void setIssuedAt() throws Exception { - token.setIssuedAt(new GregorianCalendar()); - } - - @Test - public void getMethods() throws Exception { - token.getMethods(); - } - - @Test - public void setMethods() throws Exception { - token.setMethods(Collections.<String>emptyList()); - } - - @Test - public void getDomain() throws Exception { - token.getDomain(); - } - - @Test - public void setDomain() throws Exception { - token.setDomain(new Token.Domain()); - } - - @Test - public void getProject() throws Exception { - token.getProject(); - } - - @Test - public void setProject() throws Exception { - token.setProject(new Token.Project()); - } - - @Test - public void getUser() throws Exception { - token.getUser(); - } - - @Test - public void setUser() throws Exception { - token.setUser(new Token.User()); - } - - @Test - public void getRoles() throws Exception { - token.getRoles(); - } - - @Test - public void setRoles() throws Exception { - token.setRoles(Collections.<Token.Role>emptyList()); - } - - @Test - public void getCatalog() throws Exception { - token.getCatalog(); - } - - @Test - public void setCatalog() throws Exception { - token.setCatalog(Collections.<Token.Service>emptyList()); - } - -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"token\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"methods\" : [ \"methods-v1\", \"methods-v2\" ]," + EOL + + " \"domain\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"project\" : {" + EOL + + " \"domain\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"user\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"" + EOL + + " }," + EOL + + " \"roles\" : [ { }, { } ]," + EOL + + " \"catalog\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"endpoints\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"url\" : \"url\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"enabled\" : false," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"legacy_endpoint_id\" : \"legacyendpointid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"url\" : \"url\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"enabled\" : false," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"legacy_endpoint_id\" : \"legacyendpointid\"" + EOL + + " } ]" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"type\" : \"type\"," + EOL + + " \"endpoints\" : [ {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"url\" : \"url\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"enabled\" : false," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"legacy_endpoint_id\" : \"legacyendpointid\"" + EOL + + " }, {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"url\" : \"url\"," + EOL + + " \"region\" : \"region\"," + EOL + + " \"enabled\" : false," + EOL + + " \"interface\" : \"interface\"," + EOL + + " \"legacy_endpoint_id\" : \"legacyendpointid\"" + EOL + + " } ]" + EOL + + " } ]," + EOL + + " \"expires_at\" : 1489752000000," + EOL + + " \"issued_at\" : 1488456000000" + 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: " + 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(); + + List<String> methods = token.getMethods(); + Assert.assertNotNull(methods); + Assert.assertEquals(2, methods.size()); + token.setMethods(methods); + + List<Service> catalog = token.getCatalog(); + Assert.assertNotNull(catalog); + Assert.assertEquals(2, catalog.size()); + token.setCatalog(catalog); + + Domain domain = token.getDomain(); + Assert.assertNotNull(domain); + token.setDomain(domain); + + List<Role> roles = token.getRoles(); + Assert.assertNotNull(roles); + Assert.assertEquals(2, roles.size()); + token.setRoles(roles); + + Project project = token.getProject(); + Assert.assertNotNull(project); + token.setProject(project); + + Calendar issuedAt = token.getIssuedAt(); + Assert.assertNotNull(issuedAt); + token.setIssuedAt(issuedAt); + + String id = token.getId(); + Assert.assertNotNull(id); + token.setId(id); + + User user = token.getUser(); + Assert.assertNotNull(user); + token.setUser(user); + + Calendar expiresAt = token.getExpiresAt(); + Assert.assertNotNull(expiresAt); + token.setExpiresAt(expiresAt); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/UserTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/UserTest.java index 6a8f7bc..061b0bc 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/UserTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/UserTest.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 @@ -16,92 +17,88 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.v3.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(); - - @Test - public void getId() throws Exception { - user.getId(); - } - - @Test - public void setId() throws Exception { - user.setId("Test"); - } - - @Test - public void getDomainId() throws Exception { - user.getDomainId(); - } - - @Test - public void setDomainId() throws Exception { - user.setDomainId("test"); - } - - @Test - public void getDefaultProjectId() throws Exception { - user.getDefaultProjectId(); - } - - @Test - public void setDefaultProjectId() throws Exception { - user.setDefaultProjectId("tets"); - } - - @Test - public void getName() throws Exception { - user.getName(); - } - - @Test - public void setName() throws Exception { - user.setName("test"); - } - - @Test - public void getPassword() throws Exception { - user.getPassword(); - } - - @Test - public void setPassword() throws Exception { - user.setPassword("test"); - } - - @Test - public void getEmail() throws Exception { - user.getEmail(); - } - - @Test - public void setEmail() throws Exception { - user.setEmail("test"); - } - - @Test - public void getDescription() throws Exception { - user.getDescription(); - } - - @Test - public void setDescription() throws Exception { - user.setDescription("test"); - } - - @Test - public void getEnabled() throws Exception { - user.getEnabled(); - } - - @Test - public void setEnabled() throws Exception { - user.setEnabled(true); - } - -}
\ No newline at end of file + private static final String EOL = System.lineSeparator(); + + private static final String JSON_FULL = "{" + EOL + + " \"user\" : {" + EOL + + " \"id\" : \"id\"," + EOL + + " \"name\" : \"name\"," + EOL + + " \"password\" : \"password\"," + EOL + + " \"email\" : \"email\"," + EOL + + " \"description\" : \"description\"," + EOL + + " \"enabled\" : false," + EOL + + " \"domain_id\" : \"domainid\"," + EOL + + " \"default_project_id\" : \"defaultprojectid\"" + 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: " + 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 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 description = user.getDescription(); + Assert.assertNotNull(description); + user.setDescription(description); + + String id = user.getId(); + Assert.assertNotNull(id); + user.setId(id); + + String email = user.getEmail(); + Assert.assertNotNull(email); + user.setEmail(email); + + String domainId = user.getDomainId(); + Assert.assertNotNull(domainId); + user.setDomainId(domainId); + + Boolean enabled = user.getEnabled(); + Assert.assertNotNull(enabled); + user.setEnabled(enabled); + + String defaultProjectId = user.getDefaultProjectId(); + Assert.assertNotNull(defaultProjectId); + user.setDefaultProjectId(defaultProjectId); + } +} diff --git a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/UsersTest.java b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/UsersTest.java index 2d27173..35554bd 100644 --- a/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/model/UsersTest.java +++ b/keystone-model/src/test/java/com/woorea/openstack/keystone/v3/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 @@ -16,22 +17,73 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package com.woorea.openstack.keystone.v3.model; +import com.woorea.openstack.keystone.model.User; +import com.woorea.openstack.keystone.v3.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<User> 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 +} |