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 { NgModule } from '@angular/core';
\r
20 import { BrowserModule } from '@angular/platform-browser';
\r
21 import {HttpModule} from '@angular/http'; // for future
\r
22 import {FormsModule, ReactiveFormsModule} from '@angular/forms'; // for future
\r
23 import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; // for future
\r
24 import { MaterialModule } from '@angular/material';
\r
25 import { FlexLayoutModule } from '@angular/flex-layout';
\r
26 import { RouterModule, Routes } from '@angular/router';
\r
27 import { APP_BASE_HREF } from '@angular/common';
\r
29 import {ValidateMetaSchemaService} from './validate-metaschema.service';
\r
30 import {ValidateJSONService} from './validate-json.service';
\r
31 import {MetaSchemaService} from './metaschema.service';
\r
32 import {DFSchemaComponent} from './df-schema.component';
\r
36 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
\r
37 import { By } from '@angular/platform-browser';
\r
38 import { DebugElement } from '@angular/core';
\r
40 describe('DFSchemaComponent Tests', function () {
\r
41 let de: DebugElement;
\r
42 let comp: DFSchemaComponent;
\r
43 let fixture: ComponentFixture<DFSchemaComponent>;
\r
45 beforeEach(async(() => {
\r
46 TestBed.configureTestingModule({
\r
47 imports: [ BrowserModule,
\r
48 BrowserAnimationsModule,
\r
51 ReactiveFormsModule,
\r
56 providers: [{provide: APP_BASE_HREF, useValue: '/'},
\r
57 ValidateMetaSchemaService,
\r
58 ValidateJSONService,
\r
66 .compileComponents();
\r
70 fixture = TestBed.createComponent(DFSchemaComponent);
\r
71 comp = fixture.componentInstance;
\r
72 //de = fixture.debugElement.query(By.css('h1'));
\r
75 it('should create component', () => expect(comp).toBeDefined() );
\r
77 it('should have no metaschema display as default', () => {
\r
78 expect(comp.metaButton).toMatch('Display MetaSchema');
\r
80 it('should metaschema display after toggle', () => {
\r
81 comp.toggleMetaSchema();
\r
82 expect(comp.metaButton).toMatch('Hide MetaSchema');
\r
84 it('should validate valid schema', () => {
\r
85 let ev = {target: {name: "test", value: '{"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
86 comp.doDFSchemaChange(ev);
\r
87 expect(comp.schemaMsg).toMatch("Valid Data Format Schema") ;
\r
89 it('should not validate an invalid schema', () => {
\r
90 let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"}, "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
\r
91 comp.doDFSchemaChange(ev);
\r
92 expect(comp.schemaMsg).toMatch("Invalid Data Format Schema:") ;
\r
94 it('jsonschema must be 04 or 06 schema', () => {
\r
95 let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"}, "jsonschema": { "$schema": "http://json-schema.org/draft-05/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
\r
96 comp.doDFSchemaChange(ev);
\r
97 expect(comp.schemaMsg).toMatch(/Invalid JSON Schema Data Format - jsonschema\$schema version must be 04 or 06/) ;
\r