2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.plugins.context.schema.avro;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
29 import org.onap.policy.apex.context.parameters.SchemaParameters;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
32 import org.onap.policy.apex.model.basicmodel.service.ModelService;
33 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
34 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
37 * @author Liam Fallon (liam.fallon@ericsson.com)
40 public class TestAvroSchemaHelperBadSchemas {
41 private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
42 private AxContextSchemas schemas;
45 public void initTest() {
46 schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
47 ModelService.registerModel(AxContextSchemas.class, schemas);
48 new SchemaParameters().getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters());
52 public void badSchemaTest() {
53 final AxContextSchema avroBadSchema0 = new AxContextSchema(new AxArtifactKey("AvroBad0", "0.0.1"), "Avro", "}");
54 schemas.getSchemasMap().put(avroBadSchema0.getKey(), avroBadSchema0);
57 new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema0.getKey());
58 fail("This test should throw an exception");
59 } catch (final Exception e) {
60 assertTrue(e.getMessage()
61 .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad0:0.0.1\" schema is invalid"));
64 final AxContextSchema avroBadSchema1 = new AxContextSchema(new AxArtifactKey("AvroBad1", "0.0.1"), "Avro", "");
65 schemas.getSchemasMap().put(avroBadSchema1.getKey(), avroBadSchema1);
68 new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema1.getKey());
69 fail("This test should throw an exception");
70 } catch (final Exception e) {
71 assertTrue(e.getMessage()
72 .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad1:0.0.1\" schema is invalid"));
75 final AxContextSchema avroBadSchema2 =
76 new AxContextSchema(new AxArtifactKey("AvroBad2", "0.0.1"), "Avro", "{}");
77 schemas.getSchemasMap().put(avroBadSchema2.getKey(), avroBadSchema2);
80 new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema2.getKey());
81 fail("This test should throw an exception");
82 } catch (final Exception e) {
83 assertTrue(e.getMessage()
84 .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad2:0.0.1\" schema is invalid"));
87 final AxContextSchema avroBadSchema3 =
88 new AxContextSchema(new AxArtifactKey("AvroBad3", "0.0.1"), "Avro", "{zooby}");
89 schemas.getSchemasMap().put(avroBadSchema3.getKey(), avroBadSchema3);
92 new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema3.getKey());
93 fail("This test should throw an exception");
94 } catch (final Exception e) {
95 assertTrue(e.getMessage()
96 .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad3:0.0.1\" schema is invalid"));
99 final AxContextSchema avroBadSchema4 =
100 new AxContextSchema(new AxArtifactKey("AvroBad4", "0.0.1"), "Avro", "{\"zooby\"}");
101 schemas.getSchemasMap().put(avroBadSchema4.getKey(), avroBadSchema4);
104 new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema4.getKey());
105 fail("This test should throw an exception");
106 } catch (final Exception e) {
107 assertTrue(e.getMessage()
108 .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad4:0.0.1\" schema is invalid"));
111 final AxContextSchema avroBadSchema5 =
112 new AxContextSchema(new AxArtifactKey("AvroBad5", "0.0.1"), "Avro", "{\"type\": \"zooby\"}");
113 schemas.getSchemasMap().put(avroBadSchema5.getKey(), avroBadSchema5);
116 new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema5.getKey());
117 fail("This test should throw an exception");
118 } catch (final Exception e) {
119 assertTrue(e.getMessage()
120 .startsWith("AvroTest:0.0.1: avro context schema \"AvroBad5:0.0.1\" schema is invalid"));