List of usage examples for junit.framework Assert fail
static public void fail(String message)
From source file:baggage.BaseTestCase.java
protected static void assertRoundsTo(String message, double expected, double right, double roundingFactor) { boolean isWithinBounds = right > expected - roundingFactor && right < expected + roundingFactor; if (!isWithinBounds) { Assert.fail(message); }/* www .j a v a 2 s.c o m*/ }
From source file:com.cubusmail.server.user.UserAccountDaoTest.java
@Before public void initDB() { this.userAccountDao = this.applicationContext.getBean(IUserAccountDao.class); this.testUserAccount = this.applicationContext.getBean("testUserAccount", UserAccount.class); this.dataSource = this.applicationContext.getBean(SingleConnectionDataSource.class); DBManager manager = this.applicationContext.getBean(DBManager.class); try {//from ww w .j a v a2 s. com manager.initInternalDB(); Long id = this.userAccountDao.saveUserAccount(testUserAccount); Assert.assertNotNull(id); } catch (SQLException e) { log.error(e.getMessage(), e); Assert.fail(e.getMessage()); } catch (IOException e) { log.error(e.getMessage(), e); Assert.fail(e.getMessage()); } }
From source file:cz.PA165.vozovyPark.dao.ServiceIntervalDAOTest.java
/** * *//*from w ww . j av a 2s . c om*/ @Test public void testUpdateWithNullArgument() { try { serviceIntervalDAO.updateSI(null); Assert.fail("Exception for null argument was not throwed!"); } catch (IllegalArgumentException ex) { } catch (Exception ex) { Assert.fail("Unknown exception type was throwed: " + ex + " " + ex.getMessage()); } }
From source file:org.opencastproject.remotetest.server.YoutubeDistributionRestEndpointTest.java
@Test public void testDistributeAndRetract() throws Exception { // ----------------------------------------------------- // Upload the video to youtube // ----------------------------------------------------- HttpPost postStart = new HttpPost(BASE_URL + "/youtube/"); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("mediapackage", getSampleMediaPackage())); formParams.add(new BasicNameValuePair("elementId", "track-1")); postStart.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Ensure we get a 200 OK HttpResponse response = client.execute(postStart); Assert.assertEquals("Upload to youtube failed!", 200, response.getStatusLine().getStatusCode()); String jobXML = EntityUtils.toString(response.getEntity()); long jobId = getJobId(jobXML); // Check if job is finished // Ensure that the job finishes successfully int attempts = 0; while (true) { if (++attempts == 20) Assert.fail("ServiceRegistry rest endpoint test has hung"); HttpGet getJobMethod = new HttpGet(BASE_URL + "/services/job/" + jobId + ".xml"); jobXML = EntityUtils.toString(client.execute(getJobMethod).getEntity()); String state = getJobStatus(jobXML); if ("FINISHED".equals(state)) { // Get Mediapackage Track from flavor youtube/watchpage String payload = getPayloadFromJob(jobXML); String youtubeXmlUrl = getYoutubeURL(payload); HttpURLConnection connection = (HttpURLConnection) new URL(youtubeXmlUrl).openConnection(); Assert.assertEquals("Url status code from uploaded video is not 200", 200, connection.getResponseCode()); break; }//from w w w. j ava2 s . c om if ("FAILED".equals(state)) Assert.fail("Job " + jobId + " failed"); System.out.println("Job " + jobId + " is " + state); Thread.sleep(5000); } // ----------------------------------------------------- // Retract the video from youtube // ----------------------------------------------------- retract(); }
From source file:com.smartitengineering.dao.hbase.autoincrement.AutoIncrementRowIdForLongTest.java
@BeforeClass public static void globalSetup() throws Exception { /*/* w w w. ja v a 2s .c om*/ * Start HBase and initialize tables */ //-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); try { TEST_UTIL.startMiniCluster(); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); } //Create table for testing InputStream classpathResource = AutoIncrementRowIdForLongTest.class.getClassLoader() .getResourceAsStream("ddl-config-sample1.json"); Collection<HBaseTableConfiguration> configs = ConfigurationJsonParser.getConfigurations(classpathResource); try { new HBaseTableGenerator(configs, TEST_UTIL.getConfiguration(), true).generateTables(); } catch (Exception ex) { LOGGER.error("Could not create table!", ex); Assert.fail(ex.getMessage()); } pool = new HTablePool(TEST_UTIL.getConfiguration(), 200); //Start web app jettyServer = new Server(PORT); final String webapp = "./src/main/webapp/"; if (!new File(webapp).exists()) { throw new IllegalStateException("WebApp file/dir does not exist!"); } Properties properties = new Properties(); properties.setProperty(GuiceUtil.CONTEXT_NAME_PROP, "com.smartitengineering.dao.impl.hbase"); properties.setProperty(GuiceUtil.IGNORE_MISSING_DEP_PROP, Boolean.TRUE.toString()); properties.setProperty(GuiceUtil.MODULES_LIST_PROP, TestModule.class.getName()); GuiceUtil.getInstance(properties).register(); WebAppContext webAppHandler = new WebAppContext(webapp, "/"); jettyServer.setHandler(webAppHandler); jettyServer.setSendDateHeader(true); jettyServer.start(); //Initialize client final MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.getParams().setDefaultMaxConnectionsPerHost(THREAD_COUNT); manager.getParams().setMaxTotalConnections(THREAD_COUNT); httpClient = new HttpClient(manager); }
From source file:org.opencastproject.remotetest.server.YouTubePublicationRestEndpointTest.java
@Test public void testPublishAndRetract() throws Exception { // ----------------------------------------------------- // Upload the video to youtube // ----------------------------------------------------- HttpPost postStart = new HttpPost(BASE_URL + "/youtube/"); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("mediapackage", getSampleMediaPackage())); formParams.add(new BasicNameValuePair("elementId", "track-1")); postStart.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Ensure we get a 200 OK HttpResponse response = client.execute(postStart); Assert.assertEquals("Upload to youtube failed!", 200, response.getStatusLine().getStatusCode()); String jobXML = EntityUtils.toString(response.getEntity()); long jobId = getJobId(jobXML); // Check if job is finished // Ensure that the job finishes successfully int attempts = 0; while (true) { if (++attempts == 20) Assert.fail("ServiceRegistry rest endpoint test has hung"); HttpGet getJobMethod = new HttpGet(BASE_URL + "/services/job/" + jobId + ".xml"); jobXML = EntityUtils.toString(client.execute(getJobMethod).getEntity()); String state = getJobStatus(jobXML); if ("FINISHED".equals(state)) { // Get Mediapackage Publication String payload = getPayloadFromJob(jobXML); String youtubeXmlUrl = getYoutubeURL(payload); HttpURLConnection connection = (HttpURLConnection) new URL(youtubeXmlUrl).openConnection(); Assert.assertEquals("Url status code from uploaded video is not 200", 200, connection.getResponseCode()); break; }//from ww w. jav a 2 s . com if ("FAILED".equals(state)) Assert.fail("Job " + jobId + " failed"); System.out.println("Job " + jobId + " is " + state); Thread.sleep(5000); } // ----------------------------------------------------- // Retract the video from youtube // ----------------------------------------------------- retract(getSamplePublishedMediaPackage()); }
From source file:org.zenoss.metrics.reporter.HttpPosterTest.java
@Test public void authPost() throws IOException { stubFor(post(urlEqualTo(URL_PATH)).withHeader("Accept", matching("application/json.*")) .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml") .withHeader("Set-Cookie", "cookieName=cookieValue") .withBody("<response>Some content</response>"))); URL url = new URL("http", "localhost", MOCK_PORT, URL_PATH); HttpPoster poster = new Builder(url).setUsername("test_user").setPassword("test_pass").build(); poster.start();//from www .j av a 2s . c o m MetricBatch batch = new MetricBatch(8); batch.addMetric(new Metric("mname", 8, 9999)); poster.post(batch); verify(postRequestedFor(urlEqualTo(URL_PATH)) .withHeader("Content-Type", equalTo("application/json; charset=UTF-8")) .withHeader("Authorization", equalTo("Basic dGVzdF91c2VyOnRlc3RfcGFzcw==")).withRequestBody(equalTo( "{\"metrics\":[{\"metric\":\"mname\",\"timestamp\":8,\"value\":9999.0,\"tags\":{}}]}"))); //verify cookie and auth header resent and basic auth not sent poster.post(batch); verify(postRequestedFor(urlEqualTo(URL_PATH)) .withHeader("Content-Type", equalTo("application/json; charset=UTF-8")) .withHeader("Cookie", equalTo("cookieName=cookieValue")).withoutHeader("Authorization") .withRequestBody(equalTo( "{\"metrics\":[{\"metric\":\"mname\",\"timestamp\":8,\"value\":9999.0,\"tags\":{}}]}"))); //send 401 to verify re auth stubFor(post(urlEqualTo(URL_PATH)).willReturn(aResponse().withStatus(401))); try { poster.post(batch); Assert.fail("expected unauthorized"); } catch (HttpResponseException e) { Assert.assertEquals(e.getMessage(), "Unauthorized"); } //setup for reauthentication with different cookie stubFor(post(urlEqualTo(URL_PATH)).withHeader("Accept", matching("application/json.*")) .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml") .withHeader("Set-Cookie", "cookieName=newCookie") .withBody("<response>Some content</response>"))); poster.post(batch); //verify auth sent and no cookies verify(postRequestedFor(urlEqualTo(URL_PATH)) .withHeader("Content-Type", equalTo("application/json; charset=UTF-8")) .withHeader("Authorization", equalTo("Basic dGVzdF91c2VyOnRlc3RfcGFzcw==")).withoutHeader("Cookie") .withRequestBody(equalTo( "{\"metrics\":[{\"metric\":\"mname\",\"timestamp\":8,\"value\":9999.0,\"tags\":{}}]}"))); //verify no auth and new cookie sent poster.post(batch); verify(postRequestedFor(urlEqualTo(URL_PATH)) .withHeader("Content-Type", equalTo("application/json; charset=UTF-8")) .withHeader("Cookie", notMatching("cookieName=cookieValue")) .withHeader("Cookie", equalTo("cookieName=newCookie")).withoutHeader("Authorization") .withRequestBody(equalTo( "{\"metrics\":[{\"metric\":\"mname\",\"timestamp\":8,\"value\":9999.0,\"tags\":{}}]}"))); poster.shutdown(); }
From source file:baggage.BaseTestCase.java
protected void expectEvent(String event) throws Exception { String result = eventQueue.take(); if (!event.equals(result)) { Assert.fail("Expected event [" + event + "], got [" + result + "]"); }/*from w w w. ja v a 2s .co m*/ }
From source file:at.tugraz.ist.akm.test.webservice.handler.FileRequestHandlerTest.java
public void testHandle() { HttpRequest httpRequest = new BasicHttpEntityEnclosingRequest("none", URI); HttpResponse httpResponse = new BasicHttpResponse( new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "")); try {//from w w w . j a va 2 s . c om testInstance.handle(httpRequest, httpResponse, null); Assert.assertEquals(200, httpResponse.getStatusLine().getStatusCode()); Assert.assertNotNull(httpResponse.getEntity()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); httpResponse.getEntity().writeTo(baos); FileReader reader = new FileReader(getInstrumentation().getContext(), DATA_FILE); Assert.assertEquals(reader.read(), new String(baos.toByteArray(), DEFAULT_ENCODING)); reader.close(); reader = null; } catch (HttpException httpException) { Assert.fail("Exception => " + httpException.getMessage()); httpException.printStackTrace(); } catch (IOException ioException) { Assert.fail("Exception => " + ioException.getMessage()); ioException.printStackTrace(); } }
From source file:com.rmn.qa.aws.VmManagerTest.java
@Test // Test if an AWS private key is not set, the appropriate exception if thrown public void testPrivateKeyNotSet() { MockAmazonEc2Client client = new MockAmazonEc2Client(null); Properties properties = new Properties(); properties.setProperty(AutomationConstants.AWS_ACCESS_KEY, "foo"); String region = "east"; AwsVmManager AwsVmManager = new AwsVmManager(client, properties, region); try {//www .j a v a 2 s . c o m AwsVmManager.getCredentials(); } catch (IllegalArgumentException e) { Assert.assertTrue("Message should be related to access key: " + e.getMessage(), e.getMessage().contains(AutomationConstants.AWS_PRIVATE_KEY)); return; } Assert.fail("Exception should have been throw for access key"); }