janani b | 05614f1 | 2016-10-04 12:55:43 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yms.app.ytb; |
| 18 | |
| 19 | import org.onosproject.yms.app.ysr.TestYangSchemaNodeProvider; |
| 20 | |
| 21 | /** |
| 22 | * Represents the abstract class for ytb test classes having common methods |
| 23 | * and the constants. |
| 24 | */ |
| 25 | public abstract class YtbErrMsgAndConstants { |
| 26 | |
| 27 | /** |
| 28 | * Static attribute of root name. |
| 29 | */ |
| 30 | public static final String ROOT_NAME = "rootName"; |
| 31 | |
| 32 | /** |
| 33 | * Static attribute of root name space. |
| 34 | */ |
| 35 | public static final String ROOT_NAME_SPACE = "rootNameSpace"; |
| 36 | |
| 37 | /** |
| 38 | * Static attribute of module which is YANG name. |
| 39 | */ |
| 40 | public static final String MODULE = "module"; |
| 41 | |
| 42 | /** |
| 43 | * Static attribute of list which is YANG name. |
| 44 | */ |
| 45 | public static final String LIST = "list"; |
| 46 | |
| 47 | /** |
| 48 | * Static attribute of leaf which is YANG name. |
| 49 | */ |
| 50 | public static final String LEAF = "leaf"; |
| 51 | |
| 52 | /** |
| 53 | * Static attribute of leaf-list which is YANG name. |
| 54 | */ |
| 55 | public static final String LEAF_LIST = "leaf-list"; |
| 56 | |
| 57 | /** |
| 58 | * Static attribute of container which is YANG name. |
| 59 | */ |
| 60 | public static final String CONTAINER = "container"; |
| 61 | |
| 62 | /** |
| 63 | * Static attribute of name predict. |
| 64 | */ |
| 65 | public static final String PREDICT = "predict"; |
| 66 | |
| 67 | /** |
| 68 | * Static attribute of name catch. |
| 69 | */ |
| 70 | public static final String CATCH = "catch"; |
| 71 | |
| 72 | /** |
| 73 | * Static attribute of YANG file name. |
| 74 | */ |
| 75 | public static final String RPC_NAME = "YtbSimpleRpcResponse"; |
| 76 | |
| 77 | /** |
| 78 | * Static attribute of name rpc. |
| 79 | */ |
| 80 | public static final String RPC = "rpc"; |
| 81 | |
| 82 | /** |
| 83 | * Created a schema node provider, which will register the app. |
| 84 | */ |
| 85 | public TestYangSchemaNodeProvider schemaProvider = |
| 86 | new TestYangSchemaNodeProvider(); |
| 87 | |
| 88 | /** |
| 89 | * Returns the error message for when leaf value doesn't match with the |
| 90 | * expected value. It takes name of leaf and expected value as its |
| 91 | * parameter, to throw the message. |
| 92 | * |
| 93 | * @param name leaf name |
| 94 | * @param value expected value of leaf |
| 95 | * @return error message of leaf value as incorrect |
| 96 | */ |
| 97 | public static String getInCrtLeafValue(String name, String value) { |
| 98 | return "The value of leaf " + name + " is not " + value; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns the error message, when node name doesn't match with the |
| 103 | * expected value. It takes YANG name of the node and the node name as |
| 104 | * parameter, to throw the message. |
| 105 | * |
| 106 | * @param node YANG node name |
| 107 | * @param nodeName node name |
| 108 | * @return error message as the node name is incorrect |
| 109 | */ |
| 110 | public static String getInCrtName(String node, String nodeName) { |
| 111 | return getCapitalCase(node) + "'s name " + nodeName + " is incorrect."; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Returns the error message, when operation type doesn't match with the |
| 116 | * expected value. It takes YANG name of the node and the node name as |
| 117 | * parameter, to throw the message. |
| 118 | * |
| 119 | * @param node YANG node name |
| 120 | * @param nodeName node name |
| 121 | * @return error message as the operation type is incorrect |
| 122 | */ |
| 123 | public static String getInCrtOpType(String node, String nodeName) { |
| 124 | return "The operation type of " + node + " " + nodeName + " is " + |
| 125 | "incorrect"; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Returns the error message for when leaf-list value doesn't match with the |
| 130 | * expected value. It takes name of leaf-list and expected value as its |
| 131 | * parameter, to throw the message. |
| 132 | * |
| 133 | * @param name leaf-list name |
| 134 | * @param value value in leaf-list |
| 135 | * @return error message as the value in the leaf-list is incorrect |
| 136 | */ |
| 137 | public static String getInCrtLeafListValue(String name, String value) { |
| 138 | return "The leaf-list " + name + " does not have " + value + " in it."; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Returns the capital cased first letter of the given string. |
| 143 | * |
| 144 | * @param name string to be capital cased |
| 145 | * @return capital cased string |
| 146 | */ |
| 147 | private static String getCapitalCase(String name) { |
| 148 | return name.substring(0, 1).toUpperCase() + name.substring(1); |
| 149 | } |
| 150 | } |