List of usage examples for junit.framework Assert fail
static public void fail()
From source file:org.opencastproject.remotetest.server.LtiAuthenticationTest.java
@Test public void testLtiLaunch() throws Exception { // Construct a POST message with the oauth parameters String nonce = UUID.randomUUID().toString(); String timestamp = Long.toString(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())); OAuthMessage oauthMessage = new OAuthMessage(OAuthMessage.POST, Main.BASE_URL + "/lti", null); oauthMessage.addParameter(OAuth.OAUTH_CONSUMER_KEY, CONSUMER_KEY); oauthMessage.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1); oauthMessage.addParameter(OAuth.OAUTH_NONCE, nonce); oauthMessage.addParameter(OAuth.OAUTH_TIMESTAMP, timestamp); // Add some LTI parameters oauthMessage.addParameter("user_id", LTI_CONSUMER_USER); oauthMessage.addParameter("context_id", LTI_CONSUMER_CONTEXT); oauthMessage.addParameter("consumer_gui", LTI_CONSUMER_GUID); oauthMessage.addParameter("custom_test", "true"); // Sign the request OAuthConsumer consumer = new OAuthConsumer(null, CONSUMER_KEY, CONSUMER_SECRET, null); OAuthAccessor accessor = new OAuthAccessor(consumer); oauthMessage.sign(accessor);//from ww w . j a va 2 s.c o m // Get the response OAuthResponseMessage oauthResponse = (OAuthResponseMessage) oauthClient.invoke(oauthMessage, ParameterStyle.BODY); // Make sure we got what we wanted Assert.assertEquals(HttpStatus.SC_OK, oauthResponse.getHttpResponse().getStatusCode()); String cookie = oauthResponse.getHttpResponse().getHeader("Set-Cookie"); Assert.assertNotNull(cookie); String sessionId = cookie.substring(0, cookie.lastIndexOf(";")); // Send a GET request to "/info/me.json" using this cookie HttpGet get = new HttpGet(Main.BASE_URL + "/info/me.json"); get.setHeader("Cookie", sessionId); HttpResponse httpResponse = httpClient.execute(get); String me = EntityUtils.toString(httpResponse.getEntity()); JSONObject meJson = (JSONObject) new JSONParser().parse(me); // Ensure that the "current user" was set by the LTI consumer Assert.assertEquals(LTI_USER_PREFIX + LTI_CONSUMER_NAME + LTI_CONSUMER_USER, meJson.get("username")); // Send a GET request to "/lti" using this cookie get = new HttpGet(Main.BASE_URL + "/lti"); get.setHeader("Cookie", sessionId); httpResponse = httpClient.execute(get); String lti = EntityUtils.toString(httpResponse.getEntity()); JSONObject ltiJson = (JSONObject) new JSONParser().parse(lti); // Ensure that the LTI information sent by the tool consumer is available Assert.assertEquals(LTI_CONSUMER_CONTEXT, ltiJson.get("context_id")); // Make sure we can't use the same nonce twice try { oauthResponse = (OAuthResponseMessage) oauthClient.invoke(oauthMessage, ParameterStyle.BODY); Assert.fail(); } catch (OAuthProblemException e) { // expected } }
From source file:com.tasktop.c2c.server.scm.service.ScmServiceBeanTest.java
@Test(expected = ValidationException.class) public void testCreateExternalScmRepository_BlankURL() throws Exception { String repositoryURL = ""; List<ScmRepository> repoSet = scmService.getScmRepositories(); assertEquals(0, repoSet.size());/*from w ww . j a v a 2s.c om*/ scmService.createScmRepository(createExternalRepo(repositoryURL)); // should throw exception Assert.fail(); }
From source file:org.opencastproject.remotetest.server.ComposerRestEndpointTest.java
@Test public void testImageConversion() throws Exception { HttpPost postEncode = new HttpPost(ComposerResources.getServiceUrl() + "convertimage"); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("sourceImage", SampleUtils.generateImageAttachment(BASE_URL))); formParams.add(new BasicNameValuePair("profileId", "image-conversion.http")); 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 image conversion job " + jobId + " to finish"); if (JobUtils.isJobInState(jobId, "FAILED")) { Assert.fail(); }/* w w w .jav a 2s. com*/ } }
From source file:com.tasktop.c2c.server.scm.service.ScmServiceBeanTest.java
@Test(expected = ValidationException.class) public void testCreateExternalScmRepository_NullURL() throws Exception { String repositoryURL = null;// w w w .j av a 2s . c om List<ScmRepository> repoSet = scmService.getScmRepositories(); assertEquals(0, repoSet.size()); scmService.createScmRepository(createExternalRepo(repositoryURL)); // should throw exception Assert.fail(); }
From source file:org.openxdata.server.util.LoadTest.java
@Test @Ignore("this test runs a lot of threads performing random service operations - i.e. takes a long time") public void testSimultaneousRandomConnections() throws Exception { long start = System.currentTimeMillis(); System.out.println("Start time: " + new Date()); // find the last test form created (it contains all the test data) List<FormDef> forms = studyManagerService.getForms(); if (forms != null) { for (FormDef form : forms) { FormDefVersion version = form.getDefaultVersion(); if (version != null && version.getName() != null && version.getName().startsWith("dagmar-testformversion-")) { if (this.form == null || this.form.getFormDefVersionId() < version.getFormDefVersionId()) { // first time around, or this version was created later this.form = version; }//from w w w . j a va 2 s. c o m } } if (form == null) { // we didn't find a match in the loop above ... // (perhaps the "testLotsOfData" test was never run) form = forms.get(forms.size() - 1).getDefaultVersion(); } System.out.println("Selected form " + form.getName()); } else { Assert.fail(); // can't continue the test further } // now try a lot of simultaneous random connections System.out.println("Creating the threads"); List<RandomExecutionThread> threads = new ArrayList<RandomExecutionThread>(); for (int i = 0; i < 125; i++) { threads.add(new RandomExecutionThread(i + 1)); } for (Thread thread : threads) { // ensures that the test only stops once the last thread is finished thread.join(); } long end = System.currentTimeMillis(); System.out.println("Time to run test: " + (end - start) + "ms"); int successfulCount = 0; int failedCount = 0; for (RandomExecutionThread thread : threads) { if (thread.isSuccessful()) { successfulCount++; } else { failedCount++; } } System.out.println("Successful calls: " + successfulCount + " Unsuccessful calls: " + failedCount); }
From source file:info.magnolia.utf8.Utf8ContentTest.java
@Test public void testCreateExportImportContentUtf8SpecialChars() { HierarchyManager hm = MgnlContext.getInstance().getHierarchyManager(RepositoryConstants.WEBSITE); String basePath = "utf8test"; String baseGreek = "\u03BA\u1F79\u03C3\u03BC\u03B5"; String text = "utf8!?#{}$!\u00A3%()=@"; try {/*from w w w . j a v a2 s . c o m*/ Content root = hm.getRoot(); Session session = root.getWorkspace().getSession(); Content base = root.createContent(basePath, ItemType.CONTENT); base = hm.getContent(basePath); Content special = base.createContent(text, ItemType.CONTENT); File xmlFile = exportNode(RepositoryConstants.WEBSITE, base.getWorkspace().getSession(), special); Content base2 = root.createContent(baseGreek, ItemType.CONTENT); FileInputStream inStream = new FileInputStream(xmlFile); session.importXML(base2.getHandle(), inStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); IOUtils.closeQuietly(inStream); xmlFile.delete(); assertEquals(2, root.getChildren().size()); assertEquals(1, base2.getChildren().size()); Content special2 = base2.getContent(text); assertEquals("/" + baseGreek + "/" + text, special2.getHandle()); } catch (AccessDeniedException e) { Assert.fail(); } catch (PathNotFoundException e) { Assert.fail(); } catch (RepositoryException e) { Assert.fail(); } catch (FileNotFoundException e) { Assert.fail(); } catch (IOException e) { Assert.fail(); } }
From source file:com.dianping.dpsf.centralstat.test.CentralStatTestCase.java
@Test public void testSyncServiceException() { log.info("$$$$$$$$$$testSyncServiceException"); try {//from w w w . ja v a 2 s . co m CentralStatTestService service = (CentralStatTestService) context.getBean("centralStatTestServiceSync"); service.invokeSyncServiceException("testSyncServiceException"); Assert.fail(); } catch (Exception e) { } }
From source file:com.vmware.identity.sts.auth.impl.BETAuthenticatorTest.java
private void intTestUnsupportedSecToken(Authenticator authenticator, RequestSecurityTokenType rst) { try {/*from w w w . j ava2s . c om*/ authenticator.authenticate(newReq(rst)); Assert.fail(); } catch (UnsupportedSecurityTokenException e) { // expected } }
From source file:com.dianping.dpsf.centralstat.test.CentralStatTestCase.java
@Test public void testFutureServiceException() { log.info("$$$$$$$$$$testFutureServiceException"); try {//from w w w . j a v a2 s . c o m CentralStatTestService service = (CentralStatTestService) context .getBean("centralStatTestServiceFuture"); service.invokeFutureServiceException("testFutureServiceException"); ServiceFutureFactory.getFuture()._get(); Assert.fail(); } catch (Throwable e) { } }
From source file:com.netflix.curator.TestSessionFailRetryLoop.java
@Test public void testBasic() throws Exception { Timing timing = new Timing(); final CuratorZookeeperClient client = new CuratorZookeeperClient(server.getConnectString(), timing.session(), timing.connection(), null, new RetryOneTime(1)); SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.FAIL); retryLoop.start();/*from ww w . j a v a 2 s.com*/ try { client.start(); try { while (retryLoop.shouldContinue()) { try { RetryLoop.callWithRetry(client, new Callable<Void>() { @Override public Void call() throws Exception { Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false)); KillSession.kill(client.getZooKeeper(), server.getConnectString()); client.getZooKeeper(); client.blockUntilConnectedOrTimedOut(); Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false)); return null; } }); } catch (Exception e) { retryLoop.takeException(e); } } Assert.fail(); } catch (SessionFailRetryLoop.SessionFailedException dummy) { // correct } } finally { retryLoop.close(); IOUtils.closeQuietly(client); } }