Skip to content

Commit

Permalink
test: PointValuesTest, lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciator committed Nov 20, 2023
1 parent 224b3ce commit 21fdb75
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 20 deletions.
61 changes: 41 additions & 20 deletions src/test/java/com/influxdb/v3/client/PointTest.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.influxdb.v3.client;

import com.influxdb.v3.client.write.WritePrecision;
import org.junit.jupiter.api.Test;

import java.math.BigInteger;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import com.influxdb.v3.client.write.WritePrecision;

public class PointTest
{
public class PointTest {
@Test
void setMeasurement() {
Point point = Point.measurement("measurement");
assertEquals("measurement", point.getMeasurement());
Assertions.assertThat("measurement").isEqualTo(point.getMeasurement());

point.setMeasurement("newMeasurement");
assertEquals("newMeasurement", point.getMeasurement());
Assertions.assertThat("newMeasurement").isEqualTo(point.getMeasurement());
}

@Test
Expand All @@ -27,8 +47,9 @@ void setTimestamp() {

Instant timestamp = Instant.parse("2023-11-08T12:00:00Z");
point.setTimestamp(timestamp);
assertEquals(BigInteger.valueOf(timestamp.getEpochSecond()).multiply(BigInteger.valueOf(1_000_000_000))
, point.getTimestamp());
Assertions.assertThat(BigInteger.valueOf(timestamp.getEpochSecond())
.multiply(BigInteger.valueOf(1_000_000_000)))
.isEqualTo(point.getTimestamp());
}

@Test
Expand All @@ -41,8 +62,8 @@ void setTags() {

point.setTags(tags);

assertEquals("value1", point.getTag("tag1"));
assertEquals("value2", point.getTag("tag2"));
Assertions.assertThat("value1").isEqualTo(point.getTag("tag1"));
Assertions.assertThat("value2").isEqualTo(point.getTag("tag2"));
}

@Test
Expand All @@ -53,9 +74,9 @@ void setFields() {
point.setField("field2", "value");
point.setField("field3", 3.14);

assertEquals(42L, point.getField("field1"));
assertEquals("value", point.getField("field2"));
assertEquals(3.14, point.getField("field3"));
Assertions.assertThat(42L).isEqualTo(point.getField("field1"));
Assertions.assertThat("value").isEqualTo(point.getField("field2"));
Assertions.assertThat(3.14).isEqualTo(point.getField("field3"));
}

@Test
Expand All @@ -65,7 +86,7 @@ void toLineProtocol() {
.setField("field1", 42);

String lineProtocol = point.toLineProtocol(WritePrecision.NS);
assertEquals("measurement,tag1=value1 field1=42i", lineProtocol);
Assertions.assertThat("measurement,tag1=value1 field1=42i").isEqualTo(lineProtocol);
}

@Test
Expand All @@ -77,10 +98,10 @@ void copy() {
Point copy = point.copy();

// Ensure the copy is not the same object
assertNotSame(point, copy);
Assertions.assertThat(point).isNotSameAs(copy);
// Ensure the values are equal
assertEquals(point.getMeasurement(), copy.getMeasurement());
assertEquals(point.getTag("tag1"), copy.getTag("tag1"));
assertEquals(point.getField("field1"), copy.getField("field1"));
Assertions.assertThat(point.getMeasurement()).isEqualTo(copy.getMeasurement());
Assertions.assertThat(point.getTag("tag1")).isEqualTo(copy.getTag("tag1"));
Assertions.assertThat(point.getField("field1")).isEqualTo(copy.getField("field1"));
}
}
95 changes: 95 additions & 0 deletions src/test/java/com/influxdb/v3/client/PointValuesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.influxdb.v3.client;

import java.math.BigInteger;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class PointValuesTest {
@Test
void setMeasurement() {
PointValues pointValues = PointValues.measurement("measurement");
Assertions.assertThat("measurement").isEqualTo(pointValues.getMeasurement());

pointValues.setMeasurement("newMeasurement");
Assertions.assertThat("newMeasurement").isEqualTo(pointValues.getMeasurement());
}

@Test
void setTimestamp() {
PointValues pointValues = PointValues.measurement("measurement");

Instant timestamp = Instant.parse("2023-11-08T12:00:00Z");
pointValues.setTimestamp(timestamp);
Assertions.assertThat(BigInteger.valueOf(timestamp.getEpochSecond())
.multiply(BigInteger.valueOf(1_000_000_000)))
.isEqualTo(pointValues.getTimestamp());
}

@Test
void setTags() {
PointValues pointValues = PointValues.measurement("measurement");

Map<String, String> tags = new HashMap<>();
tags.put("tag1", "value1");
tags.put("tag2", "value2");

pointValues.setTags(tags);

Assertions.assertThat("value1").isEqualTo(pointValues.getTag("tag1"));
Assertions.assertThat("value2").isEqualTo(pointValues.getTag("tag2"));
}

@Test
void setFields() {
PointValues pointValues = PointValues.measurement("measurement");

pointValues.setField("field1", 42);
pointValues.setField("field2", "value");
pointValues.setField("field3", 3.14);

Assertions.assertThat(42L).isEqualTo(pointValues.getField("field1"));
Assertions.assertThat("value").isEqualTo(pointValues.getField("field2"));
Assertions.assertThat(3.14).isEqualTo(pointValues.getField("field3"));
}

@Test
void copy() {
PointValues pointValues = PointValues.measurement("measurement")
.setTag("tag1", "value1")
.setField("field1", 42);

PointValues copy = pointValues.copy();

// Ensure the copy is not the same object
Assertions.assertThat(pointValues).isNotSameAs(copy);
// Ensure the values are equal
Assertions.assertThat(pointValues.getMeasurement()).isEqualTo(copy.getMeasurement());
Assertions.assertThat(pointValues.getTag("tag1")).isEqualTo(copy.getTag("tag1"));
Assertions.assertThat(pointValues.getField("field1")).isEqualTo(copy.getField("field1"));
}
}

0 comments on commit 21fdb75

Please sign in to comment.