Search in sources :

Example 6 with ServiceCode

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCode in project coprhd-controller by CoprHD.

the class Operation method getServiceError.

public ServiceError getServiceError() {
    ServiceCode serviceCode = ServiceCode.toServiceCode(getServiceCode());
    ServiceError serviceError = ServiceError.buildServiceError(serviceCode, getMessage());
    return serviceError;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode)

Example 7 with ServiceCode

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCode in project coprhd-controller by CoprHD.

the class ServiceErrorTest method testJSONUnauthorized.

@Test
public void testJSONUnauthorized() throws Exception {
    final ServiceCode code = ServiceCode.SECURITY_UNAUTHORIZED_OPERATION;
    final String message = "No credentials were specified";
    final String json = json(error(code, message, null));
    // useful for debugging
    // System.out.println(json);
    assertJSONContains(json, "code", "4000");
    assertJSONContains(json, "retryable", "false");
    assertJSONContains(json, "details", message);
}
Also used : ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) Test(org.junit.Test)

Example 8 with ServiceCode

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCode in project coprhd-controller by CoprHD.

the class ServiceCodeTest method codesWithoutMessages.

@Test
public void codesWithoutMessages() {
    final Set<String> failures = new TreeSet<String>();
    final ResourceBundle bundle = MessageUtils.bundleForClass(ServiceCode.class);
    for (final ServiceCode serviceCode : ServiceCode.values()) {
        String name = serviceCode.name();
        if (!bundle.keySet().contains(name)) {
            failures.add(name);
        }
    }
    assertTrue("The following ServiceCodes do not have messages in the Bundle: " + failures, failures.isEmpty());
}
Also used : ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) TreeSet(java.util.TreeSet) ResourceBundle(java.util.ResourceBundle) Test(org.junit.Test)

Example 9 with ServiceCode

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCode in project coprhd-controller by CoprHD.

the class ServiceCodeTest method serviceCodeNumbersAreUnique.

@Test
public void serviceCodeNumbersAreUnique() {
    final Map<Integer, ServiceCode> codes = new HashMap<Integer, ServiceCode>();
    final Map<Integer, Set<ServiceCode>> duplicates = new HashMap<Integer, Set<ServiceCode>>();
    for (final ServiceCode code : ServiceCode.values()) {
        final int serviceCode = code.getCode();
        final ServiceCode orginal = codes.put(serviceCode, code);
        if (orginal != null) {
            final Set<ServiceCode> set;
            if (duplicates.containsKey(serviceCode)) {
                set = duplicates.get(serviceCode);
            } else {
                set = new HashSet<ServiceCode>();
                set.add(orginal);
            }
            set.add(code);
            duplicates.put(serviceCode, set);
        }
    }
    assertTrue("Found Duplicates: " + duplicates, duplicates.isEmpty());
}
Also used : ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with ServiceCode

use of com.emc.storageos.svcs.errorhandling.resources.ServiceCode in project coprhd-controller by CoprHD.

the class Documenter method documentServiceCode.

private static void documentServiceCode(PrintStream out, final ServiceCode code, final List<DocumenterEntry> messages) throws NoSuchFieldException {
    final StatusType status = messages.get(0).getStatus();
    final boolean retryable = status.getStatusCode() == 503;
    out.println("Service Code: " + code.getCode());
    out.println("Name:         " + code.name());
    out.println("Description:  " + code.getSummary(Locale.ENGLISH));
    out.println("Retryable:    " + retryable);
    out.println("Deprecated:   " + checkDeprecation(ServiceCode.class.getField(code.name())));
    out.println("HTTP Status:  " + status.getStatusCode() + " " + status.getReasonPhrase());
    out.println();
}
Also used : ServiceCode(com.emc.storageos.svcs.errorhandling.resources.ServiceCode) StatusType(javax.ws.rs.core.Response.StatusType)

Aggregations

ServiceCode (com.emc.storageos.svcs.errorhandling.resources.ServiceCode)12 Test (org.junit.Test)5 StatusType (javax.ws.rs.core.Response.StatusType)3 DeclareServiceCode (com.emc.storageos.svcs.errorhandling.annotations.DeclareServiceCode)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 ApiErrorCode (com.emc.apidocs.model.ApiErrorCode)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 DocumenterEntry (com.emc.storageos.svcs.errorhandling.utils.Documenter.DocumenterEntry)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 TreeMap (java.util.TreeMap)1