Skip to content

Commit

Permalink
sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
loicgreffier committed Jul 29, 2024
1 parent 24488bc commit d631258
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.testcontainers.junit.jupiter.Testcontainers;

@Slf4j
Expand Down Expand Up @@ -149,17 +151,22 @@ void shouldGetStoresAndStoreMetadata() throws IOException, InterruptedException
"INPUT_TOPIC-1"), streamsMetadata.get(0).getTopicPartitions());
}

@Test
void shouldGetByKeyWrongStore() throws IOException, InterruptedException {
@ParameterizedTest
@CsvSource({
"http://localhost:8081/store/key-value/WRONG_STORE/person,State store WRONG_STORE not found",
"http://localhost:8081/store/key-value/STRING_STRING_STORE/wrongKey,Key wrongKey not found",
"http://localhost:8081/store/key-value/WRONG_STORE,State store WRONG_STORE not found",
})
void shouldGetErrorWhenWrongKeyOrStore(String url, String message) throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:8081/store/key-value/WRONG_STORE/person"))
.uri(URI.create(url))
.GET()
.build();

HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

assertEquals(404, response.statusCode());
assertEquals("State store WRONG_STORE not found", response.body());
assertEquals(message, response.body());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.serialization.Serializer;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.KeyQueryMetadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.michelin.kstreamplify.controller;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -80,7 +77,7 @@ void shouldGetAll() {

@Test
void shouldGetByKey() {
when(interactiveQueriesService.getByKey(eq("store"), eq("key")))
when(interactiveQueriesService.getByKey("store", "key"))
.thenReturn(new StateStoreRecord("key1", "value1", 1L));

StateStoreRecord response = interactiveQueriesController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down Expand Up @@ -140,22 +142,18 @@ void shouldGetStoresAndHosts() {
"INPUT_TOPIC-1"), streamsMetadata.getBody().get(0).getTopicPartitions());
}

@Test
void shouldGetByKeyWrongStore() {
ResponseEntity<String> response = restTemplate
.getForEntity("http://localhost:8085/store/key-value/WRONG_STORE/person", String.class);

assertEquals(404, response.getStatusCode().value());
assertEquals("State store WRONG_STORE not found", response.getBody());
}

@Test
void shouldGetByKeyWrongKey() {
@ParameterizedTest
@CsvSource({
"http://localhost:8085/store/key-value/WRONG_STORE/person,State store WRONG_STORE not found",
"http://localhost:8085/store/key-value/STRING_STRING_STORE/wrongKey,Key wrongKey not found",
"http://localhost:8085/store/key-value/WRONG_STORE,State store WRONG_STORE not found",
})
void shouldGetErrorWhenWrongKeyOrStore(String url, String message) {
ResponseEntity<String> response = restTemplate
.getForEntity("http://localhost:8085/store/key-value/STRING_STRING_STORE/wrongKey", String.class);
.getForEntity(url, String.class);

assertEquals(404, response.getStatusCode().value());
assertEquals("Key wrongKey not found", response.getBody());
assertEquals(message, response.getBody());
}

@Test
Expand Down Expand Up @@ -224,15 +222,6 @@ void shouldGetByKeyInStringAvroTimestampedKeyValueStore() {
assertNotNull(response.getBody().getTimestamp());
}

@Test
void shouldGetAllWrongStore() {
ResponseEntity<String> response = restTemplate
.getForEntity("http://localhost:8085/store/key-value/WRONG_STORE", String.class);

assertEquals(404, response.getStatusCode().value());
assertEquals("State store WRONG_STORE not found", response.getBody());
}

@Test
void shouldGetAllInStringStringKeyValueStore() {
ResponseEntity<List<StateStoreRecord>> response = restTemplate
Expand Down

0 comments on commit d631258

Please sign in to comment.