Skip to content

Commit

Permalink
merged pull request #83 adding set to addTags call
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhks committed Mar 22, 2024
1 parent 81735c6 commit d60a385
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
<version>1.3.0-1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit</artifactId>
<version>2.38.0</version>
<scope>test</scope>
</dependency>


<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package org.kairosdb.client.builder;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;

import java.io.IOException;
import java.util.Date;

import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
import static net.javacrumbs.jsonunit.JsonAssert.when;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

Expand Down Expand Up @@ -125,9 +131,32 @@ public void test() throws IOException
.setStart(1, TimeUnit.HOURS);
builder.addMetric("metricName")
.addTag("foo", "bar")
.addTag("fi", "fum");
.addTag("fi", Collections.singleton("fum"));

assertThat(builder.build(), equalTo("{\"metrics\":[{\"name\":\"metricName\",\"tags\":{\"fi\":[\"fum\"],\"foo\":[\"bar\"]}}],\"start_relative\":{\"value\":1,\"unit\":\"HOURS\"}}"));
}

@Test
public void testMultipleTags() throws IOException
{
QueryTagBuilder builder = QueryTagBuilder.getInstance()
.setStart(1, TimeUnit.HOURS);
Set<String> tags = new HashSet<>();
Set<String> tags1 = new HashSet<>();
tags.add("bar");
tags.add("Bar");
tags.add("bars");

tags1.add("fum");
tags1.add("Fum");
tags1.add("fums");

builder.addMetric("metricName")
.addTag("foo",tags)
.addTag("fi",tags1);
assertJsonEquals(
builder.build(),
"{\"metrics\":[{\"name\":\"metricName\",\"tags\":{\"foo\":[\"bar\",\"Bar\",\"bars\"],\"fi\":[\"fum\",\"Fum\",\"fums\"]}}],\"start_relative\":{\"value\":1,\"unit\":\"HOURS\"}}",
when(IGNORING_ARRAY_ORDER));
}
}

0 comments on commit d60a385

Please sign in to comment.