42741fad6076079eefd881a7de3f0b4ba218c03d
[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 import org.junit.Before;
32 import org.junit.Test;
33 import org.openecomp.appc.design.services.util.DesignServiceConstants;
34 import org.openecomp.sdnc.sli.SvcLogicContext;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import junit.framework.Assert;
38
39 public class TestValidatorService {
40
41 //Onap Migration    
42
43     private final Logger logger = LoggerFactory.getLogger(TestValidatorService.class);
44     @Test
45     public void testValidXMLValidation(){
46         String response = null;
47         String xmlString = "<xml><configure>" + "<operation>create</operation>" + "<base>" + "<request-information>"
48                 + "<source>SDN-GP</source>" + "</request-information>" + "</base>" + "</configure>" + "</xml>";
49
50         ValidatorService vs = new ValidatorService();
51         try {
52             response = vs.execute("", xmlString, "XML");
53         } catch (Exception e) {
54         }
55         Assert.assertEquals("success", response);
56         
57     }
58     @Test
59     public void testInvalidXMLValidation() {
60         String response = null;
61         String xmlString = "<xml><configure>" + "<operation>create</operation>" + "<base>" + "<request-information>"
62                 + "<source>SDN-GP</source>" + "</request-information>" + "</configure>" + "</xml>";
63
64         ValidatorService vs = new ValidatorService();
65         try {
66             response = vs.execute("", xmlString, "XML");
67         } catch (Exception e) {
68         }
69         Assert.assertEquals(null, response);
70     }
71     @Test
72     public void testYAMLValidation() {
73         String response = null;
74         String YAMLString = "en:";
75         ValidatorService vs = new ValidatorService();
76         try {
77             response = vs.execute("", YAMLString, "YAML");
78         } catch (Exception e) {
79         }
80         Assert.assertEquals("success", response);
81     }
82     @Test
83     public void testInvalidYAMLValidation()  {
84         String response = null;
85         String YAMLString = "Test \n A:";
86         ValidatorService vs = new ValidatorService();
87         try {
88             response = vs.execute("", YAMLString, "YAML");
89         } catch (Exception e) {
90         }
91             
92         Assert.assertEquals(null, response);
93     }
94
95     @Test
96     public void testJSONValidation(){
97         String response = null;
98         String YAMLString = "{\"Test\": \"Test1\" }";
99
100         ValidatorService vs = new ValidatorService();
101         try {
102             response = vs.execute("", YAMLString, "JSON");
103         } catch (Exception e) {
104         }
105         Assert.assertEquals("success", response);
106     }
107     @Test
108     public void testInvalidJSONValidation(){
109         String response = null;
110         String YAMLString = "{\"Test\" \"Test1\" }";
111         ValidatorService vs = new ValidatorService();
112         try {
113             response = vs.execute("", YAMLString, "JSON");
114         } catch (Exception e) {
115         }
116         Assert.assertEquals(null, response);
117     }
118     
119     @Test
120     public void testInvalidvalidateVelocity(){
121         String response = null;
122         String validateVelocity = "{\"Test\" \"Test1\" }";
123         ValidatorService vs = new ValidatorService();
124         try {
125             response = vs.execute("", validateVelocity, "Velocity");
126         } catch (Exception e) {
127         }
128         Assert.assertEquals(null, response);
129         
130     }
131 }