Example usage for java.lang IllegalStateException getMessage

List of usage examples for java.lang IllegalStateException getMessage

Introduction

In this page you can find the example usage for java.lang IllegalStateException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.github.cherimojava.data.mongo.io._DeEncoding.java

@Test
public void finalIsFinalAfterLoad() {
    ExplicitIdEntity e = factory.create(ExplicitIdEntity.class);
    e.setName("t").save();
    try {/* w ww .  j  a  v  a 2  s .  c o  m*/
        e.setName("different");
        fail("should throw an exception");
    } catch (IllegalStateException ise) {
        assertThat(ise.getMessage(), containsString("@Final property"));
    }
}

From source file:com.xtructure.xutil.valid.UTestValidateUtils.java

public void validateStateWithOnePredicateBehavesAsExpected() {
    String objectName = RandomStringUtils.randomAlphanumeric(10);
    boolean valid = validateState(objectName, new Object(), isNotNull());
    if (!valid) {
        throw new AssertionError();
    }//from w w w. java 2  s .c  o  m
    try {
        validateState(objectName, null, isNotNull());
    } catch (IllegalStateException e) {
        if (!String.format("%s (%s): %s", objectName, null, isNotNull()).equals(e.getMessage())) {
            throw new AssertionError();
        }
    }
}

From source file:com.xtructure.xutil.valid.UTestValidateUtils.java

public void validateStateWithMultiplePredicatesBehavesAsExpected() {
    String objectName = RandomStringUtils.randomAlphanumeric(10);
    boolean valid = validateState(objectName, new Object(), isNotNull(), isNotNull());
    if (!valid) {
        throw new AssertionError();
    }// ww  w  . ja va2 s.c  o  m
    try {
        validateState(objectName, null, isNotNull(), isNotNull());
    } catch (IllegalStateException e) {
        if (!String.format("%s (%s): %s", objectName, null, isNotNull()).equals(e.getMessage())) {
            throw new AssertionError();
        }
    }
}

From source file:com.xtructure.xutil.valid.UTestValidateUtils.java

public void validateStateWithValidationStrategyBehavesAsExpected() {
    String objectName = RandomStringUtils.randomAlphanumeric(10);
    StateValidationStrategy<Object> validationStrategy = new StateValidationStrategy<Object>(isNotNull());
    boolean valid = validateState(objectName, new Object(), validationStrategy);
    if (!valid) {
        throw new AssertionError();
    }/*from  ww w.j av a 2s  . c  o  m*/
    try {
        validateState(objectName, null, validationStrategy);
    } catch (IllegalStateException e) {
        if (!String.format("%s (%s): %s", objectName, null, isNotNull()).equals(e.getMessage())) {
            throw new AssertionError();
        }
    }
}

From source file:com.eTilbudsavis.etasdk.DbHelper.java

/**
 * //from   www  .  j a  v a  2 s.  co m
 * @param userId
 * @param includeDeleted
 * @return A list of shoppinglists
 */
public List<Shoppinglist> getLists(User user, boolean includeDeleted) {
    String q = null;
    if (includeDeleted) {
        q = String.format("SELECT * FROM %s WHERE %s=%s", LIST_TABLE, USER, user.getUserId());
    } else {
        q = String.format("SELECT * FROM %s WHERE %s!=%s AND %s=%s", LIST_TABLE, STATE, SyncState.DELETE, USER,
                user.getUserId());
    }
    Cursor c = null;
    List<Shoppinglist> tmp = new ArrayList<Shoppinglist>();
    try {
        c = execQuery(q);
        if (c.moveToFirst()) {
            do {
                tmp.add(cursorToSl(c));
            } while (c.moveToNext());
        }
    } catch (IllegalStateException e) {
        EtaLog.d(TAG, e.getMessage(), e);
    } finally {
        closeCursorAndDB(c);
    }

    List<Shoppinglist> lists = new ArrayList<Shoppinglist>(tmp.size());
    for (Shoppinglist sl : tmp) {
        sl.putShares(getShares(sl, user, includeDeleted));
        // Only add list, if list has user as share
        if (sl.getShares().containsKey(user.getEmail())) {
            lists.add(sl);
        }
    }
    Collections.sort(lists);
    return lists;
}

From source file:com.eTilbudsavis.etasdk.DbHelper.java

private int execQueryWithChangesCount(String query) {

    int i = 0;//from  www.  j a v a  2s  .  c  o m

    synchronized (LOCK) {

        Cursor c = null;

        // Get the actual query out of the way...
        try {
            c = execQuery(query);
            if (c != null) {
                c.moveToFirst();
            }
        } catch (IllegalStateException e) {
            EtaLog.d(TAG, e.getMessage(), e);
        } finally {
            closeCursor(c);
        }

        // Get number of affected rows in last statement (query)
        try {
            c = execQuery("SELECT changes() AS 'changes'");
            if (c != null && c.moveToFirst()) {
                i = c.getInt(0);
            }
        } catch (IllegalStateException e) {
            EtaLog.d(TAG, e.getMessage(), e);
        } finally {
            closeCursorAndDB(c);
        }

    }

    return i;
}

From source file:com.fujitsu.dc.core.rs.cell.MessageODataResource.java

/**
 * HttpResponse?JSON??.//w  w  w. j a  v a 2  s  .  co  m
 * @param objResponse HttpResponse
 * @return 
 */
private JSONObject bodyAsJson(HttpResponse objResponse) {
    JSONObject body = null;

    InputStream is = null;
    InputStreamReader isr = null;
    BufferedReader reader = null;
    String bodyString = null;
    try {
        objResponse.getHeaders("Content-Encoding");
        is = objResponse.getEntity().getContent();
        isr = new InputStreamReader(is, "UTF-8");
        reader = new BufferedReader(isr);
        StringBuffer sb = new StringBuffer();
        int chr;
        while ((chr = is.read()) != -1) {
            sb.append((char) chr);
        }
        bodyString = sb.toString();
    } catch (IllegalStateException e) {
        log.info(e.getMessage());
    } catch (IOException e) {
        log.info(e.getMessage());
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
            if (isr != null) {
                isr.close();
            }
            if (is != null) {
                is.close();
            }
        } catch (IOException e) {
            log.info(e.getMessage());
        }
    }

    try {
        if (bodyString != null) {
            body = (JSONObject) new JSONParser().parse(bodyString);
        }
    } catch (ParseException e) {
        log.info(e.getMessage());
    }

    return body;
}

From source file:it.geosolutions.opensdi.operations.FileBrowserOperationController.java

@Override
public String getJsp(ModelMap model, HttpServletRequest request, List<MultipartFile> files) {

    registerManager();/*w  w w.ja  v  a  2 s.  co  m*/

    LOGGER.debug("getJSP di FileBrowser");

    // update key
    String update = request.getParameter("update");

    HashMap<String, List<Operation>> availableOperations = getAvailableOperations();

    String baseDir = getRunTimeDir();

    FileBrowser fb = null;
    if (Boolean.TRUE.equals(this.showRunInformation)) {
        fb = new ExtendedFileBrowser();
        ((ExtendedFileBrowser) fb).setAvailableOperations(availableOperations);
        ((ExtendedFileBrowser) fb).setGeoBatchClient(geoBatchClient);
        ((ExtendedFileBrowser) fb).setUpdateStatus(update != null);
    } else {
        fb = new FileBrowser();
    }

    Object gotParam = model.get("gotParam");

    @SuppressWarnings("unchecked")
    Map<String, String[]> parameters = request.getParameterMap();

    for (String key : parameters.keySet()) {
        LOGGER.debug(key); // debug
        String[] vals = parameters.get(key);
        for (String val : vals)
            // debug
            LOGGER.debug(" -> " + val); // debug
        if (key.equalsIgnoreCase(DIRECTORY_KEY)) {
            String dirString = parameters.get(key)[0].trim();

            dirString = ControllerUtils.preventDirectoryTrasversing(dirString);

            if (dirString.startsWith(SEPARATOR)) {
                dirString = dirString.substring(1);
            }

            // remove last slash

            if (dirString.lastIndexOf(SEPARATOR) >= 0
                    && dirString.lastIndexOf(SEPARATOR) == (dirString.length() - 1)) {
                LOGGER.debug("stripping last slash"); // debug
                dirString = dirString.substring(0, dirString.length() - 1);
            }

            // second check
            if (dirString.lastIndexOf(SEPARATOR) >= 0) {
                model.addAttribute("directoryBack", dirString.substring(0, dirString.lastIndexOf(SEPARATOR)));
            } else {
                model.addAttribute("directoryBack", "");
            }

            dirString = dirString.concat(SEPARATOR);
            baseDir = baseDir + dirString;
            model.addAttribute("directory", dirString);
            model.addAttribute("jsDirectory", dirString.replace(SEPARATOR, "/"));

        }
    }

    if (gotParam != null) {
        LOGGER.debug(gotParam); // debug
    }
    String gotAction = request.getParameter("action");
    String fileToDel = request.getParameter("toDel");
    if (gotAction != null && gotAction.equalsIgnoreCase("delete") && fileToDel != null) {
        String deleteFileString = baseDir + fileToDel;
        boolean res = deleteFile(deleteFileString);
        LOGGER.debug("Deletted " + deleteFileString + ": " + res); // debug
    }

    model.addAttribute("operationName", this.operationName);
    model.addAttribute("operationRESTPath", this.getRESTPath());

    fb.setBaseDir(baseDir);
    fb.setRegex(fileRegex);
    fb.setScanDiretories(canNavigate);

    if (null != files && files.size() > 0) {
        List<String> fileNames = new ArrayList<String>();
        for (MultipartFile multipartFile : files) {
            if (multipartFile == null)
                continue;
            String fileName = multipartFile.getOriginalFilename();
            if (!"".equalsIgnoreCase(fileName)) {
                try {
                    multipartFile.transferTo(new File(baseDir + fileName));
                } catch (IllegalStateException e) {
                    LOGGER.error(e.getMessage());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                fileNames.add(fileName);
            }
            LOGGER.debug("filename: " + fileName); // debug
        }
    }

    model.addAttribute("fileBrowser", fb);

    model.addAttribute("operations", availableOperations);

    model.addAttribute("canDelete", this.canDelete);
    model.addAttribute("canUpload", this.canUpload);
    model.addAttribute("uploadMethod", this.uploadMethod.name());
    model.addAttribute("maxFileSize", this.maxFileSize);
    model.addAttribute("chunkSize", this.chunkSize);
    model.addAttribute("extensionFilter", this.extensionFilter);
    model.addAttribute("showRunInformation", this.showRunInformation);
    model.addAttribute("showRunInformationHistory", this.showRunInformationHistory);
    model.addAttribute("canManageFolders", this.canManageFolders);
    model.addAttribute("canDownloadFiles", this.canDownloadFiles);

    model.addAttribute("containerId", uniqueKey.toString().substring(0, 8));
    model.addAttribute("formId", uniqueKey.toString().substring(27, 36));
    model.addAttribute("accept", accept);
    return operationJSP;
}

From source file:org.finra.herd.service.helper.notification.StorageUnitStatusChangeMessageBuilderTest.java

@Test
public void testBuildStorageUnitStatusChangeMessagesJsonPayloadInvalidMessageType() throws Exception {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME,
            FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES,
            DATA_VERSION);//from   www  .  jav  a2s.c om

    // Override configuration.
    ConfigurationEntity configurationEntity = new ConfigurationEntity();
    configurationEntity.setKey(
            ConfigurationValue.HERD_NOTIFICATION_STORAGE_UNIT_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey());
    configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(
            Collections.singletonList(new NotificationMessageDefinition(INVALID_VALUE, MESSAGE_DESTINATION,
                    BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON,
                    Collections.singletonList(new MessageHeaderDefinition(KEY, VALUE)))))));
    configurationDao.saveAndRefresh(configurationEntity);

    // Try to build a notification message.
    try {
        storageUnitStatusChangeMessageBuilder
                .buildNotificationMessages(new StorageUnitStatusChangeNotificationEvent(businessObjectDataKey,
                        STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2));
        fail();
    } catch (IllegalStateException illegalStateException) {
        assertEquals(String.format(
                "Only \"%s\" notification message type is supported. Please update \"%s\" configuration entry.",
                MESSAGE_TYPE_SNS,
                ConfigurationValue.HERD_NOTIFICATION_STORAGE_UNIT_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey()),
                illegalStateException.getMessage());
    }
}

From source file:org.finra.herd.dao.impl.S3DaoImplTest.java

@Test
public void testTagObjectsS3ClientCreationFails() {
    // Create an S3 file transfer request parameters DTO to access S3 objects.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
    s3FileTransferRequestParamsDto.setS3BucketName(S3_BUCKET_NAME);

    // Create an S3 file transfer request parameters DTO to tag S3 objects.
    S3FileTransferRequestParamsDto s3ObjectTaggerParamsDto = new S3FileTransferRequestParamsDto();
    s3ObjectTaggerParamsDto.setAwsAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
    s3ObjectTaggerParamsDto.setAwsSecretKey(AWS_ASSUMED_ROLE_SECRET_KEY);
    s3ObjectTaggerParamsDto.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);

    // Create an S3 object summary.
    S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
    s3ObjectSummary.setKey(S3_KEY);/*from w ww  .j a v  a  2  s  .co  m*/

    // Create an S3 object tag.
    Tag tag = new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE);

    // Mock the external calls.
    when(retryPolicyFactory.getRetryPolicy()).thenThrow(new AmazonServiceException(ERROR_MESSAGE));

    // Try to call the method under test.
    try {
        s3DaoImpl.tagObjects(s3FileTransferRequestParamsDto, s3ObjectTaggerParamsDto,
                Collections.singletonList(s3ObjectSummary), tag);
    } catch (IllegalStateException e) {
        assertEquals(String.format(
                "Failed to tag S3 object with \"%s\" key and \"null\" version id in \"%s\" bucket. "
                        + "Reason: %s (Service: null; Status Code: 0; Error Code: null; Request ID: null)",
                S3_KEY, S3_BUCKET_NAME, ERROR_MESSAGE), e.getMessage());
    }

    // Verify the external calls.
    verify(retryPolicyFactory).getRetryPolicy();
    verifyNoMoreInteractionsHelper();
}