Ori Liel has posted comments on this change.
Change subject: resatpi: Eliminate Exceptions in Mapper Tests
......................................................................
Patch Set 1:
(4 comments)
....................................................
File
backend/manager/modules/restapi/types/src/test/java/org/ovirt/engine/api/restapi/types/MappingTestHelper.java
Line 19: private static final String SLAVES_PLURAL = "Slaves";
Line 20: private static final String FLOPPY_SINGLE = "Floppy";
Line 21: private static final String FLOPPIES_PLURAL = "Floppies";
Line 22: private static final String NIC_SINGLE = "NIC";
Line 23: private static final String NICS_PLURAL = "Nics";
Not possible, we're not checking if two string are equal; we need the exact
name of the class in order to instantiate it.
For example, after truncating the 's' from 'Nics' we are left with 'Nic', but
the class that we need instantiate is actually called 'NIC', and we must
provide the exact name explicitly.
We could try all premutations of uppercase and lowercase letters in the class
name, but that would be inefficient.
Line 24: private static final String XML_GREGORIAN_CALENDAR =
"javax.xml.datatype.XMLGregorianCalendar";
Line 25: private static final String SET_ROOT = "set";
Line 26: private static final String GET_ROOT = "get";
Line 27:
Line 127:
Line 128: private static void descend(Method method, Object model,
List<Class<?>> seen, int level) throws Exception {
Line 129: Class<?> type = method.getParameterTypes()[0];
Line 130: Object child;
Line 131: if (type.getName().equals(XML_GREGORIAN_CALENDAR)) {
Done
Line 132: child =
DatatypeFactory.newInstance().newXMLGregorianCalendar(new
GregorianCalendar(1111, 10, 29));
Line 133: } else {
Line 134: child = type.newInstance();
Line 135: }
Line 207: private static Class<?> coPackaged(Object model, String
elementType) throws ClassNotFoundException {
Line 208: String packageRoot = model.getClass().getPackage().getName()
+ ".";
Line 209: try {
Line 210: // Consider special case: "Usages" contains a list of
Strings, not 'Usage' elements.
Line 211: return elementType.equals("Usages") ? String.class :
Done
Line 212: Class.forName(packageRoot +
singular(elementType));
Line 213: } catch (ClassNotFoundException cnf) {
Line 214: try {
Line 215: return Class.forName(packageRoot + elementType);
Line 224: // Consider exceptional cases:
Line 225: // 'Nics' is plural of 'NIC' (uppercase)
Line 226: // 'Floppies' is plural of 'Floppy' (not 'Floppie')
Line 227: // 'Slaves' is plural of 'HostNIC' (we don't have a 'Slave'
entity)
Line 228: return s.equals(NICS_PLURAL) ? NIC_SINGLE :
s.equals(FLOPPIES_PLURAL) ? FLOPPY_SINGLE : s.equals(SLAVES_PLURAL) ?
SLAVE_SINGLE :
Done
Line 229: s.endsWith("s") ? s.substring(0,
Line 230: s.length() - 1) : s;
Line 231: }
Line 232:
--
To view, visit http://gerrit.ovirt.org/19673
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I84cabed0ff38196d8fd57d2f72ffdfe213f2ffed
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ori Liel <[email protected]>
Gerrit-Reviewer: Michael Pasternak <[email protected]>
Gerrit-Reviewer: Ori Liel <[email protected]>
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches