Skip to content

Commit

Permalink
[TEST] Remove powermock from ITs. Still needs cleanup; static mocks
Browse files Browse the repository at this point in the history
need another look and ITs were not all passing previously.
  • Loading branch information
peterrinehart committed Jun 10, 2024
1 parent f363c64 commit 72ea4e6
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2018-2021 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2018-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -26,13 +26,11 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.pentaho.metaverse.frames.FramedMetaverseNode;
import org.pentaho.metaverse.impl.MetaverseConfig;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.core.classloader.annotations.PowerMockIgnore;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -42,44 +40,53 @@
* Runs the integration test with the {@link MetaverseConfig} mocked to have
* the {@code deduplicateTransformationFields} graph dedupping turned on.
*/
@RunWith( PowerMockRunner.class )
@PowerMockIgnore( "jdk.internal.reflect.*" )
@PrepareForTest( MetaverseConfig.class )
@RunWith( MockitoJUnitRunner.class )
public class MetaverseValidationDedupIT extends MetaverseValidationIT {

@BeforeClass
public static void init() throws Exception {

PowerMockito.mockStatic( MetaverseConfig.class );
Mockito.when( MetaverseConfig.adjustExternalResourceFields() ).thenReturn( true );
Mockito.when( MetaverseConfig.deduplicateTransformationFields() ).thenReturn( true );
Mockito.when( MetaverseConfig.consolidateSubGraphs() ).thenReturn( true );
Mockito.when( MetaverseConfig.generateSubGraphs() ).thenReturn( true );

MetaverseValidationIT.init();
}

@Test
public void testSelectValuesStep() throws Exception {
testSelectValuesStep( 8 );
try ( MockedStatic<MetaverseConfig> metaverseConfigMockedStatic = Mockito.mockStatic( MetaverseConfig.class ) ) {
metaverseConfigMockedStatic.when( MetaverseConfig::adjustExternalResourceFields ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::deduplicateTransformationFields ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::consolidateSubGraphs ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::generateSubGraphs ).thenReturn( true );
testSelectValuesStep( 8 );
}
}

@Test
public void testTextFileInputNode() throws Exception {
List<FramedMetaverseNode> containedNodes = testTextFileInputNodeImpl( 3 );
// get field names
List<String> nodeNames = new ArrayList();
for ( final FramedMetaverseNode node : containedNodes ) {
nodeNames.add( node.getName() );
try ( MockedStatic<MetaverseConfig> metaverseConfigMockedStatic = Mockito.mockStatic( MetaverseConfig.class ) ) {
metaverseConfigMockedStatic.when( MetaverseConfig::adjustExternalResourceFields ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::deduplicateTransformationFields ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::consolidateSubGraphs ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::generateSubGraphs ).thenReturn( true );
List<FramedMetaverseNode> containedNodes = testTextFileInputNodeImpl( 3 );
// get field names
List<String> nodeNames = new ArrayList();
for ( final FramedMetaverseNode node : containedNodes ) {
nodeNames.add( node.getName() );
}
Assert.assertTrue( nodeNames.contains( "longitude" ) );
Assert.assertTrue( nodeNames.contains( "latitude" ) );
Assert.assertTrue( nodeNames.contains( "address" ) );
}
Assert.assertTrue( nodeNames.contains( "longitude" ) );
Assert.assertTrue( nodeNames.contains( "latitude" ) );
Assert.assertTrue( nodeNames.contains( "address" ) );
}

@Test
@Override
public void testTransformationStepNodes() throws Exception {
super.testTransformationStepNodes();
try ( MockedStatic<MetaverseConfig> metaverseConfigMockedStatic = Mockito.mockStatic( MetaverseConfig.class ) ) {
metaverseConfigMockedStatic.when( MetaverseConfig::adjustExternalResourceFields ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::deduplicateTransformationFields ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::consolidateSubGraphs ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::generateSubGraphs ).thenReturn( true );
super.testTransformationStepNodes();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2018-2021 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2018-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -25,42 +25,42 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.pentaho.metaverse.impl.MetaverseConfig;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;

/**
* Runs the integration test with the {@link MetaverseConfig} mocked to have
* the {@code deduplicateTransformationFields} graph dedupping turned off.
*/
@RunWith( PowerMockRunner.class )
@PowerMockIgnore( "jdk.internal.reflect.*" )
@PrepareForTest( MetaverseConfig.class )
@RunWith( MockitoJUnitRunner.class )
public class MetaverseValidationSkipDedupIT extends MetaverseValidationIT {

@BeforeClass
public static void init() throws Exception {

PowerMockito.mockStatic( MetaverseConfig.class );
// expecting to deduplicate by default - need to mock to return false
Mockito.when( MetaverseConfig.adjustExternalResourceFields() ).thenReturn( false );
Mockito.when( MetaverseConfig.deduplicateTransformationFields() ).thenReturn( false );
Mockito.when( MetaverseConfig.consolidateSubGraphs() ).thenReturn( true );
Mockito.when( MetaverseConfig.generateSubGraphs() ).thenReturn( true );

MetaverseValidationIT.init();
}

@Test
public void testSelectValuesStep() throws Exception {
testSelectValuesStep( 16 );
try ( MockedStatic<MetaverseConfig> metaverseConfigMockedStatic = Mockito.mockStatic( MetaverseConfig.class ) ) {
metaverseConfigMockedStatic.when( MetaverseConfig::adjustExternalResourceFields ).thenReturn( false );
metaverseConfigMockedStatic.when( MetaverseConfig::deduplicateTransformationFields ).thenReturn( false );
metaverseConfigMockedStatic.when( MetaverseConfig::consolidateSubGraphs ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::generateSubGraphs ).thenReturn( true );
testSelectValuesStep( 16 );
}
}

@Test
public void testTextFileInputNode() throws Exception {
testTextFileInputNodeImpl( 0 );
try ( MockedStatic<MetaverseConfig> metaverseConfigMockedStatic = Mockito.mockStatic( MetaverseConfig.class ) ) {
metaverseConfigMockedStatic.when( MetaverseConfig::adjustExternalResourceFields ).thenReturn( false );
metaverseConfigMockedStatic.when( MetaverseConfig::deduplicateTransformationFields ).thenReturn( false );
metaverseConfigMockedStatic.when( MetaverseConfig::consolidateSubGraphs ).thenReturn( true );
metaverseConfigMockedStatic.when( MetaverseConfig::generateSubGraphs ).thenReturn( true );
testTextFileInputNodeImpl( 0 );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2021 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2021-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -40,7 +40,7 @@
import java.util.Arrays;
import java.util.List;

import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.nullable;

public class GraphCatalogWriterIT extends StepAnalyzerValidationIT {
@Mock ICatalogLineageClient mockCatalogLineageClient;
Expand All @@ -50,7 +50,7 @@ public class GraphCatalogWriterIT extends StepAnalyzerValidationIT {

@Before
public void setup() {
Mockito.when( mockCatalogLineageClientProvider.getCatalogLineageClient( anyString(), anyString(), anyString(), anyString(), anyString(), anyString() ) )
Mockito.when( mockCatalogLineageClientProvider.getCatalogLineageClient( nullable( String.class ), nullable( String.class ), nullable( String.class ), nullable( String.class ), nullable( String.class ), nullable( String.class ) ) )
.thenReturn( mockCatalogLineageClient );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2018-2021 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2018-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -26,25 +26,40 @@
import org.apache.commons.collections.IteratorUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.pentaho.metaverse.frames.FramedMetaverseNode;
import org.pentaho.metaverse.frames.TransformationNode;
import org.pentaho.metaverse.frames.TransformationStepNode;
import org.pentaho.metaverse.impl.MetaverseConfig;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.pentaho.dictionary.DictionaryConst.*;

@RunWith( PowerMockRunner.class )
@PowerMockIgnore( "jdk.internal.reflect.*" )
@PrepareForTest( MetaverseConfig.class )
import static org.pentaho.dictionary.DictionaryConst.LINK_CONTAINS;
import static org.pentaho.dictionary.DictionaryConst.LINK_DERIVES;
import static org.pentaho.dictionary.DictionaryConst.LINK_EXECUTES;
import static org.pentaho.dictionary.DictionaryConst.LINK_HOPSTO;
import static org.pentaho.dictionary.DictionaryConst.LINK_INPUTS;
import static org.pentaho.dictionary.DictionaryConst.LINK_OUTPUTS;
import static org.pentaho.dictionary.DictionaryConst.LINK_TYPE_CONCEPT;
import static org.pentaho.dictionary.DictionaryConst.NODE_TYPE_TRANS;
import static org.pentaho.dictionary.DictionaryConst.NODE_TYPE_TRANS_FIELD;
import static org.pentaho.dictionary.DictionaryConst.NODE_VIRTUAL;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_ANALYZER;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_CATEGORY;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_COPIES;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_LOGICAL_ID;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_NAME;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_NAMESPACE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_PATH;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_PLUGIN_ID;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_STEP_TYPE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_TYPE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_VERBOSE_DETAILS;

@RunWith( MockitoJUnitRunner.class )
public class MappingAnalyzerValidationIT extends StepAnalyzerValidationIT {

private static final String VALUE = "value";
Expand Down
42 changes: 30 additions & 12 deletions core/src/it/java/org/pentaho/metaverse/step/MdiValidationIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2018-2021 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2018-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -28,28 +28,46 @@
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.pentaho.metaverse.frames.FileNode;
import org.pentaho.metaverse.frames.FramedMetaverseNode;
import org.pentaho.metaverse.frames.StreamFieldNode;
import org.pentaho.metaverse.frames.TransformationNode;
import org.pentaho.metaverse.frames.TransformationStepNode;
import org.pentaho.metaverse.impl.MetaverseConfig;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;
import static org.pentaho.dictionary.DictionaryConst.*;

@RunWith( PowerMockRunner.class )
@PowerMockIgnore( "jdk.internal.reflect.*" )
@PrepareForTest( MetaverseConfig.class )
// TODO: Ignored for now, remove the @Ignore annotation once https://jira.pentaho.com/browse/ENGOPS-4612 is resolved
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.pentaho.dictionary.DictionaryConst.LINK_CONTAINS;
import static org.pentaho.dictionary.DictionaryConst.LINK_DERIVES;
import static org.pentaho.dictionary.DictionaryConst.LINK_EXECUTES;
import static org.pentaho.dictionary.DictionaryConst.LINK_HOPSTO;
import static org.pentaho.dictionary.DictionaryConst.LINK_INPUTS;
import static org.pentaho.dictionary.DictionaryConst.LINK_OUTPUTS;
import static org.pentaho.dictionary.DictionaryConst.LINK_POPULATES;
import static org.pentaho.dictionary.DictionaryConst.LINK_TYPE_CONCEPT;
import static org.pentaho.dictionary.DictionaryConst.NODE_TYPE_STEP_PROPERTY;
import static org.pentaho.dictionary.DictionaryConst.NODE_TYPE_TRANS;
import static org.pentaho.dictionary.DictionaryConst.NODE_TYPE_TRANS_FIELD;
import static org.pentaho.dictionary.DictionaryConst.NODE_VIRTUAL;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_ANALYZER;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_CATEGORY;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_COPIES;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_LOGICAL_ID;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_NAME;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_NAMESPACE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_PLUGIN_ID;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_STEP_TYPE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_TYPE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_VERBOSE_DETAILS;

@RunWith( MockitoJUnitRunner.class )
// TODO: Ignored for now, remove the @Ignore annotation once https://jira.pentaho.com/browse/ENGOPS-4612 is resolved
@Ignore
public class MdiValidationIT extends StepAnalyzerValidationIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2018-2021 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2018-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -26,23 +26,37 @@
import org.apache.commons.collections.IteratorUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.pentaho.metaverse.frames.FramedMetaverseNode;
import org.pentaho.metaverse.frames.TransformationNode;
import org.pentaho.metaverse.frames.TransformationStepNode;
import org.pentaho.metaverse.impl.MetaverseConfig;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Arrays;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.pentaho.dictionary.DictionaryConst.*;

@RunWith( PowerMockRunner.class )
@PowerMockIgnore( "jdk.internal.reflect.*" )
@PrepareForTest( MetaverseConfig.class )
import static org.pentaho.dictionary.DictionaryConst.LINK_CONTAINS;
import static org.pentaho.dictionary.DictionaryConst.LINK_DERIVES;
import static org.pentaho.dictionary.DictionaryConst.LINK_EXECUTES;
import static org.pentaho.dictionary.DictionaryConst.LINK_INPUTS;
import static org.pentaho.dictionary.DictionaryConst.LINK_OUTPUTS;
import static org.pentaho.dictionary.DictionaryConst.LINK_TYPE_CONCEPT;
import static org.pentaho.dictionary.DictionaryConst.NODE_TYPE_TRANS;
import static org.pentaho.dictionary.DictionaryConst.NODE_TYPE_TRANS_FIELD;
import static org.pentaho.dictionary.DictionaryConst.NODE_VIRTUAL;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_ANALYZER;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_CATEGORY;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_COPIES;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_LOGICAL_ID;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_NAME;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_NAMESPACE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_PATH;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_PLUGIN_ID;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_STEP_TYPE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_TYPE;
import static org.pentaho.dictionary.DictionaryConst.PROPERTY_VERBOSE_DETAILS;

@RunWith( MockitoJUnitRunner.class )
public class SimpleMappingAnalyzerValidationIT extends StepAnalyzerValidationIT {

private static final String VALUE = "value";
Expand Down
Loading

0 comments on commit 72ea4e6

Please sign in to comment.