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() 

Source Link

Document

Fails a test with no message.

Usage

From source file:com.netflix.curator.framework.recipes.locks.TestLockCleanlinessWithFaults.java

@Test
public void testNodeDeleted() throws Exception {
    final String PATH = "/foo/bar";

    CuratorFramework client = null;/*from w w  w .ja v a 2 s .co  m*/
    try {
        client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryNTimes(0, 0));
        client.start();

        client.create().creatingParentsIfNeeded().forPath(PATH);
        Assert.assertEquals(client.checkExists().forPath(PATH).getNumChildren(), 0);

        LockInternals internals = new LockInternals(client, new StandardLockInternalsDriver(), PATH, "lock-",
                1) {
            @Override
            List<String> getSortedChildren() throws Exception {
                throw new KeeperException.NoNodeException();
            }
        };
        try {
            internals.attemptLock(0, null, null);
            Assert.fail();
        } catch (KeeperException.NoNodeException dummy) {
            // expected
        }

        // make sure no nodes are left lying around
        Assert.assertEquals(client.checkExists().forPath(PATH).getNumChildren(), 0);
    } finally {
        IOUtils.closeQuietly(client);
    }
}

From source file:io.cloudslang.worker.execution.reflection.ReflectionAdapterTest.java

@Test
public void executeControlActionTest() {
    ControlActionMetadata metadata = new ControlActionMetadata(
            "io.cloudslang.worker.execution.reflection.ReflectionAdapterTestHelper", "myMethod_1");
    Map<String, Object> map = new HashMap<>();
    map.put("parameter_1", "TEST");
    map.put("parameter_2", 3);
    try {// w  w  w  . j  a  va 2s .  com
        adapter.executeControlAction(metadata, map);
    } catch (Exception ex) {
        logger.error("Failed to run method in reflectionAdapter...", ex);
        Assert.fail();
    }
}

From source file:com.brienwheeler.lib.spring.beans.SmartXmlBeanDefinitionReaderTest.java

@Test
public void testFileNotFound() {
    try {/* w ww  . ja va 2s  . co m*/
        SmartXmlBeanDefinitionReader reader = new SmartXmlBeanDefinitionReader(
                new DefaultListableBeanFactory());
        reader.loadBeanDefinitions("classpath:this/is/bad.xml");
        Assert.fail();
    } catch (BeanDefinitionStoreException e) {
        Assert.assertEquals(FileNotFoundException.class, e.getCause().getClass());
    }
}

From source file:com.onesite.sdk.test.api.SessionApiTest.java

@Test
public void testCreateAnonymous() {
    SessionApi api = new SessionApi();

    try {//w w  w.  java 2  s  . c  o m
        Session testSession = new Session();
        testSession.setIp(ip);
        testSession.setAgent(agent);

        Session session = api.create(testSession);

        System.out.println("Anonymous Session");
        System.out.println("coreU: " + session.getCoreU());
        System.out.println("coreX: " + session.getCoreU());

        Assert.assertFalse(StringUtils.isEmpty(session.getCoreU()));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:org.jrecruiter.service.UserServiceTest.java

@Test
public void testAddUserTest2() {

    final User user = getUser();

    user.setPassword("jrecruiter");

    try {//from  www . jav a2s . c o  m
        userService.addUser(user);
        entityManager.flush();
    } catch (DuplicateUserException e) {
        Assert.fail();
    }

    final User userFromDb = userService.getUser(user.getUsername());

    //FIXME password digestion should probbly be a part of saving a user through the service
    Assert.assertEquals("jrecruiter", userFromDb.getPassword());

}

From source file:com.zimbra.cs.imap.ImapProxyTest.java

@Test(timeout = 30000)
public void bye() throws Exception {
    server = MockTcpServer.scenario().sendLine("* OK server ready").recvLine() // CAPABILITY
            .sendLine("* CAPABILITY IMAP4rev1 AUTH=X-ZIMBRA")
            .reply(Pattern.compile("(.*) CAPABILITY"), "{0} OK CAPABILITY\r\n").recvLine() // ID
            .sendLine("* ID (\"NAME\" \"Zimbra\")").reply(Pattern.compile("(.*) ID"), "{0} OK ID completed\r\n")
            .recvLine() // AUTHENTICATE
            .sendLine("+ ready for literal")
            .reply(Pattern.compile("(.*) AUTHENTICATE"), "{0} OK AUTHENTICATE\r\n").recvLine() // credential
            .recvLine() // NOOP
            .reply(Pattern.compile("(.*) NOOP"), "{0} OK NOOP\r\n").sendLine("* BYE server closing connection")
            .build().start(PORT);//w w  w.j  a va2s .c o m

    MockImapHandler handler = new MockImapHandler();
    ImapProxy proxy = new ImapProxy(new InetSocketAddress(PORT), "test@zimbra.com", "secret", handler);
    proxy.proxy("001", "NOOP");
    try {
        proxy.proxy("002", "NOOP");
        Assert.fail();
    } catch (ImapProxyException expected) {
    }

    // verify BYE was not proxied
    Assert.assertEquals("001 OK NOOP\r\n", handler.output.toString());

    server.shutdown(3000);
    Assert.assertEquals("C01 CAPABILITY\r\n", server.replay());
    String id = server.replay();
    Assert.assertTrue(id,
            id.matches("C02 ID \\(\"name\" \"ZCS\" \"version\" \".*\" \"X-VIA\" \"127\\.0\\.0\\.1\"\\)\r\n"));
    Assert.assertEquals("C03 AUTHENTICATE X-ZIMBRA\r\n", server.replay());
    server.replay(); // auth token
    Assert.assertEquals("001 NOOP\r\n", server.replay());
    Assert.assertEquals(null, server.replay());
}

From source file:org.ocpsoft.rewrite.servlet.config.SchemeChangeTest.java

@Test
public void testRedirectToHttps() {
    DefaultHttpClient client = new DefaultHttpClient();
    client.setRedirectStrategy(new RedirectStrategy() {

        @Override// www  .  ja v  a 2s .co  m
        public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context)
                throws ProtocolException {
            if (response.getFirstHeader("Location").getValue().contains("https"))
                throw new RuntimeException("Success!");
            return false;
        }

        @Override
        public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context)
                throws ProtocolException {
            throw new IllegalStateException("Not implemented.");
        }

    });
    try {
        get(client, "/login");
    } catch (Exception e) {
        if (!"Success!".equals(e.getMessage()))
            Assert.fail();
    }
}

From source file:org.tritsch.android.chargefinder.CFService.java

/**
 * <code>lockup<code> will contact the chargefinder service and will retrieve
 * a/the list of stations described by the parameters.
 *
 * @param pointX - x coordinates to start the search from
 * @param pointY - y coordinates to start the search from
 * @param radius - the radius from x, y to include in the search
 *
 * @return a/the list of stations that are within the radius
 *//*from  ww w .  ja  v  a  2s  .c  o  m*/
public static List<CFStation> lookup(final String pointX, final String pointY, final String radius) {
    if (Log.isLoggable(TAG, Log.DEBUG))
        Log.d(TAG, "Enter: lookup()");
    Assert.assertNotNull(pointX);
    Assert.assertFalse(pointX.length() == 0);
    Assert.assertNotNull(pointY);
    Assert.assertFalse(pointY.length() == 0);
    Assert.assertNotNull(radius);
    Assert.assertFalse(radius.length() == 0);

    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "pointX:" + pointX);
    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "pointY:" + pointY);
    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "radius:" + radius);

    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "create the list we will return ...");
    List<CFStation> stations = new ArrayList<CFStation>();

    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "create http client ...");
    HttpClient httpClient = new DefaultHttpClient();
    Assert.assertNotNull(httpClient);

    String url = "" + BASE_URL + "?point_x=" + pointX + "&point_y=" + pointY + "&radius=" + radius;
    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "URL:" + url);

    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "go and do it ...");
    HttpResponse response = null;
    try {
        response = httpClient.execute(new HttpGet(url));
        Assert.assertNotNull(response);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }

    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "process response ...");
    JSONArray stationsObject = null;
    try {
        HttpEntity entity = response.getEntity();
        Assert.assertNotNull(entity);

        String resultString = getString(entity.getContent());
        Assert.assertNotNull(resultString);
        if (Log.isLoggable(TAG, Log.VERBOSE))
            Log.v(TAG, "Result:" + resultString);

        JSONObject resultObject = new JSONObject(resultString);
        Assert.assertNotNull(resultObject);

        stationsObject = resultObject.getJSONArray("stations");
        Assert.assertNotNull(stationsObject);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }

    if (Log.isLoggable(TAG, Log.VERBOSE))
        Log.v(TAG, "build list of stations ...");
    try {
        for (int i = 0; i < stationsObject.length(); i++) {
            JSONObject station = stationsObject.getJSONObject(i);
            Assert.assertNotNull(station);

            CFStation newStation = new CFStation();
            newStation.setName(station.getString("name"));
            newStation.setX(station.getDouble("st_x"));
            newStation.setY(station.getDouble("st_y"));

            Assert.assertTrue(stations.add(newStation));
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }

    if (Log.isLoggable(TAG, Log.DEBUG))
        Log.d(TAG, "Leave: lookup()");
    return stations;
}

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

@Test
public void registerWithSenderId() throws Exception {
    GoogleServices googleServices = Mockito.mock(GoogleServices.class);
    Context context = Robolectric.application;
    String senderId = "senderId";

    final String registrationId = "123";

    Mockito.when(googleServices.getRegistrationId(context, senderId)).thenReturn(registrationId);

    push.setGoogleServices(googleServices);

    push.onSuccess(new Push.OnSuccess() {

        @Override// w w w  .  j  ava  2  s.c om
        public void onSuccess(JSONObject device) {
            try {
                Assert.assertNotNull(device);
                Assert.assertEquals(Push.ANDROID, device.getString("platform"));
                Assert.assertEquals(registrationId, device.getString("token"));
            } catch (JSONException je) {
                Assert.fail();
            }
        }

    }).register(context, senderId);

    Robolectric.runBackgroundTasks();
}

From source file:com.alibaba.dubbo.examples.validation.ValidationTest.java

@Test
public void testValidation() {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(
            ValidationTest.class.getPackage().getName().replace('.', '/') + "/validation-provider.xml");
    providerContext.start();/*from   www.ja v  a 2  s. c  o m*/
    try {
        ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(
                ValidationTest.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml");
        consumerContext.start();
        try {
            ValidationService validationService = (ValidationService) consumerContext
                    .getBean("validationService");

            // Save OK
            ValidationParameter parameter = new ValidationParameter();
            parameter.setName("liangfei");
            parameter.setEmail("liangfei@liang.fei");
            parameter.setAge(50);
            parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000));
            parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000));
            validationService.save(parameter);

            try {
                parameter = new ValidationParameter();
                parameter.setName("l");
                parameter.setEmail("liangfei@liang.fei");
                parameter.setAge(50);
                parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000));
                parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000));
                validationService.save(parameter);
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
            }

            // Save Error
            try {
                parameter = new ValidationParameter();
                validationService.save(parameter);
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
            }

            // Delete OK
            validationService.delete(2, "abc");

            // Delete Error
            try {
                validationService.delete(2, "a");
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
                Assert.assertEquals(1, violations.size());
            }

            // Delete Error
            try {
                validationService.delete(0, "abc");
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
                Assert.assertEquals(1, violations.size());
            }
            try {
                validationService.delete(2, null);
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
                Assert.assertEquals(1, violations.size());
            }
            try {
                validationService.delete(0, null);
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
                Assert.assertEquals(2, violations.size());
            }
        } finally {
            consumerContext.stop();
            consumerContext.close();
        }
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}