Search in sources :

Example 1 with RESTErrorCode

use of io.hops.hopsworks.restutils.RESTCodes.RESTErrorCode in project hopsworks by logicalclocks.

the class TestRESTCodes method getRESTErrorCodes.

@Before
public void getRESTErrorCodes() {
    RESTCodes restCodes = new RESTCodes();
    Class<?>[] classes = restCodes.getClass().getClasses();
    Method method;
    for (Class enumClass : classes) {
        try {
            method = enumClass.getMethod("values");
            RESTErrorCode[] obj = (RESTErrorCode[]) method.invoke(null);
            values.put(enumClass.getName(), Arrays.asList(obj));
            ranges.put(enumClass.getName(), obj[0].getRange());
        } catch (ClassCastException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        }
    }
}
Also used : RESTErrorCode(io.hops.hopsworks.restutils.RESTCodes.RESTErrorCode) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) Before(org.junit.Before)

Example 2 with RESTErrorCode

use of io.hops.hopsworks.restutils.RESTCodes.RESTErrorCode in project hopsworks by logicalclocks.

the class TestRESTCodes method validateErrorCodes.

/**
 * Validates the enums only contain error codes within the range assigned to them.
 */
@Test
public void validateErrorCodes() {
    Set<String> keySet = ranges.keySet();
    List<RESTErrorCode> restErrorCodes;
    for (String key : keySet) {
        restErrorCodes = values.get(key);
        for (RESTErrorCode errorCode : restErrorCodes) {
            if (!(errorCode instanceof RESTCodes.SchemaRegistryErrorCode)) {
                assertTrue(errorCode.toString(), errorCode.getCode() >= errorCode.getRange());
                assertTrue(errorCode.toString(), errorCode.getCode() < errorCode.getRange() + 10000);
            }
        }
    }
}
Also used : RESTErrorCode(io.hops.hopsworks.restutils.RESTCodes.RESTErrorCode) Test(org.junit.Test)

Aggregations

RESTErrorCode (io.hops.hopsworks.restutils.RESTCodes.RESTErrorCode)2 RESTCodes (io.hops.hopsworks.restutils.RESTCodes)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Before (org.junit.Before)1 Test (org.junit.Test)1