Example usage for junit.framework Assert assertNull

List of usage examples for junit.framework Assert assertNull

Introduction

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

Prototype

static public void assertNull(Object object) 

Source Link

Document

Asserts that an object is null.

Usage

From source file:com.tango.logstash.flume.redis.sink.serializer.TestLogstashSerializer.java

@Test
public void parsingNoHeaderTest() throws RedisSerializerException {

    LogstashSerializer serializer = new LogstashSerializer();

    byte[] body = new byte[] { '1', '2', '3', '4', '5' };

    Event event = new SimpleEvent();
    event.setBody(body);//from  w  ww  . j  av a2  s .  com

    LogstashEvent logstashEvent = serializer.convertToLogstashEvent(event);

    Assert.assertNotNull(logstashEvent.getMessage());
    Assert.assertEquals(new String(body), logstashEvent.getMessage());

    Assert.assertNull(logstashEvent.getTimestamp());
    Assert.assertNull(logstashEvent.getSourceHost());
    Assert.assertNull(logstashEvent.getSourcePath());
    Assert.assertNull(logstashEvent.getSource());
    Assert.assertNull(logstashEvent.getType());
    Assert.assertNull(logstashEvent.getTags());
    Assert.assertNotNull(logstashEvent.getFields());
    Assert.assertEquals(0, logstashEvent.getFields().size());
}

From source file:com.ibm.jaggr.service.impl.config.BundleVersionsHashTest.java

@Test
public void testBundleVersionsHash() throws Exception {
    URI tmpDir = new File(System.getProperty("user.dir")).toURI();
    IAggregator mockAggregator = TestUtils.createMockAggregator();
    InitParams initParams = new InitParams(Arrays
            .asList(new InitParam[] { new InitParam("propName", "getBundleVersionsHash", mockAggregator) }));
    BundleVersionsHash bvh = new BundleVersionsHash();
    IServiceReference mockServiceReference = EasyMock.createNiceMock(IServiceReference.class);
    IServiceReference[] serviceReferences = new IServiceReference[] { mockServiceReference };
    IPlatformServices mockPlatformServices = EasyMock.createNiceMock(IPlatformServices.class);
    IAggregatorExtension mockExtension = EasyMock.createMock(IAggregatorExtension.class);
    EasyMock.expect(mockAggregator.getPlatformServices()).andReturn(mockPlatformServices).anyTimes();
    EasyMock.replay(mockAggregator);//from  w ww  .j a  v  a2  s.  c o  m
    Dictionary<String, String> dict = new Hashtable<String, String>();
    dict.put("name", mockAggregator.getName());
    EasyMock.expect(mockPlatformServices.getService(mockServiceReference)).andReturn(bvh).anyTimes();
    EasyMock.expect(mockExtension.getInitParams()).andReturn(initParams).anyTimes();
    EasyMock.expect(mockPlatformServices.getServiceReferences(IConfigScopeModifier.class.getName(),
            "(name=" + mockAggregator.getName() + ")")).andReturn(serviceReferences).anyTimes();
    EasyMock.replay(mockServiceReference, mockPlatformServices, mockExtension);
    bvh.initialize(mockAggregator, mockExtension, null);
    EasyMock.verify(mockPlatformServices);

    Bundle mockBundle1 = EasyMock.createMock(Bundle.class);
    Bundle mockBundle2 = EasyMock.createMock(Bundle.class);
    PowerMock.mockStatic(Platform.class);
    EasyMock.expect(Platform.getBundle("com.test.bundle1")).andReturn(mockBundle1).anyTimes();
    EasyMock.expect(Platform.getBundle("com.test.bundle2")).andReturn(mockBundle2).anyTimes();
    EasyMock.expect(Platform.getBundle("com.test.bundle3")).andReturn(null).anyTimes();
    final Dictionary<String, String> bundle1Headers = new Hashtable<String, String>();
    final Dictionary<String, String> bundle2Headers = new Hashtable<String, String>();
    EasyMock.expect(mockBundle1.getHeaders()).andAnswer(new IAnswer<Dictionary<String, String>>() {
        @Override
        public Dictionary<String, String> answer() throws Throwable {
            return bundle1Headers;
        }
    }).anyTimes();
    EasyMock.expect(mockBundle2.getHeaders()).andAnswer(new IAnswer<Dictionary<String, String>>() {
        @Override
        public Dictionary<String, String> answer() throws Throwable {
            return bundle2Headers;
        }
    }).anyTimes();
    PowerMock.replay(Platform.class, mockBundle1, mockBundle2);

    bundle1Headers.put("Bnd-LastModified", "123456789");
    bundle2Headers.put("Bnd-LastModified", "234567890");
    bundle1Headers.put("Bundle-Version", "1.2.3.20140414");
    bundle2Headers.put("Bundle-Version", "1.2.3.20140412");
    String config = "{cacheBust:getBundleVersionsHash(['Bundle-Version', 'Bnd-LastModified'], 'com.test.bundle1', 'com.test.bundle2')}";
    ConfigImpl cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    String cacheBust = cfg.getCacheBust();

    bundle1Headers.put("Bnd-LastModified", "123456780");
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertFalse(cacheBust.equals(cfg.getCacheBust()));

    bundle1Headers.put("Bnd-LastModified", "123456789");
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertEquals(cacheBust, cfg.getCacheBust());

    bundle2Headers.put("Bundle-Version", "1.2.4");
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertFalse(cacheBust.equals(cfg.getCacheBust()));

    bundle2Headers.put("Bundle-Version", "1.2.3.20140412");
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertEquals(cacheBust, cfg.getCacheBust());

    // Test that when header names are not specified, it defaults to 'Bundle-Version'.
    config = "{cacheBust:getBundleVersionsHash('com.test.bundle1', 'com.test.bundle2')}";
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    cacheBust = cfg.getCacheBust();

    bundle1Headers.put("Bnd-LastModified", "123456780");
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertEquals(cacheBust, cfg.getCacheBust());

    bundle2Headers.put("Bundle-Version", "1.2.4");
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertFalse(cacheBust.equals(cfg.getCacheBust()));

    bundle2Headers.put("Bundle-Version", "1.2.3.20140412");
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertEquals(cacheBust, cfg.getCacheBust());

    // Ensure exception thrown if a specified bundle is not found
    config = "{cacheBust:getBundleVersionsHash('com.test.bundle1', 'com.test.bundle2', 'com.test.bundle3')}";
    try {
        cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
        Assert.fail("Expected exception");
    } catch (WrappedException ex) {
        Assert.assertTrue(NotFoundException.class.isInstance(ex.getCause()));
    }

    // ensure exception thrown if argument is wrong type
    config = "{cacheBust:getBundleVersionsHash({})}";
    try {
        cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
        Assert.fail("Expected exception");
    } catch (WrappedException ex) {
        Assert.assertTrue(IllegalArgumentException.class.isInstance(ex.getCause()));
    }

    // ensure value is null if no bundle names specified
    config = "{cacheBust:getBundleVersionsHash()}";
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertNull(cfg.getCacheBust());

    config = "{cacheBust:getBundleVersionsHash(['Bundle-Version'])}";
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertNull(cfg.getCacheBust());

    config = "{}";
    cfg = new ConfigImpl(mockAggregator, tmpDir, config, true);
    Assert.assertNull(cfg.getCacheBust());

    // Ensure that cacheBust is a base64 encoded array of 16 bytes.
    byte[] bytes = Base64.decodeBase64(cacheBust);
    Assert.assertEquals(16, bytes.length);
}

From source file:org.openmrs.module.emrapi.account.AccountComponentTest.java

@Test
public void shouldUnretireExistingUser() {

    Person person = personService.getPerson(501); // existing person with retired user account in test dataset

    AccountDomainWrapper account = accountService.getAccountByPerson(person);
    account.setUserEnabled(true);/* w ww  .j  a  v a 2  s  .co  m*/
    account.save();

    Context.flushSession();
    Context.clearSession();

    User user = userService.getUser(501);
    Assert.assertFalse(user.isRetired());
    Assert.assertNull(user.getDateRetired());
    Assert.assertNull(user.getRetiredBy());
    Assert.assertNull(user.getRetireReason());
}

From source file:com.netflix.curator.TestSessionFailRetryLoop.java

@Test
public void testBasicStatic() throws Exception {
    Timing timing = new Timing();
    final CuratorZookeeperClient client = new CuratorZookeeperClient(server.getConnectString(),
            timing.session(), timing.connection(), null, new RetryOneTime(1));
    SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.FAIL);
    retryLoop.start();//from ww  w . j a  v  a 2s .co  m
    try {
        client.start();
        try {
            SessionFailRetryLoop.callWithRetry(client, SessionFailRetryLoop.Mode.FAIL, new Callable<Object>() {
                @Override
                public Object call() throws Exception {
                    RetryLoop.callWithRetry(client, new Callable<Void>() {
                        @Override
                        public Void call() throws Exception {
                            Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                            KillSession.kill(client.getZooKeeper(), server.getConnectString());

                            client.getZooKeeper();
                            client.blockUntilConnectedOrTimedOut();
                            Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                            return null;
                        }
                    });
                    return null;
                }
            });
        } catch (SessionFailRetryLoop.SessionFailedException dummy) {
            // correct
        }
    } finally {
        retryLoop.close();
        IOUtils.closeQuietly(client);
    }
}

From source file:es.tekniker.framework.ktek.commons.mng.server.test.TestCommonsMngServer.java

@org.junit.Test
public void testLoginNotExists() {

    log.info("*************************************************************");
    log.info("testLoginNotExists: START ");
    String result = TestDefines.RESULT_OK;

    KtekUserEntity instance = null;/*  ww w.  j  a v  a 2s  .com*/

    CommonsMngServer manager = new CommonsMngServer();

    KtekLoginEntity login = new KtekLoginEntity();

    login.setReference("LoginDoesNotExist");
    login.setPassword("pwd");

    KtekLoginCoordinatesEntity[] array = new KtekLoginCoordinatesEntity[3];

    KtekLoginCoordinatesEntity coord1 = new KtekLoginCoordinatesEntity();
    coord1.setLetter("A");
    coord1.setValue("vvvv");

    KtekLoginCoordinatesEntity coord2 = new KtekLoginCoordinatesEntity();
    coord2.setLetter("B");
    coord2.setValue("FDFSDFSDFSD");

    KtekLoginCoordinatesEntity coord3 = new KtekLoginCoordinatesEntity();
    coord3.setLetter("C");
    coord3.setValue("HJJGHJG");

    array[0] = coord1;
    array[1] = coord2;
    array[2] = coord3;

    login.setCoordinates(array);

    try {
        instance = manager.login(login);

        if (instance != null) {
            System.out.println("testLoginNotExists Login.token " + instance.getToken());
            result = TestDefines.RESULT_ERROR;
            Assert.assertFalse(true);
        } else {
            log.error("testLoginNotExists: instance is NULL ");
            result = TestDefines.RESULT_ERROR;
            Assert.assertNull(instance);
        }

    } catch (KtekExceptionEntity e) {
        System.out.println("TestUsersMngServer.loginExists:  exception " + e.getMessage());
        e.printStackTrace();
        Assert.assertFalse(false);
    }

    log.info("testLoginNotExists: RESULT " + result);
    log.info("testLoginNotExists: END ");
    log.info("*************************************************************");
    log.info("");

}

From source file:org.motechproject.mobile.core.dao.hibernate.GatewayRequestDAOImplTest.java

/**
 * Test of delete method, of class GatewayRequestDAOImpl.
 *//*from w  w  w .ja  va  2  s .  c om*/
@Test
public void testDelete() {
    System.out.println("Delete");

    mDDAO.delete(md2);

    GatewayRequest fromdb = (GatewayRequestImpl) mDDAO.getSessionFactory().getCurrentSession()
            .get(GatewayRequestImpl.class, md2.getId());
    Assert.assertNull(fromdb);

}

From source file:com.test.onesignal.MainOneSignalClassRunner.java

@Test
public void shouldCorrectlyRemoveOpenedHandlerAndFireMissedOnesWhenAddedBack() throws Exception {
    OneSignal.NotificationOpenedHandler notifHandler = new OneSignal.NotificationOpenedHandler() {
        @Override/*from   w  ww .  j a va  2s  .co  m*/
        public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
            notificationOpenedMessage = message;
        }
    };
    OneSignal.init(blankActivity, "123456789", ONESIGNAL_APP_ID, notifHandler);
    threadAndTaskWait();

    OneSignal.removeNotificationOpenedHandler();
    OneSignal.handleNotificationOpened(blankActivity,
            new JSONArray("[{ \"alert\": \"Robo test message\", \"custom\": { \"i\": \"UUID\" } }]"), false);
    Assert.assertNull(notificationOpenedMessage);

    OneSignal.init(blankActivity, "123456789", ONESIGNAL_APP_ID, notifHandler);
    Assert.assertEquals("Robo test message", notificationOpenedMessage);
}

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

private void testReapUntilDelete(String namespace) throws Exception {
    Timing timing = new Timing();
    Reaper reaper = null;//from   w ww.j  a v a  2  s.  c o m
    CuratorFramework client = makeClient(timing, namespace);
    try {
        client.start();
        client.create().creatingParentsIfNeeded().forPath("/one/two/three");

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));

        reaper = new Reaper(client, 100);
        reaper.start();

        reaper.addPath("/one/two/three", Reaper.Mode.REAP_UNTIL_DELETE);
        timing.sleepABit();

        Assert.assertNull(client.checkExists().forPath("/one/two/three"));

        client.create().forPath("/one/two/three");
        timing.sleepABit();
        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));
    } finally {
        IOUtils.closeQuietly(reaper);
        IOUtils.closeQuietly(client);
    }
}

From source file:org.openmrs.module.printer.PrinterServiceComponentTest.java

@Test
public void testShouldRemoveDefaultLabelPrinterForLocation() {
    Location location = locationService.getLocation(2); // a default printer for location 2 in has been set in the dataset
    printerService.setDefaultPrinter(location, PrinterType.LABEL, null);

    Printer fetchedPrinter = printerService.getDefaultPrinter(location, PrinterType.LABEL);
    Assert.assertNull(fetchedPrinter);
}

From source file:com.impetus.client.couchdb.crud.CouchDBClientTest.java

/**
 * Assertions on delete.// www  . jav a  2 s  .  co  m
 * 
 * @param client
 *            Redis client instance.
 */
private void onDelete(CouchDBClient client) {
    PersonCouchDB result = (PersonCouchDB) client.find(PersonCouchDB.class, ROW_KEY);
    Assert.assertNotNull(result);
    client.delete(result, ROW_KEY);
    result = (PersonCouchDB) client.find(PersonCouchDB.class, ROW_KEY);
    Assert.assertNull(result);
}