Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
bvahdat committed Dec 18, 2016
1 parent 5b66536 commit 769a570
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.camel.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -453,8 +454,7 @@ public static Map<String, String> extractStringProperties(Map<String, Object> pr

Map<String, String> rc = new LinkedHashMap<String, String>(properties.size());

for (Iterator<Map.Entry<String, Object>> it = properties.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
for (Entry<String, Object> entry : properties.entrySet()) {
String name = entry.getKey();
String value = entry.getValue().toString();
rc.put(name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void logContainerHeaderTest() {
@Override
protected void setupMocks() {
Mockito.when(dockerClient.logContainerCmd(Matchers.anyString())).thenReturn(mockObject);
Mockito.when(mockObject.exec(Mockito.anyObject())).thenReturn(callback);
Mockito.when(mockObject.exec(Matchers.anyObject())).thenReturn(callback);
try {
Mockito.when(callback.awaitCompletion()).thenReturn(callback);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@
import com.google.api.services.pubsub.model.ReceivedMessage;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.google.pubsub.consumer.ExchangeAckTransaction;
import org.apache.camel.impl.DefaultConsumer;
import org.apache.camel.spi.Synchronization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException;

class GooglePubsubConsumer extends DefaultConsumer {

private Logger localLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public InfinispanLocalAggregationRepository(final String cacheName) {
public Exchange add(final CamelContext camelContext, final String key, final Exchange exchange) {
LOG.trace("Adding an Exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key);
DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders);
DefaultExchangeHolder oldHolder = (DefaultExchangeHolder) cache.put(key, newHolder);
DefaultExchangeHolder oldHolder = cache.put(key, newHolder);
return unmarshallExchange(camelContext, oldHolder);
}

@Override
public Exchange get(CamelContext camelContext, String key) {
return unmarshallExchange(camelContext, (DefaultExchangeHolder) cache.get(key));
return unmarshallExchange(camelContext, cache.get(key));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public InfinispanRemoteAggregationRepository(final String cacheName) {
public Exchange add(final CamelContext camelContext, final String key, final Exchange exchange) {
LOG.trace("Adding an Exchange with ID {} for key {} in a thread-safe manner.", exchange.getExchangeId(), key);
DefaultExchangeHolder newHolder = DefaultExchangeHolder.marshal(exchange, true, allowSerializedHeaders);
DefaultExchangeHolder oldHolder = (DefaultExchangeHolder) cache.put(key, newHolder);
DefaultExchangeHolder oldHolder = cache.put(key, newHolder);
return unmarshallExchange(camelContext, oldHolder);
}

@Override
public Exchange get(CamelContext camelContext, String key) {
return unmarshallExchange(camelContext, (DefaultExchangeHolder) cache.get(key));
return unmarshallExchange(camelContext, cache.get(key));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ protected Queue<Exchange> createExchanges(Message[] messages) {
LOG.trace("Received {} messages in this poll", messages.length);

Queue<Exchange> answer = new LinkedList<Exchange>();
for (int i = 0; i < messages.length; i++) {
Exchange exchange = getEndpoint().createExchange(messages[i]);
for (Message message : messages) {
Exchange exchange = getEndpoint().createExchange(message);
answer.add(exchange);
}
return answer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.camel.component.jacksonxml;

import java.util.LinkedHashMap;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ void execute(Cache<Object, Object> cache, Exchange exchange) {

static Action fromName(String name) {
if (ObjectHelper.isNotEmpty(name)) {
for (int i = 0; i < VALUES.length; i++) {
if (VALUES[i].name().equalsIgnoreCase(name)) {
return VALUES[i];
for (Action action : VALUES) {
if (action.name().equalsIgnoreCase(name)) {
return action;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.camel.util.ObjectHelper;
import org.springframework.jms.core.JmsOperations;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.destination.JmsDestinationAccessor;

/**
* A JMS {@link org.apache.camel.PollingConsumer}.
Expand All @@ -48,11 +49,11 @@ public JmsEndpoint getEndpoint() {
}

public Exchange receiveNoWait() {
return receive(JmsTemplate.RECEIVE_TIMEOUT_NO_WAIT);
return receive(JmsDestinationAccessor.RECEIVE_TIMEOUT_NO_WAIT);
}

public Exchange receive() {
return receive(JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT);
return receive(JmsDestinationAccessor.RECEIVE_TIMEOUT_INDEFINITE_WAIT);
}

public Exchange receive(long timeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public KafkaProducerTest() throws Exception {
Future future = Mockito.mock(Future.class);
Mockito.when(future.get()).thenReturn(rm);
org.apache.kafka.clients.producer.KafkaProducer kp = Mockito.mock(org.apache.kafka.clients.producer.KafkaProducer.class);
Mockito.when(kp.send(Mockito.any(ProducerRecord.class))).thenReturn(future);
Mockito.when(kp.send(Matchers.any(ProducerRecord.class))).thenReturn(future);

producer.setKafkaProducer(kp);
producer.setWorkerPool(Executors.newFixedThreadPool(1));
Expand Down Expand Up @@ -92,7 +92,7 @@ public void processSendsMessageWithException() throws Exception {
endpoint.getConfiguration().setTopic("sometopic");
// setup the exception here
org.apache.kafka.clients.producer.KafkaProducer kp = producer.getKafkaProducer();
Mockito.when(kp.send(Mockito.any(ProducerRecord.class))).thenThrow(new ApiException());
Mockito.when(kp.send(Matchers.any(ProducerRecord.class))).thenThrow(new ApiException());
Mockito.when(exchange.getIn()).thenReturn(in);
in.setHeader(KafkaConstants.PARTITION_KEY, "4");

Expand Down Expand Up @@ -126,7 +126,7 @@ public void processAsyncSendsMessageWithException() throws Exception {

// setup the exception here
org.apache.kafka.clients.producer.KafkaProducer kp = producer.getKafkaProducer();
Mockito.when(kp.send(Mockito.any(ProducerRecord.class), Mockito.any(Callback.class))).thenThrow(new ApiException());
Mockito.when(kp.send(Matchers.any(ProducerRecord.class), Matchers.any(Callback.class))).thenThrow(new ApiException());

in.setHeader(KafkaConstants.PARTITION_KEY, "4");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ public void sendFramedDataInMultiplePackets(String hl7Message, byte flushByte, b
} else {
log.warn("Not sending START_OF_BLOCK");
}
for (int i = 0; i < payloadBytes.length; ++i) {
outputStream.write(payloadBytes[i]);
if (flushByte == payloadBytes[i]) {
for (byte payloadByte : payloadBytes) {
outputStream.write(payloadByte);
if (flushByte == payloadByte) {
outputStream.flush();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.openstack.common.OpenstackConstants;
import org.apache.camel.component.openstack.keystone.KeystoneConstants;
import org.apache.camel.component.openstack.keystone.KeystoneEndpoint;
import org.apache.camel.util.ObjectHelper;
Expand All @@ -40,19 +41,19 @@ public GroupProducer(KeystoneEndpoint endpoint, OSClient client) {
public void process(Exchange exchange) throws Exception {
final String operation = getOperation(exchange);
switch (operation) {
case KeystoneConstants.CREATE:
case OpenstackConstants.CREATE:
doCreate(exchange);
break;
case KeystoneConstants.GET:
case OpenstackConstants.GET:
doGet(exchange);
break;
case KeystoneConstants.GET_ALL:
case OpenstackConstants.GET_ALL:
doGetAll(exchange);
break;
case KeystoneConstants.UPDATE:
case OpenstackConstants.UPDATE:
doUpdate(exchange);
break;
case KeystoneConstants.DELETE:
case OpenstackConstants.DELETE:
doDelete(exchange);
break;
case KeystoneConstants.ADD_USER_TO_GROUP:
Expand All @@ -77,7 +78,7 @@ private void doCreate(Exchange exchange) {

private void doGet(Exchange exchange) {
final Message msg = exchange.getIn();
final String id = msg.getHeader(KeystoneConstants.ID, msg.getHeader(KeystoneConstants.GROUP_ID, String.class), String.class);
final String id = msg.getHeader(OpenstackConstants.ID, msg.getHeader(KeystoneConstants.GROUP_ID, String.class), String.class);
ObjectHelper.notEmpty(id, "Group ID");
final Group result = osV3Client.identity().groups().get(id);
msg.setBody(result);
Expand All @@ -97,7 +98,7 @@ private void doUpdate(Exchange exchange) {

private void doDelete(Exchange exchange) {
final Message msg = exchange.getIn();
final String id = msg.getHeader(KeystoneConstants.ID, msg.getHeader(KeystoneConstants.GROUP_ID, String.class), String.class);
final String id = msg.getHeader(OpenstackConstants.ID, msg.getHeader(KeystoneConstants.GROUP_ID, String.class), String.class);
ObjectHelper.notEmpty(id, "Group ID");
final ActionResponse response = osV3Client.identity().groups().delete(id);
checkFailure(response, msg, "Delete group with ID " + id);
Expand Down Expand Up @@ -140,8 +141,8 @@ private Group messageToGroup(Message message) {
Map headers = message.getHeaders();
GroupBuilder builder = Builders.group();

ObjectHelper.notEmpty(message.getHeader(KeystoneConstants.NAME, String.class), "Name");
builder.name(message.getHeader(KeystoneConstants.NAME, String.class));
ObjectHelper.notEmpty(message.getHeader(OpenstackConstants.NAME, String.class), "Name");
builder.name(message.getHeader(OpenstackConstants.NAME, String.class));

if (headers.containsKey(KeystoneConstants.DOMAIN_ID)) {
builder.domainId(message.getHeader(KeystoneConstants.DOMAIN_ID, String.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.openstack.common.AbstractOpenstackProducer;
import org.apache.camel.component.openstack.common.OpenstackConstants;
import org.apache.camel.component.openstack.nova.NovaConstants;
import org.apache.camel.component.openstack.nova.NovaEndpoint;
import org.apache.camel.util.ObjectHelper;
Expand All @@ -38,16 +39,16 @@ public KeypairProducer(NovaEndpoint endpoint, OSClient client) {
public void process(Exchange exchange) throws Exception {
String operation = getOperation(exchange);
switch (operation) {
case NovaConstants.CREATE:
case OpenstackConstants.CREATE:
doCreate(exchange);
break;
case NovaConstants.GET:
case OpenstackConstants.GET:
doGet(exchange);
break;
case NovaConstants.GET_ALL:
case OpenstackConstants.GET_ALL:
doGetAll(exchange);
break;
case NovaConstants.DELETE:
case OpenstackConstants.DELETE:
doDelete(exchange);
break;
default:
Expand All @@ -57,7 +58,7 @@ public void process(Exchange exchange) throws Exception {

private void doCreate(Exchange exchange) {
final Message msg = exchange.getIn();
final String name = msg.getHeader(NovaConstants.NAME, String.class);
final String name = msg.getHeader(OpenstackConstants.NAME, String.class);
ObjectHelper.notEmpty(name, "Keypair name");

final String body = msg.getBody(String.class);
Expand All @@ -67,7 +68,7 @@ private void doCreate(Exchange exchange) {

private void doGet(Exchange exchange) {
final Message msg = exchange.getIn();
final String keypairName = msg.getHeader(NovaConstants.NAME, String.class);
final String keypairName = msg.getHeader(OpenstackConstants.NAME, String.class);
ObjectHelper.notEmpty(keypairName, "Keypair name");
final Keypair kp = os.compute().keypairs().get(keypairName);
msg.setBody(kp);
Expand All @@ -81,7 +82,7 @@ private void doGetAll(Exchange exchange) {

private void doDelete(Exchange exchange) {
final Message msg = exchange.getIn();
final String keypairName = msg.getHeader(NovaConstants.NAME, String.class);
final String keypairName = msg.getHeader(OpenstackConstants.NAME, String.class);
ObjectHelper.notEmpty(keypairName, "Keypair name");
final ActionResponse response = os.compute().keypairs().delete(keypairName);
checkFailure(response, msg, "Delete keypair " + keypairName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.UUID;

import org.apache.camel.component.openstack.AbstractProducerTestSupport;
import org.apache.camel.component.openstack.common.OpenstackConstants;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -94,7 +95,7 @@ public void reserveTest() throws Exception {
@Test
public void reserveWithHeadersTest() throws Exception {
when(endpoint.getOperation()).thenReturn(GlanceConstants.RESERVE);
msg.setHeader(GlanceConstants.NAME, dummyImage.getName());
msg.setHeader(OpenstackConstants.NAME, dummyImage.getName());
msg.setHeader(GlanceConstants.CONTAINER_FORMAT, dummyImage.getContainerFormat());
msg.setHeader(GlanceConstants.DISK_FORMAT, dummyImage.getDiskFormat());
msg.setHeader(GlanceConstants.CHECKSUM, dummyImage.getChecksum());
Expand All @@ -114,8 +115,8 @@ public void reserveWithHeadersTest() throws Exception {

@Test
public void createTest() throws Exception {
msg.setHeader(GlanceConstants.OPERATION, GlanceConstants.CREATE);
msg.setHeader(GlanceConstants.NAME, dummyImage.getName());
msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
msg.setHeader(OpenstackConstants.NAME, dummyImage.getName());
msg.setHeader(GlanceConstants.OWNER, dummyImage.getOwner());
msg.setHeader(GlanceConstants.MIN_DISK, dummyImage.getMinDisk());
msg.setHeader(GlanceConstants.MIN_RAM, dummyImage.getMinRam());
Expand All @@ -139,9 +140,9 @@ public void createTest() throws Exception {

@Test
public void uploadWithoutUpdatingTest() throws Exception {
msg.setHeader(GlanceConstants.OPERATION, GlanceConstants.UPLOAD);
msg.setHeader(OpenstackConstants.OPERATION, GlanceConstants.UPLOAD);
final String id = "id";
msg.setHeader(GlanceConstants.ID, id);
msg.setHeader(OpenstackConstants.ID, id);

final File file = File.createTempFile("image", ".iso");
msg.setBody(file);
Expand All @@ -165,10 +166,10 @@ public void uploadWithUpdatingTest() throws Exception {
final String newName = "newName";
dummyImage.setName(newName);
when(osImage.getName()).thenReturn(newName);
msg.setHeader(GlanceConstants.OPERATION, GlanceConstants.UPLOAD);
msg.setHeader(OpenstackConstants.OPERATION, GlanceConstants.UPLOAD);
final String id = "id";
msg.setHeader(GlanceConstants.ID, id);
msg.setHeader(GlanceConstants.NAME, dummyImage.getName());
msg.setHeader(OpenstackConstants.ID, id);
msg.setHeader(OpenstackConstants.NAME, dummyImage.getName());
msg.setHeader(GlanceConstants.OWNER, dummyImage.getOwner());
msg.setHeader(GlanceConstants.MIN_DISK, dummyImage.getMinDisk());
msg.setHeader(GlanceConstants.MIN_RAM, dummyImage.getMinRam());
Expand All @@ -195,7 +196,7 @@ public void uploadWithUpdatingTest() throws Exception {

@Test
public void updateTest() throws Exception {
msg.setHeader(GlanceConstants.OPERATION, GlanceConstants.UPDATE);
msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.UPDATE);
when(imageService.update(any(Image.class))).thenReturn(osImage);
final String newName = "newName";
when(osImage.getName()).thenReturn(newName);
Expand Down

0 comments on commit 769a570

Please sign in to comment.