Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yangutils.parser.parseutils; |
| 18 | |
| 19 | import org.junit.Test; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 20 | |
| 21 | import static org.hamcrest.core.Is.is; |
| 22 | import static org.junit.Assert.assertThat; |
Gaurav Agrawal | db828bd | 2016-02-27 03:57:50 +0530 | [diff] [blame] | 23 | import static org.onosproject.yangutils.utils.YangConstructType.CONTACT_DATA; |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 24 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
| 25 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
| 26 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
| 27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Test case for testing listener error message construction util. |
| 31 | */ |
| 32 | public 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 Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 41 | String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 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 |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 55 | String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 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 | /** |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 64 | * Checks for extended error message construction with parsable data type |
| 65 | * name. |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 66 | */ |
| 67 | @Test |
| 68 | public void checkExtendedErrorMsgConstructionWithName() { |
| 69 | |
| 70 | // Create an test error message |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 71 | String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, |
| 72 | "Test Instance", ENTRY, |
| 73 | "Extended Information"); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 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 | /** |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 82 | * Checks for extended error message construction without parsable data type |
| 83 | * name. |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 84 | */ |
| 85 | @Test |
| 86 | public void checkExtendedErrorMsgConstructionWithoutName() { |
| 87 | |
| 88 | // Create an test error message |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 89 | String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "", ENTRY, |
| 90 | "Extended Information"); |
Gaurav Agrawal | 2737d2a | 2016-02-13 14:23:40 +0530 | [diff] [blame] | 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 | } |
Gaurav Agrawal | 800a8e7 | 2016-02-19 12:57:13 +0530 | [diff] [blame] | 96 | } |