diff options
Diffstat (limited to 'keystone-model/src/test/java/com/woorea/openstack/keystone/v3')
23 files changed, 1505 insertions, 625 deletions
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 +} |