List of usage examples for junit.framework Assert fail
static public void fail()
From source file:com.vmware.identity.sts.auth.impl.BETAuthenticatorTest.java
private void intTestInvalidCredExc(Authenticator authenticator, RequestSecurityTokenType rst) { try {//from w w w. j ava2s .co m authenticator.authenticate(newReq(rst)); Assert.fail(); } catch (InvalidCredentialsException e) { // expected } }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.LoginTests.java
private void testLoginOperationWithParameter(final Object provider) throws Throwable { final ResultsContainer result = new ResultsContainer(); // Create client MobileServiceClient client = null;/* ww w .j ava 2s . com*/ try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); } catch (MalformedURLException e) { } // Add a new filter to the client client = client.withFilter(new ServiceFilter() { @Override public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) { result.setRequestUrl(request.getUrl()); ServiceFilterResponseMock response = new ServiceFilterResponseMock(); response.setContent("{authenticationToken:'123abc', user:{userId:'123456'}}"); final SettableFuture<ServiceFilterResponse> resultFuture = SettableFuture.create(); resultFuture.set(response); return resultFuture; } }); HashMap<String, String> parameters = new HashMap<>(); parameters.put("p1", "p1value"); parameters.put("p2", "p2value"); String parameterQueryString = "?p2=p2value&p1=p1value"; try { MobileServiceUser user; if (provider.getClass().equals(MobileServiceAuthenticationProvider.class)) { client.login((MobileServiceAuthenticationProvider) provider, "{myToken:123}", parameters).get(); } else { client.login((String) provider, "{myToken:123}", parameters).get(); } } catch (Exception exception) { Assert.fail(); } // Assert String expectedURL = appUrl + "login/" + provider.toString().toLowerCase(Locale.getDefault()) + parameterQueryString; assertEquals(expectedURL, result.getRequestUrl()); }
From source file:com.brienwheeler.lib.test.stepper.SteppableThreadTest.java
private void interruptInWait(SteppableThread stepper, TestMode mode) throws InterruptedException { final Thread testThread = Thread.currentThread(); Thread interruptThread = new Thread() { @Override/*from w w w . j a v a2 s . com*/ public void run() { try { Thread.sleep(10L); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } testThread.interrupt(); } }; interruptThread.start(); try { if (mode == TestMode.RELEASE) stepper.release(); else if (mode == TestMode.WAITDONE) stepper.waitDone(); else if (mode == TestMode.JOIN) stepper.releaseAndJoin(); Assert.fail(); } catch (RuntimeException e) { Assert.assertTrue(Thread.interrupted()); // test and clear Assert.assertEquals(InterruptedException.class, e.getCause().getClass()); } interruptThread.join(); }
From source file:org.opencastproject.remotetest.server.ComposerRestEndpointTest.java
@Test public void testTrimming() throws Exception { HttpPost postEncode = new HttpPost(ComposerResources.getServiceUrl() + "trim"); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("sourceTrack", SampleUtils.generateVideoTrack(BASE_URL))); formParams.add(new BasicNameValuePair("start", "2000")); formParams.add(new BasicNameValuePair("duration", "5000")); formParams.add(new BasicNameValuePair("profileId", "trim.work")); postEncode.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Grab the job from the response HttpResponse postResponse = client.execute(postEncode); String postResponseXml = EntityUtils.toString(postResponse.getEntity()); Assert.assertEquals(200, postResponse.getStatusLine().getStatusCode()); Assert.assertTrue(postResponseXml.contains("job")); // Poll for the finished composer job // Poll the service for the status of the job. String jobId = getJobId(postResponseXml); while (!JobUtils.isJobInState(jobId, "FINISHED")) { Thread.sleep(2000); // wait and try again System.out.println("Waiting for encoding job " + jobId + " to finish"); if (JobUtils.isJobInState(jobId, "FAILED")) { Assert.fail(); }/*from w w w . j a v a 2 s .com*/ } // Get the track xml from the job String jobXml = JobUtils.getJobAsXml(jobId); long duration = getDurationFromJob(jobXml); Assert.assertTrue(duration < 14546); }
From source file:eu.stratosphere.pact.runtime.task.ReduceTaskTest.java
@Test public void testCancelReduceTaskWhileSorting() { addInputComparator(this.comparator); setOutput(new NirvanaOutputList()); getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE); final GroupReduceDriver<Record, Record> testTask = new GroupReduceDriver<Record, Record>(); try {//from w w w. j a v a2s . com addInputSorted(new DelayingInfinitiveInputIterator(100), this.comparator.duplicate()); } catch (Exception e) { e.printStackTrace(); Assert.fail(); } final AtomicBoolean success = new AtomicBoolean(false); Thread taskRunner = new Thread() { @Override public void run() { try { testDriver(testTask, MockReduceStub.class); success.set(true); } catch (Exception ie) { ie.printStackTrace(); } } }; taskRunner.start(); TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this); tct.start(); try { tct.join(); taskRunner.join(); } catch (InterruptedException ie) { Assert.fail("Joining threads failed"); } Assert.assertTrue("Test threw an exception even though it was properly canceled.", success.get()); }
From source file:org.jongo.SaveTest.java
@Test public void shouldFailWhenMarshallerFail() throws Exception { try {/*from w w w . j a v a2 s . c om*/ collection.save(new ErrorObject()); Assert.fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains("Unable to save object"); } }
From source file:com.brienwheeler.lib.test.stepper.SteppableThreadTest.java
private void breakBarrier(CyclicBarrier barrier) throws BrokenBarrierException { final Thread testThread = Thread.currentThread(); Thread interruptThread = new Thread() { @Override/* ww w . java 2s. co m*/ public void run() { try { Thread.sleep(10L); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } testThread.interrupt(); } }; interruptThread.start(); try { barrier.await(); Assert.fail(); } catch (InterruptedException e) { } }
From source file:org.opencastproject.remotetest.server.ComposerRestEndpointTest.java
@Test public void testWatermarking() throws Exception { File workingDirectory = new File(System.getProperty("java.io.tmpdir"), "watermarktest"); if (!workingDirectory.exists()) { workingDirectory.mkdirs();//from w w w . ja v a 2 s . c o m } URL sourceUrl = getClass().getResource("/watermark.png"); File sourceFile = new File(workingDirectory, "watermark.png"); FileUtils.copyURLToFile(sourceUrl, sourceFile); HttpPost postEncode = new HttpPost(ComposerResources.getServiceUrl() + "watermark"); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("sourceTrack", SampleUtils.generateVideoTrack(BASE_URL))); formParams.add(new BasicNameValuePair("watermark", sourceFile.getAbsolutePath())); formParams.add(new BasicNameValuePair("profileId", "watermark.branding")); postEncode.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Grab the job from the response HttpResponse postResponse = client.execute(postEncode); String postResponseXml = EntityUtils.toString(postResponse.getEntity()); String jobId = getJobId(postResponseXml); Assert.assertEquals(200, postResponse.getStatusLine().getStatusCode()); Assert.assertTrue(postResponseXml.contains("job")); // Poll the service for the status of the job. while (!JobUtils.isJobInState(jobId, "FINISHED")) { Thread.sleep(2000); // wait and try again System.out.println("Waiting for watermarking job " + jobId + " to finish"); if (JobUtils.isJobInState(jobId, "FAILED")) { Assert.fail(); } } FileUtils.forceDelete(workingDirectory); }
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterTest.java
@Test public void shouldHashCodeDoNotHaveCycleWithBelongsToFields() throws Exception { // given/*w ww . ja v a2 s .com*/ Object firstEntity = classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "firstEntity")) .newInstance(); Object thirdEntity = classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "thirdEntity")) .newInstance(); BeanUtils.setProperty(firstEntity, "fieldThirdEntity", thirdEntity); BeanUtils.setProperty(thirdEntity, "fieldFirstEntity", firstEntity); // when & then try { firstEntity.hashCode(); thirdEntity.hashCode(); } catch (StackOverflowError t) { Assert.fail(); } }
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.LoginTests.java
@SuppressWarnings("deprecation") private void testLoginCallbackOperation(final Object provider) throws Throwable { final CountDownLatch latch = new CountDownLatch(1); final ResultsContainer result = new ResultsContainer(); // Create client MobileServiceClient client = null;// w w w . ja v a 2 s. com try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); } catch (MalformedURLException e) { } // Add a new filter to the client client = client.withFilter(new ServiceFilter() { @Override public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) { result.setRequestUrl(request.getUrl()); ServiceFilterResponseMock response = new ServiceFilterResponseMock(); response.setContent("{authenticationToken:'123abc', user:{userId:'123456'}}"); final SettableFuture<ServiceFilterResponse> resultFuture = SettableFuture.create(); resultFuture.set(response); return resultFuture; } }); UserAuthenticationCallback callback = new UserAuthenticationCallback() { @Override public void onCompleted(MobileServiceUser user, Exception exception, ServiceFilterResponse response) { if (exception == null) { assertEquals("123456", user.getUserId()); assertEquals("123abc", user.getAuthenticationToken()); } else { Assert.fail(); } latch.countDown(); } }; if (provider.getClass().equals(MobileServiceAuthenticationProvider.class)) { client.login((MobileServiceAuthenticationProvider) provider, "{myToken:123}", callback); } else { client.login((String) provider, "{myToken:123}", callback); } latch.await(); // Assert String expectedURL = appUrl + "login/" + provider.toString().toLowerCase(Locale.getDefault()); assertEquals(expectedURL, result.getRequestUrl()); }