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:edu.pitt.dbmi.ccd.anno.user.UserResourceAssembler.java

/**
 * Convert UserAccounts + Persons to UserResources
 *
 * @param accounts entities/*from w ww .java 2  s.c  om*/
 * @return List of resources
 */
@Override
public List<UserResource> toResources(Iterable<? extends UserAccount> accounts)
        throws IllegalArgumentException {
    // Assert accounts is not empty
    Assert.isTrue(accounts.iterator().hasNext());
    return StreamSupport.stream(accounts.spliterator(), false).map(this::toResource)
            .collect(Collectors.toList());
}

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

@Test
public void addDataSetArgumentsTest() throws Exception {
    AddCommandArguments addCommandArguments = new AddCommandArguments();
    JCommander jCommander = new JCommander();
    jCommander.addCommand("add", addCommandArguments);
    String[] args = { "add", "data_set", "test",
            "\"{ \"source\": \"internal\", \"name\": \"Test Data Set\", \"notes\": \"This is a test data set\" }\"" };
    jCommander.parse(args);//from   w w w.  jav  a2  s  .  c  om
    Assert.isTrue("add".equals(jCommander.getParsedCommand()));
    Assert.isTrue(addCommandArguments.getArgs().size() == 3);
    String label = addCommandArguments.getLabel();
    String category = addCommandArguments.getCategory();
    String body = addCommandArguments.getBody();
    Assert.notNull(label);
    Assert.notNull(category);
    Assert.notNull(body);
    Assert.isTrue("data_set".equals(category));
    Assert.isTrue("test".equals(label));
    ObjectMapper objectMapper = new ObjectMapper();
    BasicDataSetMetadata dataSetMetadata = (BasicDataSetMetadata) addCommandArguments.getDataSetMetadata();
    Assert.notNull(dataSetMetadata);
    Assert.isTrue("internal".equals(dataSetMetadata.getSource()));
    Assert.isTrue("Test Data Set".equals(dataSetMetadata.getName()));
}

From source file:com.cisco.oss.foundation.http.api.test.InterfacesResource.java

@POST
@Produces("text/plain")
//    @Transactional(rollbackFor=Exception.class)
public String testPost(@Context UriInfo uriInfo, @HeaderParam("Session-ID") String sessionId,
        @HeaderParam("Source-ID") String sourceId, @HeaderParam("Source-Type") String sourceType, String body) {

    //        FlowContextFactory.createFlowContext();
    AUDITOR.info("starting InterfacesResource.requestGetIfs...");

    LOGGER.debug("psSms InterfacesResource: Get interfaces");

    //        Assert.isTrue(config != null);

    Assert.isTrue(FlowContextFactory.getFlowContext() != null);

    AUDITOR.info("exit InterfacesResource.requestGetIfs...");
    return "psSms adaptor v3.34.0; ICD version 2.10\n" + "01. (see 7.1 in ICD)   SMS notifies PS\n"
            + "02. (see 7.3 in ICD)   Notify Pin Change\n" + "03. (see 10.5 in ICD)  Unpair Devices\n"
            + "04. (see 10.8 in ICD)  Reset Master Pin\n"
            + "05. (see 10.14 in ICD) Refresh CPE Household data\n";
}

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

@Test
public void importArgumentsTest() throws Exception {
    ImportCommandArguments arguments = new ImportCommandArguments();
    JCommander commander = new JCommander();
    commander.addCommand("import", arguments);
    String[] args = { "import", "-t", "sample_data", "-i", "test.txt", "--skip-invalid-records", "-d",
            "{\"label\": \"test\", \"name\": \"Test data\", \"source\": \"internal\"}" };
    commander.parse(args);/*from   www.  j  a v a  2  s.com*/
    Assert.isTrue("import".equals(commander.getParsedCommand()));
    Assert.isTrue("sample_data".equals(arguments.getDataType()));
    Assert.isTrue("test.txt".equals(arguments.getInputFilePath()));
    Assert.isTrue(arguments.isSkipInvalidRecords());
    Assert.isTrue(!arguments.isSkipInvalidDataSets());
    BasicDataSetMetadata metadata = (BasicDataSetMetadata) arguments.getDataSetMetadata();
    Assert.notNull(metadata);
    Assert.isTrue("internal".equals(metadata.getSource()));
    Assert.isTrue("test".equals(metadata.getLabel()));
}

From source file:org.openscada.da.server.spring.DataItemInputOutputProperty.java

@Override
public void afterPropertiesSet() throws Exception {
    // contract/*from  w w w  . ja  va 2 s. c  om*/
    Assert.notNull(this.bean, "'bean' must not be null");
    Assert.notNull(this.property, "'property' must not be null");
    Assert.isTrue(PropertyUtils.isReadable(this.bean, this.property));
    Assert.isTrue(PropertyUtils.isWriteable(this.bean, this.property));
    final Object value = PropertyUtils.getProperty(this.bean, this.property);
    updateData(Variant.valueOf(value), new HashMap<String, Variant>(), AttributeMode.SET);
    notifyData(Variant.valueOf(value), new HashMap<String, Variant>(), true);
}

From source file:edu.pitt.dbmi.ccd.anno.data.AnnotationTargetResourceAssembler.java

/**
 * convert AnnotationTargets to AnnotationTargetResources
 *
 * @param targets entities//  w  w  w  .ja v  a 2s.co m
 * @return List of resources
 */
@Override
public List<AnnotationTargetResource> toResources(Iterable<? extends AnnotationTarget> targets)
        throws IllegalArgumentException {
    // Assert targets is not empty
    Assert.isTrue(targets.iterator().hasNext());
    return StreamSupport.stream(targets.spliterator(), false).map(this::toResource)
            .collect(Collectors.toList());
}

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

@Test
public void findAllTest() {

    List<EntrezGene> genes = geneRepository.findAll();
    Assert.notNull(genes);//from w ww. j a  v  a  2  s.  c  o m
    Assert.notEmpty(genes);
    Assert.isTrue(genes.size() == 5);

    EntrezGene gene = genes.get(0);
    Assert.notNull(gene);
    Assert.isTrue(gene.getEntrezGeneId().equals(1L));
    Assert.isTrue("GeneA".equals(gene.getPrimaryGeneSymbol()));
    Assert.notNull(gene.getAliases());
    Assert.notEmpty(gene.getAliases());
    Assert.isTrue(gene.getAliases().size() == 1);
    System.out.println(gene.toString());

}

From source file:com.pw.ism.heartbeat.InMemoryHeartbeatRepositoryTest.java

@Test
public void shouldRefreshHeartbeat() throws Exception {
    Heartbeat hb1 = new Heartbeat();
    hb1.setCustomer("TEST1");
    hb1.setNetwork("NETWORK1");

    repo.addHeartbeat(hb1, Instant.now().minusSeconds(5));

    List<Heartbeat> list = repo.getExpiredHeartbeats(3);
    Assert.isTrue(list.contains(hb1));

    Heartbeat hb2 = new Heartbeat();
    hb2.setCustomer("TEST1");
    hb2.setNetwork("NETWORK1");

    repo.addHeartbeat(hb2, Instant.now().minusSeconds(2));

    list = repo.getExpiredHeartbeats(3);
    Assert.isTrue(list.isEmpty());/*www  .  jav a 2 s.  c  o m*/
}

From source file:org.apache.servicemix.camel.JbiInOnlyWithErrorHandledTrueSpringDSLTest.java

@Override
protected void setUp() throws Exception {
    receiver = new ReceiverComponent() {
        public void onMessageExchange(MessageExchange exchange) throws MessagingException {
            NormalizedMessage inMessage = getInMessage(exchange);
            try {
                Assert.notNull(exchange.getProperty(Exchange.EXCEPTION_CAUGHT),
                        Exchange.EXCEPTION_CAUGHT + " property not set");
                MessageUtil.enableContentRereadability(inMessage);
                String message = new SourceTransformer().contentToString(inMessage);
                Assert.isTrue(message.contains(MESSAGE));
            } catch (Exception e) {
                throw new MessagingException(e);
            }//from   w  ww  .j  a v  a  2s .  c  om

            super.onMessageExchange(exchange);
        }
    };
    deadLetter = new ReceiverComponent();

    super.setUp();

    // change the log level to avoid the conversion to DOMSource 
    Logger.getLogger("org.apache.servicemix").setLevel(Level.ERROR);
}

From source file:com.trenako.values.DeliveryDate.java

/**
 * Returns the list of {@code DeliveryDate}.
 * <p>// ww  w . j  a  va 2s.c  om
 * This methods provides two different years ranges:
 * <ul>
 * <li>since {@code endYearWithQuarters} back to {@code startYearWithQuarters}
 * the years are listed with quarter information;
 * <li>since {@code endYearWithoutQuarters} back to {@code startYearWithoutQuarters}
 * the years are listed without quarter information.
 * </ul>
 * </p>
 *
 * @param startYearWithoutQuarters the first year without quarters
 * @param endYearWithoutQuarters   the last year without quarters
 * @param startYearWithQuarters    the first year with quarters
 * @param endYearWithQuarters      the last year with quarters
 * @return the {@code DeliveryDate} list
 */
public static Iterable<DeliveryDate> list(int startYearWithoutQuarters, int endYearWithoutQuarters,
        int startYearWithQuarters, int endYearWithQuarters) {

    Assert.isTrue(startYearWithoutQuarters <= endYearWithoutQuarters);
    Assert.isTrue(startYearWithQuarters <= endYearWithQuarters);

    List<DeliveryDate> list = new ArrayList<DeliveryDate>();

    for (int year : inverseRange(startYearWithQuarters, endYearWithQuarters)) {
        for (int q : Utils.reverseIterable(QUARTERS)) {
            list.add(new DeliveryDate(year, q));
        }
    }

    for (int year : inverseRange(startYearWithoutQuarters, endYearWithoutQuarters)) {
        list.add(new DeliveryDate(year));
    }

    return Collections.unmodifiableList(list);
}