List of usage examples for junit.framework Assert fail
static public void fail(String message)
From source file:com.hoccer.tools.TestHelper.java
public static void assertGreater(String message, int minimum, int measured) { if (minimum > measured) { Assert.fail(message + " but " + minimum + " is greater than " + measured); }/* w ww.ja v a2 s. co m*/ }
From source file:org.opencastproject.remotetest.server.RetryStrategiesTest.java
@Test public void testHold() throws Exception { // Start a workflow instance via the rest endpoint HttpPost postStart = new HttpPost(BASE_URL + "/workflow/start"); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("definition", getSampleWorkflowDefinition("workflow-hold.xml"))); formParams.add(new BasicNameValuePair("mediapackage", getSampleMediaPackage())); formParams.add(new BasicNameValuePair("properties", "this=that")); postStart.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Grab the new workflow instance from the response String postResponse = EntityUtils.toString(client.execute(postStart).getEntity()); String id = getWorkflowInstanceId(postResponse); // Ensure that the workflow finishes successfully int attempts = 0; while (true) { if (++attempts == 20) Assert.fail("workflow rest endpoint test has hung"); HttpGet getWorkflowMethod = new HttpGet(BASE_URL + "/workflow/instance/" + id + ".xml"); String getResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity()); String state = getWorkflowInstanceStatus(getResponse); if ("PAUSED".equals(state)) break; if ("FAILED".equals(state)) Assert.fail("workflow instance " + id + " failed"); if ("SUCCEEDED".equals(state)) Assert.fail("workflow instance " + id + " succeeded"); System.out.println("workflow " + id + " is " + state); Thread.sleep(5000);/*ww w. j a va2s. co m*/ } // Get Ingest service state // Should be WARNING HttpGet getWorkflowMethod = new HttpGet( BASE_URL + "/services/services.json?serviceType=org.opencastproject.inspection&host=" + BASE_URL); String jsonResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity()); String state = new JSONObject(jsonResponse).getJSONObject("services").getJSONObject("service") .getString("service_state"); Assert.assertEquals("WARNING", state); // Get the number of failed on Ingest service, // Should be 1 getWorkflowMethod = new HttpGet(BASE_URL + "/services/count?serviceType=org.opencastproject.inspection"); String getResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity()); logger.debug("Job count response: {}", getResponse); Assert.assertEquals(1, Integer.parseInt(getResponse) - initCount); }
From source file:at.tugraz.ist.akm.test.webservice.server.SimpleWebServerTest.java
License:asdf
public void testSimpleJsonRequest() { try {/* w ww. j av a2 s.c o m*/ startServer(true); logDebug("testSimpleJsonRequest"); HttpPost httppost = newJsonHttpPost(); JSONObject request = new JSONObject(); request.put("method", "info"); httppost.setEntity(new StringEntity(request.toString())); HttpResponse httpresponse = mHttpClient.execute(httppost); stopServer(); mWebserver.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); httpresponse.getEntity().writeTo(baos); JSONObject response = new JSONObject(baos.toString(DEFAULT_ENCODING)); JSONObject batteryStatus = response.getJSONObject("battery"); String batteryIsCharging = batteryStatus.getString("is_charging"); String batteryLevel = batteryStatus.getString("battery_level"); String batteryLevelIcon = batteryStatus.getString("battery_level_icon"); String isAcCharge = batteryStatus.getString("is_ac_charge"); String isFull = batteryStatus.getString("is_full"); String isUsbCharge = batteryStatus.getString("is_usb_charge"); String hasContactChanged = response.getString("contact_changed"); String smsReceived = response.getString("sms_received"); String smsSentError = response.getString("sms_sent_error"); String smsSentSuccess = response.getString("sms_sent_success"); String requestStatus = response.getString("state"); assertFalse(null == batteryIsCharging); assertFalse(null == batteryLevel); assertFalse(null == batteryLevelIcon); assertFalse(null == isAcCharge); assertFalse(null == isFull); assertFalse(null == isUsbCharge); assertFalse(null == hasContactChanged); assertFalse(null == smsReceived); assertFalse(null == smsSentError); assertFalse(null == smsSentSuccess); assertFalse(null == requestStatus); } catch (Exception ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } }
From source file:com.smartitengineering.util.opensearch.io.impl.dom.DomIOImplTest.java
public void testWrite() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OpenSearchDescriptorWriter writer = new OpenSearchDescriptorWriter(outputStream, MAX_DESC, true); try {/*from w w w . j a v a 2 s . co m*/ final long start = System.currentTimeMillis(); writer.write(); final long end = System.currentTimeMillis(); System.out.println("Time taken to write: " + (end - start)); } catch (IOException ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } final String toString = outputStream.toString(); System.out.println(toString); assertEquals(MAX, toString); outputStream = new ByteArrayOutputStream(); MAX_BUILDER.queries(OpenSearchAPIBuilders.getQueryBuilder().searchTerms("some terms") .customAttribute("xmlns:cns", "http://google.com/1.1").customAttribute("cns:add", "value").build()); writer = new OpenSearchDescriptorWriter(outputStream, MAX_BUILDER.build(), true); try { final long start = System.currentTimeMillis(); writer.write(); final long end = System.currentTimeMillis(); System.out.println("Time taken to write: " + (end - start)); } catch (IOException ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } final String extendedString = outputStream.toString(); System.out.println(extendedString); StringBuilder newStringBuilder = new StringBuilder(MAX); int insertionPoint = newStringBuilder.indexOf("<Developer>"); String additionalString = "<Query xmlns:cns=\"http://google.com/1.1\" cns:add=\"value\" role=\"example\" " + "searchTerms=\"some terms\" />"; newStringBuilder.insert(insertionPoint, additionalString); assertEquals(newStringBuilder.toString(), extendedString); }
From source file:com.verisign.epp.codec.verificationcode.EPPVerificationCodeTst.java
/** * Unit test of extending the domain create command with a single untyped * verification code contained in the verification code extension. *///from ww w . ja v a 2 s. co m public void testDomainWithVerificationCode() { EPPCodecTst.printStart("testDomainWithVerificationCode"); // Generic objects EPPTransId respTransId = new EPPTransId("ABC-12345", "54321-XYZ"); EPPEncodeDecodeStats theStats; // -- Extend Domain Create Command EPPDomainCreateCmd theDomainCommand; theDomainCommand = new EPPDomainCreateCmd("ABC-12345", "domain.example", new EPPAuthInfo("2fooBAR")); EPPSignedCode signedCode = null; EPPEncodedSignedCodeValue encodedSignedCodeValue = null; // Create signed code and add extension try { signedCode = new EPPSignedCode("0-abc000", "domain"); signedCode.sign(privateKey, certChain); System.out.println("Signed Code = " + signedCode); if (!signedCode.validate(publicKey)) { Assert.fail("Signed code validation error using public key"); } if (!signedCode.validate(pkixParameters)) { Assert.fail("Signed code validation error using PKIX"); } if (!verificationCodeValidator.validate(signedCode.getCode(), signedCode.getTrustAnchor())) { Assert.fail("Verification code validation error"); } encodedSignedCodeValue = new EPPEncodedSignedCodeValue(signedCode); System.out.println("Encoded Signed Code = " + signedCode); // Signed Code is revoked? if (verificationCodeRevocationList.isRevoked(encodedSignedCodeValue)) { Assert.fail("testDomainWithVerificationCode(): Signed code with code = " + encodedSignedCodeValue.getCode() + " is unexpectedly revoked."); } theDomainCommand.addExtension(new EPPEncodedSignedCode(encodedSignedCodeValue)); } catch (EPPEncodeException e) { e.printStackTrace(); Assert.fail("EPPEncodeException: " + e); } catch (EPPException e) { e.printStackTrace(); Assert.fail("EPPException: " + e); } catch (Exception e) { e.printStackTrace(); Assert.fail("Exception: " + e); } theStats = EPPCodecTst.testEncodeDecode(theDomainCommand); System.out.println(theStats); if (!encodedSignedCodeValue.validate(pkixParameters)) { Assert.fail( "testDomainWithVerificationCode(): Signed code signature is NOT valid after command encode/decode"); } try { if (!verificationCodeValidator.validate(encodedSignedCodeValue.getCode(), encodedSignedCodeValue.getTrustAnchor())) { Assert.fail("testDomainWithVerificationCode(): Verification code validation error"); } } catch (EPPException e) { e.printStackTrace(); Assert.fail("Exception: " + e); } EPPCodecTst.printEnd("testDomainWithVerificationCode"); }
From source file:io.fabric8.quickstarts.restdsl.spark.CrmIT.java
/** * HTTP POST http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of * the add_customer.json file to add a new customer to the system. * <p/>/*from w w w . j av a 2s .c o m*/ * On the server side, it matches the CustomerService's addCustomer() method * * @throws Exception */ @Test @Ignore public void postCustomerTestJson() throws IOException { LOG.info("Sent HTTP POST request to add customer"); String inputFile = this.getClass().getResource("/add_customer.json").getFile(); File input = new File(inputFile); PostMethod post = new PostMethod(CUSTOMER_SERVICE_URL); post.addRequestHeader("Accept", "application/json"); RequestEntity entity = new FileRequestEntity(input, "application/json; charset=ISO-8859-1"); post.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); String res = ""; try { int result = httpclient.executeMethod(post); LOG.info("Response status code: " + result); LOG.info("Response body: "); res = post.getResponseBodyAsString(); LOG.info(res); } catch (IOException e) { LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL); LOG.error( "You should build the 'rest' quick start and deploy it to a local Fabric8 before running this test"); LOG.error("Please read the README.md file in 'rest' quick start root"); Assert.fail("Connection error"); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } Assert.assertTrue(res.contains("Jack")); }
From source file:org.atemsource.atem.utility.compare.OrderableCollectionComparatorTest.java
@Test public void testMovalAndChanged() { // we change one entity and move another one. The result is that the changed element is considered to be added and removed. EntityA a1 = createEntityA();//from ww w .j a v a2 s. co m EntityB b1 = createEntityB(); EntityA a2 = createEntityA(); EntityB b2 = createEntityB(); EntityB b3 = createEntityB(); b1.setInteger(1); b2.setInteger(5); b3.setInteger(7); a2.getList().add(b2); a2.getList().add(b1); a1.getList().add(b3); a1.getList().add(b2); Set<Difference> differences = comparisonAssociative.getDifferences(a1, a2); Assert.assertEquals(2, differences.size()); for (Difference difference : differences) { if (difference instanceof Addition) { Assert.assertEquals("list.1", ((Addition) difference).getPath().toString()); } else if (difference instanceof Removal) { Assert.assertEquals("list.0", ((Removal) difference).getPath().toString()); } else { Assert.fail("we expect an addition and a removal"); } } }
From source file:cz.PA165.vozovyPark.dao.VehicleDAOTest.java
/** * Test of findByUserClass method, of class VehicleDAO. *///from w ww . j av a 2 s.c o m @Test public void testFindByUserClass() { try { Vehicle mercedes1 = VehicleDAOTest.getVehicle("Mercedes", 20000, "R4 Diesel", "E", UserClassEnum.PRESIDENT, "2a-447i-882a45", 2009, "UEW6828"); Vehicle mercedes2 = VehicleDAOTest.getVehicle("Mercedes", 20000, "R4 Diesel", "C", UserClassEnum.MANAGER, "98-447i-883345", 2009, "UEW6828"); this.vehicleDao.createVehicle(mercedes1); this.vehicleDao.createVehicle(mercedes2); em.getTransaction().begin(); Collection<Vehicle> required = this.vehicleDao.findByUserClass(UserClassEnum.MANAGER); em.getTransaction().commit(); Assert.assertTrue("Vehicle with right user class was not loaded.", required.contains(mercedes2)); Assert.assertFalse("Vehicle with different user class was loaded as well", required.contains(mercedes1)); } catch (Exception ex) { Assert.fail("Unexpected exception was throwed: " + ex + " " + ex.getMessage()); } }
From source file:eu.stratosphere.pact.runtime.task.ReduceTaskTest.java
@Test public void testFailingReduceTask() { final int keyCnt = 100; final int valCnt = 20; addInput(new UniformRecordGenerator(keyCnt, valCnt, true)); addInputComparator(this.comparator); setOutput(this.outList); getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE); GroupReduceDriver<Record, Record> testTask = new GroupReduceDriver<Record, Record>(); try {//w w w . j a v a 2s . c o m testDriver(testTask, MockFailingReduceStub.class); Assert.fail("Function exception was not forwarded."); } catch (ExpectedTestException eetex) { // Good! } catch (Exception e) { LOG.debug(e); Assert.fail("Test caused exception."); } this.outList.clear(); }