2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.cloud.servertype;
\r
23 import static org.junit.Assert.assertEquals;
\r
24 import static org.junit.Assert.assertNotNull;
\r
25 import static org.junit.Assert.fail;
\r
27 import org.junit.BeforeClass;
\r
28 import org.junit.Ignore;
\r
29 import org.junit.Test;
\r
30 import org.openecomp.mso.cloud.CloudConfigFactory;
\r
31 import org.openecomp.mso.cloud.CloudIdentity;
\r
32 import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
\r
33 import org.openecomp.mso.cloud.IdentityServerTypeAbstract;
\r
34 import org.openecomp.mso.openstack.exceptions.MsoException;
\r
35 import org.openecomp.mso.openstack.utils.MsoKeystoneUtilsTest;
\r
37 public class ServerTypeTest {
\r
40 public static void init() throws Exception {
\r
41 String cloudConfigJson = ServerTypeTest.class.getClassLoader()
\r
42 .getResource("cloud_config.json").getPath();
\r
43 (new CloudConfigFactory()).initializeCloudConfig(cloudConfigJson, 0);
\r
47 @Ignore // IGNORED FOR 1710 MERGE TO ONAP
\r
48 public void testKeystoneServerType() {
\r
49 IdentityServerTypeAbstract keystoneServerType = IdentityServerType.valueOf("KEYSTONE");
\r
50 assertNotNull(keystoneServerType);
\r
54 public void testNewServerType() {
\r
55 IdentityServerTypeAbstract customServerType = null;
\r
57 customServerType = new IdentityServerType("NewServerType", NewServerTypeUtils.class);
\r
59 } catch (IllegalArgumentException e) {
\r
60 fail("An exception should not be raised when we register a new server type for the first time");
\r
62 System.out.println(IdentityServerType.values().toString());
\r
63 assertEquals(customServerType, IdentityServerType.valueOf("NewServerType"));
\r
66 // Create it a second time
\r
67 IdentityServerTypeAbstract customServerType2 = null;
\r
69 customServerType2 = new IdentityServerType("NewServerType", NewServerTypeUtils.class);
\r
70 fail("An exception should be raised as server type does not exist");
\r
71 } catch (IllegalArgumentException e) {
\r
72 // Fail silently -- it simply indicates we already registered it
\r
73 customServerType2 = IdentityServerType.valueOf("NewServerType");
\r
75 System.out.println(IdentityServerType.values().toString());
\r
76 assertEquals(customServerType2, IdentityServerType.valueOf("NewServerType"));
\r
79 // Check the KeystoneURL for this custom TenantUtils
\r
80 CloudIdentity cloudIdentity = new CloudIdentity();
\r
81 cloudIdentity.setIdentityUrl("LocalIdentity");
\r
82 cloudIdentity.setIdentityAuthenticationType(CloudIdentity.IdentityAuthenticationType.RACKSPACE_APIKEY);
\r
83 cloudIdentity.setIdentityServerType((CloudIdentity.IdentityServerType) CloudIdentity.IdentityServerType.valueOf("NewServerType"));
\r
84 String regionId = "RegionA";
\r
85 String msoPropID = "12345";
\r
87 assertEquals(cloudIdentity.getKeystoneUrl(regionId, msoPropID), msoPropID + ":" + regionId + ":NewServerTypeKeystoneURL/" + cloudIdentity.getIdentityUrl());
\r
88 } catch (MsoException e) {
\r
89 fail("No MSO Exception should have occured here");
\r