9ac25136ccb18d0a50ee1e3b24a514ad75dd8810
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / cloud / servertype / ServerTypeTest.java
1 /**\r
2  * \r
3  */\r
4 package org.openecomp.mso.cloud.servertype;\r
5 \r
6 import static org.junit.Assert.assertEquals;\r
7 import static org.junit.Assert.assertNotNull;\r
8 import static org.junit.Assert.fail;\r
9 \r
10 import org.junit.Test;\r
11 import org.openecomp.mso.cloud.CloudIdentity;\r
12 import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;\r
13 import org.openecomp.mso.cloud.IdentityServerTypeAbstract;\r
14 import org.openecomp.mso.openstack.exceptions.MsoException;\r
15 \r
16 public class ServerTypeTest {\r
17 \r
18     @Test\r
19     public void testKeystoneServerType() {\r
20         IdentityServerTypeAbstract keystoneServerType = IdentityServerType.valueOf("KEYSTONE");\r
21         assertNotNull(keystoneServerType);\r
22     }\r
23     \r
24     @Test\r
25     public void testNewServerType() {\r
26         IdentityServerTypeAbstract customServerType = null;\r
27         try {\r
28             customServerType = new IdentityServerType("NewServerType", NewServerTypeUtils.class);\r
29            \r
30         } catch (IllegalArgumentException e) {\r
31             fail("An exception should not be raised when we register a new server type for the first time");\r
32         } finally {\r
33             System.out.println(IdentityServerType.values().toString());\r
34             assertEquals(customServerType, IdentityServerType.valueOf("NewServerType"));\r
35         }\r
36         \r
37         // Create it a second time\r
38         IdentityServerTypeAbstract customServerType2 = null;\r
39         try {\r
40             customServerType2 = new IdentityServerType("NewServerType", NewServerTypeUtils.class);\r
41             fail("An exception should be raised as server type does not exist");\r
42         } catch (IllegalArgumentException e) {\r
43             // Fail silently -- it simply indicates we already registered it\r
44                 customServerType2 = IdentityServerType.valueOf("NewServerType");\r
45         } finally {\r
46             System.out.println(IdentityServerType.values().toString());\r
47             assertEquals(customServerType2, IdentityServerType.valueOf("NewServerType"));\r
48         }\r
49         \r
50         // Check the KeystoneURL for this custom TenantUtils\r
51         CloudIdentity cloudIdentity = new CloudIdentity();\r
52         cloudIdentity.setIdentityUrl("LocalIdentity");\r
53         cloudIdentity.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);\r
54         cloudIdentity.setIdentityServerType((CloudIdentity.IdentityServerType) CloudIdentity.IdentityServerType.valueOf("NewServerType"));\r
55         String regionId = "RegionA";\r
56         String msoPropID = "12345";\r
57         try {\r
58                         assertEquals(cloudIdentity.getKeystoneUrl(regionId, msoPropID), msoPropID + ":" + regionId + ":NewServerTypeKeystoneURL/" + cloudIdentity.getIdentityUrl());\r
59                 } catch (MsoException e) {\r
60                         fail("No MSO Exception should have occured here");\r
61                 }\r
62     }\r
63 }\r