List of usage examples for java.lang IllegalStateException getMessage
public String getMessage()
From source file:com.github.springtestdbunit.DbUnitTestExecutionListenerPrepareTests.java
@Test public void shouldFailIfNoDbConnectionBeanIsFound() throws Exception { ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(NoDbUnitConfiguration.class); try {/*from w w w . j ava2 s . c om*/ testContextManager.prepareTestInstance(); } catch (IllegalStateException e) { assertTrue(e.getMessage().startsWith("Unable to find a DB Unit database connection")); } }
From source file:ir.myket.example.iab.InAppBillingPlugin.java
@Override /**/* ww w . j ava 2 s . c o m*/ * Called by each javascript plugin function */ public boolean execute(String action, JSONArray data, final CallbackContext callbackContext) { try { // Action selector if ("init".equals(action)) { final List<String> sku = new ArrayList<String>(); if (data.length() > 0) { JSONArray jsonSkuList = new JSONArray(data.getString(0)); int len = jsonSkuList.length(); Log.d(TAG, "Num SKUs Found: " + len); for (int i = 0; i < len; i++) { sku.add(jsonSkuList.get(i).toString()); Log.d(TAG, "Product SKU Added: " + jsonSkuList.get(i).toString()); } } // Initialize init(sku, callbackContext); return true; } else if ("isPurchaseOpen".equals(action)) { if (activityOpen == true) { callbackContext.success("true"); } else { callbackContext.success("false"); } return true; } else { if (initialized == false) { throw new IllegalStateException("Billing plugin was not initialized"); } Action actionInstance = new Action(action, data, this, mHelper, callbackContext); return actionInstance.execute(); } } catch (IllegalStateException e) { callbackContext.error(e.getMessage()); } catch (JSONException e) { callbackContext.error(e.getMessage()); } // Method not found return false; }
From source file:org.apache.hive.hcatalog.templeton.ListDelegator.java
public List<JobItemBean> listJobs(String user, boolean showall, String jobId, int numRecords, boolean showDetails) throws NotAuthorizedException, BadParam, IOException, InterruptedException { UserGroupInformation ugi = null;// w w w .j a v a2 s .c o m WebHCatJTShim tracker = null; ArrayList<String> ids = new ArrayList<String>(); try { ugi = UgiFactory.getUgi(user); tracker = ShimLoader.getHadoopShims().getWebHCatShim(appConf, ugi); JobStatus[] jobs = tracker.getAllJobs(); if (jobs != null) { for (JobStatus job : jobs) { String id = job.getJobID().toString(); if (showall || user.equals(job.getUsername())) ids.add(id); } } } catch (IllegalStateException e) { throw new BadParam(e.getMessage()); } finally { if (tracker != null) tracker.close(); if (ugi != null) FileSystem.closeAllForUGI(ugi); } return getJobStatus(ids, user, showall, jobId, numRecords, showDetails); }
From source file:org.apache.omid.tso.TestBatch.java
@Test(timeOut = 10_000) public void testBatchFunctionality() { // Component to test Batch batch = new Batch(0, BATCH_SIZE); // Test initial state is OK assertTrue(batch.isEmpty(), "Batch should be empty"); assertFalse(batch.isFull(), "Batch shouldn't be full"); assertEquals(batch.getNumEvents(), 0, "Num events should be 0"); // Test getting or setting an element in the batch greater than the current number of events is illegal try {/*from ww w .ja v a 2 s . c om*/ batch.get(1); fail(); } catch (IllegalStateException ex) { // Expected, as we can not access elements in the batch greater than the current number of events } try { batch.set(1, new PersistEvent()); fail(); } catch (IllegalStateException ex) { // Expected, as we can not access elements in the batch greater than the current number of events } // Test when filling the batch with different types of events, that becomes full for (int i = 0; i < BATCH_SIZE; i++) { if (i % 4 == 0) { batch.addTimestamp(ANY_ST, channel, monCtx); } else if (i % 4 == 1) { batch.addCommit(ANY_ST, ANY_CT, channel, monCtx); } else if (i % 4 == 2) { batch.addCommitRetry(ANY_ST, channel, monCtx); } else { batch.addAbort(ANY_ST, channel, monCtx); } } assertFalse(batch.isEmpty(), "Batch should contain elements"); assertTrue(batch.isFull(), "Batch should be full"); assertEquals(batch.getNumEvents(), BATCH_SIZE, "Num events should be " + BATCH_SIZE); // Test an exception is thrown when batch is full and a new element is going to be added try { batch.addCommit(ANY_ST, ANY_CT, channel, monCtx); fail("Should throw an IllegalStateException"); } catch (IllegalStateException e) { assertEquals(e.getMessage(), "batch is full", "message returned doesn't match"); LOG.debug("IllegalStateException catch properly"); } assertTrue(batch.isFull(), "Batch shouldn't be empty"); // Check the first 3 events and the last one correspond to the filling done above assertTrue(batch.get(0).getType().equals(PersistEvent.Type.TIMESTAMP)); assertTrue(batch.get(1).getType().equals(PersistEvent.Type.COMMIT)); assertTrue(batch.get(2).getType().equals(PersistEvent.Type.COMMIT_RETRY)); assertTrue(batch.get(3).getType().equals(PersistEvent.Type.ABORT)); // Set a new value for last element in Batch and check we obtain the right result batch.decreaseNumEvents(); assertEquals(batch.getNumEvents(), BATCH_SIZE - 1, "Num events should be " + (BATCH_SIZE - 1)); try { batch.get(BATCH_SIZE - 1); fail(); } catch (IllegalStateException ex) { // Expected, as we can not access elements in the batch greater than the current number of events } // Re-check that batch is NOT full assertFalse(batch.isFull(), "Batch shouldn't be full"); // Clear the batch and goes back to its initial state batch.clear(); assertTrue(batch.isEmpty(), "Batch should be empty"); assertFalse(batch.isFull(), "Batch shouldn't be full"); assertEquals(batch.getNumEvents(), 0, "Num events should be 0"); }
From source file:org.apache.nifi.lookup.SimpleCsvFileLookupService.java
@OnEnabled public void onEnabled(final ConfigurationContext context) throws InitializationException, IOException, FileNotFoundException { this.csvFile = context.getProperty(CSV_FILE).getValue(); this.csvFormat = CSVFormat.Predefined.valueOf(context.getProperty(CSV_FORMAT).getValue()).getFormat(); this.lookupKeyColumn = context.getProperty(LOOKUP_KEY_COLUMN).getValue(); this.lookupValueColumn = context.getProperty(LOOKUP_VALUE_COLUMN).getValue(); this.ignoreDuplicates = context.getProperty(IGNORE_DUPLICATES).asBoolean(); this.watcher = new SynchronousFileWatcher(Paths.get(csvFile), new LastModifiedMonitor(), 30000L); try {// www .j a v a 2 s .c om loadCache(); } catch (final IllegalStateException e) { throw new InitializationException(e.getMessage(), e); } }
From source file:com.github.springtestdbunit.DbUnitTestExecutionListenerPrepareTest.java
@Test public void shouldFailIfNoDbConnectionBeanIsFound() throws Exception { ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(NoDbUnitConfiguration.class); try {//from www . j a v a 2s. com testContextManager.prepareTestInstance(); } catch (IllegalStateException ex) { assertTrue(ex.getMessage().startsWith("Unable to find a DB Unit database connection")); } }
From source file:com.edmunds.etm.web.page.MaintenancePage.java
protected boolean onSuspendClick() { try {/*from www. j a va2s .c om*/ failoverMonitor.suspend(); } catch (IllegalStateException e) { getContext().setFlashAttribute("error", e.getMessage()); } setRedirect(MaintenancePage.class); return false; }
From source file:com.edmunds.etm.web.page.MaintenancePage.java
protected boolean onResumeClick() { try {//from www. j av a 2s . co m failoverMonitor.resume(); } catch (IllegalStateException e) { getContext().setFlashAttribute("error", e.getMessage()); } setRedirect(MaintenancePage.class); return false; }
From source file:net.sourceforge.jwbf.mediawiki.live.LoginIT.java
/** * Test invalid installation of MW. TODO change exception test, should fail if no route to test * host// www. j a v a 2 s. co m */ @Test public final void installationDefunct() throws Exception { JettyServer server = new JettyServer(); try { server.start(); bot = new MediaWikiBot("http://localhost:" + server.getPort() + "/"); bot.login("user", "pass"); fail(); } catch (IllegalStateException e) { assertTrue(e.getMessage().startsWith("invalid status: HTTP/1.1 404 Not Found;")); } finally { server.stop(); } }
From source file:com.netflix.genie.web.configs.MvcConfigUnitTests.java
/** * Test to make sure we can't create a jobs dir resource if the directory can't be created when the input jobs * dir is invalid in any way./* w w w. jav a 2s . c o m*/ * * @throws IOException On error */ @Test public void cantGetJobsDirWhenJobsDirInvalid() throws IOException { final ResourceLoader resourceLoader = Mockito.mock(ResourceLoader.class); final String jobsDirLocation = UUID.randomUUID().toString(); final JobsProperties jobsProperties = new JobsProperties(); jobsProperties.getLocations().setJobs(jobsDirLocation); final Resource tmpResource = Mockito.mock(Resource.class); Mockito.when(resourceLoader.getResource(jobsDirLocation)).thenReturn(tmpResource); Mockito.when(tmpResource.exists()).thenReturn(true); final File file = Mockito.mock(File.class); Mockito.when(tmpResource.getFile()).thenReturn(file); Mockito.when(file.isDirectory()).thenReturn(false); try { this.mvcConfig.jobsDir(resourceLoader, jobsProperties); Assert.fail(); } catch (final IllegalStateException ise) { Assert.assertThat(ise.getMessage(), Matchers.is(jobsDirLocation + " exists but isn't a directory. Unable to continue")); } final String localJobsDir = jobsDirLocation + "/"; Mockito.when(file.isDirectory()).thenReturn(true); final Resource jobsDirResource = Mockito.mock(Resource.class); Mockito.when(resourceLoader.getResource(localJobsDir)).thenReturn(jobsDirResource); Mockito.when(tmpResource.exists()).thenReturn(false); Mockito.when(jobsDirResource.exists()).thenReturn(false); Mockito.when(jobsDirResource.getFile()).thenReturn(file); Mockito.when(file.mkdirs()).thenReturn(false); try { this.mvcConfig.jobsDir(resourceLoader, jobsProperties); Assert.fail(); } catch (final IllegalStateException ise) { Assert.assertThat(ise.getMessage(), Matchers.is("Unable to create jobs directory " + jobsDirLocation + " and it doesn't exist.")); } }