Example usage for junit.framework Assert assertNotNull

List of usage examples for junit.framework Assert assertNotNull

Introduction

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

Prototype

static public void assertNotNull(Object object) 

Source Link

Document

Asserts that an object isn't null.

Usage

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

@Test
public void searchAuthorityByUrl() {
    Assert.assertNotNull(dao.readAuthorityByUrl(AUTH_URL_PRESENT));
    Assert.assertNull(dao.readAuthorityByUrl(AUTH_URL_NOT_PRESENT));
}

From source file:com.impetus.client.crud.datatypes.ByteDataTest.java

/**
 * On insert image in cassandra blob object
 * /*w w  w  .ja  v  a  2s  . c o m*/
 * @throws Exception
 *             the exception
 */
@Test
public void onInsertBlobImageCassandra() throws Exception {

    PersonCassandra personWithKey = new PersonCassandra();
    personWithKey.setPersonId("111");

    BufferedImage originalImage = ImageIO.read(new File("src/test/resources/nature.jpg"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(originalImage, "jpg", baos);
    baos.flush();
    byte[] imageInByte = baos.toByteArray();

    baos.close();

    personWithKey.setA(imageInByte);
    em.persist(personWithKey);

    em.clear();

    String qry = "Select p from PersonCassandra p where p.personId = 111";
    Query q = em.createQuery(qry);
    List<PersonCassandra> persons = q.getResultList();
    PersonCassandra person = persons.get(0);

    InputStream in = new ByteArrayInputStream(person.getA());
    BufferedImage bImageFromConvert = ImageIO.read(in);

    ImageIO.write(bImageFromConvert, "jpg", new File("src/test/resources/nature-test.jpg"));

    Assert.assertNotNull(person.getA());
    Assert.assertEquals(new File("src/test/resources/nature.jpg").getTotalSpace(),
            new File("src/test/resources/nature-test.jpg").getTotalSpace());
    Assert.assertEquals(String.valueOf(Hex.encodeHex((byte[]) imageInByte)),
            String.valueOf(Hex.encodeHex((byte[]) person.getA())));

}

From source file:com.auditbucket.test.functional.TestCallerRef.java

@Test
public void nullCallerRefBehaviour() throws Exception {
    cleanUpGraph(); // No transaction so need to clear down the graph
    regService.registerSystemUser(new RegistrationBean(monowai, mike, "bah"));

    FortressInputBean fib = new FortressInputBean("auditTest" + System.currentTimeMillis());
    Fortress fortress = fortressEP.registerFortress(fib, null).getBody();
    // Duplicate null caller ref keys
    MetaInputBean inputBean = new MetaInputBean(fortress.getName(), "harry", "TestTrack", new DateTime(), null);
    Assert.assertNotNull(mediationFacade.createHeader(inputBean, null).getMetaKey());
    inputBean = new MetaInputBean(fortress.getName(), "wally", "TestTrack", new DateTime(), null);
    String ahKey = mediationFacade.createHeader(inputBean, null).getMetaKey();

    assertNotNull(ahKey);//from   w ww . ja  v a  2s .com
    MetaHeader metaHeader = trackService.getHeader(ahKey);
    assertNotNull(metaHeader);
    assertNull(metaHeader.getCallerRef());

    // By default this will be found via the header key as it was null when header created.
    assertNotNull(trackService.findByCallerRef(fortress, "TestTrack", ahKey));

}

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

/**
 * <code>getString</code> extract a/the string from the input stream.
 *
 * @param is an <code>InputStream</code> value
 * @return a <code>String</code> value
 *//*from www  . ja  va2  s .  c  om*/
private static String getString(final InputStream is) {
    if (Log.isLoggable(TAG, Log.DEBUG))
        Log.d(TAG, "Enter: getString()");
    Assert.assertNotNull(is);

    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    Assert.assertNotNull(reader);
    StringBuilder sb = new StringBuilder();
    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    } finally {
        try {
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail();
        }
    }

    if (Log.isLoggable(TAG, Log.DEBUG))
        Log.d(TAG, "Leave: getString()");
    return sb.toString();
}

From source file:com.hybris.backoffice.cockpitng.dataaccess.facades.DefaultPlatformPermissionFacadeStrategyTest.java

@Test
public void testGetReadableLocalesForInstance() {
    final Set<Locale> expectedLocales = permissionFacade.getReadableLocalesForInstance(product);
    Assert.assertNotNull(expectedLocales);
    Assert.assertTrue(expectedLocales.contains(englishLocale));
}

From source file:de.hybris.platform.b2badmin.services.impl.B2BUnitServiceTest.java

@Test
public void testRestrictionsOfUsersAndUnits() throws Exception {
    sessionService.executeInLocalView(new SessionExecutionBody() {
        @Override//  www . j  a  v  a  2s .  c  o  m
        public void executeWithoutResult() {
            final String userId = "IC CEO";
            login(userId);

            // test restrictions on units and employees
            Assert.assertNull(b2bUnitService.getUnitForUid("GC"));
            Assert.assertNull(baseDao.findFirstByAttribute(B2BCustomer.UID, "GC CEO", B2BCustomerModel.class));

            // test costcenter and budget restriction
            Assert.assertNotNull(
                    baseDao.findFirstByAttribute(B2BCostCenterModel.CODE, "IC 0", B2BCostCenterModel.class));
            Assert.assertNull(
                    baseDao.findFirstByAttribute(B2BCostCenterModel.CODE, "GC 0", B2BCostCenterModel.class));
            Assert.assertNotNull(baseDao.findFirstByAttribute(B2BBudgetModel.CODE, "IC BUDGET EUR 1M",
                    B2BBudgetModel.class));
            Assert.assertNull(baseDao.findFirstByAttribute(B2BBudgetModel.CODE, "GC BUDGET EUR 1M",
                    B2BBudgetModel.class));

            // change the session IC_USER to the customer who belongs to different organization
            final UserModel GC_USER = (UserModel) sessionService.executeInLocalView(new SessionExecutionBody() {
                @Override
                public Object execute() {
                    searchRestrictionService.disableSearchRestrictions();
                    final UserModel user = baseDao.findFirstByAttribute(B2BCustomerModel.UID, "GC CEO",
                            B2BCustomerModel.class);
                    Assert.assertNotNull(user);
                    return user;
                }
            });
            Assert.assertNotNull(GC_USER);
            login(GC_USER);
            // should now we able to see only items linked to C_2.. units
            Assert.assertNull(
                    baseDao.findFirstByAttribute(B2BCostCenterModel.CODE, "IC 0", B2BCostCenterModel.class));
            Assert.assertNotNull(
                    baseDao.findFirstByAttribute(B2BCostCenterModel.CODE, "GC 0", B2BCostCenterModel.class));
            Assert.assertNull(baseDao.findFirstByAttribute(B2BBudgetModel.CODE, "IC BUDGET EUR 1M",
                    B2BBudgetModel.class));
            Assert.assertNotNull(baseDao.findFirstByAttribute(B2BBudgetModel.CODE, "GC BUDGET EUR 1M",
                    B2BBudgetModel.class));
        }
    }, userService.getAdminUser());

}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest01() {
    final String sql = "SELECT TOP(word, 10), COUNT(*) FROM publicdata:samples.shakespeare";
    final String description = "The top 10 word from shakespeare #TOP #COUNT";
    String[][] expectation = new String[][] {
            { "you", "yet", "would", "world", "without", "with", "your", "young", "words", "word" },
            { "42", "42", "42", "42", "42", "42", "41", "41", "41", "41" } };
    /** somehow the result changed with time
    { "you", "yet", "would", "world", "without", "with", "will",
            "why", "whose", "whom" },/*www  .j  a va  2 s  . com*/
    { "42", "42", "42", "42", "42", "42", "42", "42", "42", "42" } };
    */

    this.logger.info("Test number: 01");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);
    HelperFunctions.printer(expectation);
    try {
        Assert.assertTrue("Comparing failed in the String[][] array",
                this.comparer(expectation, BQSupportMethods.GetQueryResult(Result)));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

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

@Test
public void testInsertIdentities() {

    try {// w  ww.j  a va 2 s .  c  om
        this.userAccountDao.saveIdentities(this.testUserAccount);

        UserAccount userAccount = userAccountDao.getUserAccountByUsername("testuser");
        Assert.assertNotNull(userAccount.getIdentities());
        Assert.assertTrue("identities not loaded!", userAccount.getIdentities().size() >= 4);
        Assert.assertEquals(userAccount, userAccount.getIdentities().get(0).getUserAccount());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
}

From source file:com.auditbucket.test.functional.TestDelta.java

@Test
public void jsonDeltasAreFound() throws Exception {
    regService.registerSystemUser(new RegistrationBean(monowai, mike, "bah"));
    setSecurity();//w ww .j  a  v  a  2 s . c om
    Fortress fortress = fortressService.registerFortress("DELTAForce");
    assertNotNull(fortress);

    String typeA = "TypeA";

    String jsonA = "{\"house\": \"red\", \"bedrooms\": 2, \"garage\": \"Y\"}";
    String jsonB = "{\"house\": \"green\", \"bedrooms\": 2, \"list\": [1,2,3]}";

    MetaInputBean header = new MetaInputBean("DELTAForce", "auditTestz", "Delta", new DateTime(), "abdelta");
    LogInputBean log = new LogInputBean("Mike", new DateTime(), jsonA);
    header.setLog(log);
    TrackResultBean result = mediationFacade.createHeader(header, null);
    TrackLog first = trackService.getLastLog(result.getMetaHeader());
    Assert.assertNotNull(first);
    log = new LogInputBean(result.getMetaKey(), "Mike", new DateTime(), jsonB);
    mediationFacade.processLog(log);
    TrackLog second = trackService.getLastLog(result.getMetaHeader());
    Assert.assertNotNull(second);

    AuditDeltaBean deltaBean = whatService.getDelta(result.getMetaHeader(), first.getChange(),
            second.getChange());
    Map added = deltaBean.getAdded();
    Assert.assertNotNull(added);
    assertTrue(added.containsKey("list"));

    Map removed = deltaBean.getRemoved();
    Assert.assertNotNull(removed);
    assertTrue(removed.containsKey("garage"));

    Map changed = deltaBean.getChanged();
    Assert.assertNotNull(changed);
    assertTrue(changed.containsKey("house"));

    assertNotNull(deltaBean);

}

From source file:org.alfresco.mobile.android.test.api.services.ActivityStreamServiceTest.java

/**
 * All Tests forActivityStreamService public methods which don't create an
 * error./*from w  ww.  j a  v  a 2s .  co  m*/
 * 
 * @Requirement 1S3, 1S4, 2F1,2F2, 2F3, 2F4, 2S1, 2S6, 2S7, 2S8, 2S9, 3S3,
 *              3S4, 4F1, 4F2, 4F3, 4F4, 4S6, 4S7, 4S8, 4S9, 5S3, 6F4, 6F6,
 *              6F7, 6S6, 6S7, 6S8, 6S9
 */
public void testActivityStreamService() {
    try {
        prepareScriptData();

        // ///////////////////////////////////////////////////////////////////////////
        // Method getActivityStream()
        // ///////////////////////////////////////////////////////////////////////////
        List<ActivityEntry> feed = activityStreamService.getActivityStream();
        if (feed == null || feed.isEmpty()) {
            // Log.d("ActivityStreamService",
            // "No stream activities available. Test aborted.");
            return;
        }
        int totalItems = feed.size();
        Assert.assertNotNull(feed);
        Assert.assertFalse(feed.isEmpty());

        // Sorting with listinContext and sort property : Sort is not
        // supported
        // by ActivityStreamService
        wait(10000);
        ListingContext lc = new ListingContext();
        lc.setSortProperty(DocumentFolderService.SORT_PROPERTY_DESCRIPTION);
        PagingResult<ActivityEntry> feedUnSorted = activityStreamService.getActivityStream(lc);
        Assert.assertEquals(lc.getMaxItems(), feedUnSorted.getList().size());
        Assert.assertEquals(feed.get(0).getIdentifier(), feed.get(0).getIdentifier());
        // ///////////////////////////////////////////////////////////////////////////
        // Paging ALL Activity Entry
        // ///////////////////////////////////////////////////////////////////////////
        lc = new ListingContext();
        lc.setMaxItems(5);
        lc.setSkipCount(0);

        // Check 1 activity
        PagingResult<ActivityEntry> pagingFeed = activityStreamService.getActivityStream(lc);
        Assert.assertNotNull(pagingFeed);
        Assert.assertEquals(5, pagingFeed.getList().size());
        Assert.assertEquals(getTotalItems(feed.size()), pagingFeed.getTotalItems());
        Assert.assertTrue(pagingFeed.hasMoreItems());

        // Check 0 activity if outside of total item
        lc.setMaxItems(10);
        lc.setSkipCount(feed.size());
        pagingFeed = activityStreamService.getActivityStream(lc);
        Assert.assertNotNull(pagingFeed);
        Assert.assertEquals(getTotalItems(feed.size()), pagingFeed.getTotalItems());
        Assert.assertEquals(hasMoreItem(), pagingFeed.hasMoreItems());

        // OnPremise max is 100 and not the case for cloud.
        if (isOnPremise()) {
            Assert.assertEquals(0, pagingFeed.getList().size());
        } else {
            Assert.assertEquals(10, pagingFeed.getList().size());
        }

        // Check feed.size() activity
        lc.setMaxItems(feed.size());
        lc.setSkipCount(0);
        pagingFeed = activityStreamService.getActivityStream(lc);
        Assert.assertNotNull(pagingFeed);
        Assert.assertEquals(feed.size(), pagingFeed.getList().size());
        Assert.assertEquals(getTotalItems(feed.size()), pagingFeed.getTotalItems());
        Assert.assertEquals(hasMoreItem(), pagingFeed.hasMoreItems());

        // ////////////////////////////////////////////////////
        // Incorrect Listing Context Value
        // ////////////////////////////////////////////////////
        // Incorrect settings in listingContext: Such as inappropriate
        // maxItems
        // (0)
        lc.setSkipCount(0);
        lc.setMaxItems(-1);
        pagingFeed = activityStreamService.getActivityStream(lc);
        Assert.assertNotNull(pagingFeed);
        Assert.assertEquals(getTotalItems(totalItems), pagingFeed.getTotalItems());
        Assert.assertEquals(
                (totalItems > ListingContext.DEFAULT_MAX_ITEMS) ? ListingContext.DEFAULT_MAX_ITEMS : totalItems,
                pagingFeed.getList().size());
        Assert.assertEquals(Boolean.TRUE, pagingFeed.hasMoreItems());

        // Incorrect settings in listingContext: Such as inappropriate
        // maxItems
        // (-1)
        lc.setSkipCount(0);
        lc.setMaxItems(-1);
        pagingFeed = activityStreamService.getActivityStream(lc);
        Assert.assertNotNull(pagingFeed);
        Assert.assertEquals(getTotalItems(totalItems), pagingFeed.getTotalItems());
        Assert.assertEquals(
                (totalItems > ListingContext.DEFAULT_MAX_ITEMS) ? ListingContext.DEFAULT_MAX_ITEMS : totalItems,
                pagingFeed.getList().size());
        Assert.assertEquals(Boolean.TRUE, pagingFeed.hasMoreItems());

        // Incorrect settings in listingContext: Such as inappropriate
        // skipcount
        // (-12)
        lc.setSkipCount(-12);
        lc.setMaxItems(5);
        pagingFeed = activityStreamService.getActivityStream(lc);
        Assert.assertNotNull(pagingFeed);
        Assert.assertEquals(getTotalItems(totalItems), pagingFeed.getTotalItems());
        Assert.assertEquals(5, pagingFeed.getList().size());
        Assert.assertTrue(pagingFeed.hasMoreItems());

        // List by User
        List<ActivityEntry> feed2 = activityStreamService.getActivityStream(alfsession.getPersonIdentifier());
        Assert.assertNotNull(feed2);

        // List with fake user
        Assert.assertNotNull(activityStreamService.getActivityStream(FAKE_USERNAME));
        Assert.assertEquals(0, activityStreamService.getActivityStream(FAKE_USERNAME).size());

        // List by site
        List<ActivityEntry> feed3 = activityStreamService.getSiteActivityStream(getSiteName(alfsession));
        Assert.assertNotNull(feed3);

        // ///////////////////////////////////////////////////////////////////////////
        // Activity Entry
        // ///////////////////////////////////////////////////////////////////////////
        ActivityEntry entry = feed.get(0);
        Assert.assertNotNull(entry.getIdentifier());
        Assert.assertNotNull(entry.getType());
        Assert.assertNotNull(entry.getCreatedBy());
        Assert.assertNotNull(entry.getCreatedAt());
        Assert.assertNotNull(entry.getSiteShortName());
        Assert.assertNotNull(entry.getData());

        // ///////////////////////////////////////////////////////////////////////////
        // Paging User Activity Entry
        // ///////////////////////////////////////////////////////////////////////////
        wait(10000);

        // Check consistency between Cloud and OnPremise
        if (!isOnPremise()) {
            // Check 1 activity
            lc.setMaxItems(1);
            lc.setSkipCount(0);
            pagingFeed = activityStreamService.getActivityStream(alfsession.getPersonIdentifier(), lc);
            Assert.assertNotNull(pagingFeed);
            Assert.assertEquals(1, pagingFeed.getList().size());
            // Assert.assertTrue(feed2.size() == pagingFeed.getTotalItems()
            // ||
            // feed2.size() - 1 == pagingFeed.getTotalItems());
            Assert.assertTrue(pagingFeed.hasMoreItems());
        }

        // ///////////////////////////////////////////////////////////////////////////
        // Paging Site Activity Entry
        // ///////////////////////////////////////////////////////////////////////////
        // Check 1 activity
        lc.setMaxItems(1);
        lc.setSkipCount(0);
        pagingFeed = activityStreamService.getSiteActivityStream(getSiteName(alfsession), lc);
        Assert.assertNotNull(pagingFeed);
        Assert.assertEquals(1, pagingFeed.getList().size());
        // Assert.assertTrue(feed3.size() == pagingFeed.getTotalItems() ||
        // feed3.size() - 1 == pagingFeed.getTotalItems());
        if (feed3.size() > 1) {
            Assert.assertTrue(pagingFeed.hasMoreItems());
        } else {
            Assert.assertFalse(pagingFeed.hasMoreItems());
        }
    } catch (Exception e) {
        Log.e(TAG, "Error during Activity Tests");
        Log.e("TAG", Log.getStackTraceString(e));
    }
}