4 package org.openecomp.mso.cloud.servertype;
6 import static org.junit.Assert.assertEquals;
7 import static org.junit.Assert.assertNotNull;
8 import static org.junit.Assert.fail;
10 import org.junit.Test;
11 import org.openecomp.mso.cloud.CloudIdentity;
12 import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
13 import org.openecomp.mso.cloud.IdentityServerTypeAbstract;
14 import org.openecomp.mso.openstack.exceptions.MsoException;
16 public class ServerTypeTest {
19 public void testKeystoneServerType() {
20 IdentityServerTypeAbstract keystoneServerType = IdentityServerType.valueOf("KEYSTONE");
21 assertNotNull(keystoneServerType);
25 public void testNewServerType() {
26 IdentityServerTypeAbstract customServerType = null;
28 customServerType = new IdentityServerType("NewServerType", NewServerTypeUtils.class);
30 } catch (IllegalArgumentException e) {
31 fail("An exception should not be raised when we register a new server type for the first time");
33 System.out.println(IdentityServerType.values().toString());
34 assertEquals(customServerType, IdentityServerType.valueOf("NewServerType"));
37 // Create it a second time
38 IdentityServerTypeAbstract customServerType2 = null;
40 customServerType2 = new IdentityServerType("NewServerType", NewServerTypeUtils.class);
41 fail("An exception should be raised as server type does not exist");
42 } catch (IllegalArgumentException e) {
43 // Fail silently -- it simply indicates we already registered it
44 customServerType2 = IdentityServerType.valueOf("NewServerType");
46 System.out.println(IdentityServerType.values().toString());
47 assertEquals(customServerType2, IdentityServerType.valueOf("NewServerType"));
50 // Check the KeystoneURL for this custom TenantUtils
51 CloudIdentity cloudIdentity = new CloudIdentity();
52 cloudIdentity.setIdentityUrl("LocalIdentity");
53 cloudIdentity.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
54 cloudIdentity.setIdentityServerType((CloudIdentity.IdentityServerType) CloudIdentity.IdentityServerType.valueOf("NewServerType"));
55 String regionId = "RegionA";
56 String msoPropID = "12345";
58 assertEquals(cloudIdentity.getKeystoneUrl(regionId, msoPropID), msoPropID + ":" + regionId + ":NewServerTypeKeystoneURL/" + cloudIdentity.getIdentityUrl());
59 } catch (MsoException e) {
60 fail("No MSO Exception should have occured here");