Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
update log accessors
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Lawrence <[email protected]>
  • Loading branch information
Mark-J-Lawrence committed Aug 19, 2024
1 parent 36c5705 commit 20bef20
Show file tree
Hide file tree
Showing 7 changed files with 730 additions and 627 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'galasa.manager'
id 'checkstyle'
id 'pmd'
id("com.github.spotbugs") version "4.7.0"
id("com.github.spotbugs") version "6.0.20"
}

description = 'Galasa SDV Manager'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<Match>
<Class name="dev.galasa.sdv.internal.properties.SdvPropertiesSingleton" />
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
</Match>
<Match>
<Class name="dev.galasa.sdv.internal.properties.SdvPropertiesSingleton" />
<Bug pattern="SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR" />
</Match>
<Match>
<Class name="dev.galasa.sdv.internal.properties.SdvPropertiesSingleton" />
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import dev.galasa.zosbatch.IZosBatchJob;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -51,6 +50,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import sun.misc.Unsafe;


class TestSdvManagerImpl {
Expand Down Expand Up @@ -93,7 +93,7 @@ class TestSdvManagerImpl {
private String frameworkString = "framework";
private String sdvRecorderVarName = "sdvRecorder";
private String logString = "LOG";
private String modifiersString = "modifiers";
private String theUnsafeString = "theUnsafe";
private String regionaApplid = "APPL1";
private String runName = "RUN123";
private String regionbApplid = "APPL2";
Expand Down Expand Up @@ -764,13 +764,14 @@ void testProvisionGenerateOldCicsVersionForRegionA()
sdvUsersToRecordList.set(sdvManager, listOfUsersForAllRegions);

// Replace LOG
Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
loggerField.setAccessible(true);
// remove final modifier
Field modifiersField = Field.class.getDeclaredField(modifiersString);
modifiersField.setAccessible(true);
modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL);
loggerField.set(sdvManager, mockLog);
final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString);
unsafeField.setAccessible(true);
final Unsafe unsafe = (Unsafe) unsafeField.get(null);

final Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField);
final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField);
unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog);

// Make call to funtion under test
sdvManager.provisionGenerate();
Expand Down Expand Up @@ -912,13 +913,14 @@ void testProvisionGenerateNoSecMsg() throws ClassNotFoundException, Instantiatio
sdvUsersToRecordList.set(sdvManager, listOfUsersForAllRegions);

// Replace LOG
Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
loggerField.setAccessible(true);
// remove final modifier
Field modifiersField = Field.class.getDeclaredField(modifiersString);
modifiersField.setAccessible(true);
modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL);
loggerField.set(sdvManager, mockLog);
final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString);
unsafeField.setAccessible(true);
final Unsafe unsafe = (Unsafe) unsafeField.get(null);

final Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField);
final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField);
unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog);

// Make call to funtion under test
sdvManager.provisionGenerate();
Expand Down Expand Up @@ -1057,13 +1059,14 @@ void testProvisionGenerateNoUsersForRegion()
sdvUsersToRecordList.set(sdvManager, listOfUsersForAllRegions);

// Replace LOG
Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
loggerField.setAccessible(true);
// remove final modifier
Field modifiersField = Field.class.getDeclaredField(modifiersString);
modifiersField.setAccessible(true);
modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL);
loggerField.set(sdvManager, mockLog);
final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString);
unsafeField.setAccessible(true);
final Unsafe unsafe = (Unsafe) unsafeField.get(null);

final Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField);
final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField);
unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog);

// Make call to funtion under test
sdvManager.provisionGenerate();
Expand Down Expand Up @@ -1422,13 +1425,14 @@ void testProvisionStopEndRecordingException() throws InstantiationException,
frameworkField.set(sdvManager, framework);

// Replace LOG
Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
loggerField.setAccessible(true);
// remove final modifier
Field modifiersField = Field.class.getDeclaredField(modifiersString);
modifiersField.setAccessible(true);
modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL);
loggerField.set(sdvManager, mockLog);
final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString);
unsafeField.setAccessible(true);
final Unsafe unsafe = (Unsafe) unsafeField.get(null);

final Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField);
final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField);
unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog);

// Make call to funtion under test
sdvManager.provisionStop();
Expand Down Expand Up @@ -1539,13 +1543,14 @@ void testProvisionStopReleaseUsersException() throws InstantiationException,
frameworkField.set(sdvManager, framework);

// Replace LOG
Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
loggerField.setAccessible(true);
// remove final modifier
Field modifiersField = Field.class.getDeclaredField(modifiersString);
modifiersField.setAccessible(true);
modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL);
loggerField.set(sdvManager, mockLog);
final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString);
unsafeField.setAccessible(true);
final Unsafe unsafe = (Unsafe) unsafeField.get(null);

final Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField);
final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField);
unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog);

// Make call to funtion under test
sdvManager.provisionStop();
Expand Down Expand Up @@ -1656,13 +1661,14 @@ void testProvisionStopcleanUpEnvironmentsException() throws InstantiationExcepti
frameworkField.set(sdvManager, framework);

// Replace LOG
Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
loggerField.setAccessible(true);
// remove final modifier
Field modifiersField = Field.class.getDeclaredField(modifiersString);
modifiersField.setAccessible(true);
modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL);
loggerField.set(sdvManager, mockLog);
final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString);
unsafeField.setAccessible(true);
final Unsafe unsafe = (Unsafe) unsafeField.get(null);

final Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField);
final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField);
unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog);

// Make call to funtion under test
sdvManager.provisionStop();
Expand Down Expand Up @@ -1896,13 +1902,14 @@ void testReleaseUsersException() throws CredentialsException, NoSuchFieldExcepti
frameworkField.set(sdvManager, framework);

// Replace LOG
Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
loggerField.setAccessible(true);
// remove final modifier
Field modifiersField = Field.class.getDeclaredField(modifiersString);
modifiersField.setAccessible(true);
modifiersField.setInt(loggerField, loggerField.getModifiers() & ~Modifier.FINAL);
loggerField.set(sdvManager, mockLog);
final Field unsafeField = Unsafe.class.getDeclaredField(theUnsafeString);
unsafeField.setAccessible(true);
final Unsafe unsafe = (Unsafe) unsafeField.get(null);

final Field loggerField = sdvManagerImplClass.getDeclaredField(logString);
final Object staticLoggerFieldBase = unsafe.staticFieldBase(loggerField);
final long staticLoggerFieldOffset = unsafe.staticFieldOffset(loggerField);
unsafe.putObject(staticLoggerFieldBase, staticLoggerFieldOffset, mockLog);

// Make call to funtion under test
sdvManager.provisionStop();
Expand Down
Loading

0 comments on commit 20bef20

Please sign in to comment.