Update license header in appc-inbound files
[appc.git] / appc-inbound / appc-design-services / provider / src / test / java / org / onap / appc / design / validator / TestValidatorService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.design.validator;
25
26 import java.io.InputStream;
27 import java.util.Enumeration;
28 import java.util.HashMap;
29 import java.util.Properties;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.appc.design.services.util.DesignServiceConstants;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import junit.framework.Assert;
37
38 public class TestValidatorService {
39
40 //Onap Migration    
41
42     private final Logger logger = LoggerFactory.getLogger(TestValidatorService.class);
43     @Test
44     public void testValidXMLValidation(){
45         String response = null;
46         String xmlString = "<xml><configure>" + "<operation>create</operation>" + "<base>" + "<request-information>"
47                 + "<source>SDN-GP</source>" + "</request-information>" + "</base>" + "</configure>" + "</xml>";
48
49         ValidatorService vs = new ValidatorService();
50         try {
51             response = vs.execute("", xmlString, "XML");
52         } catch (Exception e) {
53         }
54         Assert.assertEquals("success", response);
55         
56     }
57     @Test
58     public void testInvalidXMLValidation() {
59         String response = null;
60         String xmlString = "<xml><configure>" + "<operation>create</operation>" + "<base>" + "<request-information>"
61                 + "<source>SDN-GP</source>" + "</request-information>" + "</configure>" + "</xml>";
62
63         ValidatorService vs = new ValidatorService();
64         try {
65             response = vs.execute("", xmlString, "XML");
66         } catch (Exception e) {
67         }
68         Assert.assertEquals(null, response);
69     }
70     @Test
71     public void testYAMLValidation() {
72         String response = null;
73         String YAMLString = "en:";
74         ValidatorService vs = new ValidatorService();
75         try {
76             response = vs.execute("", YAMLString, "YAML");
77         } catch (Exception e) {
78         }
79         Assert.assertEquals("success", response);
80     }
81     @Test
82     public void testInvalidYAMLValidation()  {
83         String response = null;
84         String YAMLString = "Test \n A:";
85         ValidatorService vs = new ValidatorService();
86         try {
87             response = vs.execute("", YAMLString, "YAML");
88         } catch (Exception e) {
89         }
90             
91         Assert.assertEquals(null, response);
92     }
93
94     @Test
95     public void testJSONValidation(){
96         String response = null;
97         String YAMLString = "{\"Test\": \"Test1\" }";
98
99         ValidatorService vs = new ValidatorService();
100         try {
101             response = vs.execute("", YAMLString, "JSON");
102         } catch (Exception e) {
103         }
104         Assert.assertEquals("success", response);
105     }
106     @Test
107     public void testInvalidJSONValidation(){
108         String response = null;
109         String YAMLString = "{\"Test\" \"Test1\" }";
110         ValidatorService vs = new ValidatorService();
111         try {
112             response = vs.execute("", YAMLString, "JSON");
113         } catch (Exception e) {
114         }
115         Assert.assertEquals(null, response);
116     }
117     
118     @Test
119     public void testInvalidvalidateVelocity(){
120         String response = null;
121         String validateVelocity = "{\"Test\" \"Test1\" }";
122         ValidatorService vs = new ValidatorService();
123         try {
124             response = vs.execute("", validateVelocity, "Velocity");
125         } catch (Exception e) {
126         }
127         Assert.assertEquals(null, response);
128         
129     }
130 }