summaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2018-02-22 10:25:39 +0100
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2018-02-23 12:10:04 +0100
commite35347d6521133807e92f397820fa18a5412aee7 (patch)
tree645178cbc2f46787140ce1d8ef469a9ab4d5bd4a /adapters/mso-adapter-utils/src
parent077d14997f5663e570948a0c497e8fae80a0f5d5 (diff)
add junit for cloud wrappers
Change-Id: I699b10ee2cb6e8b57ca56e8a9baae8aa41000540 Issue-ID: SO-430 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java10
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java10
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java55
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java55
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java44
5 files changed, 154 insertions, 20 deletions
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;
+ }
+}