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:net.i2cat.netconf.test.TransportContentparserTest.java

@Test
public void unsupportedValuesInErrorsCausesFailTest() throws IOException, SAXException {

    String messageId = "1";
    String message = "Malformed XML!!!";
    String unsupported = "unsupported-:P";

    ErrorType type = ErrorType.PROTOCOL;
    ErrorTag tag = ErrorTag.OPERATION_FAILED;
    ErrorSeverity severity = ErrorSeverity.ERROR;

    String unsupportedTypeReply = buildErrorRepy(messageId, unsupported, tag.toString(), severity.toString(),
            message);//from ww w .  j a  va2s  .com
    String unsupportedTagReply = buildErrorRepy(messageId, type.toString(), unsupported, severity.toString(),
            message);
    String unsupportedSeverityReply = buildErrorRepy(messageId, type.toString(), tag.toString(), unsupported,
            message);

    try {
        parseMessage(unsupportedTypeReply);
        Assert.fail("Parsing should fail but didn't!");
    } catch (IllegalArgumentException e) {
    }

    try {
        parseMessage(unsupportedTagReply);
        Assert.fail("Parsing should fail but didn't!");
    } catch (IllegalArgumentException e) {
    }

    try {
        parseMessage(unsupportedSeverityReply);
        Assert.fail("Parsing should fail but didn't!");
    } catch (IllegalArgumentException e) {
    }
}

From source file:org.jasig.schedassist.impl.SchedulingAssistantServiceImplTest.java

/**
 * Expect a OracleCalendarDataAccessException to bubble up.
 * @throws Exception/*from ww  w  .j ava2  s. co  m*/
 */
@Test
public void testScheduleAppointmentCalendarDaoUnavailable() throws Exception {
    // construct a schedule owner
    MockCalendarAccount ownerAccount = new MockCalendarAccount();
    ownerAccount.setUsername("user1");
    DefaultScheduleOwnerImpl owner = new DefaultScheduleOwnerImpl(ownerAccount, 1);

    // construct a schedule visitor
    MockCalendarAccount visitorAccount = new MockCalendarAccount();
    visitorAccount.setUsername("user2");
    DefaultScheduleVisitorImpl visitor = new DefaultScheduleVisitorImpl(visitorAccount);

    // construct target availableblock for appointment
    AvailableBlock targetBlock = AvailableBlockBuilder.createBlock("20091111-1330", "20091111-1400", 1);

    // create mock CalendarDao and AvailableScheduleDao
    ICalendarDataDao mockCalendarDao = EasyMock.createMock(ICalendarDataDao.class);
    mockCalendarDao.checkForConflicts(owner, targetBlock);
    EasyMock.expectLastCall().andThrow(new RuntimeException());
    AvailableScheduleDao mockScheduleDao = EasyMock.createMock(AvailableScheduleDao.class);
    EasyMock.expect(mockScheduleDao.retrieveTargetBlock(owner,
            CommonDateOperations.parseDateTimePhrase("20091111-1330"))).andReturn(targetBlock);
    EasyMock.replay(mockCalendarDao, mockScheduleDao);

    SchedulingAssistantServiceImpl serviceImpl = new SchedulingAssistantServiceImpl();
    serviceImpl.setAvailableScheduleDao(mockScheduleDao);
    serviceImpl.setCalendarDataDao(mockCalendarDao);

    try {
        serviceImpl.scheduleAppointment(visitor, owner, targetBlock, "description");
        Assert.fail("expected RuntimeException not thrown");
    } catch (RuntimeException e) {
        // success
    }

    EasyMock.verify(mockCalendarDao, mockScheduleDao);
}

From source file:io.fabric8.quickstarts.fabric.rest.secure.CrmSecureTest.java

/**
 * HTTP GET http://localhost:8181/cxf/crm/customerservice/customers/123
 * returns the XML document representing customer 123
 * <p/>//  www .j a v a  2s. c om
 * On the server side, it matches the CustomerService's getCustomer() method
 *
 * @throws Exception
 */
@Test
public void getCustomerTest() throws Exception {
    String res = "";

    LOG.info("============================================");
    LOG.info("Sent HTTP GET request to query customer info");

    GetMethod get = new GetMethod(CUSTOMER_TEST_URL);
    get.getHostAuthState().setAuthScheme(scheme);
    try {
        httpClient.executeMethod(get);
        res = get.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 {
        get.releaseConnection();
    }
    Assert.assertTrue(res.contains("123"));
}

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

@Test
public void testBlock2CrossTask() {

    int keyCnt1 = 10;
    int valCnt1 = 1;

    int keyCnt2 = 100;
    int valCnt2 = 4;

    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_BLOCKED_OUTER_SECOND);
    super.getTaskConfig().setMemorySize(1 * 1024 * 1024);

    super.registerTask(testTask, MockCrossStub.class);

    try {/*from w  w w .  j a va 2s .  c o  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:org.openxdata.server.service.impl.SettingServiceTest.java

@Test
public void getSettings_shouldReturnAllSettings() throws Exception {

    List<SettingGroup> settingGroups = settingService.getSettings();

    Assert.assertNotNull(settingGroups);
    Assert.assertEquals(4, settingGroups.size());

    for (SettingGroup settingGroup : settingGroups) {

        String name = settingGroup.getName();
        List<Setting> settings = settingGroup.getSettings();
        Assert.assertNotNull(settings);/*ww  w. j a va  2s . c  om*/

        if (name.equals("General")) {
            Assert.assertEquals(1, settings.size());
        } else if (name.equals("Date")) {
            Assert.assertEquals(6, settings.size());
        } else if (name.equals("Serialization")) {
            Assert.assertEquals(3, settings.size());
        } else if (name.equals("SMS")) {
            Assert.assertEquals(5, settings.size());
        } else {
            Assert.fail("Expected Setting group name: Date, General, Serialization or SMS");
        }
    }
}

From source file:com.espertech.esper.epl.variable.VariableServiceCallable.java

private void doLoop(int loopNumber) {
    // Set a mark, there should be no number above that number
    int mark = variableVersionCoord.setVersionGetMark();
    int[] indexes = getIndexesShuffled(variables.length, random, loopNumber);
    marks[loopNumber] = mark;/*from ww w. j  a va2s . com*/

    // Perform first read of all variables
    int[] readResults = new int[variables.length];
    readAll(indexes, readResults, mark);

    // Start a write cycle for the write we are getting an exclusive write lock
    variableService.getReadWriteLock().writeLock().lock();

    // Write every second of the variables
    for (int i = 0; i < indexes.length; i++) {
        int variableNum = indexes[i];
        String variableName = variables[variableNum];

        if (i % 2 == 0) {
            int newMark = variableVersionCoord.incMark();
            if (log.isDebugEnabled()) {
                log.debug(".run Thread " + Thread.currentThread().getId() + " at mark " + mark
                        + " write variable '" + variableName + "' new value " + newMark);
            }
            variableService.write(readers[variableNum].getVariableNumber(), newMark);
        }
    }

    // Commit (apply) the changes and unlock
    variableService.commit();
    variableService.getReadWriteLock().writeLock().unlock();

    // Read again and compare to first result
    results[loopNumber] = new int[variables.length];
    readAll(indexes, results[loopNumber], mark);

    // compare first read with second read, written values are NOT visible
    for (int i = 0; i < variables.length; i++) {
        if (results[loopNumber][i] != readResults[i]) {
            String text = "Error in loop#" + loopNumber + " comparing a re-read result for variable "
                    + variables[i] + " expected " + readResults[i] + " but was " + results[loopNumber][i];
            Assert.fail(text);
        }
    }
}

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

@Test
public void testMultiLevelMergeReduceTask() {
    final int keyCnt = 32768;
    final int valCnt = 8;

    setNumFileHandlesForSort(2);//from ww w. j ava 2s. c  om

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

    try {
        addInputSorted(new UniformRecordGenerator(keyCnt, valCnt, false), this.comparator.duplicate());

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

        testDriver(testTask, MockReduceStub.class);
    } catch (Exception e) {
        LOG.debug(e);
        Assert.fail("Exception in Test.");
    }

    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() == valCnt
                - record.getField(0, IntValue.class).getValue());
    }

    this.outList.clear();

}

From source file:com.redhat.demo.CrmTest.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  w w . j av a 2s. co m
 * On the server side, it matches the Order's getProduct() method
 *
 * @throws Exception
 */
@Test
public void getProductOrderTest() throws Exception {

    LOG.info("Sent HTTP GET request to query sub resource product info");
    url = new URL(PRODUCT_ORDER_TEST_URL);
    try {
        in = url.openStream();
    } 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");
    }

    String res = getStringFromInputStream(in);
    LOG.info(res);
    Assert.assertTrue(res.contains("product 323"));
}

From source file:com.aliyun.oss.perftests.PerftestRunner.java

public void buildScenario(final String scenarioTypeString) {
    File confFile = new File(System.getProperty("user.dir") + File.separator + "runner_conf.xml");
    InputStream input = null;/*from   w  w w  .  j  av  a  2 s . c om*/
    try {
        input = new FileInputStream(confFile);
    } catch (FileNotFoundException e) {
        log.error(e);
        Assert.fail(e.getMessage());
    }
    SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(input);
        Element root = doc.getRootElement();
        scenario = new TestScenario();
        scenario.setHost(root.getChildText("host"));
        scenario.setAccessId(root.getChildText("accessid"));
        scenario.setAccessKey(root.getChildText("accesskey"));
        scenario.setBucketName(root.getChildText("bucket"));

        scenario.setType(determineScenarioType(scenarioTypeString));

        Element target = root.getChild(scenarioTypeString);
        if (target != null) {
            scenario.setContentLength(Long.parseLong(target.getChildText("size")));
            scenario.setPutThreadNumber(Integer.parseInt(target.getChildText("putthread")));
            scenario.setGetThreadNumber(Integer.parseInt(target.getChildText("getthread")));
            scenario.setDurationInSeconds(Integer.parseInt(target.getChildText("time")));
            scenario.setGetQPS(Integer.parseInt(target.getChildText("getqps")));
            scenario.setPutQPS(Integer.parseInt(target.getChildText("putqps")));
        } else {
            log.error("Unable to locate XML element " + scenarioTypeString);
            Assert.fail("Unable to locate XML element " + scenarioTypeString);
        }
    } catch (JDOMException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:de.hybris.vjdbc.VirtualDriverTest.java

@Test
public void testConnectWithAcceptedSQLWithArgsUrl() throws Exception {
    final Properties props = new Properties();

    Mockito.when(commandSinkProvider.create(Mockito.eq("//baz"), Mockito.eq(OF_EMPTY_MAP)))
            .thenThrow(new ExpectedException());

    try {// ww w  . j a va 2  s .  c om
        driver.connect("jdbc:hybris:sql://baz;someparam=X", props);
        Assert.fail("should have failed");
    } catch (SQLException e) {
        assertFirstLineOfSQLException("de.hybris.vjdbc.VirtualDriverTest$ExpectedException", e);
    }

    Mockito.verify(virtualConnectionBuilder).setProperties(props);
    Mockito.verify(virtualConnectionBuilder, Mockito.times(0)).setUrl("");
    Mockito.verify(virtualConnectionBuilder).setDataSourceString(Mockito.eq("someparam=X"));

}