blob: 7cbc7f6a0f422333b36f3a800c826684b49581bf [file] [log] [blame]
Gaurav Agrawala04483c2016-02-13 14:23:40 +05301/*
2 * Copyright 2016 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.parser.parseutils;
18
19import org.junit.Test;
20import org.onosproject.yangutils.parser.ParsableDataType;
21import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
22import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
23import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
24
25import static org.hamcrest.core.Is.is;
26import static org.junit.Assert.assertThat;
27
28/**
29 * Test case for testing listener error message construction util.
30 */
31public class ListenerErrorMessageConstructionTest {
32
33 /**
34 * Checks for error message construction with parsable data type name.
35 */
36 @Test
37 public void checkErrorMsgConstructionWithName() {
38
39 // Create an test error message
40 String testErrorMessage = ListenerErrorMessageConstruction
41 .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, ParsableDataType.CONTACT_DATA,
42 "Test Instance", ListenerErrorLocation.ENTRY);
43
44 // Check message.
45 assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact "
46 + "\"Test Instance\" before processing."));
47 }
48
49 /**
50 * Checks for error message construction without parsable data type name.
51 */
52 @Test
53 public void checkErrorMsgConstructionWithoutName() {
54
55 // Create an test error message
56 String testErrorMessage = ListenerErrorMessageConstruction
57 .constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, ParsableDataType.CONTACT_DATA,
58 "Test Instance", ListenerErrorLocation.ENTRY);
59
60 // Check message.
61 assertThat(testErrorMessage,
62 is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
63 + " before processing."));
64 }
65
66 /**
67 * Checks for extended error message construction with parsable data type name.
68 */
69 @Test
70 public void checkExtendedErrorMsgConstructionWithName() {
71
72 // Create an test error message
73 String testErrorMessage = ListenerErrorMessageConstruction
74 .constructExtendedListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
75 ParsableDataType.CONTACT_DATA, "Test Instance",
76 ListenerErrorLocation.ENTRY, "Extended Information");
77
78 // Check message.
79 assertThat(testErrorMessage,
80 is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
81 + " before processing.\n" + "Error Information: Extended Information"));
82 }
83
84 /**
85 * Checks for extended error message construction without parsable data type name.
86 */
87 @Test
88 public void checkExtendedErrorMsgConstructionWithoutName() {
89
90 // Create an test error message
91 String testErrorMessage = ListenerErrorMessageConstruction
92 .constructExtendedListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
93 ParsableDataType.CONTACT_DATA, "",
94 ListenerErrorLocation.ENTRY, "Extended Information");
95
96 // Check message.
97 assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact"
98 + " before processing.\n" + "Error Information: Extended Information"));
99 }
100}