Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenischev committed Dec 11, 2023
1 parent 554dcee commit 5c0508b
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 46 deletions.
29 changes: 17 additions & 12 deletions tests/__snapshots__/kafka.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,28 @@ exports[`template integration tests for generated files using the generator and
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import com.asyncapi.model.LightMeasuredPayload;
import com.asyncapi.model.LightMeasuredPayload;
import javax.annotation.processing.Generated;
import java.util.ArrayList;
import java.util.List;
@Generated(value="com.asyncapi.generator.template.spring", date="AnyDate")
@Service
public class MessageHandlerService {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageHandlerService.class);
@KafkaListener(topics = "event.lighting.measured", groupId = "my-group")
public void readLightMeasurement(@Payload LightMeasuredPayload payload,
Expand All @@ -150,7 +152,7 @@ public class MessageHandlerService {
}
}
"
`;
Expand Down Expand Up @@ -644,26 +646,28 @@ exports[`template integration tests for generated files using the generator and
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import com.asyncapi.model.LightMeasuredPayload;
import com.asyncapi.model.LightMeasuredPayload;
import javax.annotation.processing.Generated;
import java.util.ArrayList;
import java.util.List;
@Generated(value="com.asyncapi.generator.template.spring", date="AnyDate")
@Service
public class MessageHandlerService {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageHandlerService.class);
@KafkaListener(topicPattern = "event\.lighting\..*\.measured\..*", groupId = "my-group")
public void readLightMeasurement(@Payload LightMeasuredPayload payload,
Expand All @@ -674,7 +678,8 @@ public class MessageHandlerService {
}
}
"
`;
118 changes: 96 additions & 22 deletions tests/__snapshots__/mqtt.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -202,36 +202,73 @@ exports[`template integration tests for generated files using the generator and
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
import org.springframework.integration.mqtt.support.MqttHeaders;
import com.asyncapi.model.LightMeasuredPayload;
import javax.annotation.processing.Generated;
import java.util.ArrayList;
import java.util.List;
@Generated(value="com.asyncapi.generator.template.spring", date="AnyDate")
@Service
public class MessageHandlerService {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageHandlerService.class);
@Value("\${mqtt.topic.receiveLightMeasurement}")
private String receiveLightMeasurementTopic;
/**
* The topic on which measured values may be produced and consumed.
*/
* The topic on which measured values may be produced and consumed.
*/
public void handleReceiveLightMeasurement(Message<?> message) {
String topic = message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC).toString();
List<String> parameters = decodeTopic(receiveLightMeasurementTopic, topic);
receiveLightMeasurement(parameters.get(0), (LightMeasuredPayload) message.getPayload());
}
/**
* The topic on which measured values may be produced and consumed.
*/
public void receiveLightMeasurement(String streetlightId, LightMeasuredPayload payload) {
LOGGER.info("handler smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured");
LOGGER.info(String.valueOf(message.getPayload().toString()));
LOGGER.info(String.valueOf(payload.toString()));
}
private List<String> decodeTopic(String topicPattern, String topic) {
List<String> parameters = new ArrayList<>();
int topicPossition = 0;
int patternPosition = 0;
while (topicPossition < topic.length()) {
while (topicPattern.charAt(patternPosition) == topic.charAt(topicPossition)) {
topicPossition++;
patternPosition++;
}
topicPossition++;
patternPosition += 2; // skip +
StringBuilder parameter = new StringBuilder();
while (topicPattern.charAt(patternPosition) != topic.charAt(topicPossition)) {
parameter.append(topic.charAt(topicPossition));
topicPossition++;
}
parameters.add(parameter.toString());
}
return parameters;
}
}
"
`;
Expand Down Expand Up @@ -1182,32 +1219,69 @@ exports[`template integration tests for generated files using the generator and
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
import org.springframework.integration.mqtt.support.MqttHeaders;
import com.asyncapi.model.LightMeasuredPayload;
import javax.annotation.processing.Generated;
import java.util.ArrayList;
import java.util.List;
@Generated(value="com.asyncapi.generator.template.spring", date="AnyDate")
@Service
public class MessageHandlerService {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageHandlerService.class);
@Value("\${mqtt.topic.receiveLightMeasurement}")
private String receiveLightMeasurementTopic;
/**
* The topic on which measured values may be produced and consumed.
*/
* The topic on which measured values may be produced and consumed.
*/
public void handleReceiveLightMeasurement(Message<?> message) {
String topic = message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC).toString();
List<String> parameters = decodeTopic(receiveLightMeasurementTopic, topic);
receiveLightMeasurement(parameters.get(0), (LightMeasuredPayload) message.getPayload());
}
/**
* The topic on which measured values may be produced and consumed.
*/
public void receiveLightMeasurement(String streetlightId, LightMeasuredPayload payload) {
LOGGER.info("handler smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured");
LOGGER.info(String.valueOf(message.getPayload().toString()));
LOGGER.info(String.valueOf(payload.toString()));
}
private List<String> decodeTopic(String topicPattern, String topic) {
List<String> parameters = new ArrayList<>();
int topicPossition = 0;
int patternPosition = 0;
while (topicPossition < topic.length()) {
while (topicPattern.charAt(patternPosition) == topic.charAt(topicPossition)) {
topicPossition++;
patternPosition++;
}
topicPossition++;
patternPosition += 2; // skip +
StringBuilder parameter = new StringBuilder();
while (topicPattern.charAt(patternPosition) != topic.charAt(topicPossition)) {
parameter.append(topic.charAt(topicPossition));
topicPossition++;
}
parameters.add(parameter.toString());
}
return parameters;
}
}
"
`;
Expand Down
14 changes: 8 additions & 6 deletions tests/__snapshots__/oneOf.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@ exports[`template integration tests for generated files using the generator and
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import com.asyncapi.model.AnonymousSchema1;
import com.asyncapi.model.AnonymousSchema7;
import javax.annotation.processing.Generated;
import java.util.ArrayList;
import java.util.List;
@Generated(value="com.asyncapi.generator.template.spring", date="AnyDate")
@Service
public class MessageHandlerService {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageHandlerService.class);
@KafkaListener(topics = "song.released")
public void release(@Payload Object payload,
Expand All @@ -36,7 +38,7 @@ public class MessageHandlerService {
}
}
"
`;
Expand Down
14 changes: 8 additions & 6 deletions tests/__snapshots__/parameters.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -139,26 +139,28 @@ exports[`integration tests for generated files under different template paramete
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import com.asyncapi.model.LightMeasuredPayload;
import com.asyncapi.model.LightMeasuredPayload;
import javax.annotation.processing.Generated;
import java.util.ArrayList;
import java.util.List;
@Generated(value="com.asyncapi.generator.template.spring", date="AnyDate")
@Service
public class MessageHandlerService {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageHandlerService.class);
@KafkaListener(topics = "event.lighting.measured", groupId = "my-group")
public void readLightMeasurement(@Payload LightMeasuredPayload payload,
Expand All @@ -169,7 +171,7 @@ public class MessageHandlerService {
}
}
"
`;
Expand Down

0 comments on commit 5c0508b

Please sign in to comment.