blob: d10e009274a4c455a5801024f500f3497765483a [file] [log] [blame]
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +05301/*
2 * Copyright 2016-present 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;
20
21import static org.hamcrest.core.Is.is;
22import static org.junit.Assert.assertThat;
23import static org.onosproject.yangutils.utils.YangConstructType.CONTACT_DATA;
24import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
25import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
26import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
27import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
28
29/**
30 * Test case for testing listener error message construction util.
31 */
32public class ListenerErrorMessageConstructionTest {
33
34 /**
35 * Checks for error message construction with parsable data type name.
36 */
37 @Test
38 public void checkErrorMsgConstructionWithName() {
39
40 // Create an test error message
41 String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
42
43 // Check message.
44 assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact "
45 + "\"Test Instance\" before processing."));
46 }
47
48 /**
49 * Checks for error message construction without parsable data type name.
50 */
51 @Test
52 public void checkErrorMsgConstructionWithoutName() {
53
54 // Create an test error message
55 String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
56
57 // Check message.
58 assertThat(testErrorMessage,
59 is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
60 + " before processing."));
61 }
62
63 /**
64 * Checks for extended error message construction with parsable data type
65 * name.
66 */
67 @Test
68 public void checkExtendedErrorMsgConstructionWithName() {
69
70 // Create an test error message
71 String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
72 "Test Instance", ENTRY,
73 "Extended Information");
74
75 // Check message.
76 assertThat(testErrorMessage,
77 is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
78 + " before processing.\n" + "Error Information: Extended Information"));
79 }
80
81 /**
82 * Checks for extended error message construction without parsable data type
83 * name.
84 */
85 @Test
86 public void checkExtendedErrorMsgConstructionWithoutName() {
87
88 // Create an test error message
89 String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "", ENTRY,
90 "Extended Information");
91
92 // Check message.
93 assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact"
94 + " before processing.\n" + "Error Information: Extended Information"));
95 }
96}