blob: 79c46f4f427c885cb20719bf2dba7fa454a8f70d [file] [log] [blame]
Gaurav Agrawala04483c2016-02-13 14:23:40 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawala04483c2016-02-13 14:23:40 +05303 *
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
Bharat saraswalef2e6392016-04-19 19:50:32 +053017package org.onosproject.yangutils.parser.impl.parseutils;
Gaurav Agrawala04483c2016-02-13 14:23:40 +053018
19import org.junit.Test;
Gaurav Agrawala04483c2016-02-13 14:23:40 +053020
21import static org.hamcrest.core.Is.is;
22import static org.junit.Assert.assertThat;
Gaurav Agrawal8e8770a2016-02-27 03:57:50 +053023import static org.onosproject.yangutils.utils.YangConstructType.CONTACT_DATA;
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053024import 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;
Gaurav Agrawala04483c2016-02-13 14:23:40 +053028
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
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053041 String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
Gaurav Agrawala04483c2016-02-13 14:23:40 +053042
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
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053055 String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
Gaurav Agrawala04483c2016-02-13 14:23:40 +053056
57 // Check message.
58 assertThat(testErrorMessage,
59 is("Internal parser error detected: Invalid holder for contact \"Test Instance\""
60 + " before processing."));
61 }
62
63 /**
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053064 * Checks for extended error message construction with parsable data type
65 * name.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053066 */
67 @Test
68 public void checkExtendedErrorMsgConstructionWithName() {
69
70 // Create an test error message
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053071 String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
72 "Test Instance", ENTRY,
73 "Extended Information");
Gaurav Agrawala04483c2016-02-13 14:23:40 +053074
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 /**
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053082 * Checks for extended error message construction without parsable data type
83 * name.
Gaurav Agrawala04483c2016-02-13 14:23:40 +053084 */
85 @Test
86 public void checkExtendedErrorMsgConstructionWithoutName() {
87
88 // Create an test error message
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053089 String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "", ENTRY,
90 "Extended Information");
Gaurav Agrawala04483c2016-02-13 14:23:40 +053091
92 // Check message.
93 assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact"
94 + " before processing.\n" + "Error Information: Extended Information"));
95 }
Gaurav Agrawal02b05d22016-02-19 12:57:13 +053096}