Commit 7d7c19d6 authored by Komal Makkar's avatar Komal Makkar
Browse files

UTs and clean up

parent b26bde71
Pipeline #30629 failed with stages
in 2 minutes and 9 seconds
......@@ -26,7 +26,6 @@ import org.opengroup.osdu.register.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.register.provider.azure.di.CosmosContainerConfig;
import org.opengroup.osdu.register.provider.azure.util.CryptographyUtil;
import org.opengroup.osdu.register.provider.azure.util.PartitionHelper;
import org.opengroup.osdu.register.provider.azure.util.TopicsHelper;
import org.opengroup.osdu.register.provider.interfaces.subscriber.ISubscriptionRepository;
import org.opengroup.osdu.register.subscriber.model.GsaSecret;
import org.opengroup.osdu.register.subscriber.model.GsaSecretValue;
......
......@@ -5,14 +5,12 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.notification.Topic;
import org.opengroup.osdu.register.provider.azure.util.PartitionHelper;
import org.opengroup.osdu.register.provider.azure.util.TopicsHelper;
import org.opengroup.osdu.register.provider.interfaces.subscriber.ITopicsRepository;
import org.opengroup.osdu.register.utils.FileUtil;
import org.springframework.context.annotation.Primary;
......@@ -56,7 +54,7 @@ public class TopicsRepositoryImpl implements ITopicsRepository {
return fullyQualifiedNameToAliasMap.get(fullyQualifiedTopicName);
}
private List<Topic> getTopicTemplate() {
List<Topic> getTopicTemplate() {
Type type = new TypeToken<ArrayList<Topic>>() {
}.getType();
return new Gson().fromJson(FileUtil.readFile("topics.json", log), type);
......
package org.opengroup.osdu.register.provider.azure.util;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
@RequiredArgsConstructor
public class TopicsHelper {
private final DpsHeaders headers;
private Map<String, String> topicNames = new HashMap<>();
public String nameResolver(String name) {
return topicNames.get(formatKey(name));
}
//TODO: it will be ideal to adds {prifix} as value to keyvault and
// use for extracting displayName instead of hardcoded '-grid-'
public String extractDisplayName(String topicName) {
// topicName = `{prefix}-grid-{displayName}`
String displayName = topicName.split("-grid-")[1];
topicNames.putIfAbsent(formatKey(displayName), topicName);
return displayName;
}
private String formatKey(String name) {
return headers.getPartitionId() + "_" + name;
}
}
/*
package org.opengroup.osdu.register.provider.azure.subscriber;
import org.junit.jupiter.api.BeforeEach;
......@@ -11,7 +10,6 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.notification.Topic;
import org.opengroup.osdu.register.provider.azure.util.PartitionHelper;
import org.opengroup.osdu.register.provider.azure.util.TopicsHelper;
import java.util.Arrays;
import java.util.List;
......@@ -35,21 +33,17 @@ public class TopicsRepositoryImplTest {
@BeforeEach
void init() {
topicsRepository = new TopicsRepositoryImpl(log, headers, partitionHelper, new TopicsHelper(headers));
topicsRepository = new TopicsRepositoryImpl(log, headers, partitionHelper);
}
@Test
public void shouldReturnUserFriendlyTopicName() {
when(headers.getPartitionId()).thenReturn("partitionId");
when(partitionHelper.retrieveTopicNames())
.thenReturn(Arrays.asList("rg1-grid-recordstopic", "rg1-grid-recordstopic-function"));
List<Topic> topics = topicsRepository.listMessages();
assertEquals(2, topics.size());
List<String> expected = Arrays.asList("recordstopic", "recordstopic-function");
List<String> expected = Arrays.asList("recordstopic", "testtopic");
assertArrayEquals(expected.toArray(), topics.stream().map(Topic::getName).toArray());
}
}
*/
package org.opengroup.osdu.register.provider.azure.util;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class TopicsHelperTest {
@Mock
private DpsHeaders headers;
@InjectMocks
private TopicsHelper topicsHelper;
@Test
public void shouldExtractTopicName() {
when(headers.getPartitionId()).thenReturn("partitionId");
assertEquals("recordstopic", topicsHelper.extractDisplayName("rg-grid-recordstopic"));
}
}
[
{
"name": "topic-name",
"name": "recordstopic",
"description": "This notification is sent whenever a new record or record version is created, updated or deleted, and when a new schema is created in storage.",
"state": "ACTIVE",
"example": [
{
"id": "common:abc:123",
"kind": "common:petrel:regularheightfieldsurface:1.0.0",
"op" : "create",
"recordUpdated": "false"
},
{
"id": "common:abc:124",
"kind": "common:petrel:regularheightfieldsurface:1.0.0",
"op" : "create",
"recordUpdated": "true"
},
{
"kind": "common:petrel:regularheightfieldsurface:1.0.0",
"op" : "create_schema"
},
{
"id": "common:ghi:345",
"kind": "common:petrel:regularheightfieldsurface:1.0.0",
"op" : "delete"
}
]
},
{
"name": "testtopic",
"description": "This notification is sent whenever a new record or record version is created, updated or deleted, and when a new schema is created in storage.",
"state": "ACTIVE",
"example": [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment