Example usage for org.springframework.util Assert isTrue

List of usage examples for org.springframework.util Assert isTrue

Introduction

In this page you can find the example usage for org.springframework.util Assert isTrue.

Prototype

@Deprecated
public static void isTrue(boolean expression) 

Source Link

Document

Assert a boolean expression, throwing an IllegalArgumentException if the expression evaluates to false .

Usage

From source file:org.oncoblocks.centromere.dataimport.cli.test.ImportCommandTests.java

@Test
public void importRunnerTest() throws Exception {
    Assert.isTrue(sampleDataRepository.count() == 0);
    Assert.isTrue(dataFileRepository.count() == 0);
    Assert.isTrue(dataSetRepository.count() == 0);
    String[] args = { "import", "-t", "sample_data", "-i",
            ClassLoader.getSystemResource("placeholder.txt").getPath(), "--skip-invalid-records", "-d",
            "{\"label\": \"test\", \"name\": \"Test data\", \"source\": \"internal\"}" };
    ImportCommandArguments arguments = new ImportCommandArguments();
    JCommander commander = new JCommander();
    commander.addCommand("import", arguments);
    commander.parse(args);/* w ww.j a v  a2  s  .c om*/
    ImportCommandRunner runner = new ImportCommandRunner(manager);
    runner.run(arguments);
    Assert.isTrue(sampleDataRepository.count() == 5);
    Assert.isTrue(dataFileRepository.count() == 1);
    Assert.isTrue(dataSetRepository.count() == 1);
}

From source file:org.oncoblocks.centromere.web.test.util.HttpMessageConverterTests.java

@Test
public void writeToJsonWithFieldFilter() throws Exception {
    List<EntrezGene> genes = EntrezGene.createDummyData();
    Set<String> fields = new HashSet<>();
    fields.add("primaryGeneSymbol");
    ResponseEnvelope envelope = new ResponseEnvelope(genes, fields, new HashSet<>());
    Assert.isTrue(jsonConverter.canWrite(envelope.getClass(), MediaType.APPLICATION_JSON));
    MockHttpOutputMessage message = new MockHttpOutputMessage();
    jsonConverter.write(envelope, MediaType.APPLICATION_JSON, message);
    Object document = Configuration.defaultConfiguration().jsonProvider().parse(message.getBodyAsString());
    Assert.isTrue(!((List<String>) JsonPath.read(document, "$")).isEmpty());
    Assert.isTrue(((List<String>) JsonPath.read(document, "$")).size() == 5);
    Map<String, Object> gene = JsonPath.read(document, "$[0]");
    Assert.isTrue(!gene.containsKey("entrezGeneId"));
    Assert.isTrue(!gene.containsKey("aliases"));
    Assert.isTrue(!gene.containsKey("attributes"));
    Assert.isTrue(gene.containsKey("primaryGeneSymbol"));
    Assert.isTrue(gene.get("primaryGeneSymbol").equals("GeneA"));
}

From source file:com.google.code.guice.repository.SimpleBatchStoreJpaRepository.java

@Override
public void saveInBatch(Iterable<T> entities, int batchSize) {
    List<T> list = Lists.newArrayList(entities);
    Assert.notEmpty(list);//from  w w w.  j  a v  a2 s  .c o  m
    Assert.isTrue(batchSize > 0);

    String entityClassName = list.iterator().next().getClass().getSimpleName();
    logger.info(String.format("batch for [%d] of [%s]", list.size(), entityClassName));

    int startIndex = 0;
    int count = list.size();
    while (startIndex < count) {
        int endIndex = startIndex + batchSize;

        if (endIndex > count) {
            endIndex = count;
        }

        Iterable<T> batch = list.subList(startIndex, endIndex);
        try {
            logger.info(String.format("Storing elements: [%d - %d]", startIndex, endIndex));
            saveInBatch(batch);
            logger.info(String.format("[%d - %d] stored", startIndex, endIndex));
        } catch (Exception e) {
            logger.error(String.format("Error while storing [%d - %d] of [%s], trying single store...",
                    startIndex, endIndex, entityClassName), e);
            for (T entity : batch) {
                T saved = saveAndFlush(entity);
                if (saved != null) {
                    entityManager.detach(entity);
                }
            }
        } finally {
            startIndex += batchSize;
        }
    }

    logger.info(String.format("batch for [%d] of [%s] stored", list.size(), entityClassName));
}

From source file:net.chrisrichardson.bankingExample.domain.jdbc.JdbcAccountDao.java

public void saveAccount(Account account) {
    int count = jdbcTemplate.update(
            "UPDATE BANK_ACCOUNT set accountId = ?, BALANCE = ?, overdraftPolicy = ?, dateOpened = ?, requiredYearsOpen = ?, limit = ? WHERE ACCOUNT_ID = ?",
            new Object[] { account.getAccountId(), account.getBalance(), account.getOverdraftPolicy(),
                    new Timestamp(account.getDateOpened().getTime()), account.getRequiredYearsOpen(),
                    account.getLimit(), account.getId() },
            new int[] { Types.VARCHAR, Types.DOUBLE, Types.INTEGER, Types.TIMESTAMP, Types.DOUBLE, Types.DOUBLE,
                    Types.INTEGER });
    Assert.isTrue(count == 1);

}

From source file:com.epam.catgenome.dao.DaoHelper.java

/**
 * Generates and returns the next value for a sequence with the given name.
 *
 * @param sequenceName {@code String} specifies full-qualified name of sequence which
 *                     next value should be returned by a call
 * @return {@code Long}/*w  w w  . ja v a 2  s . c o m*/
 * @throws IllegalArgumentException will be thrown if the provided <tt>sequenceName</tt>
 *                                  id <tt>null</tt> or empty string
 */
@Transactional(propagation = Propagation.MANDATORY)
public Long createId(final String sequenceName) {
    Assert.isTrue(StringUtils.isNotBlank(sequenceName));
    return getNamedParameterJdbcTemplate().queryForObject(createIdQuery,
            new MapSqlParameterSource(HelperParameters.SEQUENCE_NAME.name(), sequenceName), Long.class);
}

From source file:org.openscada.spring.client.redundancy.RedundancySwitchHandler.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(this.redundancySwitcherConnection, "'redundancySwitcherConnection' must not be null");
    Assert.notNull(this.redundancySwitcherItemId, "'redundancySwitcherItemId' must not be null");
    Assert.notNull(this.masterFlagItems, "'masterFlagItems' must not be null");
    Assert.isTrue(this.masterFlagItems.size() > 0);
    if (Long.valueOf(0).equals(this.lastSwitchOccured)) {
        this.lastSwitchOccured.set(System.currentTimeMillis());
    }/* w  ww  .  j  a va2 s . com*/

    // first evaluate master flags
    for (final Entry<String, ItemEventAdapter> masterFlagItem : this.masterFlagItems.entrySet()) {
        masterFlagItem.getValue().attachTarget(new ItemEventListener() {

            @Override
            public void itemEvent(final String topic, final DataItemValue value) {
                if (value == null) {
                    logger.info("Master flag changed for {} to {}", masterFlagItem.getKey(), value);
                    RedundancySwitchHandler.this.lastMasterFlags.put(masterFlagItem.getKey(), false);
                    return;
                }
                logger.info("Master flag changed for {} to {} subscription state: {}",
                        new Object[] { masterFlagItem.getKey(), value, value.getSubscriptionState() });
                RedundancySwitchHandler.this.lastConnectionStates.put(masterFlagItem.getKey(),
                        SubscriptionState.CONNECTED.equals(value.getSubscriptionState()));
                RedundancySwitchHandler.this.lastMasterFlags.put(masterFlagItem.getKey(),
                        value.getValue().asBoolean());
                if (hasError(value)) {
                    logger.info("Master flag {} has error", masterFlagItem.getKey());
                    RedundancySwitchHandler.this.lastConnectionStates.put(masterFlagItem.getKey(), false);
                    RedundancySwitchHandler.this.lastMasterFlags.put(masterFlagItem.getKey(), false);
                }
                switchConnection();
            }
        });
    }

    // 2nd evaluate if there is a connection at all (e.g. OPC connection)
    for (final Entry<String, ItemEventAdapter> connectedFlagItem : this.connectedFlagItems.entrySet()) {
        connectedFlagItem.getValue().attachTarget(new ItemEventListener() {

            @Override
            public void itemEvent(final String topic, final DataItemValue value) {
                if (value == null) {
                    logger.info("Connected flag changed for {} to {}", connectedFlagItem.getKey(), value);
                    RedundancySwitchHandler.this.lastMasterFlags.put(connectedFlagItem.getKey(), false);
                    RedundancySwitchHandler.this.lastConnectionStates.put(connectedFlagItem.getKey(), false);
                } else if (value.getValue().asBoolean()) {
                    logger.info("Connected flag changed for " + connectedFlagItem.getKey() + " to " + value
                            + " subscription state: " + value.getSubscriptionState());
                    RedundancySwitchHandler.this.lastConnectionStates.put(connectedFlagItem.getKey(), true);
                } else {
                    logger.info("Connected flag changed for " + connectedFlagItem.getKey() + " to " + value
                            + " subscription state: " + value.getSubscriptionState());
                    RedundancySwitchHandler.this.lastConnectionStates.put(connectedFlagItem.getKey(), false);
                    RedundancySwitchHandler.this.lastMasterFlags.put(connectedFlagItem.getKey(), false);
                }
                switchConnection();
            }
        });
    }

    this.redundancySwitcherItem.attachTarget(new ItemEventListener() {
        @Override
        public void itemEvent(final String topic, final DataItemValue value) {
            logger.info("Current redundant connection changed to {}", value);
            try {
                RedundancySwitchHandler.this.currentConnection.set(value.getValue().asString());
            } catch (final NullValueException e) {
                RedundancySwitchHandler.this.currentConnection.set(null);
            }
        };
    });
}

From source file:com.streamreduce.util.JiraClient.java

/**
 * Constructs a client for GitHub using the credentials in the connection provided.
 *
 * @param connection the connection to use for interacting with GitHub
 *///  w  w  w . j  a v  a  2 s .c om
public JiraClient(Connection connection) {
    super(connection);

    Assert.isTrue(connection.getProviderId().equals(ProviderIdConstants.JIRA_PROVIDER_ID));

    init();
}

From source file:org.oncoblocks.centromere.jpa.test.JpaRepositoryTests.java

@Test
public void countTest() {

    long count = geneRepository.count();
    Assert.notNull(count);
    Assert.isTrue(count == 5L);

}

From source file:com.alibaba.otter.canal.example.db.dialect.AbstractDbDialect.java

private void initTables(final JdbcTemplate jdbcTemplate) {
    this.tables = MigrateMap.makeComputingMap(new Function<List<String>, Table>() {

        public Table apply(List<String> names) {
            Assert.isTrue(names.size() == 2);
            try {
                Table table = DdlUtils.findTable(jdbcTemplate, names.get(0), names.get(0), names.get(1));
                if (table == null) {
                    throw new NestableRuntimeException(
                            "no found table [" + names.get(0) + "." + names.get(1) + "] , pls check");
                } else {
                    return table;
                }/* www .  ja  v a 2s. c o m*/
            } catch (Exception e) {
                throw new NestableRuntimeException(
                        "find table [" + names.get(0) + "." + names.get(1) + "] error", e);
            }
        }
    });
}

From source file:org.oncoblocks.centromere.mongodb.test.GenericMongoRepositoryTests.java

@Test
public void findBySimpleCriteriaTest() {

    List<QueryCriteria> searchCriterias = new ArrayList<>();
    searchCriterias.add(new QueryCriteria("primaryGeneSymbol", "GeneB"));
    List<EntrezGene> genes = geneRepository.find(searchCriterias);
    Assert.notNull(genes);/*from   w  w w  . j  a  v a  2  s .  co  m*/
    Assert.notEmpty(genes);
    Assert.isTrue(genes.size() == 1);

    EntrezGene gene = genes.get(0);
    Assert.notNull(gene);
    Assert.isTrue(gene.getEntrezGeneId().equals(2L));
    Assert.isTrue("GeneB".equals(gene.getPrimaryGeneSymbol()));

}