2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.adapters.tenant.test;
27 import javax.xml.ws.Holder;
29 import org.openecomp.mso.adapters.tenant.MsoTenantAdapter;
30 import org.openecomp.mso.adapters.tenant.MsoTenantAdapterImpl;
31 import org.openecomp.mso.adapters.tenant.exceptions.TenantException;
32 import org.openecomp.mso.adapters.tenantrest.TenantRollback;
34 public class TenantTest {
35 public static final void main (String args[])
37 String cloudId = "MT";
38 cloudId = "AIC_GAMMALAB";
40 MsoTenantAdapter tenantAdapter = new MsoTenantAdapterImpl();
42 Holder<String> tenantId = new Holder<String>();
43 Holder<String> tenantName = new Holder<String>();
44 Holder<Map<String,String>> tenantMetadata = new Holder<Map<String,String>>();
45 Holder<Boolean> tenantDeleted = new Holder<Boolean>();
46 Holder<TenantRollback> rollback = new Holder<TenantRollback>();
49 tenantAdapter.queryTenant (cloudId, "934a4ac9c4bd4b8d9d8ab3ef900281b0", null, tenantId, tenantName, tenantMetadata);
50 System.out.println ("Got Tenant ID=" + tenantId.value + ", name=" + tenantName.value + ", metadata = " + tenantMetadata.value);
52 catch (TenantException e) {
53 System.out.println ("Got Tenant Exception: " + e);
57 Map<String,String> metadata = new HashMap<String,String>();
58 metadata.put("sdn-global-id", "abc");
59 metadata.put("service-type", "gamma");
61 // Create a new tenant
63 tenantAdapter.createTenant(cloudId, "TEST_META6", metadata, true, tenantId, rollback);
64 System.out.println ("Created Tenant ID " + tenantId.value);
66 catch (TenantAlreadyExists e) {
67 System.out.println ("Create: Tenant already exists: " + "TEST_META6");
69 catch (TenantException e) {
70 System.out.println ("Got Tenant Exception on Create: " + e);
74 // Query the new tenant
76 tenantAdapter.queryTenant (cloudId, "TEST_META6", tenantId, tenantName, tenantMetadata);
77 System.out.println ("Queried Tenant ID=" + tenantId.value + ", name=" + tenantName.value + ", metadata = " + tenantMetadata.value);
79 catch (TenantException e) {
80 System.out.println ("Got Tenant Exception on Query: " + e);
86 } catch (InterruptedException e1) {}
88 // Delete the new tenant
90 tenantAdapter.deleteTenant (cloudId, tenantId.value, tenantDeleted);
91 if (tenantDeleted.value)
92 System.out.println ("Deleted Tenant " + tenantId.value);
94 System.out.println ("Delete: Tenant " + tenantId.value + " does not exist");
96 catch (TenantException e) {
97 System.out.println ("Got Tenant Exception on Delete: " + e);
100 // Create another new tenant
102 tenantAdapter.createTenant(cloudId, "TEST_MSO2", null, false, tenantId, rollback);
103 System.out.println ("Created Tenant ID " + tenantId.value);
105 catch (TenantException e) {
106 System.out.println ("Got Tenant Exception on Create: " + e);
109 // Query the new tenant
111 tenantAdapter.queryTenant (cloudId, "TEST_MSO2", tenantId, tenantName);
112 System.out.println ("Queried Tenant ID=" + tenantId.value + ", name=" + tenantName.value);
114 catch (TenantException e) {
115 System.out.println ("Got Tenant Exception on Query: " + e);
120 } catch (InterruptedException e1) {}
122 // Rollback the new tenant
124 tenantAdapter.rollbackTenant(rollback.value);
125 System.out.println ("Rolled Back Tenant ID " + tenantId.value);
127 catch (TenantException e) {
128 System.out.println ("Got Tenant Exception on Rollback: " + e);