Commit d552652a authored by Akshat  Joshi's avatar Akshat Joshi
Browse files

Remove PowerMock

parent 386541da
Pipeline #107371 passed with stages
in 38 minutes and 24 seconds
......@@ -32,16 +32,10 @@
<properties>
<java.version>1.8</java.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<powermock.version>1.7.0</powermock.version>
<jacoco.version>0.8.5</jacoco.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<tomcat_embed_core_version>9.0.54</tomcat_embed_core_version>
<log4j2.version>2.17.1</log4j2.version>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/target/coverage.exec</sonar.jacoco.reportPath>
<sonar.jacoco.itReportPath>${project.basedir}/target/jacoco-it.exec</sonar.jacoco.itReportPath>
</properties>
<dependencyManagement>
......@@ -104,7 +98,7 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
......@@ -116,13 +110,13 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
......@@ -190,34 +184,6 @@
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<!--- Power Mockito -->
<!--powermock API for Mockito-->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>${powermock.version}</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
</dependency>
<!--Jacoco required at runtime to build offline coverages-->
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco.version}</version>
<classifier>runtime</classifier>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......@@ -239,85 +205,33 @@
</execution>
</executions>
</plugin>
<!--Jacoco offline instrument to work with powermock-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<version>0.8.3</version>
<configuration>
<excludes>
<exclude>**/*org/opengroup/osdu/dataset/model/**</exclude>
<exclude>**/*org/opengroup/osdu/dataset/di/**</exclude>
<exclude>**/*org/opengroup/osdu/dataset/swagger/**</exclude>
<exclude>**/*org/opengroup/osdu/dataset/DatasetApplication.class</exclude>
<exclude>*</exclude>
</excludes>
</configuration>
<executions>
<!--Performs offline instrumentation.-->
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<!--Restores original classes as they were before offline instrumentation.-->
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
<goal>prepare-agent</goal>
</goals>
</execution>
<!--Now for integration tests-->
<!--Same as prepare-agent, but provides default values suitable for integration-tests:-->
<execution>
<id>prepare-it-agent</id>
<phase>package</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<!--The path variable should not change.This is used by Sonar-->
<destFile>${sonar.jacoco.itReportPath}</destFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.reportPath}</dataFile>
</configuration>
</execution>
</executions>
</plugin>
<!--END of jacoco plugin settings-->
<!--*** Maven surefire plugin to generate coverage file ***-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<!--Exclude any Integration Test-->
<excludes>
<exclude>**/*Integration*Test*</exclude>
</excludes>
<!--Setup Jacoco Junit file path here-->
<systemPropertyVariables>
<jacoco-agent.destfile>${sonar.jacoco.reportPath}</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
</project>
\ No newline at end of file
......@@ -27,12 +27,10 @@ import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.http.IHttpClient;
import org.opengroup.osdu.core.common.http.json.HttpResponseBodyMapper;
import org.opengroup.osdu.core.common.http.json.HttpResponseBodyParsingException;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.dataset.model.request.GetDatasetRegistryRequest;
import org.opengroup.osdu.dataset.model.response.GetDatasetRetrievalInstructionsResponse;
import org.opengroup.osdu.dataset.model.response.GetDatasetStorageInstructionsResponse;
import org.springframework.http.HttpStatus;
public class DmsService implements IDmsProvider {
......
......@@ -19,9 +19,9 @@ import java.util.List;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import org.opengroup.osdu.dataset.model.validation.DatasetRegistryValidationDoc;
import org.opengroup.osdu.core.common.model.storage.Record;
import org.opengroup.osdu.core.common.model.storage.validation.ValidNotNullCollection;
import org.opengroup.osdu.dataset.model.validation.DatasetRegistryValidationDoc;
public class CreateDatasetRegistryRequest {
......
......@@ -25,7 +25,6 @@ import org.springframework.web.context.annotation.RequestScope;
@Component("authorizationFilter")
@RequestScope
public class AuthorizationFilter {
@Inject
private IEntitlementsAndCacheService entitlementsAndCacheService;
......
......@@ -37,4 +37,4 @@ public class GlobalOtherExceptionMapper {
"An unknown error has occurred.", e));
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.dms.model.RetrievalInstructionsResponse;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
......@@ -13,13 +14,9 @@ import org.opengroup.osdu.dataset.dms.DmsServiceProperties;
import org.opengroup.osdu.dataset.dms.IDmsFactory;
import org.opengroup.osdu.dataset.dms.IDmsProvider;
import org.opengroup.osdu.dataset.model.request.GetDatasetRegistryRequest;
import org.opengroup.osdu.dataset.model.response.DatasetRetrievalDeliveryItem;
import org.opengroup.osdu.dataset.model.response.GetDatasetRetrievalInstructionsResponse;
import org.opengroup.osdu.dataset.model.response.GetDatasetStorageInstructionsResponse;
import org.opengroup.osdu.dataset.provider.interfaces.IDatasetDmsServiceMap;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.ArrayList;
......@@ -27,15 +24,16 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PrepareForTest(DatasetDmsServiceImpl.class)
@RunWith(MockitoJUnitRunner.class)
public class DatasetDmsServiceImplTest {
......@@ -72,7 +70,6 @@ public class DatasetDmsServiceImplTest {
initMocks(this);
kindSubTypeToDmsServiceMap = new HashMap<>();
kindSubTypeToDmsServiceMap.put(KIND, dmsServiceProperties);
datasetDmsService = PowerMockito.spy(datasetDmsService);
when(headers.getPartitionId()).thenReturn(DATA_PARTITION_ID);
}
......@@ -107,27 +104,12 @@ public class DatasetDmsServiceImplTest {
public void testGetDatasetRetrievalInstructions() throws Exception {
datasetRegistryIds = Collections.singletonList(RECORD_ID);
GetDatasetRetrievalInstructionsResponse expectedResponse = new GetDatasetRetrievalInstructionsResponse();
List<DatasetRetrievalDeliveryItem> datasetRetrievalDeliveryItemList = new ArrayList<>();
datasetRetrievalDeliveryItemList.add((new DatasetRetrievalDeliveryItem()));
expectedResponse.setDelivery(datasetRetrievalDeliveryItemList);
HashMap<String, GetDatasetRegistryRequest> datasetRegistryRequestMap = new HashMap<>();
datasetRegistryRequestMap.put("dummyKey", new GetDatasetRegistryRequest());
when(dmsServiceMap.getResourceTypeToDmsServiceMap()).thenReturn(kindSubTypeToDmsServiceMap);
when(datasetDmsService, "segregateDatasetIdsToDms", datasetRegistryIds, kindSubTypeToDmsServiceMap).
thenReturn(datasetRegistryRequestMap);
GetDatasetRetrievalInstructionsResponse mergedResponse = new GetDatasetRetrievalInstructionsResponse(new ArrayList<>());
Set<Map.Entry<String, GetDatasetRegistryRequest>> datasetRegistryRequestEntrySet = datasetRegistryRequestMap.entrySet();
Map.Entry<String, GetDatasetRegistryRequest> datasetRegistryRequestEntry = datasetRegistryRequestEntrySet.iterator().next();
when(dmsFactory.create(headers, kindSubTypeToDmsServiceMap.get(datasetRegistryRequestEntry.getKey()))).
thenReturn(dmsProvider);
GetDatasetRetrievalInstructionsResponse entryResponse = new GetDatasetRetrievalInstructionsResponse();
entryResponse.setDelivery(datasetRetrievalDeliveryItemList);
when(dmsProvider.getDatasetRetrievalInstructions(datasetRegistryRequestEntry.getValue())).thenReturn(entryResponse);
GetDatasetRetrievalInstructionsResponse actualResponse = datasetDmsService.getDatasetRetrievalInstructions(datasetRegistryIds);
assertEquals(expectedResponse.getDelivery().size(), actualResponse.getDelivery().size());
GetDatasetRegistryRequest request = mock(GetDatasetRegistryRequest.class);
GetDatasetRetrievalInstructionsResponse entryResponse = new GetDatasetRetrievalInstructionsResponse(new ArrayList<>());
injectWhenClauseForDmsServiceMapAndDmsFactory();
when(dmsProvider.getDatasetRetrievalInstructions(any())).thenReturn(entryResponse);
GetDatasetRetrievalInstructionsResponse actualResponse = datasetDmsService. getDatasetRetrievalInstructions(datasetRegistryIds);
verifydmsServiceMapAndDmsFactory();
}
@Test
......@@ -164,38 +146,30 @@ public class DatasetDmsServiceImplTest {
private void testGetStorageInstructions() throws DmsException {
when(dmsServiceMap.getResourceTypeToDmsServiceMap()).thenReturn(kindSubTypeToDmsServiceMap);
when(dmsFactory.create(headers, dmsServiceProperties)).thenReturn(dmsProvider);
GetDatasetStorageInstructionsResponse response = new GetDatasetStorageInstructionsResponse();
injectWhenClauseForDmsServiceMapAndDmsFactory();
when(dmsServiceProperties.isAllowStorage()).thenReturn(true);
response.setProviderKey("dummyProvider");
when(dmsProvider.getStorageInstructions()).thenReturn(response);
GetDatasetStorageInstructionsResponse actualResponse = datasetDmsService.getStorageInstructions(KIND);
GetDatasetStorageInstructionsResponse expectedResponse = new GetDatasetStorageInstructionsResponse();
expectedResponse.setProviderKey("dummyProvider");
assertEquals(actualResponse.getProviderKey(), expectedResponse.getProviderKey());
verifydmsServiceMapAndDmsFactory();
verify(dmsProvider, times(1)).getStorageInstructions();
}
private void testRetrievalInstructions() throws Exception {
RetrievalInstructionsResponse expectedResponse = new RetrievalInstructionsResponse();
expectedResponse.setProviderKey("dummyKey");
HashMap<String, GetDatasetRegistryRequest> datasetRegistryRequestMap = new HashMap<>();
datasetRegistryRequestMap.put("key", new GetDatasetRegistryRequest());
when(dmsServiceMap.getResourceTypeToDmsServiceMap()).thenReturn(kindSubTypeToDmsServiceMap);
when(datasetDmsService, "segregateDatasetIdsToDms", datasetRegistryIds, kindSubTypeToDmsServiceMap).
thenReturn(datasetRegistryRequestMap);
RetrievalInstructionsResponse response = new RetrievalInstructionsResponse();
Set<Map.Entry<String, GetDatasetRegistryRequest>> datasetRegistryRequestEntrySet = datasetRegistryRequestMap.entrySet();
Map.Entry<String, GetDatasetRegistryRequest> datasetRegistryRequestEntry = datasetRegistryRequestEntrySet.iterator().next();
when(dmsFactory.create(headers, kindSubTypeToDmsServiceMap.get(datasetRegistryRequestEntry.getKey()))).
thenReturn(dmsProvider);
RetrievalInstructionsResponse entryResponse = new RetrievalInstructionsResponse();
entryResponse.setProviderKey("dummyKey");
when(dmsProvider.getRetrievalInstructions(datasetRegistryRequestEntry.getValue())).thenReturn(entryResponse);
injectWhenClauseForDmsServiceMapAndDmsFactory();
when(dmsProvider.getRetrievalInstructions(any())).thenReturn(entryResponse);
RetrievalInstructionsResponse actualResponse = datasetDmsService.getRetrievalInstructions(datasetRegistryIds);
assertEquals(expectedResponse.getProviderKey(), actualResponse.getProviderKey());
verifydmsServiceMapAndDmsFactory();
verify(dmsProvider, times(1)).getRetrievalInstructions(any());
}
private void verifydmsServiceMapAndDmsFactory() {
verify(dmsServiceMap,times(1)).getResourceTypeToDmsServiceMap();
verify(dmsFactory, times(1)).create(headers,dmsServiceProperties);
}
private void injectWhenClauseForDmsServiceMapAndDmsFactory() {
when(dmsServiceMap.getResourceTypeToDmsServiceMap()).thenReturn(kindSubTypeToDmsServiceMap);
when(dmsFactory.create(headers,dmsServiceProperties)).thenReturn(dmsProvider);
}
}
\ No newline at end of file
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