2 // ============LICENSE_START====================================================
\r
3 // Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
\r
4 // =============================================================================
\r
5 // Licensed under the Apache License, Version 2.0 (the "License");
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.apache.org/licenses/LICENSE-2.0
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an "AS IS" BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
16 // ============LICENSE_END======================================================
\r
18 // ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
19 import { Injectable } from '@angular/core';
\r
20 import {ValidateMetaSchemaService} from './validate-metaschema.service';
\r
21 import {MetaSchemaService} from './metaschema.service';
\r
22 import {ValidateJSONService} from './validate-json.service';
\r
24 describe('ValidateMetaSchemaService test suite', function () {
\r
25 let service: ValidateMetaSchemaService;
\r
28 let jsonservice = new ValidateJSONService;
\r
29 let metaservice = new MetaSchemaService;
\r
30 service = new ValidateMetaSchemaService(metaservice, jsonservice);
\r
33 it('should create service', () => expect(service).toBeDefined() );
\r
36 it('should fail to validate invalid json', () => {
\r
37 var jsonString = '"testjson": "teststring"}'
\r
38 expect(service.validate(jsonString)).toBe(false) ;
\r
39 expect(service.validateMsgs()).toMatch("Invalid JSON.*");
\r
41 it('should validate valid JSON schema', () => {
\r
42 var jsonString = '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'
\r
43 expect(service.validate(jsonString)).toBe(true) ;
\r
46 it('should validate valid reference schema', () => {
\r
47 var jsonString ='{ "self": { "name": "Common Event Format Definition", "version": "25.0.0", "description": "Common Event Format Definition"}, "dataformatversion": "1.0.0", "reference": { "name": "Common Event Format", "format": "JSON", "version": "25.0.0" }}';
\r
48 expect(service.validate(jsonString)).toBe(true) ;
\r
51 it('should validate valid delimited schema', () => {
\r
52 var jsonString ='{"self": {"name": "Delimited Format Example", "version": "1.0.0", "description": "Delimited format example just for testing" }, "dataformatversion": "1.0.0", "delimitedschema": { "delimiter": "|", "fields": [{ "name": "field1", "description": "test field1", "fieldtype": "string" }, { "name": "field2", "description": "test field2", "fieldtype": "boolean" }] } }'
\r
53 expect(service.validate(jsonString)).toBe(true) ;
\r
56 it('should validate valid unstructured schema', () => {
\r
57 var jsonString ='{ "self": { "name": "CUDA Unstructured Text Example","version": "25.0.0", "description": "An example of a unstructured text used for both input and output for CUDA"}, "dataformatversion": "1.0.0","unstructured": { "encoding": "UTF-8"}}';
\r
58 expect(service.validate(jsonString)).toBe(true) ;
\r
61 it('should fail to validate invalid schema', () => {
\r
62 var jsonString = '{"testjson": "teststring"}'
\r
63 expect(service.validate(jsonString)).toBe(false) ;
\r