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:org.obiba.onyx.core.etl.participant.impl.XmlParticipantReaderTest.java

/**
 * Tests processing of an appointment list where an attribute (Appointment Time, line 5) has been assigned a value of
 * the wrong type.//ww w.ja  va2  s.  co  m
 * 
 * @throws IOException if the appointment list could not be read
 */
@Test
public void testProcessWithWrongAttributeValueType() throws IOException {
    XmlParticipantReaderForTest reader = createXmlParticipantReaderForTest(false,
            TEST_RESOURCES_DIR + "/appointmentList_wrongAttributeValueType.xml");
    reader.setColumnNameToAttributeNameMap(columnNameToAttributeNameMap);
    reader.setParticipantMetadata(participantMetadata);

    reader.open(context);
    List<Participant> participants = new ArrayList<Participant>();

    try {
        while (reader.getIterator().hasNext()) {
            Participant participant = reader.read();
            if (participant != null)
                participants.add(participant);
        }
    } catch (Exception e) {
        String errorMessage = e.getMessage();
        Assert.assertEquals("Wrong data type value for field 'Appointment Time': TEST", errorMessage);
        return;
    }

    Assert.fail("Should have thrown an IllegalArgumentException");
}

From source file:eu.trentorise.smartcampus.ac.provider.repository.persistence.AcDaoPersistenceImplTest.java

@Test
public void updateUserAttributeNoAuth() {
    User u = dao.readUser("token_3");

    List<Attribute> list = u.getAttributes();
    List<Attribute> cloneList = new ArrayList<Attribute>(list);

    // new attribute authority not exist
    Authority newAuth = new Authority();
    newAuth.setName("newAuthority");
    newAuth.setRedirectUrl("url_authority");

    Attribute newA = new Attribute();
    newA.setKey("key1");
    newA.setValue("valueA");
    newA.setAuthority(newAuth);// w  ww .  j a  v a2 s  . c o m

    cloneList.add(newA);

    Assert.assertTrue(dao.readUsers(list).size() > 0);
    Assert.assertTrue(dao.readUsers(cloneList).size() == 0);
    Assert.assertTrue(dao.readAuthorityByName("newAuthority") == null);

    u.setAttributes(cloneList);
    try {
        dao.update(u);
        Assert.fail("IllegalArgumentException not throw");
    } catch (IllegalArgumentException e) {

    }
    Assert.assertTrue(dao.readAuthorityByName("newAuthority") == null);
    Assert.assertTrue(dao.readUsers(cloneList).size() == 0);

}

From source file:com.smartitengineering.util.opensearch.io.impl.dom.DomIOImplTest.java

public void testRead() {
    OpenSearchDescriptorParser parser = new OpenSearchDescriptorParser(IOUtils.toInputStream(MIN));
    try {/*  www  .j  a v a  2s .c om*/
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        final OpenSearchDescriptor parsedDesc = parser.parse();
        OpenSearchDescriptorWriter writer = new OpenSearchDescriptorWriter(outputStream, parsedDesc, true);
        writer.write();
        final String toString = outputStream.toString();
        System.out.println(toString);
        assertEquals(MIN, toString);
    } catch (IOException ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
    parser = new OpenSearchDescriptorParser(IOUtils.toInputStream(MAX));
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        final OpenSearchDescriptor parsedDesc = parser.parse();
        OpenSearchDescriptorWriter writer = new OpenSearchDescriptorWriter(outputStream, parsedDesc, true);
        writer.write();
        final String toString = outputStream.toString();
        System.out.println(toString);
        assertEquals(MAX, toString);
    } catch (IOException ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
    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);
    parser = new OpenSearchDescriptorParser(IOUtils.toInputStream(newStringBuilder.toString()));
    try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        final OpenSearchDescriptor parsedDesc = parser.parse();
        OpenSearchDescriptorWriter writer = new OpenSearchDescriptorWriter(outputStream, parsedDesc, true);
        writer.write();
        final String toString = outputStream.toString();
        System.out.println(toString);
        assertEquals(newStringBuilder.toString(), toString);
    } catch (IOException ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
}

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

@Test
@SuppressWarnings("unchecked")
public void testSortingDataSinkTask() {

    int keyCnt = 100;
    int valCnt = 20;

    super.initEnvironment(MEMORY_MANAGER_SIZE * 4, NETWORK_BUFFER_SIZE);
    super.addInput(new UniformRecordGenerator(keyCnt, valCnt, true), 0);

    DataSinkTask<Record> testTask = new DataSinkTask<Record>();

    // set sorting
    super.getTaskConfig().setInputLocalStrategy(0, LocalStrategy.SORT);
    super.getTaskConfig().setInputComparator(new RecordComparatorFactory(new int[] { 1 },
            ((Class<? extends Key<?>>[]) new Class[] { IntValue.class })), 0);
    super.getTaskConfig().setMemoryInput(0, 4 * 1024 * 1024);
    super.getTaskConfig().setFilehandlesInput(0, 8);
    super.getTaskConfig().setSpillingThresholdInput(0, 0.8f);

    super.registerFileOutputTask(testTask, MockOutputFormat.class, new File(tempTestPath).toURI().toString());

    try {/*www.ja  v  a 2 s  .  c  o  m*/
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    File tempTestFile = new File(this.tempTestPath);

    Assert.assertTrue("Temp output file does not exist", tempTestFile.exists());

    FileReader fr = null;
    BufferedReader br = null;
    try {
        fr = new FileReader(tempTestFile);
        br = new BufferedReader(fr);

        Set<Integer> keys = new HashSet<Integer>();

        int curVal = -1;
        while (br.ready()) {
            String line = br.readLine();

            Integer key = Integer.parseInt(line.substring(0, line.indexOf("_")));
            Integer val = Integer.parseInt(line.substring(line.indexOf("_") + 1, line.length()));

            // check that values are in correct order
            Assert.assertTrue("Values not in ascending order", val >= curVal);
            // next value hit
            if (val > curVal) {
                if (curVal != -1) {
                    // check that we saw 100 distinct keys for this values
                    Assert.assertTrue("Keys missing for value", keys.size() == 100);
                }
                // empty keys set
                keys.clear();
                // update current value
                curVal = val;
            }

            Assert.assertTrue("Duplicate key for value", keys.add(key));
        }

    } catch (FileNotFoundException e) {
        Assert.fail("Out file got lost...");
    } catch (IOException ioe) {
        Assert.fail("Caught IOE while reading out file");
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (Throwable t) {
            }
        }
        if (fr != null) {
            try {
                fr.close();
            } catch (Throwable t) {
            }
        }
    }
}

From source file:org.deviceconnect.android.profile.restful.test.RESTfulDConnectTestCase.java

/**
 * RESTful?dConnectManager??./*ww  w. j  av  a  2s  . co m*/
 * @param request Http
 * @return HttpResponse
 */
protected final HttpResponse requestHttpResponse(final HttpUriRequest request) {
    HttpClient client = new DefaultHttpClient();
    try {
        return client.execute(request);
    } catch (ClientProtocolException e) {
        Assert.fail("ClientProtocolException: " + e.getMessage());
    } catch (IOException e) {
        Assert.fail("IOException: " + e.getMessage());
    }
    return null;
}

From source file:com.smartitengineering.dao.hbase.autoincrement.AutoIncrementRowIdForLongTest.java

@Test
public void testMultithreadedKeys() throws Exception {
    ExecutorService service = Executors.newFixedThreadPool(THREAD_COUNT);
    final long start = 102;
    final int bound = THREAD_COUNT;
    final int innerBound = 30;
    List<Future> futures = new ArrayList<Future>();
    final long startTime = System.currentTimeMillis();
    for (int i = 0; i < bound; ++i) {
        final int index = i;
        futures.add(service.submit(new Runnable() {

            @Override/* ww  w .j  av  a  2s.  c o m*/
            public void run() {
                for (int j = 0; j < innerBound; ++j) {
                    final HTableInterface table = pool.getTable(TABLE_NAME);
                    long id = index * bound + j + start;
                    final long id1 = getId();
                    synchronized (ids) {
                        final long mainId = Long.MAX_VALUE - id1;
                        Assert.assertFalse(ids.contains(mainId));
                        ids.add(mainId);
                    }
                    final byte[] row = Bytes.toBytes(id1);
                    Put put = new Put(row);
                    final byte[] toBytes = Bytes.toBytes("value " + id);
                    put.add(FAMILY_BYTES, CELL_BYTES, toBytes);
                    Result get1;
                    try {
                        table.put(put);
                        Get get = new Get(row);
                        get1 = table.get(get);
                    } catch (Exception ex) {
                        LOGGER.error(ex.getMessage(), ex);
                        get1 = null;
                        Assert.fail(ex.getMessage());
                    }
                    pool.putTable(table);
                    Assert.assertNotNull(get1);
                    Assert.assertFalse(get1.isEmpty());
                    Assert.assertTrue(Arrays.equals(row, get1.getRow()));
                    Assert.assertTrue(Arrays.equals(toBytes, get1.getValue(FAMILY_BYTES, CELL_BYTES)));
                }
            }
        }));
    }
    for (Future future : futures) {
        future.get();
    }
    final long endTime = System.currentTimeMillis();
    LOGGER.info("Time for " + (bound * innerBound) + " rows ID retrieval, put and get is "
            + (endTime - startTime) + "ms");
    Assert.assertEquals(bound * innerBound + start - 1, ids.size());
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitUtilTest.java

/**
 * Test the createControl function with Empty endUserId
 *//*  w  ww.  j a  va  2  s  . c om*/
@Test
public void createControlEmptyEndUser() {
    DbeExpendLimit limit = new DbeExpendLimit();
    DbeExpendLimitPK id = new DbeExpendLimitPK();
    id.setTxElType(ProcessingLimitService.DAY_PERIOD_TYPE);
    limit.setId(id);
    DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction();
    tx.setTxEndUserId(" ");
    DbeExpendControl control;
    try {
        control = utils.createControl(tx, limit);
        Assert.assertEquals(tx.getTxGlobalUserId(), control.getId().getTxEndUserId());
    } catch (RSSException e) {
        Assert.fail("Exception received: " + e.getMessage());
    }
}

From source file:byps.test.TestRemoteServerR.java

/**
 * The server tries to use a non-existing client interface implementation.
 * This must cause an exception. The call must not hang.
 * @throws BException//  w w w  .ja v  a  2s .  c  om
 * @throws InterruptedException
 */
@Test
public void testCallClientFromServerNoRemoteImpl() throws RemoteException {
    log.info("testCallClientFromServerNoRemoteImpl(");

    // Do not provide an implementation for the requested interface 
    // omit: client.addRemote(new BSkeleton_ClientIF() { ...

    try {
        remote.callClientIncrementInt(5);
        Assert.fail("Exception expected");
    } catch (BException e) {
        TestUtils.assertEquals(log, "exception", BExceptionC.SERVICE_NOT_IMPLEMENTED, e.code);
    }

    log.info(")testCallClientFromServerNoRemoteImpl");
}

From source file:com.redhat.demo.CrmTest.java

/**
 * HTTP PUT http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the update_customer.xml file to update the customer information for customer 123.
 * <p/>//from   w w w .j a  v  a  2  s .c  om
 * On the server side, it matches the CustomerService's updateCustomer() method
 *
 * @throws Exception
 */
@Test
public void putCustomerTest() throws IOException {

    LOG.info("Sent HTTP PUT request to update customer info");

    String inputFile = this.getClass().getResource("/update_customer.xml").getFile();
    File input = new File(inputFile);
    PutMethod put = new PutMethod(CUSTOMER_SERVICE_URL);
    RequestEntity entity = new FileRequestEntity(input, "application/xml; charset=ISO-8859-1");
    put.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    int result = 0;
    try {
        result = httpclient.executeMethod(put);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        LOG.info(put.getResponseBodyAsString());
    } 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
        put.releaseConnection();
    }

    Assert.assertEquals(result, 200);
}

From source file:io.fabric8.quickstarts.cxfcdi.CrmTest.java

/**
 * HTTP PUT http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of
 * the update_customer.xml file to update the customer information for customer 123.
 * <p/>// ww w  . ja v a2  s. c o m
 * On the server side, it matches the CustomerService's updateCustomer() method
 *
 * @throws Exception
 */
@Test
public void putCustomerTest() throws IOException {

    LOG.info("Sent HTTP PUT request to update customer info");

    String inputFile = this.getClass().getResource("/update_customer.xml").getFile();
    File input = new File(inputFile);
    PutMethod put = new PutMethod(CUSTOMER_SERVICE_URL);
    RequestEntity entity = new FileRequestEntity(input, "application/xml; charset=ISO-8859-1");
    put.setRequestEntity(entity);
    HttpClient httpclient = new HttpClient();
    int result = 0;
    try {
        result = httpclient.executeMethod(put);
        LOG.info("Response status code: " + result);
        LOG.info("Response body: ");
        LOG.info(put.getResponseBodyAsString());
    } catch (IOException e) {
        LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL);
        LOG.error(
                "You should build the 'cxf-cdi' quick start and deploy it to a local Fabric8 before running this test");
        LOG.error("Please read the README.md file in 'cxf-cdi' quick start root");
        Assert.fail("Connection error");
    } finally {
        // Release current connection to the connection pool once you are
        // done
        put.releaseConnection();
    }

    Assert.assertEquals(result, 200);
}