From e35347d6521133807e92f397820fa18a5412aee7 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Thu, 22 Feb 2018 10:25:39 +0100 Subject: add junit for cloud wrappers Change-Id: I699b10ee2cb6e8b57ca56e8a9baae8aa41000540 Issue-ID: SO-430 Signed-off-by: Lukasz Muszkieta --- .../wrappers/RackspaceAPIKeyWrapper.java | 10 ---- .../wrappers/UsernamePasswordWrapper.java | 10 ---- .../wrappers/RackspaceAPIKeyWrapperTest.java | 55 ++++++++++++++++++++++ .../wrappers/UsernamePasswordWrapperTest.java | 55 ++++++++++++++++++++++ .../wrappers/WrapperTestUtility.java | 44 +++++++++++++++++ 5 files changed, 154 insertions(+), 20 deletions(-) create mode 100644 adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java create mode 100644 adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java create mode 100644 adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java (limited to 'adapters') diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java index 5cf5587481..e82306b6cd 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java @@ -35,16 +35,6 @@ import com.woorea.openstack.keystone.model.Authentication; */ public class RackspaceAPIKeyWrapper extends AuthenticationWrapper { - /** - * - */ - public RackspaceAPIKeyWrapper() { - // TODO Auto-generated constructor stub - } - - /* (non-Javadoc) - * @see org.openecomp.mso.cloud.authentication.AuthenticationWrapper#getAuthentication(org.openecomp.mso.cloud.CloudIdentity) - */ @Override public Authentication getAuthentication(CloudIdentity cloudIdentity) { if (cloudIdentity == null) { diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java index 5fd3e521f0..a1beabe564 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java @@ -32,19 +32,9 @@ import com.woorea.openstack.keystone.model.authentication.UsernamePassword; /** * This class implements the authentication wrapper for Openstack provided for * user name and password authentication. - * */ public class UsernamePasswordWrapper extends AuthenticationWrapper { - /** - * - */ - public UsernamePasswordWrapper() { - } - - /* (non-Javadoc) - * @see org.openecomp.mso.cloud.authentication.AuthenticationWrapper#getAuthentication(org.openecomp.mso.cloud.CloudIdentity) - */ @Override public Authentication getAuthentication(CloudIdentity cloudIdentity) { if (cloudIdentity == null) { diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java new file mode 100644 index 0000000000..33f91c641e --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START========================================== + * =================================================================== + * Copyright (c) 2017 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============================================ + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + * + */ + +package org.openecomp.mso.cloud.authentication.wrappers; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.woorea.openstack.keystone.model.Authentication; +import org.junit.Test; +import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication; + +public class RackspaceAPIKeyWrapperTest { + + @Test + public void getAuthenticationSuccessful() { + RackspaceAPIKeyWrapper testedObject = new RackspaceAPIKeyWrapper(); + Authentication authentication = testedObject.getAuthentication(WrapperTestUtility.createCloudIdentity()); + + assertThat(authentication).isInstanceOf(RackspaceAuthentication.class); + RackspaceAuthentication rackspaceAuthentication = (RackspaceAuthentication) authentication; + assertThat(rackspaceAuthentication.getToken().getUsername()) + .isEqualTo(WrapperTestUtility.CLOUD_IDENTITY_MSO_ID); + assertThat(rackspaceAuthentication.getToken().getApiKey()) + .isEqualTo(WrapperTestUtility.CLOUD_IDENTITY_MSO_PASS); + } + + @Test + public void getAuthenticationThrowsException() { + assertThatThrownBy(() -> new RackspaceAPIKeyWrapper().getAuthentication(null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage(WrapperTestUtility.EXCEPTION_MESSAGE); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java new file mode 100644 index 0000000000..0cfe287dfe --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START========================================== + * =================================================================== + * Copyright (c) 2017 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============================================ + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + * + */ + +package org.openecomp.mso.cloud.authentication.wrappers; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.woorea.openstack.keystone.model.Authentication; +import com.woorea.openstack.keystone.model.authentication.UsernamePassword; +import org.junit.Test; + +public class UsernamePasswordWrapperTest { + + @Test + public void getAuthenticationSuccessful() { + UsernamePasswordWrapper testedObject = new UsernamePasswordWrapper(); + Authentication authentication = testedObject.getAuthentication(WrapperTestUtility.createCloudIdentity()); + + assertThat(authentication).isInstanceOf(UsernamePassword.class); + UsernamePassword usernamePassword = (UsernamePassword) authentication; + assertThat(usernamePassword.getPasswordCredentials().getUsername()) + .isEqualTo(WrapperTestUtility.CLOUD_IDENTITY_MSO_ID); + assertThat(usernamePassword.getPasswordCredentials().getPassword()) + .isEqualTo(WrapperTestUtility.CLOUD_IDENTITY_MSO_PASS); + } + + @Test + public void getAuthenticationThrowsException() { + assertThatThrownBy(() -> new UsernamePasswordWrapper().getAuthentication(null)). + isInstanceOf(IllegalArgumentException.class). + hasMessage(WrapperTestUtility.EXCEPTION_MESSAGE); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java new file mode 100644 index 0000000000..3cbc48d090 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START========================================== + * =================================================================== + * Copyright (c) 2017 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============================================ + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + * + */ + +package org.openecomp.mso.cloud.authentication.wrappers; + +import org.openecomp.mso.cloud.CloudIdentity; + +final class WrapperTestUtility { + + static final String CLOUD_IDENTITY_MSO_ID = "msoIdTest"; + static final String CLOUD_IDENTITY_MSO_PASS = "msoPassTest"; + static final String EXCEPTION_MESSAGE = "Provided cloud identity is null, cannot extract username and " + + "password"; + + private WrapperTestUtility() { + } + + static CloudIdentity createCloudIdentity() { + CloudIdentity cloudIdentity = new CloudIdentity(); + cloudIdentity.setMsoId(CLOUD_IDENTITY_MSO_ID); + cloudIdentity.setMsoPass(CloudIdentity.encryptPassword(CLOUD_IDENTITY_MSO_PASS)); + return cloudIdentity; + } +} -- cgit 1.2.3-korg