http://git-wip-us.apache.org/repos/asf/metron/blob/0c4c622b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts index 647e02f..1ba297c 100644 --- a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts +++ b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts @@ -15,30 +15,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {Component, OnInit, ViewChild} from '@angular/core'; -import {FormGroup, Validators, FormControl} from '@angular/forms'; -import {SensorParserConfig} from '../../model/sensor-parser-config'; -import {SensorParserConfigService} from '../../service/sensor-parser-config.service'; -import {Router, ActivatedRoute} from '@angular/router'; -import {MetronAlerts} from '../../shared/metron-alerts'; -import {SensorParserContext} from '../../model/sensor-parser-context'; -import {SensorEnrichmentConfigService} from '../../service/sensor-enrichment-config.service'; -import {SensorEnrichmentConfig} from '../../model/sensor-enrichment-config'; -import {SensorFieldSchemaComponent} from '../sensor-field-schema/sensor-field-schema.component'; -import {SensorRawJsonComponent} from '../sensor-raw-json/sensor-raw-json.component'; -import {KafkaService} from '../../service/kafka.service'; -import {SensorIndexingConfigService} from '../../service/sensor-indexing-config.service'; -import {IndexingConfigurations} from '../../model/sensor-indexing-config'; -import {RestError} from '../../model/rest-error'; -import {HdfsService} from '../../service/hdfs.service'; -import {GrokValidationService} from '../../service/grok-validation.service'; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { FormGroup, Validators, FormControl } from '@angular/forms'; +import { SensorParserConfig } from '../../model/sensor-parser-config'; +import { SensorParserConfigService } from '../../service/sensor-parser-config.service'; +import { Router, ActivatedRoute } from '@angular/router'; +import { MetronAlerts } from '../../shared/metron-alerts'; +import { SensorParserContext } from '../../model/sensor-parser-context'; +import { SensorEnrichmentConfigService } from '../../service/sensor-enrichment-config.service'; +import { SensorEnrichmentConfig } from '../../model/sensor-enrichment-config'; +import { SensorFieldSchemaComponent } from '../sensor-field-schema/sensor-field-schema.component'; +import { SensorRawJsonComponent } from '../sensor-raw-json/sensor-raw-json.component'; +import { KafkaService } from '../../service/kafka.service'; +import { SensorIndexingConfigService } from '../../service/sensor-indexing-config.service'; +import { IndexingConfigurations } from '../../model/sensor-indexing-config'; +import { RestError } from '../../model/rest-error'; +import { HdfsService } from '../../service/hdfs.service'; +import { GrokValidationService } from '../../service/grok-validation.service'; export enum Pane { - GROK, RAWJSON, FIELDSCHEMA, THREATTRIAGE, STORMSETTINGS + GROK, + RAWJSON, + FIELDSCHEMA, + THREATTRIAGE, + STORMSETTINGS } export enum KafkaStatus { - NO_TOPIC, NOT_EMITTING, EMITTING + NO_TOPIC, + NOT_EMITTING, + EMITTING } @Component({ @@ -46,9 +52,7 @@ export enum KafkaStatus { templateUrl: 'sensor-parser-config.component.html', styleUrls: ['sensor-parser-config.component.scss'] }) - export class SensorParserConfigComponent implements OnInit { - sensorConfigForm: FormGroup; transformsValidationForm: FormGroup; @@ -73,7 +77,7 @@ export class SensorParserConfigComponent implements OnInit { grokStatementValid = false; availableParsers = {}; availableParserNames = []; - grokStatement = ''; + grokStatement = {}; patternLabel = ''; currentSensors = []; @@ -81,7 +85,10 @@ export class SensorParserConfigComponent implements OnInit { topicExists: boolean = false; - transformsValidationResult: {map: any, keys: string[]} = {map: {}, keys: []}; + transformsValidationResult: { map: any; keys: string[] } = { + map: {}, + keys: [] + }; transformsValidation: SensorParserContext = new SensorParserContext(); pane = Pane; @@ -90,65 +97,94 @@ export class SensorParserConfigComponent implements OnInit { kafkaStatus = KafkaStatus; currentKafkaStatus = null; - @ViewChild(SensorFieldSchemaComponent) sensorFieldSchema: SensorFieldSchemaComponent; - @ViewChild(SensorRawJsonComponent) sensorRawJson: SensorRawJsonComponent; - - constructor(private sensorParserConfigService: SensorParserConfigService, private metronAlerts: MetronAlerts, - private sensorEnrichmentConfigService: SensorEnrichmentConfigService, private route: ActivatedRoute, - private sensorIndexingConfigService: SensorIndexingConfigService, private grokValidationService: GrokValidationService, - private router: Router, private kafkaService: KafkaService, private hdfsService: HdfsService) { + @ViewChild(SensorFieldSchemaComponent) + sensorFieldSchema: SensorFieldSchemaComponent; + @ViewChild(SensorRawJsonComponent) + sensorRawJson: SensorRawJsonComponent; + + constructor( + private sensorParserConfigService: SensorParserConfigService, + private metronAlerts: MetronAlerts, + private sensorEnrichmentConfigService: SensorEnrichmentConfigService, + private route: ActivatedRoute, + private sensorIndexingConfigService: SensorIndexingConfigService, + private grokValidationService: GrokValidationService, + private router: Router, + private kafkaService: KafkaService, + private hdfsService: HdfsService + ) { this.sensorParserConfig.parserConfig = {}; } - init(id: string): void { if (id !== 'new') { this.editMode = true; this.sensorName = id; - this.sensorParserConfigService.get(id).subscribe((results: SensorParserConfig) => { - this.sensorParserConfig = results; - this.sensorNameValid = true; - this.getKafkaStatus(); - if (Object.keys(this.sensorParserConfig.parserConfig).length > 0) { - this.showAdvancedParserConfiguration = true; - } - if (this.isGrokParser(this.sensorParserConfig)) { - let path = this.sensorParserConfig.parserConfig['grokPath']; - if (path) { - this.hdfsService.read(path).subscribe(contents => { - this.grokStatement = contents; - }, (hdfsError: RestError) => { - this.grokValidationService.getStatement(path).subscribe(contents => { - this.grokStatement = contents; - }, (grokError: RestError) => { - this.metronAlerts.showErrorMessage('Could not find grok statement in HDFS or classpath at ' + path); - }); - }); + this.sensorParserConfigService + .get(id) + .subscribe((results: SensorParserConfig) => { + this.sensorParserConfig = results; + this.sensorNameValid = true; + this.getKafkaStatus(); + if (Object.keys(this.sensorParserConfig.parserConfig).length > 0) { + this.showAdvancedParserConfiguration = true; } - let patternLabel = this.sensorParserConfig.parserConfig['patternLabel']; - if (patternLabel) { - this.patternLabel = patternLabel; + if (this.isGrokParser(this.sensorParserConfig)) { + let path = this.sensorParserConfig.parserConfig['grokPath']; + if (path) { + this.hdfsService.read(path).subscribe( + contents => { + this.grokStatement = contents; + }, + (hdfsError: RestError) => { + this.grokValidationService.getStatement(path).subscribe( + contents => { + this.grokStatement = contents; + }, + (grokError: RestError) => { + this.metronAlerts.showErrorMessage( + 'Could not find grok statement in HDFS or classpath at ' + + path + ); + } + ); + } + ); + } + let patternLabel = this.sensorParserConfig.parserConfig[ + 'patternLabel' + ]; + if (patternLabel) { + this.patternLabel = patternLabel; + } } - }}); + }); - this.sensorEnrichmentConfigService.get(id).subscribe((result: SensorEnrichmentConfig) => { - this.sensorEnrichmentConfig = result; - }, (error: RestError) => { - if (error.responseCode !== 404) { - this.metronAlerts.showErrorMessage(error.message); + this.sensorEnrichmentConfigService.get(id).subscribe( + (result: SensorEnrichmentConfig) => { + this.sensorEnrichmentConfig = result; + }, + (error: RestError) => { + if (error.status !== 404) { + this.metronAlerts.showErrorMessage(error.message); + } } - }); - - this.sensorIndexingConfigService.get(id).subscribe((result: IndexingConfigurations) => { - this.indexingConfigurations = result; - }, (error: RestError) => { - if (error.responseCode !== 404) { - this.metronAlerts.showErrorMessage(error.message); + ); + + this.sensorIndexingConfigService.get(id).subscribe( + (result: IndexingConfigurations) => { + this.indexingConfigurations = result; + }, + (error: RestError) => { + if (error.status !== 404) { + this.metronAlerts.showErrorMessage(error.message); + } } - }); + ); } else { this.sensorParserConfig = new SensorParserConfig(); - this.sensorParserConfig.parserClassName = 'org.apache.metron.parsers.GrokParser'; + this.sensorParserConfig.parserClassName = + 'org.apache.metron.parsers.GrokParser'; this.sensorParserConfigService.getAll().subscribe((results: {}) => { this.currentSensors = Object.keys(results); }); @@ -168,21 +204,56 @@ export class SensorParserConfigComponent implements OnInit { let group: any = {}; group['sensorName'] = new FormControl(this.sensorName, Validators.required); - group['sensorTopic'] = new FormControl(this.sensorParserConfig.sensorTopic, Validators.required); - group['parserClassName'] = new FormControl(this.sensorParserConfig.parserClassName, Validators.required); + group['sensorTopic'] = new FormControl( + this.sensorParserConfig.sensorTopic, + Validators.required + ); + group['parserClassName'] = new FormControl( + this.sensorParserConfig.parserClassName, + Validators.required + ); group['grokStatement'] = new FormControl(this.grokStatement); - group['transforms'] = new FormControl(this.sensorParserConfig['transforms']); + group['transforms'] = new FormControl( + this.sensorParserConfig['transforms'] + ); group['stellar'] = new FormControl(this.sensorParserConfig); group['threatTriage'] = new FormControl(this.sensorEnrichmentConfig); - group['hdfsIndex'] = new FormControl(this.indexingConfigurations.hdfs.index, Validators.required); - group['hdfsBatchSize'] = new FormControl(this.indexingConfigurations.hdfs.batchSize, Validators.required); - group['hdfsEnabled'] = new FormControl(this.indexingConfigurations.hdfs.enabled, Validators.required); - group['elasticsearchIndex'] = new FormControl(this.indexingConfigurations.elasticsearch.index, Validators.required); - group['elasticsearchBatchSize'] = new FormControl(this.indexingConfigurations.elasticsearch.batchSize, Validators.required); - group['elasticsearchEnabled'] = new FormControl(this.indexingConfigurations.elasticsearch.enabled, Validators.required); - group['solrIndex'] = new FormControl(this.indexingConfigurations.solr.index, Validators.required); - group['solrBatchSize'] = new FormControl(this.indexingConfigurations.solr.batchSize, Validators.required); - group['solrEnabled'] = new FormControl(this.indexingConfigurations.solr.enabled, Validators.required); + group['hdfsIndex'] = new FormControl( + this.indexingConfigurations.hdfs.index, + Validators.required + ); + group['hdfsBatchSize'] = new FormControl( + this.indexingConfigurations.hdfs.batchSize, + Validators.required + ); + group['hdfsEnabled'] = new FormControl( + this.indexingConfigurations.hdfs.enabled, + Validators.required + ); + group['elasticsearchIndex'] = new FormControl( + this.indexingConfigurations.elasticsearch.index, + Validators.required + ); + group['elasticsearchBatchSize'] = new FormControl( + this.indexingConfigurations.elasticsearch.batchSize, + Validators.required + ); + group['elasticsearchEnabled'] = new FormControl( + this.indexingConfigurations.elasticsearch.enabled, + Validators.required + ); + group['solrIndex'] = new FormControl( + this.indexingConfigurations.solr.index, + Validators.required + ); + group['solrBatchSize'] = new FormControl( + this.indexingConfigurations.solr.batchSize, + Validators.required + ); + group['solrEnabled'] = new FormControl( + this.indexingConfigurations.solr.enabled, + Validators.required + ); return new FormGroup(group); } @@ -190,8 +261,14 @@ export class SensorParserConfigComponent implements OnInit { createTransformsValidationForm(): FormGroup { let group: any = {}; - group['sampleData'] = new FormControl(this.transformsValidation.sampleData, Validators.required); - group['sensorParserConfig'] = new FormControl(this.transformsValidation.sensorParserConfig, Validators.required); + group['sampleData'] = new FormControl( + this.transformsValidation.sampleData, + Validators.required + ); + group['sensorParserConfig'] = new FormControl( + this.transformsValidation.sensorParserConfig, + Validators.required + ); return new FormGroup(group); } @@ -205,12 +282,12 @@ export class SensorParserConfigComponent implements OnInit { } getAvailableParsers() { - this.sensorParserConfigService.getAvailableParsers().subscribe( - availableParsers => { + this.sensorParserConfigService + .getAvailableParsers() + .subscribe(availableParsers => { this.availableParsers = availableParsers; this.availableParserNames = Object.keys(availableParsers); - } - ); + }); } getMessagePrefix(): string { @@ -219,14 +296,17 @@ export class SensorParserConfigComponent implements OnInit { onSetSensorName(): void { this.sensorNameUnique = this.currentSensors.indexOf(this.sensorName) === -1; - this.sensorNameValid = this.sensorName !== undefined && - this.sensorName.length > 0 && this.sensorNameUnique; + this.sensorNameValid = + this.sensorName !== undefined && + this.sensorName.length > 0 && + this.sensorNameUnique; this.isConfigValid(); } onSetKafkaTopic(): void { - this.kafkaTopicValid = this.sensorParserConfig.sensorTopic !== undefined && - /[a-zA-Z0-9._-]+$/.test(this.sensorParserConfig.sensorTopic); + this.kafkaTopicValid = + this.sensorParserConfig.sensorTopic !== undefined && + /[a-zA-Z0-9._-]+$/.test(this.sensorParserConfig.sensorTopic); if (this.kafkaTopicValid) { this.getKafkaStatus(); } @@ -234,8 +314,9 @@ export class SensorParserConfigComponent implements OnInit { } onParserTypeChange(): void { - this.parserClassValid = this.sensorParserConfig.parserClassName !== undefined && - this.sensorParserConfig.parserClassName.length > 0; + this.parserClassValid = + this.sensorParserConfig.parserClassName !== undefined && + this.sensorParserConfig.parserClassName.length > 0; if (this.parserClassValid) { if (this.isGrokParser(this.sensorParserConfig)) { } else { @@ -246,34 +327,48 @@ export class SensorParserConfigComponent implements OnInit { } onGrokStatementChange(): void { - this.grokStatementValid = this.grokStatement !== undefined && - this.grokStatement.length > 0; + this.grokStatementValid = + this.grokStatement !== undefined && + Object.keys(this.grokStatement).length > 0; this.isConfigValid(); } isConfigValid() { let isGrokParser = this.isGrokParser(this.sensorParserConfig); - this.configValid = this.sensorNameValid && this.kafkaTopicValid && this.parserClassValid && (!isGrokParser || this.grokStatementValid); + this.configValid = + this.sensorNameValid && + this.kafkaTopicValid && + this.parserClassValid && + (!isGrokParser || this.grokStatementValid); } getKafkaStatus() { - if (!this.sensorParserConfig.sensorTopic || this.sensorParserConfig.sensorTopic.length === 0) { + if ( + !this.sensorParserConfig.sensorTopic || + this.sensorParserConfig.sensorTopic.length === 0 + ) { this.currentKafkaStatus = null; return; } - this.kafkaService.get(this.sensorParserConfig.sensorTopic).subscribe(kafkaTopic => { - this.kafkaService.sample(this.sensorParserConfig.sensorTopic).subscribe((sampleData: string) => { - this.currentKafkaStatus = (sampleData && sampleData.length > 0) ? KafkaStatus.EMITTING : KafkaStatus.NOT_EMITTING; + this.kafkaService.get(this.sensorParserConfig.sensorTopic).subscribe( + kafkaTopic => { + this.kafkaService.sample(this.sensorParserConfig.sensorTopic).subscribe( + (sampleData: string) => { + this.currentKafkaStatus = + sampleData && sampleData.length > 0 + ? KafkaStatus.EMITTING + : KafkaStatus.NOT_EMITTING; + }, + error => { + this.currentKafkaStatus = KafkaStatus.NOT_EMITTING; + } + ); }, error => { - this.currentKafkaStatus = KafkaStatus.NOT_EMITTING; - }); - }, - error => { - this.currentKafkaStatus = KafkaStatus.NO_TOPIC; - }); - + this.currentKafkaStatus = KafkaStatus.NO_TOPIC; + } + ); } getTransforms(): string { @@ -298,7 +393,8 @@ export class SensorParserConfigComponent implements OnInit { this.grokStatement = grokStatement; let grokPath = this.sensorParserConfig.parserConfig['grokPath']; if (!grokPath || grokPath.indexOf('/patterns') === 0) { - this.sensorParserConfig.parserConfig['grokPath'] = '/apps/metron/patterns/' + this.sensorName; + this.sensorParserConfig.parserConfig['grokPath'] = + '/apps/metron/patterns/' + this.sensorName; } } @@ -317,42 +413,76 @@ export class SensorParserConfigComponent implements OnInit { if (!this.indexingConfigurations.solr.index) { this.indexingConfigurations.solr.index = this.sensorName; } - this.sensorParserConfigService.post(this.sensorName, this.sensorParserConfig).subscribe( - sensorParserConfig => { - if (this.isGrokParser(sensorParserConfig)) { - this.hdfsService.post(this.sensorParserConfig.parserConfig['grokPath'], this.grokStatement).subscribe( - response => {}, (error: RestError) => this.metronAlerts.showErrorMessage(error.message)); + this.sensorParserConfigService + .post(this.sensorName, this.sensorParserConfig) + .subscribe( + sensorParserConfig => { + if (this.isGrokParser(sensorParserConfig)) { + this.hdfsService + .post( + this.sensorParserConfig.parserConfig['grokPath'], + this.grokStatement.toString() + ) + .subscribe( + response => {}, + (error: RestError) => + this.metronAlerts.showErrorMessage(error.message) + ); + } + this.sensorEnrichmentConfigService + .post(this.sensorName, this.sensorEnrichmentConfig) + .subscribe( + (sensorEnrichmentConfig: SensorEnrichmentConfig) => {}, + (error: RestError) => { + let msg = + ' Sensor parser config but unable to save enrichment configuration: '; + this.metronAlerts.showErrorMessage( + this.getMessagePrefix() + msg + error.message + ); + } + ); + this.sensorIndexingConfigService + .post(this.sensorName, this.indexingConfigurations) + .subscribe( + (indexingConfigurations: IndexingConfigurations) => {}, + (error: RestError) => { + let msg = + ' Sensor parser config but unable to save indexing configuration: '; + this.metronAlerts.showErrorMessage( + this.getMessagePrefix() + msg + error.message + ); + } + ); + this.metronAlerts.showSuccessMessage( + this.getMessagePrefix() + ' Sensor ' + this.sensorName + ); + this.sensorParserConfigService.dataChangedSource.next([ + this.sensorName + ]); + this.goBack(); + }, + (error: RestError) => { + this.metronAlerts.showErrorMessage( + 'Unable to save sensor config: ' + error.message + ); } - this.sensorEnrichmentConfigService.post(this.sensorName, this.sensorEnrichmentConfig).subscribe( - (sensorEnrichmentConfig: SensorEnrichmentConfig) => { - }, (error: RestError) => { - let msg = ' Sensor parser config but unable to save enrichment configuration: '; - this.metronAlerts.showErrorMessage(this.getMessagePrefix() + msg + error.message); - }); - this.sensorIndexingConfigService.post(this.sensorName, this.indexingConfigurations).subscribe( - (indexingConfigurations: IndexingConfigurations) => { - }, (error: RestError) => { - let msg = ' Sensor parser config but unable to save indexing configuration: '; - this.metronAlerts.showErrorMessage(this.getMessagePrefix() + msg + error.message); - }); - this.metronAlerts.showSuccessMessage(this.getMessagePrefix() + ' Sensor ' + this.sensorName); - this.sensorParserConfigService.dataChangedSource.next([this.sensorName]); - this.goBack(); - }, (error: RestError) => { - this.metronAlerts.showErrorMessage('Unable to save sensor config: ' + error.message); - }); + ); } isGrokParser(sensorParserConfig: SensorParserConfig): boolean { if (sensorParserConfig && sensorParserConfig.parserClassName) { - return sensorParserConfig.parserClassName === 'org.apache.metron.parsers.GrokParser'; + return ( + sensorParserConfig.parserClassName === + 'org.apache.metron.parsers.GrokParser' + ); } return false; } getTransformationCount(): number { - let stellarTransformations = this.sensorParserConfig.fieldTransformations.filter(fieldTransformer => - fieldTransformer.transformation === 'STELLAR'); + let stellarTransformations = this.sensorParserConfig.fieldTransformations.filter( + fieldTransformer => fieldTransformer.transformation === 'STELLAR' + ); if (stellarTransformations.length > 0 && stellarTransformations[0].config) { return Object.keys(stellarTransformations[0].config).length; } else { @@ -365,14 +495,22 @@ export class SensorParserConfigComponent implements OnInit { if (this.sensorEnrichmentConfig.enrichment.fieldMap) { for (let enrichment in this.sensorEnrichmentConfig.enrichment.fieldMap) { if (enrichment !== 'hbaseEnrichment' && enrichment !== 'stellar') { - count += this.sensorEnrichmentConfig.enrichment.fieldMap[enrichment].length; + count += this.sensorEnrichmentConfig.enrichment.fieldMap[enrichment] + .length; } } } if (this.sensorEnrichmentConfig.enrichment.fieldToTypeMap) { - for (let fieldName in this.sensorEnrichmentConfig.enrichment.fieldToTypeMap) { - if (this.sensorEnrichmentConfig.enrichment.fieldToTypeMap.hasOwnProperty(fieldName)) { - count += this.sensorEnrichmentConfig.enrichment.fieldToTypeMap[fieldName].length; + for (let fieldName in this.sensorEnrichmentConfig.enrichment + .fieldToTypeMap) { + if ( + this.sensorEnrichmentConfig.enrichment.fieldToTypeMap.hasOwnProperty( + fieldName + ) + ) { + count += this.sensorEnrichmentConfig.enrichment.fieldToTypeMap[ + fieldName + ].length; } } } @@ -382,9 +520,16 @@ export class SensorParserConfigComponent implements OnInit { getThreatIntelCount(): number { let count = 0; if (this.sensorEnrichmentConfig.threatIntel.fieldToTypeMap) { - for (let fieldName in this.sensorEnrichmentConfig.threatIntel.fieldToTypeMap) { - if (this.sensorEnrichmentConfig.threatIntel.fieldToTypeMap.hasOwnProperty(fieldName)) { - count += this.sensorEnrichmentConfig.threatIntel.fieldToTypeMap[fieldName].length; + for (let fieldName in this.sensorEnrichmentConfig.threatIntel + .fieldToTypeMap) { + if ( + this.sensorEnrichmentConfig.threatIntel.fieldToTypeMap.hasOwnProperty( + fieldName + ) + ) { + count += this.sensorEnrichmentConfig.threatIntel.fieldToTypeMap[ + fieldName + ].length; } } } @@ -394,7 +539,9 @@ export class SensorParserConfigComponent implements OnInit { getRuleCount(): number { let count = 0; if (this.sensorEnrichmentConfig.threatIntel.triageConfig.riskLevelRules) { - count = Object.keys(this.sensorEnrichmentConfig.threatIntel.triageConfig.riskLevelRules).length; + count = Object.keys( + this.sensorEnrichmentConfig.threatIntel.triageConfig.riskLevelRules + ).length; } return count; } @@ -415,19 +562,18 @@ export class SensorParserConfigComponent implements OnInit { } setPaneVisibility(pane: Pane, visibilty: boolean) { - this.showGrokValidator = (pane === Pane.GROK) ? visibilty : false; - this.showFieldSchema = (pane === Pane.FIELDSCHEMA) ? visibilty : false; - this.showRawJson = (pane === Pane.RAWJSON) ? visibilty : false; - this.showThreatTriage = (pane === Pane.THREATTRIAGE) ? visibilty : false; - this.showStormSettings = (pane === Pane.STORMSETTINGS) ? visibilty : false; + this.showGrokValidator = pane === Pane.GROK ? visibilty : false; + this.showFieldSchema = pane === Pane.FIELDSCHEMA ? visibilty : false; + this.showRawJson = pane === Pane.RAWJSON ? visibilty : false; + this.showThreatTriage = pane === Pane.THREATTRIAGE ? visibilty : false; + this.showStormSettings = pane === Pane.STORMSETTINGS ? visibilty : false; } onRawJsonChanged(): void { this.sensorFieldSchema.createFieldSchemaRows(); } - onStormSettingsChanged(): void { - } + onStormSettingsChanged(): void {} onAdvancedConfigFormClose(): void { this.showAdvancedParserConfiguration = false;
http://git-wip-us.apache.org/repos/asf/metron/blob/0c4c622b/metron-interface/metron-config/src/app/sensors/sensor-parser-list/sensor-parser-list.component.spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-config/src/app/sensors/sensor-parser-list/sensor-parser-list.component.spec.ts b/metron-interface/metron-config/src/app/sensors/sensor-parser-list/sensor-parser-list.component.spec.ts index fb2a175..ec07cbb 100644 --- a/metron-interface/metron-config/src/app/sensors/sensor-parser-list/sensor-parser-list.component.spec.ts +++ b/metron-interface/metron-config/src/app/sensors/sensor-parser-list/sensor-parser-list.component.spec.ts @@ -15,56 +15,62 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {async, ComponentFixture, TestBed} from '@angular/core/testing'; -import {SpyLocation} from '@angular/common/testing'; -import {Http, ResponseOptions, RequestOptions, Response} from '@angular/http'; - -import {DebugElement, Inject} from '@angular/core'; -import {By} from '@angular/platform-browser'; -import {Router, NavigationStart} from '@angular/router'; -import {Observable} from 'rxjs/Observable'; -import {SensorParserListComponent} from './sensor-parser-list.component'; -import {SensorParserConfigService} from '../../service/sensor-parser-config.service'; -import {MetronAlerts} from '../../shared/metron-alerts'; -import {TopologyStatus} from '../../model/topology-status'; -import {SensorParserConfig} from '../../model/sensor-parser-config'; -import {AuthenticationService} from '../../service/authentication.service'; -import {SensorParserListModule} from './sensor-parser-list.module'; -import {MetronDialogBox} from '../../shared/metron-dialog-box'; -import {Sort} from '../../util/enums'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { SpyLocation } from '@angular/common/testing'; +import { HttpClient, HttpResponse } from '@angular/common/http'; + +import { DebugElement, Inject } from '@angular/core'; +import { By } from '@angular/platform-browser'; +import { Router, NavigationStart } from '@angular/router'; +import { Observable } from 'rxjs'; +import { SensorParserListComponent } from './sensor-parser-list.component'; +import { SensorParserConfigService } from '../../service/sensor-parser-config.service'; +import { MetronAlerts } from '../../shared/metron-alerts'; +import { TopologyStatus } from '../../model/topology-status'; +import { SensorParserConfig } from '../../model/sensor-parser-config'; +import { AuthenticationService } from '../../service/authentication.service'; +import { SensorParserListModule } from './sensor-parser-list.module'; +import { MetronDialogBox } from '../../shared/metron-dialog-box'; +import { Sort } from '../../util/enums'; import 'jquery'; -import {SensorParserConfigHistoryService} from '../../service/sensor-parser-config-history.service'; -import {SensorParserConfigHistory} from '../../model/sensor-parser-config-history'; -import {APP_CONFIG, METRON_REST_CONFIG} from '../../app.config'; -import {StormService} from '../../service/storm.service'; -import {IAppConfig} from '../../app.config.interface'; +import { SensorParserConfigHistoryService } from '../../service/sensor-parser-config-history.service'; +import { SensorParserConfigHistory } from '../../model/sensor-parser-config-history'; +import { APP_CONFIG, METRON_REST_CONFIG } from '../../app.config'; +import { StormService } from '../../service/storm.service'; +import { IAppConfig } from '../../app.config.interface'; class MockAuthenticationService extends AuthenticationService { - - constructor(private http2: Http, private router2: Router, @Inject(APP_CONFIG) private config2: IAppConfig) { + constructor( + private http2: HttpClient, + private router2: Router, + @Inject(APP_CONFIG) private config2: IAppConfig + ) { super(http2, router2, config2); } - public checkAuthentication() { - } + public checkAuthentication() {} - public getCurrentUser(options: RequestOptions): Observable<Response> { + public getCurrentUser(options: {}): Observable<HttpResponse<{}>> { return Observable.create(observer => { - observer.next(new Response(new ResponseOptions({body: 'test'}))); + observer.next(new HttpResponse({ body: 'test' })); observer.complete(); }); } } class MockSensorParserConfigHistoryService extends SensorParserConfigHistoryService { - private allSensorParserConfigHistory: SensorParserConfigHistory[]; - constructor(private http2: Http, @Inject(APP_CONFIG) private config2: IAppConfig) { + constructor( + private http2: HttpClient, + @Inject(APP_CONFIG) private config2: IAppConfig + ) { super(http2, config2); } - public setSensorParserConfigHistoryForTest(allSensorParserConfigHistory: SensorParserConfigHistory[]) { + public setSensorParserConfigHistoryForTest( + allSensorParserConfigHistory: SensorParserConfigHistory[] + ) { this.allSensorParserConfigHistory = allSensorParserConfigHistory; } @@ -79,7 +85,10 @@ class MockSensorParserConfigHistoryService extends SensorParserConfigHistoryServ class MockSensorParserConfigService extends SensorParserConfigService { private sensorParserConfigs: {}; - constructor(private http2: Http, @Inject(APP_CONFIG) private config2: IAppConfig) { + constructor( + private http2: HttpClient, + @Inject(APP_CONFIG) private config2: IAppConfig + ) { super(http2, config2); } @@ -87,22 +96,27 @@ class MockSensorParserConfigService extends SensorParserConfigService { this.sensorParserConfigs = sensorParserConfigs; } - public getAll(): Observable<{string: SensorParserConfig}> { + public getAll(): Observable<{ string: SensorParserConfig }> { return Observable.create(observer => { observer.next(this.sensorParserConfigs); observer.complete(); }); } - public deleteSensorParserConfigs(sensorNames: string[]): Observable<{success: Array<string>, failure: Array<string>}> { - let result: {success: Array<string>, failure: Array<string>} = {success: [], failure: []}; - let observable = Observable.create((observer => { + public deleteSensorParserConfigs( + sensorNames: string[] + ): Observable<{ success: Array<string>; failure: Array<string> }> { + let result: { success: Array<string>; failure: Array<string> } = { + success: [], + failure: [] + }; + let observable = Observable.create(observer => { for (let i = 0; i < sensorNames.length; i++) { result.success.push(sensorNames[i]); } observer.next(result); observer.complete(); - })); + }); return observable; } } @@ -110,7 +124,10 @@ class MockSensorParserConfigService extends SensorParserConfigService { class MockStormService extends StormService { private topologyStatuses: TopologyStatus[]; - constructor(private http2: Http, @Inject(APP_CONFIG) private config2: IAppConfig) { + constructor( + private http2: HttpClient, + @Inject(APP_CONFIG) private config2: IAppConfig + ) { super(http2, config2); } @@ -139,12 +156,10 @@ class MockRouter { observer.complete(); }); - navigateByUrl(url: string) { - } + navigateByUrl(url: string) {} } class MockMetronDialogBox { - public showConfirmationMessage(message: string) { return Observable.create(observer => { observer.next(true); @@ -154,7 +169,6 @@ class MockMetronDialogBox { } describe('Component: SensorParserList', () => { - let comp: SensorParserListComponent; let fixture: ComponentFixture<SensorParserListComponent>; let authenticationService: MockAuthenticationService; @@ -167,43 +181,45 @@ describe('Component: SensorParserList', () => { let dialogEl: DebugElement; beforeEach(async(() => { - TestBed.configureTestingModule({ imports: [SensorParserListModule], providers: [ - {provide: Http}, - {provide: Location, useClass: SpyLocation}, - {provide: AuthenticationService, useClass: MockAuthenticationService}, - {provide: SensorParserConfigService, useClass: MockSensorParserConfigService}, - {provide: StormService, useClass: MockStormService}, - {provide: SensorParserConfigHistoryService, useClass: MockSensorParserConfigHistoryService}, - {provide: Router, useClass: MockRouter}, - {provide: MetronDialogBox, useClass: MockMetronDialogBox}, - {provide: APP_CONFIG, useValue: METRON_REST_CONFIG}, + { provide: HttpClient }, + { provide: Location, useClass: SpyLocation }, + { provide: AuthenticationService, useClass: MockAuthenticationService }, + { + provide: SensorParserConfigService, + useClass: MockSensorParserConfigService + }, + { provide: StormService, useClass: MockStormService }, + { + provide: SensorParserConfigHistoryService, + useClass: MockSensorParserConfigHistoryService + }, + { provide: Router, useClass: MockRouter }, + { provide: MetronDialogBox, useClass: MockMetronDialogBox }, + { provide: APP_CONFIG, useValue: METRON_REST_CONFIG }, MetronAlerts ] - }).compileComponents() - .then(() => { - fixture = TestBed.createComponent(SensorParserListComponent); - comp = fixture.componentInstance; - authenticationService = fixture.debugElement.injector.get(AuthenticationService); - sensorParserConfigService = fixture.debugElement.injector.get(SensorParserConfigService); - stormService = fixture.debugElement.injector.get(StormService); - sensorParserConfigHistoryService = fixture.debugElement.injector.get(SensorParserConfigHistoryService); - router = fixture.debugElement.injector.get(Router); - metronAlerts = fixture.debugElement.injector.get(MetronAlerts); - metronDialog = fixture.debugElement.injector.get(MetronDialogBox); - dialogEl = fixture.debugElement.query(By.css('.primary')); - }); - + }); + fixture = TestBed.createComponent(SensorParserListComponent); + comp = fixture.componentInstance; + authenticationService = TestBed.get(AuthenticationService); + sensorParserConfigService = TestBed.get(SensorParserConfigService); + stormService = TestBed.get(StormService); + sensorParserConfigHistoryService = TestBed.get( + SensorParserConfigHistoryService + ); + router = TestBed.get(Router); + metronAlerts = TestBed.get(MetronAlerts); + metronDialog = TestBed.get(MetronDialogBox); + dialogEl = fixture.debugElement.query(By.css('.primary')); })); it('should create an instance', async(() => { - let component: SensorParserListComponent = fixture.componentInstance; expect(component).toBeDefined(); fixture.destroy(); - })); it('getSensors should call getStatus and poll status and all variables should be initialised', async(() => { @@ -224,8 +240,14 @@ describe('Component: SensorParserList', () => { sensorParserStatus2.name = 'bro'; sensorParserStatus2.status = 'KILLED'; - sensorParserConfigService.setSensorParserConfigForTest({'squid': sensorParserConfig1, 'bro': sensorParserConfig2}); - stormService.setTopologyStatusForTest([sensorParserStatus1, sensorParserStatus2]); + sensorParserConfigService.setSensorParserConfigForTest({ + squid: sensorParserConfig1, + bro: sensorParserConfig2 + }); + stormService.setTopologyStatusForTest([ + sensorParserStatus1, + sensorParserStatus2 + ]); let component: SensorParserListComponent = fixture.componentInstance; @@ -233,33 +255,40 @@ describe('Component: SensorParserList', () => { component.ngOnInit(); - expect(component.sensors[0].sensorName).toEqual(sensorParserConfigHistory1.sensorName); - expect(component.sensors[1].sensorName).toEqual(sensorParserConfigHistory2.sensorName); - expect(component.sensorsStatus[0]).toEqual(Object.assign(new TopologyStatus(), sensorParserStatus1)); - expect(component.sensorsStatus[1]).toEqual(Object.assign(new TopologyStatus(), sensorParserStatus2)); + expect(component.sensors[0].sensorName).toEqual( + sensorParserConfigHistory1.sensorName + ); + expect(component.sensors[1].sensorName).toEqual( + sensorParserConfigHistory2.sensorName + ); + expect(component.sensorsStatus[0]).toEqual( + Object.assign(new TopologyStatus(), sensorParserStatus1) + ); + expect(component.sensorsStatus[1]).toEqual( + Object.assign(new TopologyStatus(), sensorParserStatus2) + ); expect(component.selectedSensors).toEqual([]); expect(component.count).toEqual(2); fixture.destroy(); - })); it('getParserType should return the Type of Parser', async(() => { - let component: SensorParserListComponent = fixture.componentInstance; let sensorParserConfig1 = new SensorParserConfig(); sensorParserConfig1.sensorTopic = 'squid'; - sensorParserConfig1.parserClassName = 'org.apache.metron.parsers.GrokParser'; + sensorParserConfig1.parserClassName = + 'org.apache.metron.parsers.GrokParser'; let sensorParserConfig2 = new SensorParserConfig(); sensorParserConfig2.sensorTopic = 'bro'; - sensorParserConfig2.parserClassName = 'org.apache.metron.parsers.bro.BasicBroParser'; + sensorParserConfig2.parserClassName = + 'org.apache.metron.parsers.bro.BasicBroParser'; expect(component.getParserType(sensorParserConfig1)).toEqual('Grok'); expect(component.getParserType(sensorParserConfig2)).toEqual('Bro'); fixture.destroy(); - })); it('navigateToSensorEdit should set selected sensor and change url', async(() => { @@ -295,11 +324,9 @@ describe('Component: SensorParserList', () => { fixture.destroy(); })); - it('onRowSelected should add add/remove items from the selected stack', async(() => { - let component: SensorParserListComponent = fixture.componentInstance; - let event = {target: {checked: true}}; + let event = { target: { checked: true } }; let sensorParserConfigHistory = new SensorParserConfigHistory(); let sensorParserConfig = new SensorParserConfig(); @@ -311,7 +338,7 @@ describe('Component: SensorParserList', () => { expect(component.selectedSensors[0]).toEqual(sensorParserConfigHistory); - event = {target: {checked: false}}; + event = { target: { checked: false } }; component.onRowSelected(sensorParserConfigHistory, event); expect(component.selectedSensors).toEqual([]); @@ -320,7 +347,6 @@ describe('Component: SensorParserList', () => { })); it('onSelectDeselectAll should populate items into selected stack', async(() => { - let component: SensorParserListComponent = fixture.componentInstance; let sensorParserConfig1 = new SensorParserConfig(); @@ -336,13 +362,16 @@ describe('Component: SensorParserList', () => { component.sensors.push(sensorParserConfigHistory1); component.sensors.push(sensorParserConfigHistory2); - let event = {target: {checked: true}}; + let event = { target: { checked: true } }; component.onSelectDeselectAll(event); - expect(component.selectedSensors).toEqual([sensorParserConfigHistory1, sensorParserConfigHistory2]); + expect(component.selectedSensors).toEqual([ + sensorParserConfigHistory1, + sensorParserConfigHistory2 + ]); - event = {target: {checked: false}}; + event = { target: { checked: false } }; component.onSelectDeselectAll(event); @@ -352,12 +381,13 @@ describe('Component: SensorParserList', () => { })); it('onSensorRowSelect should change the url and updated the selected items stack', async(() => { - let sensorParserConfigHistory1 = new SensorParserConfigHistory(); sensorParserConfigHistory1.sensorName = 'squid'; let component: SensorParserListComponent = fixture.componentInstance; - let event = {target: {type: 'div', parentElement: {firstChild: {type: 'div'}}}}; + let event = { + target: { type: 'div', parentElement: { firstChild: { type: 'div' } } } + }; component.selectedSensor = sensorParserConfigHistory1; component.onSensorRowSelect(sensorParserConfigHistory1, event); @@ -369,7 +399,12 @@ describe('Component: SensorParserList', () => { expect(component.selectedSensor).toEqual(sensorParserConfigHistory1); component.selectedSensor = sensorParserConfigHistory1; - event = {target: {type: 'checkbox', parentElement: {firstChild: {type: 'div'}}}}; + event = { + target: { + type: 'checkbox', + parentElement: { firstChild: { type: 'div' } } + } + }; component.onSensorRowSelect(sensorParserConfigHistory1, event); @@ -379,8 +414,7 @@ describe('Component: SensorParserList', () => { })); it('onSensorRowSelect should change the url and updated the selected items stack', async(() => { - - let component: SensorParserListComponent = fixture.componentInstance; + let component: SensorParserListComponent = fixture.componentInstance; let sensorParserConfigHistory = new SensorParserConfigHistory(); let sensorParserConfig = new SensorParserConfig(); @@ -395,15 +429,14 @@ describe('Component: SensorParserList', () => { expect(sensorParserConfig['startStopInProgress']).toEqual(false); })); - it('onDeleteSensor should call the appropriate url', async(() => { - + it('onDeleteSensor should call the appropriate url', async(() => { spyOn(metronAlerts, 'showSuccessMessage'); spyOn(metronDialog, 'showConfirmationMessage').and.callThrough(); let event = new Event('mouse'); event.stopPropagation = jasmine.createSpy('stopPropagation'); - let component: SensorParserListComponent = fixture.componentInstance; + let component: SensorParserListComponent = fixture.componentInstance; let sensorParserConfigHistory1 = new SensorParserConfigHistory(); let sensorParserConfigHistory2 = new SensorParserConfigHistory(); let sensorParserConfig1 = new SensorParserConfig(); @@ -426,13 +459,16 @@ describe('Component: SensorParserList', () => { expect(metronDialog.showConfirmationMessage).toHaveBeenCalled(); expect(metronDialog.showConfirmationMessage['calls'].count()).toEqual(2); expect(metronDialog.showConfirmationMessage['calls'].count()).toEqual(2); - expect(metronDialog.showConfirmationMessage['calls'].all()[0].args).toEqual(['Are you sure you want to delete sensor(s) squid, bro ?']); - expect(metronDialog.showConfirmationMessage['calls'].all()[1].args).toEqual(['Are you sure you want to delete sensor(s) squid ?']); + expect(metronDialog.showConfirmationMessage['calls'].all()[0].args).toEqual( + ['Are you sure you want to delete sensor(s) squid, bro ?'] + ); + expect(metronDialog.showConfirmationMessage['calls'].all()[1].args).toEqual( + ['Are you sure you want to delete sensor(s) squid ?'] + ); expect(event.stopPropagation).toHaveBeenCalled(); fixture.destroy(); - })); it('onStopSensor should call the appropriate url', async(() => { @@ -446,7 +482,7 @@ describe('Component: SensorParserList', () => { sensorParserConfigHistory1.config = sensorParserConfig1; let observableToReturn = Observable.create(observer => { - observer.next({status: 'success', message: 'Some Message'}); + observer.next({ status: 'success', message: 'Some Message' }); observer.complete(); }); @@ -475,7 +511,7 @@ describe('Component: SensorParserList', () => { sensorParserConfigHistory1.config = sensorParserConfig1; let observableToReturn = Observable.create(observer => { - observer.next({status: 'success', message: 'Some Message'}); + observer.next({ status: 'success', message: 'Some Message' }); observer.complete(); }); @@ -504,7 +540,7 @@ describe('Component: SensorParserList', () => { sensorParserConfigHistory1.config = sensorParserConfig1; let observableToReturn = Observable.create(observer => { - observer.next({status: 'success', message: 'Some Message'}); + observer.next({ status: 'success', message: 'Some Message' }); observer.complete(); }); @@ -533,7 +569,7 @@ describe('Component: SensorParserList', () => { sensorParserConfigHistory1.config = sensorParserConfig1; let observableToReturn = Observable.create(observer => { - observer.next({status: 'success', message: 'Some Message'}); + observer.next({ status: 'success', message: 'Some Message' }); observer.complete(); }); @@ -551,146 +587,167 @@ describe('Component: SensorParserList', () => { fixture.destroy(); })); - it('onStartSensors/onStopSensors should call start on all sensors that have status != ' + - 'Running and status != Running respectively', async(() => { - let component: SensorParserListComponent = fixture.componentInstance; - - spyOn(component, 'onStartSensor'); - spyOn(component, 'onStopSensor'); - spyOn(component, 'onDisableSensor'); - spyOn(component, 'onEnableSensor'); - - let sensorParserConfigHistory1 = new SensorParserConfigHistory(); - let sensorParserConfigHistory2 = new SensorParserConfigHistory(); - let sensorParserConfigHistory3 = new SensorParserConfigHistory(); - let sensorParserConfigHistory4 = new SensorParserConfigHistory(); - let sensorParserConfigHistory5 = new SensorParserConfigHistory(); - let sensorParserConfigHistory6 = new SensorParserConfigHistory(); - let sensorParserConfigHistory7 = new SensorParserConfigHistory(); - - let sensorParserConfig1 = new SensorParserConfig(); - let sensorParserConfig2 = new SensorParserConfig(); - let sensorParserConfig3 = new SensorParserConfig(); - let sensorParserConfig4 = new SensorParserConfig(); - let sensorParserConfig5 = new SensorParserConfig(); - let sensorParserConfig6 = new SensorParserConfig(); - let sensorParserConfig7 = new SensorParserConfig(); - - sensorParserConfig1.sensorTopic = 'squid'; - sensorParserConfigHistory1['status'] = 'Running'; - sensorParserConfigHistory1.config = sensorParserConfig1; - - sensorParserConfig2.sensorTopic = 'bro'; - sensorParserConfigHistory2['status'] = 'Stopped'; - sensorParserConfigHistory2.config = sensorParserConfig2; - - sensorParserConfig3.sensorTopic = 'test'; - sensorParserConfigHistory3['status'] = 'Stopped'; - sensorParserConfigHistory3.config = sensorParserConfig3; - - sensorParserConfig4.sensorTopic = 'test1'; - sensorParserConfigHistory4['status'] = 'Stopped'; - sensorParserConfigHistory4.config = sensorParserConfig4; - - sensorParserConfig5.sensorTopic = 'test2'; - sensorParserConfigHistory5['status'] = 'Running'; - sensorParserConfigHistory5.config = sensorParserConfig5; - - sensorParserConfig6.sensorTopic = 'test2'; - sensorParserConfigHistory6['status'] = 'Disabled'; - sensorParserConfigHistory6.config = sensorParserConfig6; - - sensorParserConfig7.sensorTopic = 'test3'; - sensorParserConfigHistory7['status'] = 'Disabled'; - sensorParserConfigHistory7.config = sensorParserConfig7; - - component.selectedSensors = [sensorParserConfigHistory1, sensorParserConfigHistory2, sensorParserConfigHistory3, - sensorParserConfigHistory4, sensorParserConfigHistory5, sensorParserConfigHistory6, sensorParserConfigHistory7]; - - component.onStartSensors(); - expect(component.onStartSensor['calls'].count()).toEqual(3); - - component.onStopSensors(); - expect(component.onStopSensor['calls'].count()).toEqual(4); - - component.onDisableSensors(); - expect(component.onDisableSensor['calls'].count()).toEqual(2); - - component.onEnableSensors(); - expect(component.onEnableSensor['calls'].count()).toEqual(2); - - fixture.destroy(); - })); + it( + 'onStartSensors/onStopSensors should call start on all sensors that have status != ' + + 'Running and status != Running respectively', + async(() => { + let component: SensorParserListComponent = fixture.componentInstance; + + spyOn(component, 'onStartSensor'); + spyOn(component, 'onStopSensor'); + spyOn(component, 'onDisableSensor'); + spyOn(component, 'onEnableSensor'); + + let sensorParserConfigHistory1 = new SensorParserConfigHistory(); + let sensorParserConfigHistory2 = new SensorParserConfigHistory(); + let sensorParserConfigHistory3 = new SensorParserConfigHistory(); + let sensorParserConfigHistory4 = new SensorParserConfigHistory(); + let sensorParserConfigHistory5 = new SensorParserConfigHistory(); + let sensorParserConfigHistory6 = new SensorParserConfigHistory(); + let sensorParserConfigHistory7 = new SensorParserConfigHistory(); + + let sensorParserConfig1 = new SensorParserConfig(); + let sensorParserConfig2 = new SensorParserConfig(); + let sensorParserConfig3 = new SensorParserConfig(); + let sensorParserConfig4 = new SensorParserConfig(); + let sensorParserConfig5 = new SensorParserConfig(); + let sensorParserConfig6 = new SensorParserConfig(); + let sensorParserConfig7 = new SensorParserConfig(); + + sensorParserConfig1.sensorTopic = 'squid'; + sensorParserConfigHistory1['status'] = 'Running'; + sensorParserConfigHistory1.config = sensorParserConfig1; + + sensorParserConfig2.sensorTopic = 'bro'; + sensorParserConfigHistory2['status'] = 'Stopped'; + sensorParserConfigHistory2.config = sensorParserConfig2; + + sensorParserConfig3.sensorTopic = 'test'; + sensorParserConfigHistory3['status'] = 'Stopped'; + sensorParserConfigHistory3.config = sensorParserConfig3; + + sensorParserConfig4.sensorTopic = 'test1'; + sensorParserConfigHistory4['status'] = 'Stopped'; + sensorParserConfigHistory4.config = sensorParserConfig4; + + sensorParserConfig5.sensorTopic = 'test2'; + sensorParserConfigHistory5['status'] = 'Running'; + sensorParserConfigHistory5.config = sensorParserConfig5; + + sensorParserConfig6.sensorTopic = 'test2'; + sensorParserConfigHistory6['status'] = 'Disabled'; + sensorParserConfigHistory6.config = sensorParserConfig6; + + sensorParserConfig7.sensorTopic = 'test3'; + sensorParserConfigHistory7['status'] = 'Disabled'; + sensorParserConfigHistory7.config = sensorParserConfig7; + + component.selectedSensors = [ + sensorParserConfigHistory1, + sensorParserConfigHistory2, + sensorParserConfigHistory3, + sensorParserConfigHistory4, + sensorParserConfigHistory5, + sensorParserConfigHistory6, + sensorParserConfigHistory7 + ]; + + component.onStartSensors(); + expect(component.onStartSensor['calls'].count()).toEqual(3); + + component.onStopSensors(); + expect(component.onStopSensor['calls'].count()).toEqual(4); + + component.onDisableSensors(); + expect(component.onDisableSensor['calls'].count()).toEqual(2); + + component.onEnableSensors(); + expect(component.onEnableSensor['calls'].count()).toEqual(2); + + fixture.destroy(); + }) + ); it('sort', async(() => { let component: SensorParserListComponent = fixture.componentInstance; component.sensors = [ Object.assign(new SensorParserConfigHistory(), { - 'sensorName': 'abc', - 'config': { - 'parserClassName': 'org.apache.metron.parsers.GrokParser', - 'sensorTopic': 'abc', + sensorName: 'abc', + config: { + parserClassName: 'org.apache.metron.parsers.GrokParser', + sensorTopic: 'abc' }, - 'createdBy': 'raghu', - 'modifiedBy': 'abc', - 'createdDate': '2016-11-25 09:09:12', - 'modifiedByDate': '2016-11-25 09:09:12' + createdBy: 'raghu', + modifiedBy: 'abc', + createdDate: '2016-11-25 09:09:12', + modifiedByDate: '2016-11-25 09:09:12' }), Object.assign(new SensorParserConfigHistory(), { - 'sensorName': 'plm', - 'config': { - 'parserClassName': 'org.apache.metron.parsers.Bro', - 'sensorTopic': 'plm', + sensorName: 'plm', + config: { + parserClassName: 'org.apache.metron.parsers.Bro', + sensorTopic: 'plm' }, - 'createdBy': 'raghu', - 'modifiedBy': 'plm', - 'createdDate': '2016-11-25 12:39:21', - 'modifiedByDate': '2016-11-25 12:39:21' + createdBy: 'raghu', + modifiedBy: 'plm', + createdDate: '2016-11-25 12:39:21', + modifiedByDate: '2016-11-25 12:39:21' }), Object.assign(new SensorParserConfigHistory(), { - 'sensorName': 'xyz', - 'config': { - 'parserClassName': 'org.apache.metron.parsers.GrokParser', - 'sensorTopic': 'xyz', + sensorName: 'xyz', + config: { + parserClassName: 'org.apache.metron.parsers.GrokParser', + sensorTopic: 'xyz' }, - 'createdBy': 'raghu', - 'modifiedBy': 'xyz', - 'createdDate': '2016-11-25 12:44:03', - 'modifiedByDate': '2016-11-25 12:44:03' + createdBy: 'raghu', + modifiedBy: 'xyz', + createdDate: '2016-11-25 12:44:03', + modifiedByDate: '2016-11-25 12:44:03' }) ]; - component.onSort({sortBy: 'sensorName', sortOrder: Sort.ASC}); + component.onSort({ sortBy: 'sensorName', sortOrder: Sort.ASC }); expect(component.sensors[0].sensorName).toEqual('abc'); expect(component.sensors[1].sensorName).toEqual('plm'); expect(component.sensors[2].sensorName).toEqual('xyz'); - component.onSort({sortBy: 'sensorName', sortOrder: Sort.DSC}); + component.onSort({ sortBy: 'sensorName', sortOrder: Sort.DSC }); expect(component.sensors[0].sensorName).toEqual('xyz'); expect(component.sensors[1].sensorName).toEqual('plm'); expect(component.sensors[2].sensorName).toEqual('abc'); - component.onSort({sortBy: 'parserClassName', sortOrder: Sort.ASC}); - expect(component.sensors[0].config.parserClassName).toEqual('org.apache.metron.parsers.Bro'); - expect(component.sensors[1].config.parserClassName).toEqual('org.apache.metron.parsers.GrokParser'); - expect(component.sensors[2].config.parserClassName).toEqual('org.apache.metron.parsers.GrokParser'); - - component.onSort({sortBy: 'parserClassName', sortOrder: Sort.DSC}); - expect(component.sensors[0].config.parserClassName).toEqual('org.apache.metron.parsers.GrokParser'); - expect(component.sensors[1].config.parserClassName).toEqual('org.apache.metron.parsers.GrokParser'); - expect(component.sensors[2].config.parserClassName).toEqual('org.apache.metron.parsers.Bro'); - - component.onSort({sortBy: 'modifiedBy', sortOrder: Sort.ASC}); + component.onSort({ sortBy: 'parserClassName', sortOrder: Sort.ASC }); + expect(component.sensors[0].config.parserClassName).toEqual( + 'org.apache.metron.parsers.Bro' + ); + expect(component.sensors[1].config.parserClassName).toEqual( + 'org.apache.metron.parsers.GrokParser' + ); + expect(component.sensors[2].config.parserClassName).toEqual( + 'org.apache.metron.parsers.GrokParser' + ); + + component.onSort({ sortBy: 'parserClassName', sortOrder: Sort.DSC }); + expect(component.sensors[0].config.parserClassName).toEqual( + 'org.apache.metron.parsers.GrokParser' + ); + expect(component.sensors[1].config.parserClassName).toEqual( + 'org.apache.metron.parsers.GrokParser' + ); + expect(component.sensors[2].config.parserClassName).toEqual( + 'org.apache.metron.parsers.Bro' + ); + + component.onSort({ sortBy: 'modifiedBy', sortOrder: Sort.ASC }); expect(component.sensors[0].modifiedBy).toEqual('abc'); expect(component.sensors[1].modifiedBy).toEqual('plm'); expect(component.sensors[2].modifiedBy).toEqual('xyz'); - component.onSort({sortBy: 'modifiedBy', sortOrder: Sort.DSC}); + component.onSort({ sortBy: 'modifiedBy', sortOrder: Sort.DSC }); expect(component.sensors[0].modifiedBy).toEqual('xyz'); expect(component.sensors[1].modifiedBy).toEqual('plm'); expect(component.sensors[2].modifiedBy).toEqual('abc'); - })); it('sort', async(() => { @@ -698,24 +755,25 @@ describe('Component: SensorParserList', () => { component.sensors = [ Object.assign(new SensorParserConfigHistory(), { - 'sensorName': 'abc', - 'config': { - 'parserClassName': 'org.apache.metron.parsers.GrokParser', - 'sensorTopic': 'abc', + sensorName: 'abc', + config: { + parserClassName: 'org.apache.metron.parsers.GrokParser', + sensorTopic: 'abc' }, - 'createdBy': 'raghu', - 'modifiedBy': 'abc', - 'createdDate': '2016-11-25 09:09:12', - 'modifiedByDate': '2016-11-25 09:09:12' - })]; + createdBy: 'raghu', + modifiedBy: 'abc', + createdDate: '2016-11-25 09:09:12', + modifiedByDate: '2016-11-25 09:09:12' + }) + ]; component.sensorsStatus = [ - Object.assign(new TopologyStatus(), { - 'name': 'abc', - 'status': 'ACTIVE', - 'latency': '10', - 'throughput': '23' - }) + Object.assign(new TopologyStatus(), { + name: 'abc', + status: 'ACTIVE', + latency: '10', + throughput: '23' + }) ]; component.updateSensorStatus(); @@ -740,7 +798,5 @@ describe('Component: SensorParserList', () => { expect(component.sensors[0]['status']).toEqual('Stopped'); expect(component.sensors[0]['latency']).toEqual('-'); expect(component.sensors[0]['throughput']).toEqual('-'); - })); - }); http://git-wip-us.apache.org/repos/asf/metron/blob/0c4c622b/metron-interface/metron-config/src/app/sensors/sensor-raw-json/sensor-raw-json.component.spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-config/src/app/sensors/sensor-raw-json/sensor-raw-json.component.spec.ts b/metron-interface/metron-config/src/app/sensors/sensor-raw-json/sensor-raw-json.component.spec.ts index f680f10..427e837 100644 --- a/metron-interface/metron-config/src/app/sensors/sensor-raw-json/sensor-raw-json.component.spec.ts +++ b/metron-interface/metron-config/src/app/sensors/sensor-raw-json/sensor-raw-json.component.spec.ts @@ -16,176 +16,201 @@ * limitations under the License. */ -import {async, TestBed, ComponentFixture} from '@angular/core/testing'; -import {SensorRawJsonComponent} from './sensor-raw-json.component'; -import {SharedModule} from '../../shared/shared.module'; -import {SimpleChanges, SimpleChange} from '@angular/core'; -import {SensorParserConfig} from '../../model/sensor-parser-config'; -import {SensorEnrichmentConfig, EnrichmentConfig, ThreatIntelConfig} from '../../model/sensor-enrichment-config'; -import {SensorRawJsonModule} from './sensor-raw-json.module'; -import {IndexingConfigurations} from '../../model/sensor-indexing-config'; -import '../../rxjs-operators'; +import { async, TestBed, ComponentFixture } from '@angular/core/testing'; +import { SensorRawJsonComponent } from './sensor-raw-json.component'; +import { SharedModule } from '../../shared/shared.module'; +import { SimpleChanges, SimpleChange } from '@angular/core'; +import { SensorParserConfig } from '../../model/sensor-parser-config'; +import { + SensorEnrichmentConfig, + EnrichmentConfig, + ThreatIntelConfig +} from '../../model/sensor-enrichment-config'; +import { SensorRawJsonModule } from './sensor-raw-json.module'; +import { IndexingConfigurations } from '../../model/sensor-indexing-config'; describe('Component: SensorRawJsonComponent', () => { - - let fixture: ComponentFixture<SensorRawJsonComponent>; - let component: SensorRawJsonComponent; - let sensorParserConfigString = '{"parserClassName":"org.apache.metron.parsers.bro.BasicBroParser","sensorTopic":"bro",' + - '"parserConfig": {},"fieldTransformations":[]}'; - let sensorParserConfig: SensorParserConfig = new SensorParserConfig(); - sensorParserConfig.sensorTopic = 'bro'; - sensorParserConfig.parserClassName = 'org.apache.metron.parsers.bro.BasicBroParser'; - sensorParserConfig.parserConfig = {}; - - let sensorParserConfigWithClassNameString = `{"parserClassName":"org.apache.metron.parsers.bro.BasicBroParser","sensorTopic":"bro", - "parserConfig": {},"fieldTransformations":[], "writerClassName": "org.example.writerClassName", - "errorWriterClassName": "org.example.errorWriterClassName", + let fixture: ComponentFixture<SensorRawJsonComponent>; + let component: SensorRawJsonComponent; + let sensorParserConfigString = + '{"parserClassName":"org.apache.metron.parsers.bro.BasicBroParser","sensorTopic":"bro",' + + '"parserConfig": {},"fieldTransformations":[]}'; + let sensorParserConfig: SensorParserConfig = new SensorParserConfig(); + sensorParserConfig.sensorTopic = 'bro'; + sensorParserConfig.parserClassName = + 'org.apache.metron.parsers.bro.BasicBroParser'; + sensorParserConfig.parserConfig = {}; + + let sensorParserConfigWithClassNameString = `{"parserClassName":"org.apache.metron.parsers.bro.BasicBroParser","sensorTopic":"bro", + "parserConfig": {},"fieldTransformations":[], "writerClassName": "org.example.writerClassName", + "errorWriterClassName": "org.example.errorWriterClassName", "filterClassName": "org.example.filterClassName", "invalidWriterClassName": "org.example.invalidWriterClassName"}`; - let sensorParserConfigWithClassName = Object.assign(new SensorParserConfig(), sensorParserConfig); - sensorParserConfigWithClassName.writerClassName = 'org.example.writerClassName'; - sensorParserConfigWithClassName.errorWriterClassName = 'org.example.errorWriterClassName'; - sensorParserConfigWithClassName.filterClassName = 'org.example.filterClassName'; - sensorParserConfigWithClassName.invalidWriterClassName = 'org.example.invalidWriterClassName'; - - let sensorEnrichmentConfigString = '{"enrichment" : {"fieldMap": ' + - '{"geo": ["ip_dst_addr", "ip_src_addr"],"host": ["host"]}},"threatIntel": {"fieldMap": {"hbaseThreatIntel":' + - ' ["ip_src_addr", "ip_dst_addr"]},"fieldToTypeMap": {"ip_src_addr" : ["malicious_ip"],"ip_dst_addr" : ["malicious_ip"]}}}'; - let sensorEnrichmentConfig = new SensorEnrichmentConfig(); - sensorEnrichmentConfig.enrichment = Object.assign(new EnrichmentConfig(), { - 'fieldMap': { - 'geo': ['ip_dst_addr', 'ip_src_addr'], - 'host': ['host'] - } - }); - sensorEnrichmentConfig.threatIntel = Object.assign(new ThreatIntelConfig(), { - 'fieldMap': { - 'hbaseThreatIntel': ['ip_src_addr', 'ip_dst_addr'] - }, - 'fieldToTypeMap': { - 'ip_src_addr' : ['malicious_ip'], - 'ip_dst_addr' : ['malicious_ip'] - } - }); - - let sensorEnrichmentConfigWithConfigString = `{"configuration": "some-configuration", + let sensorParserConfigWithClassName = Object.assign( + new SensorParserConfig(), + sensorParserConfig + ); + sensorParserConfigWithClassName.writerClassName = + 'org.example.writerClassName'; + sensorParserConfigWithClassName.errorWriterClassName = + 'org.example.errorWriterClassName'; + sensorParserConfigWithClassName.filterClassName = + 'org.example.filterClassName'; + sensorParserConfigWithClassName.invalidWriterClassName = + 'org.example.invalidWriterClassName'; + + let sensorEnrichmentConfigString = + '{"enrichment" : {"fieldMap": ' + + '{"geo": ["ip_dst_addr", "ip_src_addr"],"host": ["host"]}},"threatIntel": {"fieldMap": {"hbaseThreatIntel":' + + ' ["ip_src_addr", "ip_dst_addr"]},"fieldToTypeMap": {"ip_src_addr" : ["malicious_ip"],"ip_dst_addr" : ["malicious_ip"]}}}'; + let sensorEnrichmentConfig = new SensorEnrichmentConfig(); + sensorEnrichmentConfig.enrichment = Object.assign(new EnrichmentConfig(), { + fieldMap: { + geo: ['ip_dst_addr', 'ip_src_addr'], + host: ['host'] + } + }); + sensorEnrichmentConfig.threatIntel = Object.assign(new ThreatIntelConfig(), { + fieldMap: { + hbaseThreatIntel: ['ip_src_addr', 'ip_dst_addr'] + }, + fieldToTypeMap: { + ip_src_addr: ['malicious_ip'], + ip_dst_addr: ['malicious_ip'] + } + }); + + let sensorEnrichmentConfigWithConfigString = `{"configuration": "some-configuration", "enrichment" : {"fieldMap": {"geo": ["ip_dst_addr", "ip_src_addr"],"host": ["host"]}}, "threatIntel": {"fieldMap": {"hbaseThreatIntel":["ip_src_addr", "ip_dst_addr"]}, "fieldToTypeMap": {"ip_src_addr" : ["malicious_ip"],"ip_dst_addr" : ["malicious_ip"]}}}`; - let sensorEnrichmentConfigWithConfig = Object.assign(new SensorEnrichmentConfig(), sensorEnrichmentConfig); - sensorEnrichmentConfigWithConfig.configuration = 'some-configuration'; + let sensorEnrichmentConfigWithConfig = Object.assign( + new SensorEnrichmentConfig(), + sensorEnrichmentConfig + ); + sensorEnrichmentConfigWithConfig.configuration = 'some-configuration'; - let sensorIndexingConfigString = `{"hdfs": {"index": "bro","batchSize": 5,"enabled":true}, + let sensorIndexingConfigString = `{"hdfs": {"index": "bro","batchSize": 5,"enabled":true}, "elasticsearch": {"index": "bro","batchSize": 5,"enabled":true}, "solr": {"index": "bro","batchSize": 5,"enabled":true}}`; - let sensorIndexingConfig = new IndexingConfigurations(); - sensorIndexingConfig.hdfs.index = 'bro'; - sensorIndexingConfig.hdfs.batchSize = 5; - sensorIndexingConfig.hdfs.enabled = true; - sensorIndexingConfig.elasticsearch.index = 'bro'; - sensorIndexingConfig.elasticsearch.batchSize = 5; - sensorIndexingConfig.elasticsearch.enabled = true; - sensorIndexingConfig.solr.index = 'bro'; - sensorIndexingConfig.solr.batchSize = 5; - sensorIndexingConfig.solr.enabled = true; - - let sensorIndexingConfigChangedString = `{"hdfs": {"index": "squid","batchSize": 1,"enabled":true}, + let sensorIndexingConfig = new IndexingConfigurations(); + sensorIndexingConfig.hdfs.index = 'bro'; + sensorIndexingConfig.hdfs.batchSize = 5; + sensorIndexingConfig.hdfs.enabled = true; + sensorIndexingConfig.elasticsearch.index = 'bro'; + sensorIndexingConfig.elasticsearch.batchSize = 5; + sensorIndexingConfig.elasticsearch.enabled = true; + sensorIndexingConfig.solr.index = 'bro'; + sensorIndexingConfig.solr.batchSize = 5; + sensorIndexingConfig.solr.enabled = true; + + let sensorIndexingConfigChangedString = `{"hdfs": {"index": "squid","batchSize": 1,"enabled":true}, "elasticsearch": {"index": "squid","batchSize": 1,"enabled":true}, "solr": {"index": "squid","batchSize": 1,"enabled":true}}`; - let sensorIndexingConfigChanged = new IndexingConfigurations(); - sensorIndexingConfigChanged.hdfs.index = 'squid'; - sensorIndexingConfigChanged.hdfs.batchSize = 1; - sensorIndexingConfigChanged.hdfs.enabled = true; - sensorIndexingConfigChanged.elasticsearch.index = 'squid'; - sensorIndexingConfigChanged.elasticsearch.batchSize = 1; - sensorIndexingConfigChanged.elasticsearch.enabled = true; - sensorIndexingConfigChanged.solr.index = 'squid'; - sensorIndexingConfigChanged.solr.batchSize = 1; - sensorIndexingConfigChanged.solr.enabled = true; - - - beforeEach(async(() => { - TestBed.configureTestingModule({ - imports: [SharedModule, SensorRawJsonModule], - }); - - fixture = TestBed.createComponent(SensorRawJsonComponent); - component = fixture.componentInstance; - })); - - it('should create an instance', () => { - expect(component).toBeDefined(); - }); - - it('should create an instance', () => { - spyOn(component, 'init'); - let changes: SimpleChanges = {'showRawJson': new SimpleChange(false, true)}; - - component.ngOnChanges(changes); - expect(component.init).toHaveBeenCalled(); - - changes = {'showRawJson': new SimpleChange(true, false)}; - component.ngOnChanges(changes); - expect(component.init['calls'].count()).toEqual(1); - - fixture.destroy(); - }); - - it('should initialise the fields', () => { - - component.init(); - expect(component.newSensorParserConfig).toEqual(undefined); - expect(component.newSensorEnrichmentConfig).toEqual(undefined); - expect(component.newIndexingConfigurations).toEqual(undefined); - - component.sensorParserConfig = sensorParserConfig; - component.sensorEnrichmentConfig = sensorEnrichmentConfig; - component.indexingConfigurations = sensorIndexingConfig; - component.init(); - expect(component.newSensorParserConfig).toEqual(JSON.stringify(sensorParserConfig, null, '\t')); - expect(component.newSensorEnrichmentConfig).toEqual(JSON.stringify(sensorEnrichmentConfig, null, '\t')); - expect(component.newIndexingConfigurations).toEqual(JSON.stringify(sensorIndexingConfig, null, '\t')); - - fixture.destroy(); - }); - - it('should save the fields', () => { - spyOn(component.hideRawJson, 'emit'); - spyOn(component.onRawJsonChanged, 'emit'); - component.sensorParserConfig = new SensorParserConfig(); - component.sensorEnrichmentConfig = new SensorEnrichmentConfig(); - component.indexingConfigurations = new IndexingConfigurations(); - - component.newSensorParserConfig = sensorParserConfigString; - component.newSensorEnrichmentConfig = sensorEnrichmentConfigString; - component.newIndexingConfigurations = sensorIndexingConfigString; - component.onSave(); - expect(component.sensorParserConfig).toEqual(sensorParserConfig); - expect(component.sensorEnrichmentConfig).toEqual(sensorEnrichmentConfig); - expect(component.indexingConfigurations).toEqual(sensorIndexingConfig); - expect(component.hideRawJson.emit).toHaveBeenCalled(); - expect(component.onRawJsonChanged.emit).toHaveBeenCalled(); - - - component.newSensorParserConfig = sensorParserConfigWithClassNameString; - component.newSensorEnrichmentConfig = sensorEnrichmentConfigWithConfigString; - component.newIndexingConfigurations = sensorIndexingConfigChangedString; - component.onSave(); - expect(component.sensorParserConfig).toEqual(sensorParserConfigWithClassName); - expect(component.sensorEnrichmentConfig).toEqual(sensorEnrichmentConfigWithConfig); - expect(component.indexingConfigurations).toEqual(sensorIndexingConfigChanged); - expect(component.hideRawJson.emit['calls'].count()).toEqual(2); - expect(component.onRawJsonChanged.emit['calls'].count()).toEqual(2); - - fixture.destroy(); - }); - - it('should hide panel', () => { - spyOn(component.hideRawJson, 'emit'); - - component.onCancel(); - - expect(component.hideRawJson.emit).toHaveBeenCalled(); - - fixture.destroy(); + let sensorIndexingConfigChanged = new IndexingConfigurations(); + sensorIndexingConfigChanged.hdfs.index = 'squid'; + sensorIndexingConfigChanged.hdfs.batchSize = 1; + sensorIndexingConfigChanged.hdfs.enabled = true; + sensorIndexingConfigChanged.elasticsearch.index = 'squid'; + sensorIndexingConfigChanged.elasticsearch.batchSize = 1; + sensorIndexingConfigChanged.elasticsearch.enabled = true; + sensorIndexingConfigChanged.solr.index = 'squid'; + sensorIndexingConfigChanged.solr.batchSize = 1; + sensorIndexingConfigChanged.solr.enabled = true; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [SharedModule, SensorRawJsonModule] }); + fixture = TestBed.createComponent(SensorRawJsonComponent); + component = fixture.componentInstance; + })); + + it('should create an instance', () => { + expect(component).toBeDefined(); + }); + + it('should create an instance', () => { + spyOn(component, 'init'); + let changes: SimpleChanges = { + showRawJson: new SimpleChange(false, true, true) + }; + + component.ngOnChanges(changes); + expect(component.init).toHaveBeenCalled(); + + changes = { showRawJson: new SimpleChange(true, false, false) }; + component.ngOnChanges(changes); + expect(component.init['calls'].count()).toEqual(1); + + fixture.destroy(); + }); + + it('should initialise the fields', () => { + component.init(); + expect(component.newSensorParserConfig).toEqual(undefined); + expect(component.newSensorEnrichmentConfig).toEqual(undefined); + expect(component.newIndexingConfigurations).toEqual(undefined); + + component.sensorParserConfig = sensorParserConfig; + component.sensorEnrichmentConfig = sensorEnrichmentConfig; + component.indexingConfigurations = sensorIndexingConfig; + component.init(); + expect(component.newSensorParserConfig).toEqual( + JSON.stringify(sensorParserConfig, null, '\t') + ); + expect(component.newSensorEnrichmentConfig).toEqual( + JSON.stringify(sensorEnrichmentConfig, null, '\t') + ); + expect(component.newIndexingConfigurations).toEqual( + JSON.stringify(sensorIndexingConfig, null, '\t') + ); + + fixture.destroy(); + }); + + it('should save the fields', () => { + spyOn(component.hideRawJson, 'emit'); + spyOn(component.onRawJsonChanged, 'emit'); + component.sensorParserConfig = new SensorParserConfig(); + component.sensorEnrichmentConfig = new SensorEnrichmentConfig(); + component.indexingConfigurations = new IndexingConfigurations(); + + component.newSensorParserConfig = sensorParserConfigString; + component.newSensorEnrichmentConfig = sensorEnrichmentConfigString; + component.newIndexingConfigurations = sensorIndexingConfigString; + component.onSave(); + expect(component.sensorParserConfig).toEqual(sensorParserConfig); + expect(component.sensorEnrichmentConfig).toEqual(sensorEnrichmentConfig); + expect(component.indexingConfigurations).toEqual(sensorIndexingConfig); + expect(component.hideRawJson.emit).toHaveBeenCalled(); + expect(component.onRawJsonChanged.emit).toHaveBeenCalled(); + + component.newSensorParserConfig = sensorParserConfigWithClassNameString; + component.newSensorEnrichmentConfig = sensorEnrichmentConfigWithConfigString; + component.newIndexingConfigurations = sensorIndexingConfigChangedString; + component.onSave(); + expect(component.sensorParserConfig).toEqual( + sensorParserConfigWithClassName + ); + expect(component.sensorEnrichmentConfig).toEqual( + sensorEnrichmentConfigWithConfig + ); + expect(component.indexingConfigurations).toEqual( + sensorIndexingConfigChanged + ); + expect(component.hideRawJson.emit['calls'].count()).toEqual(2); + expect(component.onRawJsonChanged.emit['calls'].count()).toEqual(2); + + fixture.destroy(); + }); + + it('should hide panel', () => { + spyOn(component.hideRawJson, 'emit'); + + component.onCancel(); + + expect(component.hideRawJson.emit).toHaveBeenCalled(); + + fixture.destroy(); + }); });