Add JavaDoc, refactor staff for clean code convention and modify unit
tests Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -130,9 +130,9 @@ public class AmqpConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create amqp handler service bean.
|
* Create default amqp sender service bean.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the default amqp sender service bean
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
|
|||||||
@@ -127,10 +127,7 @@ public class AmqpControllerAuthentfication {
|
|||||||
|
|
||||||
LOGGER.debug("preAuthenticatedPrincipal = {} trying to authenticate", principal);
|
LOGGER.debug("preAuthenticatedPrincipal = {} trying to authenticate", principal);
|
||||||
|
|
||||||
final PreAuthenticatedAuthenticationToken authRequest = new PreAuthenticatedAuthenticationToken(principal,
|
return new PreAuthenticatedAuthenticationToken(principal, credentials);
|
||||||
credentials);
|
|
||||||
|
|
||||||
return authRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setControllerManagement(final ControllerManagement controllerManagement) {
|
public void setControllerManagement(final ControllerManagement controllerManagement) {
|
||||||
|
|||||||
@@ -36,9 +36,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link AmqpMessageDispatcherService} handles all outgoing AMQP messages.
|
* {@link AmqpMessageDispatcherService} create all outgoing AMQP messages and
|
||||||
*
|
* delegate the messages to a {@link AmqpSenderService}.
|
||||||
*
|
*
|
||||||
|
* Additionally the dispatcher listener/subscribe for some target events e.g.
|
||||||
|
* assignment.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@EventSubscriber
|
@EventSubscriber
|
||||||
@@ -160,4 +162,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
public void setArtifactUrlHandler(final ArtifactUrlHandler artifactUrlHandler) {
|
public void setArtifactUrlHandler(final ArtifactUrlHandler artifactUrlHandler) {
|
||||||
this.artifactUrlHandler = artifactUrlHandler;
|
this.artifactUrlHandler = artifactUrlHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAmqpSenderService(final AmqpSenderService amqpSenderService) {
|
||||||
|
this.amqpSenderService = amqpSenderService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,15 +98,25 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
private HostnameResolver hostnameResolver;
|
private HostnameResolver hostnameResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
* @param messageConverter
|
* @param messageConverter
|
||||||
|
* the message converter.
|
||||||
|
* @param defaultTemplate
|
||||||
|
* the configured amqp template.
|
||||||
*/
|
*/
|
||||||
@Autowired
|
|
||||||
public AmqpMessageHandlerService(final MessageConverter messageConverter, final RabbitTemplate defaultTemplate) {
|
public AmqpMessageHandlerService(final MessageConverter messageConverter, final RabbitTemplate defaultTemplate) {
|
||||||
super(messageConverter, defaultTemplate);
|
super(messageConverter, defaultTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RabbitListener(queues = "${hawkbit.dmf.rabbitmq.receiverQueue}", containerFactory = "listenerContainerFactory")
|
||||||
|
private Message onMessage(final Message message, @Header(MessageHeaderKey.TYPE) final String type,
|
||||||
|
@Header(MessageHeaderKey.TENANT) final String tenant) {
|
||||||
|
return onMessage(message, type, tenant, internalAmqpTemplate.getConnectionFactory().getVirtualHost());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* /** Method to handle all incoming amqp messages.
|
* Method to handle all incoming amqp messages.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
* incoming message
|
* incoming message
|
||||||
@@ -116,11 +126,11 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
* the contentType of the message
|
* the contentType of the message
|
||||||
* @param tenant
|
* @param tenant
|
||||||
* the contentType of the message
|
* the contentType of the message
|
||||||
|
* @param virtualHost
|
||||||
|
* the virtual host
|
||||||
* @return a message if <null> no message is send back to sender
|
* @return a message if <null> no message is send back to sender
|
||||||
*/
|
*/
|
||||||
@RabbitListener(queues = "${hawkbit.dmf.rabbitmq.receiverQueue}", containerFactory = "listenerContainerFactory")
|
public Message onMessage(final Message message, final String type, final String tenant, final String virtualHost) {
|
||||||
public Message onMessage(final Message message, @Header(MessageHeaderKey.TYPE) final String type,
|
|
||||||
@Header(MessageHeaderKey.TENANT) final String tenant) {
|
|
||||||
checkContentTypeJson(message);
|
checkContentTypeJson(message);
|
||||||
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
||||||
try {
|
try {
|
||||||
@@ -128,7 +138,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
switch (messageType) {
|
switch (messageType) {
|
||||||
case THING_CREATED:
|
case THING_CREATED:
|
||||||
setTenantSecurityContext(tenant);
|
setTenantSecurityContext(tenant);
|
||||||
registerTarget(message);
|
registerTarget(message, virtualHost);
|
||||||
break;
|
break;
|
||||||
case EVENT:
|
case EVENT:
|
||||||
setTenantSecurityContext(tenant);
|
setTenantSecurityContext(tenant);
|
||||||
@@ -230,7 +240,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
* @param ip
|
* @param ip
|
||||||
* the ip of the target/thing
|
* the ip of the target/thing
|
||||||
*/
|
*/
|
||||||
private void registerTarget(final Message message) {
|
private void registerTarget(final Message message, final String virtualHost) {
|
||||||
final String thingId = getStringHeaderKey(message, MessageHeaderKey.THING_ID, "ThingId is null");
|
final String thingId = getStringHeaderKey(message, MessageHeaderKey.THING_ID, "ThingId is null");
|
||||||
final String replyTo = message.getMessageProperties().getReplyTo();
|
final String replyTo = message.getMessageProperties().getReplyTo();
|
||||||
|
|
||||||
@@ -238,7 +248,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
logAndThrowMessageError(message, "No ReplyTo was set for the createThing Event.");
|
logAndThrowMessageError(message, "No ReplyTo was set for the createThing Event.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final URI amqpUri = IpUtil.createAmqpUri(getVirtualHost(message), replyTo);
|
final URI amqpUri = IpUtil.createAmqpUri(virtualHost, replyTo);
|
||||||
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotexist(thingId, amqpUri);
|
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotexist(thingId, amqpUri);
|
||||||
LOG.debug("Target {} reported online state.", thingId);
|
LOG.debug("Target {} reported online state.", thingId);
|
||||||
|
|
||||||
@@ -271,6 +281,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
private void handleIncomingEvent(final Message message, final EventTopic topic) {
|
private void handleIncomingEvent(final Message message, final EventTopic topic) {
|
||||||
if (EventTopic.UPDATE_ACTION_STATUS.equals(topic)) {
|
if (EventTopic.UPDATE_ACTION_STATUS.equals(topic)) {
|
||||||
updateActionStatus(message);
|
updateActionStatus(message);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
logAndThrowMessageError(message, "Got event without appropriate topic.");
|
logAndThrowMessageError(message, "Got event without appropriate topic.");
|
||||||
}
|
}
|
||||||
@@ -321,19 +332,20 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
logAndThrowMessageError(message, "Status for action does not exisit.");
|
logAndThrowMessageError(message, "Status for action does not exisit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Action addUpdateActionStatus;
|
final Action addUpdateActionStatus = getUpdateActionStatus(action, actionStatus);
|
||||||
|
|
||||||
if (!actionStatus.getStatus().equals(Status.CANCELED)) {
|
|
||||||
addUpdateActionStatus = controllerManagement.addUpdateActionStatus(actionStatus, action);
|
|
||||||
} else {
|
|
||||||
addUpdateActionStatus = controllerManagement.addCancelActionStatus(actionStatus, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!addUpdateActionStatus.isActive()) {
|
if (!addUpdateActionStatus.isActive()) {
|
||||||
lookIfUpdateAvailable(action.getTarget());
|
lookIfUpdateAvailable(action.getTarget());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Action getUpdateActionStatus(final Action action, final ActionStatus actionStatus) {
|
||||||
|
if (actionStatus.getStatus().equals(Status.CANCELED)) {
|
||||||
|
return controllerManagement.addCancelActionStatus(actionStatus, action);
|
||||||
|
}
|
||||||
|
return controllerManagement.addUpdateActionStatus(actionStatus, action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param message
|
* @param message
|
||||||
* @param actionUpdateStatus
|
* @param actionUpdateStatus
|
||||||
|
|||||||
@@ -8,16 +8,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.amqp;
|
package org.eclipse.hawkbit.amqp;
|
||||||
|
|
||||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bean which holds the necessary properties for configuring the AMQP
|
* Bean which holds the necessary properties for configuring the AMQP
|
||||||
* connection.
|
* connection.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties("hawkbit.dmf.rabbitmq")
|
@ConfigurationProperties("hawkbit.dmf.rabbitmq")
|
||||||
public class AmqpProperties {
|
public class AmqpProperties {
|
||||||
@@ -27,59 +23,26 @@ public class AmqpProperties {
|
|||||||
private String receiverQueue = "dmf_receiver";
|
private String receiverQueue = "dmf_receiver";
|
||||||
private boolean missingQueuesFatal = false;
|
private boolean missingQueuesFatal = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Is missingQueuesFatal enabled
|
|
||||||
*
|
|
||||||
* @see SimpleMessageListenerContainer#setMissingQueuesFatal
|
|
||||||
* @return the missingQueuesFatal <true> enabled <false> disabled
|
|
||||||
*/
|
|
||||||
public boolean isMissingQueuesFatal() {
|
public boolean isMissingQueuesFatal() {
|
||||||
return missingQueuesFatal;
|
return missingQueuesFatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param missingQueuesFatal
|
|
||||||
* the missingQueuesFatal to set.
|
|
||||||
* @see SimpleMessageListenerContainer#setMissingQueuesFatal
|
|
||||||
*/
|
|
||||||
public void setMissingQueuesFatal(final boolean missingQueuesFatal) {
|
public void setMissingQueuesFatal(final boolean missingQueuesFatal) {
|
||||||
this.missingQueuesFatal = missingQueuesFatal;
|
this.missingQueuesFatal = missingQueuesFatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the dead letter exchange.
|
|
||||||
*
|
|
||||||
* @return dead letter exchange
|
|
||||||
*/
|
|
||||||
public String getDeadLetterExchange() {
|
public String getDeadLetterExchange() {
|
||||||
return deadLetterExchange;
|
return deadLetterExchange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the dead letter exchange.
|
|
||||||
*
|
|
||||||
* @param deadLetterExchange
|
|
||||||
* the deadLetterExchange to be set
|
|
||||||
*/
|
|
||||||
public void setDeadLetterExchange(final String deadLetterExchange) {
|
public void setDeadLetterExchange(final String deadLetterExchange) {
|
||||||
this.deadLetterExchange = deadLetterExchange;
|
this.deadLetterExchange = deadLetterExchange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the dead letter queue.
|
|
||||||
*
|
|
||||||
* @return the dead letter queue
|
|
||||||
*/
|
|
||||||
public String getDeadLetterQueue() {
|
public String getDeadLetterQueue() {
|
||||||
return deadLetterQueue;
|
return deadLetterQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the dead letter queue.
|
|
||||||
*
|
|
||||||
* @param deadLetterQueue
|
|
||||||
* the deadLetterQueue ro be set
|
|
||||||
*/
|
|
||||||
public void setDeadLetterQueue(final String deadLetterQueue) {
|
public void setDeadLetterQueue(final String deadLetterQueue) {
|
||||||
this.deadLetterQueue = deadLetterQueue;
|
this.deadLetterQueue = deadLetterQueue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*/
|
||||||
package org.eclipse.hawkbit.amqp;
|
package org.eclipse.hawkbit.amqp;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@@ -5,20 +13,32 @@ import java.net.URI;
|
|||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
* Interface to send a amqp message.
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface AmqpSenderService {
|
public interface AmqpSenderService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Send the given message to the given uri. The uri contains the (virtual)
|
||||||
|
* host and exchange.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
|
* the amqp message
|
||||||
* @param uri
|
* @param uri
|
||||||
|
* the reply to uri
|
||||||
*/
|
*/
|
||||||
void sendMessage(Message message, URI uri);
|
void sendMessage(Message message, URI uri);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the exchange from the uri. Default implementation removes the
|
||||||
|
* first /.
|
||||||
|
*
|
||||||
|
* @param amqpUri
|
||||||
|
* the amqp uri
|
||||||
|
* @return the exchange.
|
||||||
|
*/
|
||||||
|
default String extractExchange(final URI amqpUri) {
|
||||||
|
return amqpUri.getPath().substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.amqp;
|
package org.eclipse.hawkbit.amqp;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -14,34 +18,22 @@ import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
|
|||||||
import org.springframework.amqp.support.converter.MessageConverter;
|
import org.springframework.amqp.support.converter.MessageConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* A base class which provide basis amqp staff.
|
||||||
*/
|
*/
|
||||||
public class BaseAmqpService {
|
public class BaseAmqpService {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(BaseAmqpService.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(BaseAmqpService.class);
|
||||||
protected static final String VIRTUAL_HOST_MESSAGE_HEADER = "VHOST_HEADER";
|
|
||||||
|
|
||||||
protected MessageConverter messageConverter;
|
protected MessageConverter messageConverter;
|
||||||
|
|
||||||
protected RabbitTemplate spInternalConnectorTemplate;
|
protected RabbitTemplate internalAmqpTemplate;
|
||||||
|
|
||||||
public BaseAmqpService(final MessageConverter messageConverter, final RabbitTemplate defaultTemplate) {
|
public BaseAmqpService(final MessageConverter messageConverter, final RabbitTemplate defaultTemplate) {
|
||||||
this.messageConverter = messageConverter;
|
this.messageConverter = messageConverter;
|
||||||
spInternalConnectorTemplate = defaultTemplate;
|
internalAmqpTemplate = defaultTemplate;
|
||||||
}
|
|
||||||
|
|
||||||
protected String getVirtualHost(final Message message) {
|
|
||||||
final Object virtualHost = message.getMessageProperties().getHeaders().get(VIRTUAL_HOST_MESSAGE_HEADER);
|
|
||||||
|
|
||||||
if (virtualHost == null) {
|
|
||||||
return spInternalConnectorTemplate.getConnectionFactory().getVirtualHost();
|
|
||||||
}
|
|
||||||
return virtualHost.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void cleanMessage(final Message message) {
|
protected void cleanMessage(final Message message) {
|
||||||
message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME);
|
message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME);
|
||||||
message.getMessageProperties().getHeaders().remove(VIRTUAL_HOST_MESSAGE_HEADER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,10 +52,6 @@ public class BaseAmqpService {
|
|||||||
return (T) messageConverter.fromMessage(message);
|
return (T) messageConverter.fromMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getExchangeFromAmqpUri(final URI amqpUri) {
|
|
||||||
return amqpUri.getPath().substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getStringHeaderKey(final Message message, final String key, final String errorMessageIfNull) {
|
protected String getStringHeaderKey(final Message message, final String key, final String errorMessageIfNull) {
|
||||||
final Map<String, Object> header = message.getMessageProperties().getHeaders();
|
final Map<String, Object> header = message.getMessageProperties().getHeaders();
|
||||||
final Object value = header.get(key);
|
final Object value = header.get(key);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.amqp;
|
package org.eclipse.hawkbit.amqp;
|
||||||
|
|
||||||
@@ -9,21 +14,27 @@ import org.springframework.amqp.core.Message;
|
|||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* A default implementation for the sender service. The service sends all amqp
|
||||||
|
* message to the configured spring rabbitmq connections. The exchange is
|
||||||
|
* extracted from the uri.
|
||||||
*/
|
*/
|
||||||
public class DefaultAmqpSenderService extends BaseAmqpService implements AmqpSenderService {
|
public class DefaultAmqpSenderService implements AmqpSenderService {
|
||||||
|
|
||||||
|
private final RabbitTemplate internalAmqpTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param messageConverter
|
* Constructor.
|
||||||
* @param defaultTemplate
|
*
|
||||||
|
* @param internalAmqpTemplate
|
||||||
|
* the amqp template
|
||||||
*/
|
*/
|
||||||
public DefaultAmqpSenderService(final RabbitTemplate defaultTemplate) {
|
public DefaultAmqpSenderService(final RabbitTemplate internalAmqpTemplate) {
|
||||||
super(defaultTemplate.getMessageConverter(), defaultTemplate);
|
this.internalAmqpTemplate = internalAmqpTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(final Message message, final URI uri) {
|
public void sendMessage(final Message message, final URI uri) {
|
||||||
spInternalConnectorTemplate.send(getExchangeFromAmqpUri(uri), message);
|
internalAmqpTemplate.send(extractExchange(uri), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.amqp.AmqpSenderService;
|
||||||
|
import org.eclipse.hawkbit.amqp.DefaultAmqpSenderService;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||||
|
import org.springframework.amqp.support.converter.MessageConverter;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class AmqpTestConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to set the Jackson2JsonMessageConverter.
|
||||||
|
*
|
||||||
|
* @return the Jackson2JsonMessageConverter
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MessageConverter jsonMessageConverter() {
|
||||||
|
return new Jackson2JsonMessageConverter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create default amqp sender service bean.
|
||||||
|
*
|
||||||
|
* @param rabbitTemplate
|
||||||
|
*
|
||||||
|
* @return the default amqp sender service bean
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@Autowired
|
||||||
|
public AmqpSenderService amqpSenderServiceBean(final RabbitTemplate rabbitTemplate) {
|
||||||
|
return new DefaultAmqpSenderService(rabbitTemplate);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -125,7 +125,7 @@ public class AmqpControllerAuthentficationTest {
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
||||||
TENANT);
|
TENANT, "vHost");
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||||
@@ -147,7 +147,7 @@ public class AmqpControllerAuthentficationTest {
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
||||||
TENANT);
|
TENANT, "vHost");
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||||
@@ -169,7 +169,7 @@ public class AmqpControllerAuthentficationTest {
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
||||||
TENANT);
|
TENANT, "vHost");
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyObject;
|
import static org.mockito.Matchers.anyObject;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -44,7 +46,6 @@ import org.springframework.amqp.core.MessageProperties;
|
|||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
|
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
|
||||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||||
import org.springframework.amqp.support.converter.MessageConverter;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
|
||||||
import ru.yandex.qatools.allure.annotations.Description;
|
import ru.yandex.qatools.allure.annotations.Description;
|
||||||
@@ -58,30 +59,29 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
|||||||
|
|
||||||
private AmqpMessageDispatcherService amqpMessageDispatcherService;
|
private AmqpMessageDispatcherService amqpMessageDispatcherService;
|
||||||
|
|
||||||
private AmqpSenderService senderService;
|
|
||||||
|
|
||||||
private MessageConverter messageConverter;
|
|
||||||
|
|
||||||
private RabbitTemplate rabbitTemplate;
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
private DefaultAmqpSenderService senderService;
|
||||||
|
|
||||||
private static final String CONTROLLER_ID = "1";
|
private static final String CONTROLLER_ID = "1";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void before() throws Exception {
|
public void before() throws Exception {
|
||||||
super.before();
|
super.before();
|
||||||
amqpMessageDispatcherService = new AmqpMessageDispatcherService(messageConverter, rabbitTemplate);
|
this.rabbitTemplate = Mockito.mock(RabbitTemplate.class);
|
||||||
|
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
||||||
|
amqpMessageDispatcherService = new AmqpMessageDispatcherService(new Jackson2JsonMessageConverter(),
|
||||||
|
rabbitTemplate);
|
||||||
amqpMessageDispatcherService = spy(amqpMessageDispatcherService);
|
amqpMessageDispatcherService = spy(amqpMessageDispatcherService);
|
||||||
messageConverter = new Jackson2JsonMessageConverter();
|
|
||||||
|
senderService = Mockito.mock(DefaultAmqpSenderService.class);
|
||||||
|
amqpMessageDispatcherService.setAmqpSenderService(senderService);
|
||||||
|
|
||||||
final ArtifactUrlHandler artifactUrlHandlerMock = Mockito.mock(ArtifactUrlHandler.class);
|
final ArtifactUrlHandler artifactUrlHandlerMock = Mockito.mock(ArtifactUrlHandler.class);
|
||||||
when(artifactUrlHandlerMock.getUrl(anyString(), any(), anyObject())).thenReturn("http://mockurl");
|
when(artifactUrlHandlerMock.getUrl(anyString(), any(), anyObject())).thenReturn("http://mockurl");
|
||||||
|
|
||||||
this.rabbitTemplate = Mockito.mock(RabbitTemplate.class);
|
|
||||||
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
|
|
||||||
|
|
||||||
amqpMessageDispatcherService.setArtifactUrlHandler(artifactUrlHandlerMock);
|
amqpMessageDispatcherService.setArtifactUrlHandler(artifactUrlHandlerMock);
|
||||||
|
|
||||||
senderService = new DefaultAmqpSenderService(rabbitTemplate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -91,7 +91,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
|||||||
1L, "default", CONTROLLER_ID, 1l, new ArrayList<SoftwareModule>(),
|
1L, "default", CONTROLLER_ID, 1l, new ArrayList<SoftwareModule>(),
|
||||||
IpUtil.createAmqpUri("vHost", "mytest"));
|
IpUtil.createAmqpUri("vHost", "mytest"));
|
||||||
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
||||||
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress().getHost());
|
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress());
|
||||||
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
||||||
assertTrue(downloadAndUpdateRequest.getSoftwareModules().isEmpty());
|
assertTrue(downloadAndUpdateRequest.getSoftwareModules().isEmpty());
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
|||||||
final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent(
|
final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent(
|
||||||
1L, "default", CONTROLLER_ID, 1l, dsA.getModules(), IpUtil.createAmqpUri("vHost", "mytest"));
|
1L, "default", CONTROLLER_ID, 1l, dsA.getModules(), IpUtil.createAmqpUri("vHost", "mytest"));
|
||||||
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
||||||
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress().getHost());
|
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress());
|
||||||
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
||||||
assertEquals(3, downloadAndUpdateRequest.getSoftwareModules().size());
|
assertEquals(3, downloadAndUpdateRequest.getSoftwareModules().size());
|
||||||
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest
|
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest
|
||||||
@@ -138,7 +138,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
|||||||
final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent(
|
final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent(
|
||||||
1L, "default", CONTROLLER_ID, 1l, dsA.getModules(), IpUtil.createAmqpUri("vHost", "mytest"));
|
1L, "default", CONTROLLER_ID, 1l, dsA.getModules(), IpUtil.createAmqpUri("vHost", "mytest"));
|
||||||
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent);
|
||||||
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress().getHost());
|
final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress());
|
||||||
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage);
|
||||||
assertEquals(3, downloadAndUpdateRequest.getSoftwareModules().size());
|
assertEquals(3, downloadAndUpdateRequest.getSoftwareModules().size());
|
||||||
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest
|
for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest
|
||||||
@@ -157,8 +157,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
|||||||
1L, "default", CONTROLLER_ID, 1l, IpUtil.createAmqpUri("vHost", "mytest"));
|
1L, "default", CONTROLLER_ID, 1l, IpUtil.createAmqpUri("vHost", "mytest"));
|
||||||
amqpMessageDispatcherService
|
amqpMessageDispatcherService
|
||||||
.targetCancelAssignmentToDistributionSet(cancelTargetAssignmentDistributionSetEvent);
|
.targetCancelAssignmentToDistributionSet(cancelTargetAssignmentDistributionSetEvent);
|
||||||
final Message sendMessage = createArgumentCapture(
|
final Message sendMessage = createArgumentCapture(cancelTargetAssignmentDistributionSetEvent.getTargetAdress());
|
||||||
cancelTargetAssignmentDistributionSetEvent.getTargetAdress().getHost());
|
|
||||||
assertCancelMessage(sendMessage);
|
assertCancelMessage(sendMessage);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -194,10 +193,9 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit
|
|||||||
assertEquals(MessageProperties.CONTENT_TYPE_JSON, sendMessage.getMessageProperties().getContentType());
|
assertEquals(MessageProperties.CONTENT_TYPE_JSON, sendMessage.getMessageProperties().getContentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Message createArgumentCapture(final String exchange) {
|
protected Message createArgumentCapture(final URI uri) {
|
||||||
final ArgumentCaptor<Message> argumentCaptor = ArgumentCaptor.forClass(Message.class);
|
final ArgumentCaptor<Message> argumentCaptor = ArgumentCaptor.forClass(Message.class);
|
||||||
// Mockito.verify(senderService).sendMessage(argumentCaptor.capture(),
|
Mockito.verify(senderService).sendMessage(argumentCaptor.capture(), eq(uri));
|
||||||
// eq(exchange));
|
|
||||||
return argumentCaptor.getValue();
|
return argumentCaptor.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
final MessageProperties messageProperties = new MessageProperties();
|
final MessageProperties messageProperties = new MessageProperties();
|
||||||
messageProperties.setContentType("xml");
|
messageProperties.setContentType("xml");
|
||||||
final Message message = new Message(new byte[0], messageProperties);
|
final Message message = new Message(new byte[0], messageProperties);
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, "vHost");
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,11 +140,11 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
uriCaptor.capture())).thenReturn(null);
|
uriCaptor.capture())).thenReturn(null);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, "vHost");
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
assertThat(targetIdCaptor.getValue()).isEqualTo(knownThingId);
|
assertThat(targetIdCaptor.getValue()).isEqualTo(knownThingId);
|
||||||
assertThat(uriCaptor.getValue().toString()).isEqualTo("amqp://MyTest");
|
assertThat(uriCaptor.getValue().toString()).isEqualTo("amqp://vHost/MyTest");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
final Message message = messageConverter.toMessage("", messageProperties);
|
final Message message = messageConverter.toMessage("", messageProperties);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, "vHost");
|
||||||
fail("IllegalArgumentException was excepeted since no replyTo header was set");
|
fail("IllegalArgumentException was excepeted since no replyTo header was set");
|
||||||
} catch (final IllegalArgumentException exception) {
|
} catch (final IllegalArgumentException exception) {
|
||||||
// test ok - exception was excepted
|
// test ok - exception was excepted
|
||||||
@@ -170,7 +170,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED);
|
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED);
|
||||||
final Message message = messageConverter.toMessage(new byte[0], messageProperties);
|
final Message message = messageConverter.toMessage(new byte[0], messageProperties);
|
||||||
try {
|
try {
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, "vHost");
|
||||||
fail("IllegalArgumentException was excepeted since no thingID was set");
|
fail("IllegalArgumentException was excepeted since no thingID was set");
|
||||||
} catch (final IllegalArgumentException exception) {
|
} catch (final IllegalArgumentException exception) {
|
||||||
// test ok - exception was excepted
|
// test ok - exception was excepted
|
||||||
@@ -186,7 +186,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
final Message message = messageConverter.toMessage(new byte[0], messageProperties);
|
final Message message = messageConverter.toMessage(new byte[0], messageProperties);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
amqpMessageHandlerService.onMessage(message, type, TENANT);
|
amqpMessageHandlerService.onMessage(message, type, TENANT, "vHost");
|
||||||
fail("IllegalArgumentException was excepeted due to unknown message type");
|
fail("IllegalArgumentException was excepeted due to unknown message type");
|
||||||
} catch (final IllegalArgumentException exception) {
|
} catch (final IllegalArgumentException exception) {
|
||||||
// test ok - exception was excepted
|
// test ok - exception was excepted
|
||||||
@@ -199,21 +199,21 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
|
||||||
final Message message = new Message(new byte[0], messageProperties);
|
final Message message = new Message(new byte[0], messageProperties);
|
||||||
try {
|
try {
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
|
||||||
fail();
|
fail();
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, "wrongTopic");
|
messageProperties.setHeader(MessageHeaderKey.TOPIC, "wrongTopic");
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
|
||||||
fail();
|
fail();
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.CANCEL_DOWNLOAD.name());
|
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.CANCEL_DOWNLOAD.name());
|
||||||
try {
|
try {
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
|
||||||
fail("IllegalArgumentException was excepeted because there was no event topic");
|
fail("IllegalArgumentException was excepeted because there was no event topic");
|
||||||
} catch (final IllegalArgumentException exception) {
|
} catch (final IllegalArgumentException exception) {
|
||||||
// test ok - exception was excepted
|
// test ok - exception was excepted
|
||||||
@@ -232,7 +232,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
messageProperties);
|
messageProperties);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
|
||||||
fail("IllegalArgumentException was excepeted since no action id was set");
|
fail("IllegalArgumentException was excepeted since no action id was set");
|
||||||
} catch (final IllegalArgumentException exception) {
|
} catch (final IllegalArgumentException exception) {
|
||||||
// test ok - exception was excepted
|
// test ok - exception was excepted
|
||||||
@@ -249,7 +249,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
messageProperties);
|
messageProperties);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
|
||||||
fail("IllegalArgumentException was excepeted since no action id was set");
|
fail("IllegalArgumentException was excepeted since no action id was set");
|
||||||
} catch (final IllegalArgumentException exception) {
|
} catch (final IllegalArgumentException exception) {
|
||||||
// test ok - exception was excepted
|
// test ok - exception was excepted
|
||||||
@@ -267,7 +267,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
||||||
TENANT);
|
TENANT, "vHost");
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||||
@@ -290,7 +290,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
||||||
TENANT);
|
TENANT, "vHost");
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||||
@@ -321,7 +321,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
final Message onMessage = amqpMessageHandlerService.onMessage(message, MessageType.AUTHENTIFICATION.name(),
|
||||||
TENANT);
|
TENANT, "vHost");
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
final DownloadResponse downloadResponse = (DownloadResponse) messageConverter.fromMessage(onMessage);
|
||||||
@@ -355,7 +355,7 @@ public class AmqpMessageHandlerServiceTest {
|
|||||||
messageProperties);
|
messageProperties);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT);
|
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
|
||||||
|
|
||||||
// verify
|
// verify
|
||||||
final ArgumentCaptor<TargetAssignDistributionSetEvent> captorTargetAssignDistributionSetEvent = ArgumentCaptor
|
final ArgumentCaptor<TargetAssignDistributionSetEvent> captorTargetAssignDistributionSetEvent = ArgumentCaptor
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ package org.eclipse.hawkbit.util;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
|
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
|
||||||
|
import org.eclipse.hawkbit.AmqpTestConfiguration;
|
||||||
|
import org.eclipse.hawkbit.RepositoryApplicationConfiguration;
|
||||||
|
import org.eclipse.hawkbit.TestConfiguration;
|
||||||
import org.eclipse.hawkbit.TestDataUtil;
|
import org.eclipse.hawkbit.TestDataUtil;
|
||||||
import org.eclipse.hawkbit.dmf.json.model.Artifact;
|
import org.eclipse.hawkbit.dmf.json.model.Artifact;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||||
@@ -20,6 +23,7 @@ import org.eclipse.hawkbit.tenancy.TenantAware;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||||
|
|
||||||
import ru.yandex.qatools.allure.annotations.Description;
|
import ru.yandex.qatools.allure.annotations.Description;
|
||||||
import ru.yandex.qatools.allure.annotations.Features;
|
import ru.yandex.qatools.allure.annotations.Features;
|
||||||
@@ -31,6 +35,8 @@ import ru.yandex.qatools.allure.annotations.Stories;
|
|||||||
*/
|
*/
|
||||||
@Features("Component Tests - Artifact URL Handler")
|
@Features("Component Tests - Artifact URL Handler")
|
||||||
@Stories("Test to generate the artifact download URL")
|
@Stories("Test to generate the artifact download URL")
|
||||||
|
@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class,
|
||||||
|
AmqpTestConfiguration.class })
|
||||||
public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTestWithMongoDB {
|
public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTestWithMongoDB {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import java.util.concurrent.Callable;
|
|||||||
|
|
||||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware.TenantRunner;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -30,7 +29,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Michael Hirsch
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@@ -45,15 +43,12 @@ public class SystemSecurityContext {
|
|||||||
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
final SecurityContext oldContext = SecurityContextHolder.getContext();
|
||||||
try {
|
try {
|
||||||
logger.debug("entering system code execution");
|
logger.debug("entering system code execution");
|
||||||
return tenantAware.runAsTenant(tenantAware.getCurrentTenant(), new TenantRunner<T>() {
|
return tenantAware.runAsTenant(tenantAware.getCurrentTenant(), () -> {
|
||||||
@Override
|
try {
|
||||||
public T run() {
|
setSystemContext();
|
||||||
try {
|
return callable.call();
|
||||||
setSystemContext();
|
} catch (final Exception e) {
|
||||||
return callable.call();
|
throw Throwables.propagate(e);
|
||||||
} catch (final Exception e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -106,7 +101,8 @@ public class SystemSecurityContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAuthenticated(final boolean isAuthenticated) throws IllegalArgumentException {
|
public void setAuthenticated(final boolean isAuthenticated) {
|
||||||
|
// not needed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ import com.google.common.net.HttpHeaders;
|
|||||||
* A utility which determines the correct IP of a connected {@link Target}. E.g
|
* A utility which determines the correct IP of a connected {@link Target}. E.g
|
||||||
* from a {@link HttpServletRequest}.
|
* from a {@link HttpServletRequest}.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class IpUtil {
|
public final class IpUtil {
|
||||||
|
|
||||||
@@ -103,12 +100,14 @@ public final class IpUtil {
|
|||||||
*
|
*
|
||||||
* @param host
|
* @param host
|
||||||
* the host
|
* the host
|
||||||
|
* @param exchange
|
||||||
|
* the exchange will store in the path
|
||||||
* @return the {@link URI}
|
* @return the {@link URI}
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
* If the given string not parsable
|
* If the given string not parsable
|
||||||
*/
|
*/
|
||||||
public static URI createAmqpUri(final String virtualHost, final String exchange) {
|
public static URI createAmqpUri(final String host, final String exchange) {
|
||||||
return createUri(AMPQP_SCHEME, virtualHost).resolve("/" + exchange);
|
return createUri(AMPQP_SCHEME, host).resolve("/" + exchange);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user