Commit d97c217c authored by devesh bajpai's avatar devesh bajpai
Browse files

modifiy test and remove unused code

parent 1073fd7c
Pipeline #25574 failed with stages
in 17 seconds
package org.opengroup.osdu.wks.provider.azure.storage;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.SqlParameter;
import com.azure.cosmos.models.SqlQuerySpec;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.List;
import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.opengroup.osdu.wks.config.RequestIdentity;
import org.opengroup.osdu.wks.constants.Constants;
import org.opengroup.osdu.wks.model.mapping.MappingDefinition;
import org.opengroup.osdu.wks.model.mapping.MappingInfo;
import org.opengroup.osdu.wks.model.MappingsModel;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.wks.provider.azure.di.CosmosContainerConfig;
import org.opengroup.osdu.wks.provider.interfaces.MappingStore;
......@@ -18,9 +16,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.SqlParameter;
import com.azure.cosmos.models.SqlQuerySpec;
import com.fasterxml.jackson.databind.ObjectMapper;
@Component
public class MappingStoreImpl implements MappingStore {
......@@ -86,22 +85,6 @@ public class MappingStoreImpl implements MappingStore {
return mappingsDocList;
}
public List<MappingDefinition> getMappingFilesFromStorage(List<MappingInfo> mappingsDocList) {
List<MappingDefinition> mappingsList = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
for (MappingInfo mappingInfoDoc : mappingsDocList) {
try {
String content = blobStore.readFromStorageContainer(requestIdentity.getDataPartitionId(),
mappingInfoDoc.getFileName(),
azureBootstrapConfig.containerName());
mappingsList.add(mapper.readValue(content, MappingDefinition.class));
} catch (Exception e) {
LOGGER.error("Error while processing mappings from blob store {}", e.getMessage(), e);
}
}
return mappingsList;
}
public MappingDefinition getMappingDefinitionFromStorage(MappingInfo MappingInfo) {
ObjectMapper mapper = new ObjectMapper();
try {
......
package org.opengroup.osdu.wks.provider.azure.storage;
import com.azure.cosmos.models.SqlParameter;
import com.azure.cosmos.models.SqlQuerySpec;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
......@@ -16,28 +16,20 @@ import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.wks.config.RequestIdentity;
import org.opengroup.osdu.wks.model.AttributeMappingModel;
import org.opengroup.osdu.wks.model.mapping.Mapping;
import org.opengroup.osdu.wks.model.mapping.MappingDefinition;
import org.opengroup.osdu.wks.model.mapping.MappingInfo;
import org.opengroup.osdu.wks.model.MappingsModel;
import org.opengroup.osdu.wks.model.mapping.operation.Operation;
import org.opengroup.osdu.wks.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.wks.provider.azure.di.CosmosContainerConfig;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.azure.cosmos.models.SqlParameter;
import com.azure.cosmos.models.SqlQuerySpec;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
......@@ -134,33 +126,26 @@ public class MappingStoreImplTest {
ObjectMapper mapper = new ObjectMapper();
String content = mapper.writeValueAsString(mappingDefinition);
List<MappingInfo> mappingInfoDocList = Arrays.asList(mappingInfoDoc1, mappingInfoDoc2);
doReturn("file1").when(mappingInfoDoc1).getFileName();
doReturn("file2").when(mappingInfoDoc2).getFileName();
when(blobStore.readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, "file1", containerName)).thenReturn(content);
when(blobStore.readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, "file2", containerName)).thenReturn(content);
List<MappingDefinition> resultMappings = mappingStore.getMappingFilesFromStorage(mappingInfoDocList);
MappingDefinition resultMappings = mappingStore.getMappingDefinitionFromStorage(mappingInfoDoc1);
assertEquals(mappingDefinition.toString(), resultMappings.get(0).toString());
assertEquals(mappingDefinition.toString(), resultMappings.get(1).toString());
assertEquals(mappingDefinition.toString(), resultMappings.toString());
verify(blobStore, times(1)).readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, "file1", containerName);
verify(blobStore, times(1)).readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, "file2", containerName);
}
@Test
public void shouldReturnEmptyListOfMappingFilesListWhenAllMappingsAreInvalid() {
String content = "{\n" + " \"name\": \"invalid_json\"\n" + "}";
List<MappingInfo> mappingInfoDocList = Arrays.asList(mappingInfoDoc1);
doReturn("file1").when(mappingInfoDoc1).getFileName();
when(blobStore.readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, "file1", containerName)).thenReturn(content);
List<MappingDefinition> resultMappings = mappingStore.getMappingFilesFromStorage(mappingInfoDocList);
MappingDefinition resultMappings = mappingStore.getMappingDefinitionFromStorage(mappingInfoDoc1);
assertEquals(resultMappings.size(), 0);
verify(blobStore, times(1)).readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, "file1", containerName);
verify(blobStore, never()).readFromStorageContainer(DpsHeaders.DATA_PARTITION_ID, "file2", containerName);
}
......
......@@ -46,11 +46,6 @@ public class MappingStoreImpl implements MappingStore {
return new ArrayList<>();
}
@Override
public List<MappingDefinition> getMappingFilesFromStorage(List<MappingInfo> mappingsDocList) {
return new ArrayList<>();
}
@Override
public MappingDefinition getMappingDefinitionFromStorage(MappingInfo mappingsDoc) {
return new MappingDefinition();
......
package org.opengroup.osdu.wks.provider.interfaces;
import java.util.List;
import org.opengroup.osdu.wks.model.mapping.MappingDefinition;
import org.opengroup.osdu.wks.model.mapping.MappingInfo;
import org.opengroup.osdu.wks.model.MappingsModel;
import java.util.List;
public interface MappingStore {
List<MappingInfo> getMappingInfo(String authorityName, String entityNamePrefix, String sourceName, String majorVersion);
MappingDefinition getMappingDefinitionFromStorage(MappingInfo mappingsInfo);
List<MappingDefinition> getMappingFilesFromStorage(List<MappingInfo> mappingsDocList);
}
package org.opengroup.osdu.wks.service;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import java.util.List;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
public interface ISchemaService {
public List<String> getSchemas(String authority, String source, String entityType, String majorVersion) throws ApplicationException;
List<String> getSchemas(String authority, String source, String entityType, String majorVersion) throws ApplicationException;
}
package org.opengroup.osdu.wks.service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.opengroup.osdu.wks.model.mapping.MappingDefinition;
import org.opengroup.osdu.wks.model.mapping.MappingInfo;
import org.opengroup.osdu.wks.model.MappingsModel;
import org.opengroup.osdu.wks.provider.interfaces.MappingStore;
import org.opengroup.osdu.wks.util.KindUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Service
public class MappingServiceImpl implements MappingService {
......
package org.opengroup.osdu.wks.service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -15,22 +11,18 @@ import org.opengroup.osdu.wks.constants.Constants;
import org.opengroup.osdu.wks.exceptions.ApplicationException;
import org.opengroup.osdu.wks.exceptions.BadRequestException;
import org.opengroup.osdu.wks.exceptions.NotFoundException;
import org.opengroup.osdu.wks.model.MappingsModel;
import org.opengroup.osdu.wks.model.RawRecordDetails;
import org.opengroup.osdu.wks.model.RelationshipStatus;
import org.opengroup.osdu.wks.model.TransformRequest;
import org.opengroup.osdu.wks.model.TransformationResult;
import org.opengroup.osdu.wks.model.mapping.MappingDefinition;
import org.opengroup.osdu.wks.provider.interfaces.StatusStoreService;
import org.opengroup.osdu.wks.util.KindUtil;
import org.opengroup.osdu.wks.util.WksTransformator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.datatree.Tree;
@Service("wKSService")
......@@ -58,12 +50,6 @@ public class WKSServiceImpl implements WKSService {
@Autowired
private StatusStoreService statusStoreService;
@Autowired
private KindUtil kindUtil;
@Autowired
private SchemaService schemaService;
/**
* This method applies the WKS transformation on the valid raw records
*
......
......@@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
public class JsonTreeUtil {
private final static Logger LOGGER = LoggerFactory.getLogger(JsonTreeUtil.class);
private static final Logger LOGGER = LoggerFactory.getLogger(JsonTreeUtil.class);
private JsonTreeUtil(){
throw new IllegalStateException("JsonTreeUtil should not be instantiated");
}
......
......@@ -36,7 +36,7 @@ import io.datatree.Tree;
@Component
public class RelationshipBlockHandler {
private final static Logger LOGGER = LoggerFactory.getLogger(RelationshipBlockHandler.class);
private static final Logger LOGGER = LoggerFactory.getLogger(RelationshipBlockHandler.class);
private final StorageService storageService;
......
Supports Markdown
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