Merge "Cleanup project's name in Sonar"
[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.Ignore;\r
11 import org.junit.Test;\r
12 import org.openecomp.mso.cloud.CloudIdentity;\r
13 import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;\r
14 import org.openecomp.mso.cloud.IdentityServerTypeAbstract;\r
15 import org.openecomp.mso.openstack.exceptions.MsoException;\r
16 \r
17 public class ServerTypeTest {\r
18 \r
19     @Test\r
20     @Ignore // IGNORED FOR 1710 MERGE TO ONAP\r
21     public void testKeystoneServerType() {\r
22         IdentityServerTypeAbstract keystoneServerType = IdentityServerType.valueOf("KEYSTONE");\r
23         assertNotNull(keystoneServerType);\r
24     }\r
25     \r
26     @Test\r
27     public void testNewServerType() {\r
28         IdentityServerTypeAbstract customServerType = null;\r
29         try {\r
30             customServerType = new IdentityServerType("NewServerType", NewServerTypeUtils.class);\r
31            \r
32         } catch (IllegalArgumentException e) {\r
33             fail("An exception should not be raised when we register a new server type for the first time");\r
34         } finally {\r
35             System.out.println(IdentityServerType.values().toString());\r
36             assertEquals(customServerType, IdentityServerType.valueOf("NewServerType"));\r
37         }\r
38         \r
39         // Create it a second time\r
40         IdentityServerTypeAbstract customServerType2 = null;\r
41         try {\r
42             customServerType2 = new IdentityServerType("NewServerType", NewServerTypeUtils.class);\r
43             fail("An exception should be raised as server type does not exist");\r
44         } catch (IllegalArgumentException e) {\r
45             // Fail silently -- it simply indicates we already registered it\r
46                 customServerType2 = IdentityServerType.valueOf("NewServerType");\r
47         } finally {\r
48             System.out.println(IdentityServerType.values().toString());\r
49             assertEquals(customServerType2, IdentityServerType.valueOf("NewServerType"));\r
50         }\r
51         \r
52         // Check the KeystoneURL for this custom TenantUtils\r
53         CloudIdentity cloudIdentity = new CloudIdentity();\r
54         cloudIdentity.setIdentityUrl("LocalIdentity");\r
55         cloudIdentity.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);\r
56         cloudIdentity.setIdentityServerType((CloudIdentity.IdentityServerType) CloudIdentity.IdentityServerType.valueOf("NewServerType"));\r
57         String regionId = "RegionA";\r
58         String msoPropID = "12345";\r
59         try {\r
60                         assertEquals(cloudIdentity.getKeystoneUrl(regionId, msoPropID), msoPropID + ":" + regionId + ":NewServerTypeKeystoneURL/" + cloudIdentity.getIdentityUrl());\r
61                 } catch (MsoException e) {\r
62                         fail("No MSO Exception should have occured here");\r
63                 }\r
64     }\r
65 }\r