d7b53a4af3267148ec16bbbac0e37ab4a4745003
[so.git] / mso-catalog-db / src / test / java / org / openecomp / mso / db / catalog / test / CatalogTestDatabase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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.db.catalog.test;
22
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Set;
31
32 import org.openecomp.mso.db.catalog.CatalogDatabase;
33 import org.openecomp.mso.db.catalog.beans.HeatTemplate;
34 import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
35
36 /**
37  * This class is purely for development testing.  It hard-codes a very limited
38  * catalog of HeatTemplates and Services for the case where no actual database
39  * is available.
40  * 
41  *
42  */
43 public class CatalogTestDatabase extends CatalogDatabase {
44         
45         private static int id = 1;
46         private static Map<String,HeatTemplate> heatTemplates;
47         
48         static {
49                 heatTemplates = new HashMap<String,HeatTemplate>();
50                 
51                 addTemplate("ApacheDemo", "C:/temp/apache-demo.json", 2,
52                                         new ArrayList<String>(Arrays.asList("private_subnet_gateway", "private_subnet_cidr")),
53                                         new ArrayList<String> (Arrays.asList("vnf_id", "public_net_id")));
54         }
55
56         public CatalogTestDatabase () {
57         }
58         
59         private static void addTemplate (String name, String path, int timeout, List<String> reqd, List<String> opt)
60         {
61                 HeatTemplate template = new HeatTemplate();
62                 template.setId(id++);
63                 template.setTemplateName("ApacheDemo");
64                 template.setTemplatePath("C:/temp/apache-demo.json");
65                 template.setTimeoutMinutes(2);
66                 
67                 Set<HeatTemplateParam> params = new HashSet<HeatTemplateParam>();
68                 
69                 for (String s : reqd) {
70                         HeatTemplateParam param = new HeatTemplateParam();
71                         param.setId(id++);
72                         param.setParamName(s);
73                         param.setRequired(true);
74                         params.add(param);
75                 }
76                 
77                 for (String s : opt) {
78                         HeatTemplateParam param = new HeatTemplateParam();
79                         param.setId(id++);
80                         param.setParamName(s);
81                         param.setRequired(false);
82                         params.add(param);
83                 }
84                 template.setParameters(params);
85                 
86                 heatTemplates.put(name,  template);
87         }
88         
89     @Override
90     public HeatTemplate getHeatTemplate (String templateName)
91     {
92         if (heatTemplates.containsKey(templateName)) {
93                 return heatTemplates.get(templateName);
94         } else {
95                 return null;
96         }
97     }
98     
99     @Override
100     public HeatTemplate getHeatTemplate (String templateName, String version)
101     {
102         return getHeatTemplate(templateName);
103     }
104
105 }