Example usage for junit.framework Assert fail

List of usage examples for junit.framework Assert fail

Introduction

In this page you can find the example usage for junit.framework Assert fail.

Prototype

static public void fail(String message) 

Source Link

Document

Fails a test with the given message.

Usage

From source file:eu.stratosphere.pact.runtime.task.CrossTaskExternalITCase.java

@Test
public void testExternalStreamCrossTask() {

    int keyCnt1 = 2;
    int valCnt1 = 1;

    // 87381 fit into memory, 87382 do not!
    int keyCnt2 = 87385;
    int valCnt2 = 1;

    super.initEnvironment(1 * 1024 * 1024);
    super.addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, false), 1);
    super.addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, false), 2);
    super.addOutput(this.outList);

    CrossTask<PactRecord, PactRecord, PactRecord> testTask = new CrossTask<PactRecord, PactRecord, PactRecord>();
    super.getTaskConfig().setLocalStrategy(LocalStrategy.NESTEDLOOP_STREAMED_OUTER_FIRST);
    super.getTaskConfig().setMemorySize(1 * 1024 * 1024);

    super.registerTask(testTask, MockCrossStub.class);

    try {/*w  ww .  jav  a  2  s  .  co m*/
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    int expCnt = keyCnt1 * valCnt1 * keyCnt2 * valCnt2;

    Assert.assertTrue("Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
            this.outList.size() == expCnt);

    this.outList.clear();

}

From source file:com.aliyun.oss.integrationtests.ImageProcessTest.java

@Test
public void testCropImage() {
    String style = "image/crop,w_100,h_100,x_100,y_100,r_1"; // ?

    try {//from   w  w  w.j ava 2  s  .c  om
        GetObjectRequest request = new GetObjectRequest(bucketName, originalImage);
        request.setProcess(style);

        OSSObject ossObject = ossClient.getObject(request);
        ossClient.putObject(bucketName, newImage, ossObject.getObjectContent());

        ImageInfo imageInfo = getImageInfo(bucketName, newImage);
        Assert.assertEquals(imageInfo.getHeight(), 100);
        Assert.assertEquals(imageInfo.getWidth(), 100);
        Assert.assertEquals(imageInfo.getSize(), 2281);
        Assert.assertEquals(imageInfo.getFormat(), "jpg");

    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:com.liferay.mobile.push.ReceivePushNotificationTest.java

@Test
public void receivePushNotification() throws JSONException {
    final String body = "body";
    final String message = "message";

    PushNotificationsService service = new PushNotificationsService();

    Intent intent = new Intent(Robolectric.application, PushNotificationsService.class);

    JSONObject payload = new JSONObject();
    payload.put(body, message);/*ww  w.  j a va 2 s  .c om*/

    intent.putExtra("payload", payload.toString());

    GoogleServices googleServices = Mockito.spy(GoogleServices.class);

    Mockito.when(googleServices.getMessageType(service, intent))
            .thenReturn(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE);

    service.setGoogleServices(googleServices);

    service.onCreate();

    push.onPushNotification(new OnPushNotification() {

        @Override
        public void onPushNotification(JSONObject pushNotification) {
            try {
                Assert.assertEquals(message, pushNotification.getString(body));
            } catch (JSONException je) {
                Assert.fail(je.getMessage());
            }
        }

    });

    service.onHandleIntent(intent);
}

From source file:de.fhg.iais.cortex.search.SolrSearchServerTest.java

@Test
public void testStartExceptions() {
    final String malformedContextURI = "ht:/iam.mal\\formed";
    SolrSearchServer solrSearchServer = new SolrSearchServer(this.homeMock, this.factoryMock,
            malformedContextURI, this.SOLR_SEARCH_DIR, this.SOLR_NODESTORE_DIR, this.SOLR_ENTITY_DIR);

    try {//w w w  . j  a  v  a  2  s  .  c o  m
        solrSearchServer.doStart();
        Assert.fail("Should throw a DbcException.");
    } catch (DbcException e) {
        ;
    }

    Mockito.when(this.factoryMock.createJetty9SolrRunner(new File(this.baseDir, "solr").getAbsolutePath(),
            this.CONTEXT_URI, 8183, false, 5000)).thenThrow(new RuntimeException("Just an exception."));

    solrSearchServer = new SolrSearchServer(this.homeMock, this.factoryMock, this.CONTEXT_URI,
            this.SOLR_SEARCH_DIR, this.SOLR_NODESTORE_DIR, this.SOLR_ENTITY_DIR);

    try {
        solrSearchServer.doStart();
        Assert.fail("Should throw a DbcException.");
    } catch (DbcException e) {
        ;
    }
}

From source file:com.liferay.mobile.push.DeviceRegistrationTest.java

protected void register(String registrationId) throws Exception {
    push.onFailure(new Push.OnFailure() {

        @Override/*from w w w. j av  a  2s.com*/
        public void onFailure(Exception e) {
            Assert.fail(e.getMessage());
        }

    }).register(registrationId);

    Robolectric.runBackgroundTasks();
}

From source file:dk.netarkivet.harvester.harvesting.MetadataFileWriterTester.java

public void testMetadataFileWriterWarc() {
    File metafile = new File("metadata.warc");
    MetadataFileWriter mdfw = MetadataFileWriterWarc.createWriter(metafile);

    String uri = "http://www.netarkivet.dk/";
    long ctm = System.currentTimeMillis();

    SecureRandom random = new SecureRandom();
    byte[] payload = new byte[8192];
    random.nextBytes(payload);/*from w  ww .j ava 2  s  .  co  m*/

    try {
        mdfw.write(uri, "application/binary", "127.0.0.1", ctm, payload);
        mdfw.close();
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail("Unexpected exception!");
    }

    metafile.deleteOnExit();

    File metadataArcFile = new File(TestInfo.WORKING_DIR, "42-metadata-1.warc");
    MetadataFileWriter mfwa = MetadataFileWriterWarc.createWriter(metadataArcFile);
    ((MetadataFileWriterWarc) mfwa).insertInfoRecord(new ANVLRecord());
    for (File f : logsDir.listFiles()) {
        mfwa.writeFileTo(f, "metadata://netarkivet.dk/crawl/logs/" + f.getName(), "text/plain");
    }
}

From source file:org.openmrs.module.feedback.web.FeedbackListControllerTest.java

/**
 * Test of referenceData method, of class FeedbackListController.
 *///from w w w.  j a va2  s.  c  o m
@Test
public void testReferenceData() throws Exception {
    System.out.println("referenceData");

    HttpServletRequest req = null;
    FeedbackAdminListController instance = new FeedbackAdminListController();
    Map expResult = null;
    Map result = instance.referenceData(req);

    /* to checl wheather the data is sent or not binded into the key feedback */
    if (!result.containsKey("feedbacks")) {
        Assert.fail("Do not contain the object feedbacks");
    }
}

From source file:org.opencastproject.remotetest.server.perf.ConcurrentWorkflowTest.java

@Test
@PerfTest(invocations = 100, threads = 100)
public void testStartAndRetrieveWorkflowInstance() 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()));
    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 we can retrieve the workflow instance from the rest endpoint
    HttpGet getWorkflowMethod = new HttpGet(BASE_URL + "/workflow/instance/" + id + ".xml");
    String getResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity());
    Assert.assertEquals(id, getWorkflowInstanceId(getResponse));

    // Make sure we can retrieve it via json, too
    HttpGet getWorkflowJson = new HttpGet(BASE_URL + "/workflow/instance/" + id + ".json");
    String jsonResponse = EntityUtils.toString(client.execute(getWorkflowJson).getEntity());
    JSONObject json = (JSONObject) JSONValue.parse(jsonResponse);
    if (json == null)
        Assert.fail("JSON response should not be null, but is " + jsonResponse);
    Assert.assertEquals(id, json.get("workflow_id"));

    // Ensure that the workflow finishes successfully
    int attempts = 0;
    while (true) {
        if (++attempts == 1000)
            Assert.fail("workflow rest endpoint test has hung");
        getWorkflowMethod = new HttpGet(BASE_URL + "/workflow/instance/" + id + ".xml");
        getResponse = EntityUtils.toString(client.execute(getWorkflowMethod).getEntity());
        String state = getWorkflowInstanceStatus(getResponse);
        if ("FAILED".equals(state))
            Assert.fail("workflow instance " + id + " failed");
        if ("SUCCEEDED".equals(state))
            break;
        System.out.println("workflow " + id + " is " + state);
        Thread.sleep(5000);//from   w w  w. j a v a 2 s .  c o  m
    }
}

From source file:com.pivotal.hawq.mapreduce.TPCHLocalTester.java

@Override
protected void testTPCHTable(HAWQTPCHSpec tpchSpec, String tableName) throws Exception {
    String caseName = tpchSpec.toString();

    final File caseFolder = new File(TEST_FOLDER, caseName);
    final File metadataFile = new File(caseFolder, tableName + ".yaml");
    final File answerFile = new File(caseFolder, tableName + ".ans");
    final File outputFile = new File(caseFolder, "output/part-r-00000");

    List<String> answers;

    if (caseFolder.exists()) {
        answers = Files.readLines(answerFile, Charsets.UTF_8);

    } else {/*from w w w  .jav a  2  s .  c  om*/
        caseFolder.mkdir();

        Connection conn = null;
        try {
            conn = MRFormatTestUtils.getTestDBConnection();

            // load TPCH data
            Map<String, String> rs = HAWQJdbcUtils.executeSafeQueryForSingleRow(conn,
                    "SELECT COUNT(*) segnum FROM gp_segment_configuration WHERE content>=0;");
            int segnum = Integer.parseInt(rs.get("segnum"));
            MRFormatTestUtils.runShellCommand(tpchSpec.getLoadCmd(segnum));

            // generate answer
            answers = MRFormatTestUtils.dumpTable(conn, tableName);
            Collections.sort(answers);
            Files.write(Joiner.on('\n').join(answers).getBytes(), answerFile);

            // extract metadata
            MRFormatTestUtils.runShellCommand(
                    String.format("gpextract -d %s -o %s %s", TEST_DB_NAME, metadataFile.getPath(), tableName));

            // copy data files to local
            MRFormatTestUtils.copyDataFilesToLocal(metadataFile);

            // transform metadata file to use local file locations
            MRFormatTestUtils.transformMetadata(metadataFile);

        } catch (Exception e) {
            // clean up if any error happens
            FileUtils.deleteDirectory(caseFolder);
            throw e;

        } finally {
            HAWQJdbcUtils.closeConnection(conn);
        }
    }

    // run input format driver
    int exitCode = MRFormatTestUtils.runMapReduceLocally(new Path(metadataFile.getPath()),
            new Path(outputFile.getParent()), null);
    Assert.assertEquals(0, exitCode);

    // compare result
    List<String> outputs = Files.readLines(outputFile, Charsets.UTF_8);

    if (!answers.equals(outputs))
        Assert.fail(String.format("HAWQInputFormat output for table %s differs with DB output:\n%s\n%s",
                tableName, answerFile, outputFile));
}

From source file:de.unentscheidbar.validation.DefaultMessageTextGetterTest.java

@Test
public void testDefaultMessageTexts() {

    Locale[] locales = { Locale.ROOT, Locale.GERMAN };

    Reflections r = new Reflections(new ConfigurationBuilder()
            .setUrls(ClasspathHelper.forPackage(ClassUtils.getPackageName(Validators.class)))
            .setScanners(new ResourcesScanner(), new SubTypesScanner(false)));

    Collection<Class<? extends Id>> defaultMessageClasses = Collections2.filter(
            r.getSubTypesOf(ValidationMessage.Id.class), Predicates.and(IS_NOT_ABSTRACT, IsTestClass.NO));
    Assert.assertTrue("Suspiciously few message ID classes found", defaultMessageClasses.size() > 10);

    MessageTextGetter mtg = Validation.defaultMessageTextGetter();

    for (Class<? extends Id> idClass : defaultMessageClasses) {
        /* only works with enums atm (all default message ids are enums) */
        if (!idClass.isEnum()) {
            Assert.fail("Cannot test " + idClass.getName());
        }/*from  w  ww  .  j  a  v a 2s. com*/
        for (Id id : idClass.getEnumConstants()) {
            for (Locale locale : locales) {
                Assert.assertTrue("Missing default message text for " + locale + " -> "
                        + id.getClass().getName() + " -> " + id.name(), mtg.hasText(id, locale));
            }
        }
    }
}