1
1
package io .hyperfoil .tools .horreum .svc ;
2
2
3
+ import com .fasterxml .jackson .core .JsonProcessingException ;
4
+ import com .fasterxml .jackson .databind .ObjectMapper ;
5
+ import com .fasterxml .jackson .databind .node .ObjectNode ;
3
6
import io .hyperfoil .tools .horreum .api .SortDirection ;
4
- import io .hyperfoil .tools .horreum .api .data .Access ;
5
- import io .hyperfoil .tools .horreum .api .data .Extractor ;
6
- import io .hyperfoil .tools .horreum .api .data .Label ;
7
- import io .hyperfoil .tools .horreum .api .data .Schema ;
8
- import io .hyperfoil .tools .horreum .api .data .Transformer ;
7
+ import io .hyperfoil .tools .horreum .api .data .*;
9
8
import io .hyperfoil .tools .horreum .api .services .SchemaService ;
10
9
import io .hyperfoil .tools .horreum .entity .data .LabelDAO ;
11
10
import io .hyperfoil .tools .horreum .entity .data .SchemaDAO ;
35
34
import static org .junit .jupiter .api .Assertions .assertNull ;
36
35
import static org .junit .jupiter .api .Assertions .assertThrows ;
37
36
import static org .junit .jupiter .api .Assertions .assertTrue ;
37
+ import static org .keycloak .util .JsonSerialization .mapper ;
38
38
39
39
@ QuarkusTest
40
40
@ QuarkusTestResource (PostgresResource .class )
@@ -46,6 +46,9 @@ class SchemaServiceNoRestTest extends BaseServiceNoRestTest {
46
46
@ Inject
47
47
SchemaService schemaService ;
48
48
49
+ @ Inject
50
+ ObjectMapper objectMapper ;
51
+
49
52
@ org .junit .jupiter .api .Test
50
53
void testCreateSchema () {
51
54
String schemaUri = "urn:dummy:schema" ;
@@ -649,6 +652,82 @@ void testDeleteSchemaLabelWithFailures() {
649
652
assertEquals (Response .Status .BAD_REQUEST .getStatusCode (), thrown .getResponse ().getStatus ());
650
653
}
651
654
655
+ @ org .junit .jupiter .api .Test
656
+ void testImportSchemaWithValidStructure () throws JsonProcessingException {
657
+ String schemaImport = """
658
+ {
659
+ "labels" : [ {
660
+ "name" : "kb_report_results_podLatencyQuantilesMeasurement_quantiles_Ready_P99",
661
+ "filtering" : true,
662
+ "metrics" : true,
663
+ "schemaId" : "221",
664
+ "access" : "PUBLIC",
665
+ "owner" : "TEAM_NAME",
666
+ "extractors" : [ {
667
+ "name" : "P99",
668
+ "jsonpath" : "$.results.podLatencyQuantilesMeasurement.quantiles.Ready.P99",
669
+ "isarray" : false
670
+ } ]
671
+ } ],
672
+ "transformers": [],
673
+ "id": 221,
674
+ "uri": "urn:kube-burner-report:0.1",
675
+ "name": "kube-burner-report",
676
+ "description": "Kube Burner test for the report variant of results",
677
+ "schema": {
678
+ "$id": "urn:kube-burner-report:0.2",
679
+ "type": "object",
680
+ "$schema": "http://json-schema.org/draft-07/schema#"
681
+ },
682
+ "access": "PUBLIC",
683
+ "owner": "TEAM_NAME"
684
+ } """ ;
685
+
686
+ ObjectNode schemaJson = (ObjectNode ) objectMapper .readTree (schemaImport .replaceAll ("TEAM_NAME" , FOO_TEAM ));
687
+ schemaService .importSchema (schemaJson );
688
+
689
+ }
690
+
691
+ @ org .junit .jupiter .api .Test
692
+ void testImportSchemaWithInvalidStructure () throws JsonProcessingException {
693
+ String schemaImport = """
694
+ {
695
+ "labels" : [ {
696
+ "name" : "kb_report_results_podLatencyQuantilesMeasurement_quantiles_Ready_P99",
697
+ "filtering" : true,
698
+ "metrics" : true,
699
+ "schemaId" : "221",
700
+ "acccess" : "PUBLIC",
701
+ "owner" : "TEAM_NAME",
702
+ "extractors" : [ {
703
+ "name" : "P99",
704
+ "path" : "$.results.podLatencyQuantilesMeasurement.quantiles.Ready.P99",
705
+ "isarray" : false
706
+ } ]
707
+ } ],
708
+ "transformers": [],
709
+ "id": 221,
710
+ "uri": "urn:kube-burner-report:0.2",
711
+ "name": "kube-burner-report",
712
+ "description": "Kube Burner test for the report variant of results",
713
+ "schema": {
714
+ "$id": "urn:kube-burner-report:0.2",
715
+ "type": "object",
716
+ "$schema": "http://json-schema.org/draft-07/schema#"
717
+ },
718
+ "acccess": "PUBLIC",
719
+ "owner": "TEAM_NAME"
720
+ }
721
+ """ ;
722
+
723
+ ObjectNode schemaJson = (ObjectNode ) objectMapper .readTree (schemaImport .replaceAll ("TEAM_NAME" , FOO_TEAM ));
724
+
725
+
726
+ ServiceException thrown = assertThrows (ServiceException .class , () -> schemaService .importSchema (schemaJson ));
727
+ assertEquals (Response .Status .BAD_REQUEST .getStatusCode (), thrown .getResponse ().getStatus ());
728
+
729
+ }
730
+
652
731
// utility to create a schema in the db, tested with testCreateSchema
653
732
private Schema createSchema (String name , String uri ) {
654
733
return createSchema (name , uri , null );
0 commit comments