|
1 | 1 | package org.influxdb.dto;
|
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat;
|
| 4 | +import static org.mockito.Mockito.mock; |
4 | 5 |
|
5 | 6 | import java.lang.reflect.Field;
|
6 | 7 | import java.math.BigDecimal;
|
|
15 | 16 | import java.util.concurrent.atomic.AtomicLong;
|
16 | 17 |
|
17 | 18 | import org.influxdb.BuilderException;
|
| 19 | +import org.influxdb.InfluxDB; |
18 | 20 | import org.influxdb.annotation.Column;
|
19 | 21 | import org.influxdb.annotation.Measurement;
|
20 | 22 | import org.influxdb.annotation.TimeColumn;
|
| 23 | +import org.influxdb.impl.InfluxDBImpl; |
21 | 24 | import org.junit.Assert;
|
22 | 25 | import org.junit.jupiter.api.Assertions;
|
23 | 26 | import org.junit.jupiter.api.Test;
|
24 | 27 | import org.junit.platform.runner.JUnitPlatform;
|
25 | 28 | import org.junit.runner.RunWith;
|
| 29 | +import org.mockito.Mockito; |
26 | 30 |
|
27 | 31 | /**
|
28 | 32 | * Test for the Point DTO.
|
@@ -615,6 +619,32 @@ public void testAddFieldsFromPOJOWithData() throws NoSuchFieldException, Illegal
|
615 | 619 | Assertions.assertEquals(pojo.uuid, p.getTags().get("uuid"));
|
616 | 620 | }
|
617 | 621 |
|
| 622 | + @Test |
| 623 | + public void testAddFieldsFromPOJOConsistentWithAddField() { |
| 624 | + PojoNumberPrimitiveTypes pojo = new PojoNumberPrimitiveTypes(); |
| 625 | + pojo.shortType = 128; |
| 626 | + pojo.intType = 1_048_576; |
| 627 | + pojo.longType = 1_073_741_824; |
| 628 | + pojo.floatType = 246.8f; |
| 629 | + pojo.doubleType = 123.4; |
| 630 | + |
| 631 | + Point pojo_point = Point.measurementByPOJO(pojo.getClass()).addFieldsFromPOJO(pojo).build(); |
| 632 | + |
| 633 | + InfluxDB mockInfluxDB = mock(InfluxDBImpl.class); |
| 634 | + mockInfluxDB.write(pojo_point); |
| 635 | + |
| 636 | + Point expected = Point.measurement("PojoNumberPrimitiveTypes") |
| 637 | + .addField("shortType", pojo.shortType) |
| 638 | + .addField("intType", pojo.intType) |
| 639 | + .addField("longType", pojo.longType) |
| 640 | + .addField("floatType", pojo.floatType) |
| 641 | + .addField("doubleType", pojo.doubleType) |
| 642 | + .build(); |
| 643 | + |
| 644 | + Assert.assertEquals(pojo_point.lineProtocol(), expected.lineProtocol()); |
| 645 | + Mockito.verify(mockInfluxDB).write(expected); |
| 646 | + } |
| 647 | + |
618 | 648 | @Test
|
619 | 649 | public void testAddFieldsFromPOJOWithPublicAttributes() {
|
620 | 650 |
|
@@ -858,4 +888,23 @@ static class SubClassMeasurement extends SuperMeasurement {
|
858 | 888 | @Column(name = "subClassField")
|
859 | 889 | String subValue;
|
860 | 890 | }
|
| 891 | + |
| 892 | + @Measurement(name = "PojoNumberPrimitiveTypes") |
| 893 | + static class PojoNumberPrimitiveTypes |
| 894 | + { |
| 895 | + @Column(name = "shortType") |
| 896 | + public short shortType; |
| 897 | + |
| 898 | + @Column(name = "intType") |
| 899 | + public int intType; |
| 900 | + |
| 901 | + @Column(name = "longType") |
| 902 | + public long longType; |
| 903 | + |
| 904 | + @Column(name = "floatType") |
| 905 | + public float floatType; |
| 906 | + |
| 907 | + @Column(name = "doubleType") |
| 908 | + public double doubleType; |
| 909 | + } |
861 | 910 | }
|
0 commit comments