add junit for cloud wrappers 91/32491/3
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Thu, 22 Feb 2018 09:25:39 +0000 (10:25 +0100)
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Fri, 23 Feb 2018 11:10:04 +0000 (12:10 +0100)
Change-Id: I699b10ee2cb6e8b57ca56e8a9baae8aa41000540
Issue-ID: SO-430
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java
adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java
adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapperTest.java [new file with mode: 0644]
adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapperTest.java [new file with mode: 0644]
adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/wrappers/WrapperTestUtility.java [new file with mode: 0644]

index 5cf5587..e82306b 100644 (file)
@@ -35,16 +35,6 @@ import com.woorea.openstack.keystone.model.Authentication;
  */\r
 public class RackspaceAPIKeyWrapper extends AuthenticationWrapper {\r
 \r
-       /**\r
-        * \r
-        */\r
-       public RackspaceAPIKeyWrapper() {\r
-               // TODO Auto-generated constructor stub\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.mso.cloud.authentication.AuthenticationWrapper#getAuthentication(org.openecomp.mso.cloud.CloudIdentity)\r
-        */\r
        @Override\r
        public Authentication getAuthentication(CloudIdentity cloudIdentity) {\r
                if (cloudIdentity == null) {\r
index 5fd3e52..a1beabe 100644 (file)
@@ -32,19 +32,9 @@ import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
 /**\r
  * This class implements the authentication wrapper for Openstack provided for\r
  * user name and password authentication.\r
- *\r
  */\r
 public class UsernamePasswordWrapper extends AuthenticationWrapper {\r
 \r
-       /**\r
-        * \r
-        */\r
-       public UsernamePasswordWrapper() {\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.mso.cloud.authentication.AuthenticationWrapper#getAuthentication(org.openecomp.mso.cloud.CloudIdentity)\r
-        */\r
        @Override\r
        public Authentication getAuthentication(CloudIdentity cloudIdentity) {\r
                if (cloudIdentity == null) {\r
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 (file)
index 0000000..33f91c6
--- /dev/null
@@ -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 (file)
index 0000000..0cfe287
--- /dev/null
@@ -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 (file)
index 0000000..3cbc48d
--- /dev/null
@@ -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;
+    }
+}