Change the header to SO
[so.git] / adapters / mso-tenant-adapter / src / test / java / org / openecomp / mso / adapters / tenant / test / TenantTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.mso.adapters.tenant.test;
22
23
24
25 import java.util.Map;
26
27 import javax.xml.ws.Holder;
28
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;
33
34 public class TenantTest {
35         public static final void main (String args[])
36         {
37                 String cloudId = "MT";
38                  cloudId = "AIC_GAMMALAB";
39                 
40                 MsoTenantAdapter tenantAdapter = new MsoTenantAdapterImpl();
41                 
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>();
47                 
48                 try {
49                         tenantAdapter.queryTenant (cloudId, "934a4ac9c4bd4b8d9d8ab3ef900281b0", null, tenantId, tenantName, tenantMetadata);
50                         System.out.println ("Got Tenant ID=" + tenantId.value + ", name=" + tenantName.value + ", metadata = " + tenantMetadata.value);
51                 }
52                 catch (TenantException e) {
53                         System.out.println ("Got Tenant Exception: " + e);
54                         System.exit(1);
55                 }
56 /*              
57                 Map<String,String> metadata = new HashMap<String,String>();
58                 metadata.put("sdn-global-id", "abc");
59                 metadata.put("service-type", "gamma");
60                 
61                 // Create a new tenant
62                 try {
63                         tenantAdapter.createTenant(cloudId, "TEST_META6", metadata, true, tenantId, rollback);
64                         System.out.println ("Created Tenant ID " + tenantId.value);
65                 }
66                 catch (TenantAlreadyExists e) {
67                         System.out.println ("Create: Tenant already exists: " + "TEST_META6");
68                 }
69                 catch (TenantException e) {
70                         System.out.println ("Got Tenant Exception on Create: " + e);
71                         System.exit(1);
72                 }
73                 
74                 // Query the new tenant
75                 try {
76                         tenantAdapter.queryTenant (cloudId, "TEST_META6", tenantId, tenantName, tenantMetadata);
77                         System.out.println ("Queried Tenant ID=" + tenantId.value + ", name=" + tenantName.value + ", metadata = " + tenantMetadata.value);
78                 }
79                 catch (TenantException e) {
80                         System.out.println ("Got Tenant Exception on Query: " + e);
81                         System.exit(1);
82                 }
83                 
84                 try {
85                         Thread.sleep(10000);
86                 } catch (InterruptedException e1) {}
87                 
88                 // Delete the new tenant
89                 try {
90                         tenantAdapter.deleteTenant (cloudId, tenantId.value, tenantDeleted);
91                         if (tenantDeleted.value)
92                                 System.out.println ("Deleted Tenant " + tenantId.value);
93                         else
94                                 System.out.println ("Delete: Tenant " + tenantId.value + " does not exist");
95                 }
96                 catch (TenantException e) {
97                         System.out.println ("Got Tenant Exception on Delete: " + e);
98                 }
99 /*
100                 // Create another new tenant
101                 try {
102                         tenantAdapter.createTenant(cloudId, "TEST_MSO2", null, false, tenantId, rollback);
103                         System.out.println ("Created Tenant ID " + tenantId.value);
104                 }
105                 catch (TenantException e) {
106                         System.out.println ("Got Tenant Exception on Create: " + e);
107                 }
108                 
109                 // Query the new tenant
110                 try {
111                         tenantAdapter.queryTenant (cloudId, "TEST_MSO2", tenantId, tenantName);
112                         System.out.println ("Queried Tenant ID=" + tenantId.value + ", name=" + tenantName.value);
113                 }
114                 catch (TenantException e) {
115                         System.out.println ("Got Tenant Exception on Query: " + e);
116                 }
117                 
118                 try {
119                         Thread.sleep(10000);
120                 } catch (InterruptedException e1) {}
121
122                 // Rollback the new tenant
123                 try {
124                         tenantAdapter.rollbackTenant(rollback.value);
125                         System.out.println ("Rolled Back Tenant ID " + tenantId.value);
126                 }
127                 catch (TenantException e) {
128                         System.out.println ("Got Tenant Exception on Rollback: " + e);
129                 }
130 */
131         }
132 }