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:io.fabric8.quickstarts.fabric.rest.secure.CrmSecureTest.java

/**
 * HTTP GET http://localhost:8181/cxf/crm/customerservice/orders/223/products/323
 * returns the XML document representing product 323 in order 223
 * <p/>/*from   w  ww .  j  av  a  2s.  c  o m*/
 * On the server side, it matches the Order's getProduct() method
 *
 * @throws Exception
 */
@Test
public void getProductOrderTest() throws Exception {
    String res = "";

    LOG.info("============================================");
    LOG.info("Sent HTTP GET request to query sub resource product info");
    GetMethod get = new GetMethod(PRODUCT_ORDER_TEST_URL);

    get.getHostAuthState().setAuthScheme(scheme);
    try {
        httpClient.executeMethod(get);
        res = get.getResponseBodyAsString();
        LOG.info(res);
    } catch (IOException e) {
        LOG.error("Error connecting to {}", PRODUCT_ORDER_TEST_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 {
        get.releaseConnection();
    }
    Assert.assertTrue(res.contains("product 323"));
}

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

@Test
public void testMultiLevelMergeCombineTask() {

    int keyCnt = 32768;
    int valCnt = 8;

    super.initEnvironment(3 * 1024 * 1024);
    super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1);
    super.addOutput(this.outList);

    CombineTask<PactRecord> testTask = new CombineTask<PactRecord>();
    super.getTaskConfig().setLocalStrategy(LocalStrategy.COMBININGSORT);
    super.getTaskConfig().setMemorySize(3 * 1024 * 1024);
    super.getTaskConfig().setNumFilehandles(2);

    final int[] keyPos = new int[] { 0 };
    @SuppressWarnings("unchecked")
    final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class };
    PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(),
            super.getTaskConfig().getPrefixForInputParameters(0), keyPos, keyClasses);

    super.registerTask(testTask, MockCombiningReduceStub.class);

    try {/*from w w  w.  j  a va2 s  .c o m*/
        testTask.invoke();
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    }

    int expSum = 0;
    for (int i = 1; i < valCnt; i++) {
        expSum += i;
    }

    // wee need to do the final aggregation manually in the test, because the
    // combiner is not guaranteed to do that
    HashMap<PactInteger, PactInteger> aggMap = new HashMap<PactInteger, PactInteger>();
    for (PactRecord record : this.outList) {
        PactInteger key = new PactInteger();
        PactInteger value = new PactInteger();
        record.getField(0, key);
        record.getField(1, value);

        PactInteger prevVal = aggMap.get(key);
        if (prevVal != null) {
            aggMap.put(key, new PactInteger(prevVal.getValue() + value.getValue()));
        } else {
            aggMap.put(key, value);
        }
    }

    Assert.assertTrue("Resultset size was " + aggMap.size() + ". Expected was " + keyCnt,
            aggMap.size() == keyCnt);

    for (PactInteger integer : aggMap.values()) {
        Assert.assertTrue("Incorrect result", integer.getValue() == expSum);
    }

    this.outList.clear();

}

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

@Test
public void testSharpenImage() {
    String style = "image/sharpen,100"; // ?

    try {//from   w  w w  . jav a 2s. c  o m
        GetObjectRequest request = new GetObjectRequest(bucketName, originalImage);
        request.addParameter("x-oss-process", style);

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

        ImageInfo imageInfo = getImageInfo(bucketName, newImage);
        Assert.assertEquals(imageInfo.getHeight(), 267);
        Assert.assertEquals(imageInfo.getWidth(), 400);
        Assert.assertEquals(imageInfo.getSize(), 24183);
        Assert.assertEquals(imageInfo.getFormat(), "jpg");

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

From source file:com.cubusmail.server.user.CreateAddressTestData.java

@Before
public void init() {

    DBManager manager = this.applicationContext.getBean(DBManager.class);
    try {//from w ww . jav a2 s.co m
        manager.initInternalDB();
        this.userAccountDao = this.applicationContext.getBean(IUserAccountDao.class);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
}

From source file:com.mnxfst.testing.server.cfg.TestPTestServerConfigurationParser.java

@Test
public void testEvaluateIntegerWithPortExpressionAndInvalidValue()
        throws ParserConfigurationException, XPathExpressionException, SAXException, IOException {
    PTestServerConfigurationParser p = new PTestServerConfigurationParser();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
            .parse(new ByteArrayInputStream("<ptest-server><port>123-test</port></ptest-server>".getBytes()));
    try {/*from w ww. ja v a 2 s . c  om*/
        p.evaluateInteger(p.xpathExpressionPort, document);
        Assert.fail("Invalid value provided as port");
    } catch (XPathExpressionException e) {
        //
    }
}

From source file:com.impetus.kundera.EntityManagerImplTest.java

@Test
public void testUnsupportedMethod() {

    try {//from   w w w . ja  v a2  s. c o m
        // find(Class<T> paramClass, Object paramObject, LockModeType
        // paramLockModeType)
        em.find(PersonBMM.class, null, LockModeType.NONE);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }

    try {
        // find(Class<T> arg0, Object arg1, LockModeType arg2, Map<String,
        // Object> arg3)
        em.find(PersonBMM.class, null, LockModeType.NONE, null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }

    try {
        // createNativeQuery(String sqlString)
        em.createNativeQuery("Query without class is not supported");
    } catch (NotImplementedException niex) {
        Assert.fail();
    }
    try {
        // createNativeQuery(String sqlString, String resultSetMapping)
        em.createNativeQuery("Query without class is not supported", "noreuslt");
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // getReference(Class<T> entityClass, Object primaryKey)
        em.getReference(Person.class, null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // lock(Object paramObject, LockModeType paramLockModeType,
        // Map<String, Object> paramMap)
        em.lock(null, LockModeType.NONE, null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // refresh(Object paramObject, LockModeType paramLockModeType)
        em.refresh(null, LockModeType.NONE);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // refresh(Object paramObject, LockModeType paramLockModeType,
        // Map<String, Object> paramMap)
        em.refresh(null, LockModeType.NONE, null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // getLockMode(Object paramObject)
        em.getLockMode(null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // unwrap(Class<T> paramClass)
        em.unwrap(null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }

}

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

@Test
public void testSingleLevelMergeCombiningReduceTask() {
    final int keyCnt = 8192;
    final int valCnt = 8;

    addInputComparator(this.comparator);
    setOutput(this.outList);
    getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE);

    CombiningUnilateralSortMerger<Record> sorter = null;
    try {//from  w  w  w. j  ava 2  s.co m
        sorter = new CombiningUnilateralSortMerger<Record>(new MockCombiningReduceStub(), getMemoryManager(),
                getIOManager(), new UniformRecordGenerator(keyCnt, valCnt, false), getOwningNepheleTask(),
                RecordSerializerFactory.get(), this.comparator.duplicate(), this.perSortMem, 2, 0.8f);
        addInput(sorter.getIterator());

        GroupReduceDriver<Record, Record> testTask = new GroupReduceDriver<Record, Record>();

        testDriver(testTask, MockCombiningReduceStub.class);
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Invoke method caused exception.");
    } finally {
        if (sorter != null) {
            sorter.close();
        }
    }

    int expSum = 0;
    for (int i = 1; i < valCnt; i++) {
        expSum += i;
    }

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

    for (Record record : this.outList) {
        Assert.assertTrue("Incorrect result", record.getField(1, IntValue.class).getValue() == expSum
                - record.getField(0, IntValue.class).getValue());
    }

    this.outList.clear();
}

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

@Test
public void testSharpenImage() {
    String style = "image/sharpen,100"; // ?

    try {// www . j av a  2  s .co m
        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(), 267);
        Assert.assertEquals(imageInfo.getWidth(), 400);
        Assert.assertEquals(imageInfo.getSize(), 24183);
        Assert.assertEquals(imageInfo.getFormat(), "jpg");

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

From source file:cz.PA165.vozovyPark.dao.VehicleDAOTest.java

/**
 * Test of findAll method, of class VehicleDAO.
 *///  ww  w.  j a  v a  2  s  .co  m
@Test
public void testFindAll() {
    List<Vehicle> allVehicles = null;
    try {

        Vehicle mercedes1 = VehicleDAOTest.getVehicle("Mercedes", 20000, "R4 Diesel", "E",
                UserClassEnum.PRESIDENT, "2a-447i-882a45", 2009, "UEW6828");
        Vehicle mercedes2 = VehicleDAOTest.getVehicle("Mercedes Piano", 20000, "R4 Diesel", "C",
                UserClassEnum.PRESIDENT, "98-447i-883345", 2009, "UEW6828");
        vehicleDao.createVehicle(mercedes1);
        vehicleDao.createVehicle(mercedes2);
        em.getTransaction().begin();
        allVehicles = vehicleDao.findAll();
        em.getTransaction().commit();
        if (allVehicles.size() != 2) {
            Assert.fail("Wrong size of list. Should be 2. List size: " + allVehicles.size());
        }
        Assert.assertTrue("Contains..", allVehicles.contains(mercedes1) && allVehicles.contains(mercedes2));

    } catch (Exception ex) {
        Assert.fail("Unexpected exception was thrown: " + ex + " " + ex.getMessage());
    }

}

From source file:eu.stratosphere.pact.runtime.sort.AsynchonousPartialSorterITCase.java

@Test
public void testLargeSortAcrossTwoWindows() throws Exception {
    try {/*from   w ww. j  ava  2  s. co  m*/
        final int NUM_RECORDS = 100000;

        // reader
        final TestData.Generator generator = new TestData.Generator(SEED, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM,
                ValueMode.CONSTANT, VAL);
        final MutableObjectIterator<Record> source = new TestData.GeneratorIterator(generator, NUM_RECORDS);

        // merge iterator
        LOG.debug("Initializing sortmerger...");
        Sorter<Record> sorter = new AsynchronousPartialSorter<Record>(this.memoryManager, source,
                this.parentTask, this.serializer, this.comparator, 32 * 1024 * 1024);

        runPartialSorter(sorter, NUM_RECORDS, 2);
    } catch (Exception t) {
        t.printStackTrace();
        Assert.fail("Test failed due to an uncaught exception: " + t.getMessage());
    }
}