[MSO-8] Update the maven dependency
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / cloud / servertype / ServerTypeTest.java
1 /**
2  * 
3  */
4 package org.openecomp.mso.cloud.servertype;
5
6 import static org.junit.Assert.assertEquals;
7 import static org.junit.Assert.assertNotNull;
8 import static org.junit.Assert.fail;
9
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;
15
16 public class ServerTypeTest {
17
18     @Test
19     public void testKeystoneServerType() {
20         IdentityServerTypeAbstract keystoneServerType = IdentityServerType.valueOf("KEYSTONE");
21         assertNotNull(keystoneServerType);
22     }
23     
24     @Test
25     public void testNewServerType() {
26         IdentityServerTypeAbstract customServerType = null;
27         try {
28             customServerType = new IdentityServerType("NewServerType", NewServerTypeUtils.class);
29            
30         } catch (IllegalArgumentException e) {
31             fail("An exception should not be raised when we register a new server type for the first time");
32         } finally {
33             System.out.println(IdentityServerType.values().toString());
34             assertEquals(customServerType, IdentityServerType.valueOf("NewServerType"));
35         }
36         
37         // Create it a second time
38         IdentityServerTypeAbstract customServerType2 = null;
39         try {
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");
45         } finally {
46             System.out.println(IdentityServerType.values().toString());
47             assertEquals(customServerType2, IdentityServerType.valueOf("NewServerType"));
48         }
49         
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";
57         try {
58                         assertEquals(cloudIdentity.getKeystoneUrl(regionId, msoPropID), msoPropID + ":" + regionId + ":NewServerTypeKeystoneURL/" + cloudIdentity.getIdentityUrl());
59                 } catch (MsoException e) {
60                         fail("No MSO Exception should have occured here");
61                 }
62     }
63 }