List of usage examples for java.lang IllegalStateException getMessage
public String getMessage()
From source file:org.finra.herd.service.helper.AttributeDaoHelperTest.java
@Test public void testUpdateBusinessObjectDataAttributesDuplicateAttributes() { // Create two business object data attribute entities that use the same attribute name (case-insensitive). BusinessObjectDataAttributeEntity businessObjectDataAttributeEntityA = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntityA.setName(ATTRIBUTE_NAME.toUpperCase()); businessObjectDataAttributeEntityA.setValue(ATTRIBUTE_VALUE); BusinessObjectDataAttributeEntity businessObjectDataAttributeEntityB = new BusinessObjectDataAttributeEntity(); businessObjectDataAttributeEntityB.setName(ATTRIBUTE_NAME.toLowerCase()); businessObjectDataAttributeEntityB.setValue(ATTRIBUTE_VALUE_2); // Create a business object data entity that contains duplicate attributes (case-insensitive). BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); List<BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntities = new ArrayList<>(); businessObjectDataEntity.setAttributes(businessObjectDataAttributeEntities); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntityA); businessObjectDataAttributeEntities.add(businessObjectDataAttributeEntityB); // Mock the external calls. when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)) .thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try {/*from w w w . j a v a2s .c om*/ attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, NO_ATTRIBUTES); fail(); } catch (IllegalStateException e) { assertEquals(String.format( "Found duplicate attribute with name \"%s\" for business object data. Business object data: {%s}", ATTRIBUTE_NAME.toLowerCase(), BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
From source file:com.blackducksoftware.integration.hub.teamcity.agent.scan.HubBuildProcess.java
private HubScanConfig getScanConfig(final File workingDirectory, final File toolsDir, final IntLogger logger, final CIEnvironmentVariables commonVariables) throws IOException { final String dryRun = commonVariables.getValue(HubConstantValues.HUB_DRY_RUN); final String cleanupLogs = commonVariables.getValue(HubConstantValues.HUB_CLEANUP_LOGS_ON_SUCCESS); final String scanMemory = commonVariables.getValue(HubConstantValues.HUB_SCAN_MEMORY); final String codeLocationName = commonVariables.getValue(HubConstantValues.HUB_CODE_LOCATION_NAME); final String unmapPreviousCodeLocations = commonVariables .getValue(HubConstantValues.HUB_UNMAP_PREVIOUS_CODE_LOCATIONS); final String deletePreviousCodeLocations = commonVariables .getValue(HubConstantValues.HUB_DELETE_PREVIOUS_CODE_LOCATIONS); final String hubWorkspaceCheck = commonVariables.getValue(HubConstantValues.HUB_WORKSPACE_CHECK); String[] excludePatternArray = new String[0]; final String excludePatternParameter = commonVariables.getValue(HubConstantValues.HUB_EXCLUDE_PATTERNS); if (StringUtils.isNotBlank(excludePatternParameter)) { excludePatternArray = excludePatternParameter.split("\\r?\\n"); }//from w w w. j ava2 s. c o m final List<String> scanTargets = new ArrayList<>(); final String scanTargetParameter = commonVariables.getValue(HubConstantValues.HUB_SCAN_TARGETS); if (StringUtils.isNotBlank(scanTargetParameter)) { final String[] scanTargetPathsArray = scanTargetParameter.split("\\r?\\n"); for (final String target : scanTargetPathsArray) { if (StringUtils.isNotBlank(target)) { final File tmpTarget = new File(target); if (tmpTarget.isAbsolute()) { scanTargets.add(tmpTarget.getCanonicalPath()); } else { scanTargets.add(new File(workingDirectory, target).getCanonicalPath()); } } } } else { scanTargets.add(workingDirectory.getAbsolutePath()); } final HubScanConfigBuilder hubScanConfigBuilder = new HubScanConfigBuilder(); hubScanConfigBuilder.setWorkingDirectory(workingDirectory); hubScanConfigBuilder.setDryRun(Boolean.valueOf(dryRun)); hubScanConfigBuilder.setScanMemory(scanMemory); hubScanConfigBuilder.setCodeLocationAlias(codeLocationName); hubScanConfigBuilder.addAllScanTargetPaths(scanTargets); hubScanConfigBuilder.setToolsDir(toolsDir); hubScanConfigBuilder.setCleanupLogsOnSuccess(Boolean.valueOf(cleanupLogs)); hubScanConfigBuilder.setUnmapPreviousCodeLocations(Boolean.valueOf(unmapPreviousCodeLocations)); hubScanConfigBuilder.setDeletePreviousCodeLocations(Boolean.valueOf(deletePreviousCodeLocations)); hubScanConfigBuilder.setExcludePatterns(excludePatternArray); if (Boolean.valueOf(hubWorkspaceCheck)) { hubScanConfigBuilder.enableScanTargetPathsWithinWorkingDirectoryCheck(); } try { return hubScanConfigBuilder.build(); } catch (final IllegalStateException e) { logger.error(e.getMessage(), e); } return null; }
From source file:fr.cph.chicago.core.fragment.NearbyFragment.java
private void showProgress(final boolean show) { try {//from w ww . j a v a 2 s . c om if (isAdded()) { int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); loadLayout.setVisibility(View.VISIBLE); loadLayout.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { loadLayout.setVisibility(show ? View.VISIBLE : View.GONE); } }); } } catch (final IllegalStateException e) { Log.w(TAG, e.getMessage(), e); } }
From source file:nuclei.media.MediaService.java
@Override public void onDestroy() { LOG.d("onDestroy"); unregisterCarConnectionReceiver();// ww w. jav a 2 s .c o m // Service is being killed, so make sure we release our resources mPlaybackManager.handleStopRequest(null); mMediaNotificationManager.stopNotification(); try { VideoCastManager.getInstance().removeVideoCastConsumer(mCastConsumer); } catch (IllegalStateException e) { LOG.w("Error removing cast video consumer : " + e.getMessage()); } mDelayedStopHandler.removeCallbacksAndMessages(null); mSession.release(); }
From source file:org.mybatis.spring.SqlSessionFactoryBeanTest.java
@Test public void testSpecifyConfigurationAndConfigLocation() throws Exception { setupFactoryBean();/* w w w .ja va 2 s . c om*/ factoryBean.setConfiguration(new Configuration()); factoryBean.setConfigLocation( new org.springframework.core.io.ClassPathResource("org/mybatis/spring/mybatis-config.xml")); try { factoryBean.getObject(); fail(); } catch (IllegalStateException e) { assertEquals("Property 'configuration' and 'configLocation' can not specified with together", e.getMessage()); } }
From source file:org.apache.beam.sdk.io.FileBasedSinkTest.java
/** Reject non-distinct output filenames. */ @Test/* w w w.j a va2 s .co m*/ public void testCollidingOutputFilenames() throws IOException { ResourceId root = getBaseOutputDirectory(); SimpleSink sink = new SimpleSink(root, "file", "-NN", "test"); SimpleSink.SimpleWriteOperation writeOp = new SimpleSink.SimpleWriteOperation(sink); ResourceId temp1 = root.resolve("temp1", StandardResolveOptions.RESOLVE_FILE); ResourceId temp2 = root.resolve("temp2", StandardResolveOptions.RESOLVE_FILE); ResourceId temp3 = root.resolve("temp3", StandardResolveOptions.RESOLVE_FILE); ResourceId output = root.resolve("file-03.test", StandardResolveOptions.RESOLVE_FILE); // More than one shard does. try { Iterable<FileResult> results = Lists.newArrayList(new FileResult(temp1, 1, null, null), new FileResult(temp2, 1, null, null), new FileResult(temp3, 1, null, null)); writeOp.buildOutputFilenames(results); fail("Should have failed."); } catch (IllegalStateException exn) { assertEquals("Only generated 1 distinct file names for 3 files.", exn.getMessage()); } }
From source file:org.apache.phoenix.mapreduce.index.IndexScrutinyTool.java
@Override public int run(String[] args) throws Exception { Connection connection = null; try {/* w ww. j a va 2 s . c om*/ /** start - parse command line configs **/ CommandLine cmdLine = null; try { cmdLine = parseOptions(args); } catch (IllegalStateException e) { printHelpAndExit(e.getMessage(), getOptions()); } final Configuration configuration = HBaseConfiguration.addHbaseResources(getConf()); boolean useTenantId = cmdLine.hasOption(TENANT_ID_OPTION.getOpt()); String tenantId = null; if (useTenantId) { tenantId = cmdLine.getOptionValue(TENANT_ID_OPTION.getOpt()); configuration.set(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); LOG.info(String.format("IndexScrutinyTool uses a tenantId %s", tenantId)); } connection = ConnectionUtil.getInputConnection(configuration); final String schemaName = cmdLine.getOptionValue(SCHEMA_NAME_OPTION.getOpt()); final String dataTable = cmdLine.getOptionValue(DATA_TABLE_OPTION.getOpt()); String indexTable = cmdLine.getOptionValue(INDEX_TABLE_OPTION.getOpt()); final String qDataTable = SchemaUtil.getQualifiedTableName(schemaName, dataTable); String basePath = cmdLine.getOptionValue(OUTPUT_PATH_OPTION.getOpt()); boolean isForeground = cmdLine.hasOption(RUN_FOREGROUND_OPTION.getOpt()); boolean useSnapshot = cmdLine.hasOption(SNAPSHOT_OPTION.getOpt()); boolean outputInvalidRows = cmdLine.hasOption(OUTPUT_INVALID_ROWS_OPTION.getOpt()); SourceTable sourceTable = cmdLine.hasOption(SOURCE_TABLE_OPTION.getOpt()) ? SourceTable.valueOf(cmdLine.getOptionValue(SOURCE_TABLE_OPTION.getOpt())) : SourceTable.BOTH; long batchSize = cmdLine.hasOption(BATCH_SIZE_OPTION.getOpt()) ? Long.parseLong(cmdLine.getOptionValue(BATCH_SIZE_OPTION.getOpt())) : PhoenixConfigurationUtil.DEFAULT_SCRUTINY_BATCH_SIZE; long ts = cmdLine.hasOption(TIMESTAMP.getOpt()) ? Long.parseLong(cmdLine.getOptionValue(TIMESTAMP.getOpt())) : EnvironmentEdgeManager.currentTimeMillis() - 60000; if (indexTable != null) { if (!IndexTool.isValidIndexTable(connection, qDataTable, indexTable, tenantId)) { throw new IllegalArgumentException( String.format(" %s is not an index table for %s ", indexTable, qDataTable)); } } String outputFormatOption = cmdLine.getOptionValue(OUTPUT_FORMAT_OPTION.getOpt()); OutputFormat outputFormat = outputFormatOption != null ? OutputFormat.valueOf(outputFormatOption.toUpperCase()) : OutputFormat.TABLE; long outputMaxRows = cmdLine.hasOption(OUTPUT_MAX.getOpt()) ? Long.parseLong(cmdLine.getOptionValue(OUTPUT_MAX.getOpt())) : 1000000L; /** end - parse command line configs **/ if (outputInvalidRows && OutputFormat.TABLE.equals(outputFormat)) { // create the output table if it doesn't exist try (Connection outputConn = ConnectionUtil.getOutputConnection(configuration)) { outputConn.createStatement().execute(IndexScrutinyTableOutput.OUTPUT_TABLE_DDL); outputConn.createStatement().execute(IndexScrutinyTableOutput.OUTPUT_METADATA_DDL); } } LOG.info(String.format( "Running scrutiny [schemaName=%s, dataTable=%s, indexTable=%s, useSnapshot=%s, timestamp=%s, batchSize=%s, outputBasePath=%s, outputFormat=%s, outputMaxRows=%s]", schemaName, dataTable, indexTable, useSnapshot, ts, batchSize, basePath, outputFormat, outputMaxRows)); JobFactory jobFactory = new JobFactory(connection, configuration, batchSize, useSnapshot, ts, outputInvalidRows, outputFormat, basePath, outputMaxRows, tenantId); // If we are running the scrutiny with both tables as the source, run two separate jobs, // one for each direction if (SourceTable.BOTH.equals(sourceTable)) { jobs.add(jobFactory.createSubmittableJob(schemaName, indexTable, dataTable, SourceTable.DATA_TABLE_SOURCE)); jobs.add(jobFactory.createSubmittableJob(schemaName, indexTable, dataTable, SourceTable.INDEX_TABLE_SOURCE)); } else { jobs.add(jobFactory.createSubmittableJob(schemaName, indexTable, dataTable, sourceTable)); } if (!isForeground) { LOG.info("Running Index Scrutiny in Background - Submit async and exit"); for (Job job : jobs) { job.submit(); } return 0; } LOG.info( "Running Index Scrutiny in Foreground. Waits for the build to complete. This may take a long time!."); boolean result = true; for (Job job : jobs) { result = result && job.waitForCompletion(true); } // write the results to the output metadata table if (outputInvalidRows && OutputFormat.TABLE.equals(outputFormat)) { LOG.info("Writing results of jobs to output table " + IndexScrutinyTableOutput.OUTPUT_METADATA_TABLE_NAME); IndexScrutinyTableOutput.writeJobResults(connection, args, jobs); } if (result) { return 0; } else { LOG.error("IndexScrutinyTool job failed! Check logs for errors.."); return -1; } } catch (Exception ex) { LOG.error("An exception occurred while performing the indexing job: " + ExceptionUtils.getMessage(ex) + " at:\n" + ExceptionUtils.getStackTrace(ex)); return -1; } finally { try { if (connection != null) { connection.close(); } } catch (SQLException sqle) { LOG.error("Failed to close connection ", sqle.getMessage()); throw new RuntimeException("Failed to close connection"); } } }
From source file:org.finra.herd.core.helper.ConfigurationHelper.java
/** * Logs the error message, and then throws {@link IllegalStateException} * * @param configurationValue - {@link ConfigurationValue} * @param targetTypeName - the name of the data type we want to convert the configuration value to(boolean, BigDecimal...etc) * @param stringValue - the configuration value in string type * @param exception - the exception thrown when converting the configuration value from string type to the target data type *//*from ww w.j a va2s . c o m*/ private void logErrorAndThrowIllegalStateException(ConfigurationValue configurationValue, String targetTypeName, String stringValue, Exception exception) { // Create an invalid state exception. IllegalStateException illegalStateException = new IllegalStateException( String.format("Configuration \"%s\" has an invalid %s value: \"%s\".", configurationValue.getKey(), targetTypeName, stringValue), exception); // Log the exception. LOGGER.error(illegalStateException.getMessage(), illegalStateException); // This will produce a 500 HTTP status code error. throw illegalStateException; }
From source file:n3phele.storage.swift.CloudStorageImpl.java
private final String signSwiftQueryString(String stringToSign, Credential credential) { try {//from w w w . j a v a2 s . c om byte[] keyBytes = credential.decrypt().getSecret().getBytes(); SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signingKey); byte[] rawHmac = mac.doFinal(stringToSign.getBytes()); byte[] hexBytes = new Hex().encode(rawHmac); return new String(hexBytes, "UTF-8"); } catch (IllegalStateException e) { log.log(Level.SEVERE, "Signing error", e); throw new IllegalArgumentException(e.getMessage()); } catch (InvalidKeyException e) { log.log(Level.SEVERE, "Signing error", e); throw new IllegalArgumentException(e.getMessage()); } catch (NoSuchAlgorithmException e) { log.log(Level.SEVERE, "Signing error", e); throw new IllegalArgumentException(e.getMessage()); } catch (UnsupportedEncodingException e) { log.log(Level.SEVERE, "Signing error", e); throw new IllegalArgumentException(e.getMessage()); } }
From source file:no.abmu.common.excel.BaseExcelParserTest.java
public void testNotExcelFile() { String dummyFileName = resourceDir + File.separator + "dummy.txt"; BaseExcelParser baseExcelParser = new BaseExcelParserImpl(); baseExcelParser.setExcelFileName(dummyFileName); baseExcelParser.setSheetName(sheetName1); try {/*w w w .j a v a 2 s . c om*/ baseExcelParser.load(); fail("Should have thrown exception."); } catch (IllegalStateException e) { String expectedErrorMessage = "Can't parse Excel document. Failed to read file '" + dummyFileName + "' java.io.IOException: Unable to read entire header; 27 bytes read; expected 512 bytes"; assertEquals(expectedErrorMessage, e.getMessage()); } }