Added New Junit Cases for APPC Design Services
[appc.git] / appc-inbound / appc-design-services / provider / src / test / java / org / openecomp / appc / design / validator / TestValidatorService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.design.validator;
26
27 import java.io.InputStream;
28 import java.util.Enumeration;
29 import java.util.HashMap;
30 import java.util.Properties;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.openecomp.appc.design.services.util.DesignServiceConstants;
35 import org.openecomp.sdnc.sli.SvcLogicContext;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 import junit.framework.Assert;
40
41 public class TestValidatorService {
42
43 //Onap Migration    
44
45     private final Logger logger = LoggerFactory.getLogger(TestValidatorService.class);
46 @Test
47     public void testvalidXMLValidation() throws Exception {
48         String response = null;
49         String xmlString = "<xml><configure>"
50                 + "<operation>create</operation>"
51                 + "<base>"
52                 + "<request-information>"
53                 + "<source>SDN-GP</source>"
54                 + "</request-information>"
55                 + "</base>" 
56                 + "</configure>"
57                 + "</xml>";
58         
59         ValidatorService vs = new ValidatorService();
60         try{
61          response = vs.execute("", xmlString, "XML");
62         }
63         catch(Exception e){
64             System.out.println(e.getMessage());
65         }
66             
67         Assert.assertEquals("success", response);
68         
69     }
70     @Test
71     public void testInvalidXMLValidation() throws Exception {
72         String response = null;
73         String xmlString = "<xml><configure>"
74                 + "<operation>create</operation>"
75                 + "<base>"
76                 + "<request-information>"
77                 + "<source>SDN-GP</source>"
78                 + "</request-information>"
79                 + "</configure>"
80                 + "</xml>";
81         
82         ValidatorService vs = new ValidatorService();
83         try{
84          response = vs.execute("", xmlString, "XML");
85         }
86         catch(Exception e){
87             System.out.println(e.getMessage());
88         }
89             
90         Assert.assertEquals(null, response);
91         
92     }
93     @Test
94     public void testYAMLValidation() throws Exception {
95         String response = null;
96         String YAMLString = "en:";
97             
98         
99         ValidatorService vs = new ValidatorService();
100         try{
101          response = vs.execute("", YAMLString, "YAML");
102         }
103         catch(Exception e){
104             System.out.println(e.getMessage());
105             e.printStackTrace();
106         }
107             
108         Assert.assertEquals("success", response);
109         
110     }
111     @Test
112     public void testInvalidYAMLValidation() throws Exception {
113         String response = null;
114         String YAMLString = "Test \n A:";
115             
116         
117         ValidatorService vs = new ValidatorService();
118         try{
119          response = vs.execute("", YAMLString,"YAML");
120         }
121         catch(Exception e){
122             System.out.println(e.getMessage());
123         }
124             
125         Assert.assertEquals(null, response);
126         
127     }
128     
129 @Test
130     public void testJSONValidation() throws Exception {
131         String response = null;
132         String YAMLString = "{\"Test\": \"Test1\" }";
133             
134         
135         ValidatorService vs = new ValidatorService();
136         try{
137          response = vs.execute("", YAMLString, "JSON");
138         }
139         catch(Exception e){
140             System.out.println(e.getMessage());
141         
142         }            
143         Assert.assertEquals("success", response);
144         
145     }
146     @Test
147     public void testInvalidJSONValidation() throws Exception {
148         String response = null;
149         String YAMLString = "{\"Test\" \"Test1\" }";
150             
151         
152         ValidatorService vs = new ValidatorService();
153         try{
154          response = vs.execute("", YAMLString, "JSON");
155         }
156         catch(Exception e){
157             System.out.println(e.getMessage());
158         
159         }            
160         Assert.assertEquals(null, response);
161         
162     }
163     
164     @Test
165     public void testainvalidvalidateVelocity() throws Exception {
166         String response = null;
167         String validateVelocity = "{\"Test\" \"Test1\" }";
168             
169         
170         ValidatorService vs = new ValidatorService();
171         try{
172          response = vs.execute("", validateVelocity, "Velocity");
173         }
174         catch(Exception e){
175             System.out.println(e.getMessage());
176         
177         }            
178         Assert.assertEquals(null, response);
179         
180     }
181 }