Search in sources :

Example 91 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class EC2ProducerTest method ec2DescribeStatusSpecificInstancesTest.

@Test
public void ec2DescribeStatusSpecificInstancesTest() throws Exception {
    mock.expectedMessageCount(1);
    Exchange exchange = template.request("direct:describeStatus", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Collection l = new ArrayList();
            l.add("test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCES_IDS, l);
        }
    });
    assertMockEndpointsSatisfied();
    DescribeInstanceStatusResult resultGet = (DescribeInstanceStatusResult) exchange.getIn().getBody();
    assertEquals(resultGet.getInstanceStatuses().size(), 1);
    assertEquals(resultGet.getInstanceStatuses().get(0).getInstanceState().getName(), InstanceStateName.Running.toString());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Test(org.junit.Test)

Example 92 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class EC2ProducerTest method ec2StopTest.

@Test
public void ec2StopTest() throws Exception {
    mock.expectedMessageCount(1);
    Exchange exchange = template.request("direct:stop", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Collection l = new ArrayList();
            l.add("test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCES_IDS, l);
        }
    });
    assertMockEndpointsSatisfied();
    StopInstancesResult resultGet = (StopInstancesResult) exchange.getIn().getBody();
    assertEquals(resultGet.getStoppingInstances().get(0).getInstanceId(), "test-1");
    assertEquals(resultGet.getStoppingInstances().get(0).getPreviousState().getName(), InstanceStateName.Running.toString());
    assertEquals(resultGet.getStoppingInstances().get(0).getCurrentState().getName(), InstanceStateName.Stopped.toString());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Test(org.junit.Test)

Example 93 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class EC2ProducerTest method ec2StartTest.

@Test
public void ec2StartTest() throws Exception {
    mock.expectedMessageCount(1);
    Exchange exchange = template.request("direct:start", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Collection l = new ArrayList();
            l.add("test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCES_IDS, l);
        }
    });
    assertMockEndpointsSatisfied();
    StartInstancesResult resultGet = (StartInstancesResult) exchange.getIn().getBody();
    assertEquals(resultGet.getStartingInstances().get(0).getInstanceId(), "test-1");
    assertEquals(resultGet.getStartingInstances().get(0).getPreviousState().getName(), InstanceStateName.Stopped.toString());
    assertEquals(resultGet.getStartingInstances().get(0).getCurrentState().getName(), InstanceStateName.Running.toString());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Test(org.junit.Test)

Example 94 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class BindyCsvFactory method initAnnotatedFields.

@Override
public void initAnnotatedFields() {
    maxpos = 0;
    for (Class<?> cl : models) {
        List<Field> linkFields = new ArrayList<Field>();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Class retrieved: {}", cl.getName());
        }
        for (Field field : cl.getDeclaredFields()) {
            DataField dataField = field.getAnnotation(DataField.class);
            if (dataField != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Position defined in the class: {}, position: {}, Field: {}", new Object[] { cl.getName(), dataField.pos(), dataField });
                }
                if (dataField.required()) {
                    ++numberMandatoryFields;
                } else {
                    ++numberOptionalFields;
                }
                int pos = dataField.pos();
                if (annotatedFields.containsKey(pos)) {
                    Field f = annotatedFields.get(pos);
                    LOG.warn("Potentially invalid model: existing @DataField '{}' replaced by '{}'", f.getName(), field.getName());
                }
                dataFields.put(pos, dataField);
                annotatedFields.put(pos, field);
                maxpos = Math.max(maxpos, pos);
            }
            Link linkField = field.getAnnotation(Link.class);
            if (linkField != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Class linked: {}, Field: {}", cl.getName(), field);
                }
                linkFields.add(field);
            }
        }
        if (!linkFields.isEmpty()) {
            annotatedLinkFields.put(cl.getName(), linkFields);
        }
        totalFields = numberMandatoryFields + numberOptionalFields;
        if (LOG.isDebugEnabled()) {
            LOG.debug("Number of optional fields: {}", numberOptionalFields);
            LOG.debug("Number of mandatory fields: {}", numberMandatoryFields);
            LOG.debug("Total: {}", totalFields);
        }
    }
    if (annotatedFields.size() < maxpos) {
        LOG.info("Potentially incomplete model: some csv fields may not be mapped to @DataField members");
    }
}
Also used : Field(java.lang.reflect.Field) DataField(org.apache.camel.dataformat.bindy.annotation.DataField) DataField(org.apache.camel.dataformat.bindy.annotation.DataField) ArrayList(java.util.ArrayList) Link(org.apache.camel.dataformat.bindy.annotation.Link)

Example 95 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CsvTest method testUnmarshal.

/*
    @Test
    public void testMarshal() throws Exception {
        List<Employee> employees = getEmployees();

        MockEndpoint mock = getMockEndpoint("mock:beanio-marshal");
        mock.expectedBodiesReceived(FIXED_DATA);

        template.sendBody("direct:marshal", employees);

        mock.assertIsSatisfied();
    }
*/
@Test
public void testUnmarshal() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:beanio-unmarshal");
    mock.expectedMessageCount(2);
    template.sendBody("direct:unmarshal", FIXED_DATA);
    mock.assertIsSatisfied();
    List<Exchange> exchanges = mock.getExchanges();
    if (verbose) {
        for (Exchange exchange : exchanges) {
            Object body = exchange.getIn().getBody();
            log.info("received message {} of class {}", body, body.getClass().getName());
        }
    }
    List<Map> results = new ArrayList<Map>();
    for (Exchange exchange : exchanges) {
        Map body = exchange.getIn().getBody(Map.class);
        if (body != null) {
            results.add(body);
        }
    }
    assertRecord(results, 0, "James", "Strachan", 22);
    assertRecord(results, 1, "Claus", "Ibsen", 21);
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ArrayList(java.util.ArrayList) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611