aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/test
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-02-21 09:59:31 +0000
committerGerrit Code Review <gerrit@onap.org>2018-02-21 09:59:31 +0000
commit6bf073fdfa10a3b5c9b5d726b4284e8b30b727ce (patch)
tree78c876dfe4e92d37719d871fdc348ad9a2574075 /adapters/mso-adapter-utils/src/test
parent8f596cf8bbe7df943b0ff53442b0f1ad59d67c89 (diff)
parentef8c8012c037b0cefbdbf930819524e2050d7c87 (diff)
Merge "add junit for AuthenticationMethodFactory"
Diffstat (limited to 'adapters/mso-adapter-utils/src/test')
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java103
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java61
2 files changed, 110 insertions, 54 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java
new file mode 100644
index 0000000000..2cfce276d8
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactoryTest.java
@@ -0,0 +1,103 @@
+/*
+ * ============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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.woorea.openstack.keystone.model.Authentication;
+import org.junit.Test;
+import org.openecomp.mso.cloud.CloudIdentity;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityAuthenticationType;
+import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;
+
+public class AuthenticationMethodFactoryTest {
+
+ private static final Class WRAPPER_CLASS = RackspaceAPIKeyWrapper.class;
+ private static final String AUTHENTICATION_TYPE = "authenticationTest";
+
+ @Test
+ public void register_NoExceptionThrown() throws IllegalAccessException, InstantiationException {
+ AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, WRAPPER_CLASS);
+ }
+
+ @Test
+ public void register_throwExceptionWhenAuthTypeIsNull() throws InstantiationException, IllegalAccessException {
+ try {
+ AuthenticationMethodFactory.register(null, WRAPPER_CLASS);
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null "
+ + "or an empty name string");
+ }
+ }
+
+ @Test
+ public void register_throwExceptionWhenAuthTypeIsEmpty() throws InstantiationException, IllegalAccessException {
+ try {
+ AuthenticationMethodFactory.register("", WRAPPER_CLASS);
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty().contains("Authentication Type to register cannot be null "
+ + "or an empty name string");
+ }
+ }
+
+ @Test
+ public void register_throwExceptionWhenWrapperIsNull() throws IllegalAccessException, InstantiationException {
+ try {
+ AuthenticationMethodFactory.register(AUTHENTICATION_TYPE, null);
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty()
+ .contains("Wrapper Class to register for Authentication cannot be null");
+ }
+ }
+
+ @Test
+ public void getAuthentication_NoExceptionThrown() {
+ CloudIdentity cloudIdentity = new CloudIdentity();
+ cloudIdentity.setIdentityAuthenticationType(IdentityAuthenticationType.RACKSPACE_APIKEY);
+ cloudIdentity.setMsoId("msoIdTest");
+ cloudIdentity.setMsoPass("123");
+ Authentication result = AuthenticationMethodFactory.getAuthenticationFor(cloudIdentity);
+ assertThat(result).isNotNull();
+ }
+
+ @Test
+ public void getAuthentication_ThrowExWhenCloudSiteIsNull() {
+ try {
+ AuthenticationMethodFactory.getAuthenticationFor(null);
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty().contains("Cloud identity cannot be null");
+ }
+ }
+
+ @Test
+ public void getAuthentication_ThrowExWhenIdentityAuthenticationTypeIsNotSet() {
+ try {
+ AuthenticationMethodFactory.getAuthenticationFor(new CloudIdentity());
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage()).isNotEmpty()
+ .contains("Cloud identity authentication type cannot be null or empty");
+ }
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java
index ccfede7297..b6c1c7373f 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodTest.java
@@ -25,16 +25,11 @@ package org.openecomp.mso.cloud.authentication;
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
+import com.woorea.openstack.keystone.model.Authentication;
+import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
import org.junit.Test;
import org.openecomp.mso.cloud.CloudIdentity;
import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-
-import com.woorea.openstack.keystone.model.Authentication;
-import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
/**
* A few JUnit tests to evaluate the new factory that manages authentication
@@ -50,52 +45,15 @@ public class AuthenticationMethodTest {
public AuthenticationMethodTest() {
// TODO Auto-generated constructor stub
}
-
- @Test
- public void testCustomRackspaceAuth() {
- CloudIdentity ci = new CloudIdentity();
- ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
- ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
- ci.setMsoId("test");
-
- try {
- Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);
- assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
- | URISyntaxException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testCoreUsernamePasswordAuth() {
- CloudIdentity ci = new CloudIdentity();
- ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
- ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
- ci.setMsoId("someuser");
-
- try {
- Authentication auth = AuthenticationMethodFactory.getAuthenticationFor(ci);
- assertTrue(UsernamePassword.class.equals(auth.getClass()));
- } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException
- | URISyntaxException e) {
- e.printStackTrace();
- }
- }
-
+
@Test
public void testCustomRackspaceAuthFromCloudIdentity() {
CloudIdentity ci = new CloudIdentity();
ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
ci.setMsoId("test");
-
- try {
- Authentication auth = ci.getAuthentication();
- assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
- } catch (MsoException e) {
- e.printStackTrace();
- }
+ Authentication auth = ci.getAuthentication();
+ assertTrue(RackspaceAuthentication.class.equals(auth.getClass()));
}
@Test
@@ -104,12 +62,7 @@ public class AuthenticationMethodTest {
ci.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.USERNAME_PASSWORD);
ci.setMsoPass("FD205490A48D48475607C36B9AD902BF");
ci.setMsoId("someuser");
-
- try {
- Authentication auth = ci.getAuthentication();
- assertTrue(UsernamePassword.class.equals(auth.getClass()));
- } catch (MsoException e) {
- e.printStackTrace();
- }
+ Authentication auth = ci.getAuthentication();
+ assertTrue(UsernamePassword.class.equals(auth.getClass()));
}
}