diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java index b1db3272ebdd5e1de4e08a5fad41848826855e13..934dd8672caad9ed2ad945c1af2761d640d1b7b9 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java @@ -21,15 +21,16 @@ import com.microsoft.aad.adal4j.ClientCredential; import org.apache.http.HttpStatus; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.search.IdToken; -import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; -import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.net.MalformedURLException; -import java.util.concurrent.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; @Component public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClient { @@ -37,15 +38,10 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien @Autowired private AppProperties config; - @Autowired - private ITenantFactory tenantInfoServiceProvider; - @Autowired private IJwtCache tenantJwtCache; public String getIdToken(String tenantName) { - - String ACCESS_TOKEN = ""; ExecutorService service = null; @@ -97,4 +93,3 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien return ACCESS_TOKEN; } } - diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java index 65206d2aed741a3444974be0e8d9e30acc46a38a..2124bff88a50d6fcceb7814729277e57bfb09e0f 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java @@ -19,11 +19,9 @@ import com.auth0.jwt.algorithms.Algorithm; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.notification.provider.azure.util.AppProperties; import org.opengroup.osdu.notification.provider.azure.util.AzureServiceAccountValidatorImpl; @@ -34,7 +32,6 @@ import static org.mockito.MockitoAnnotations.initMocks; public class AzureServiceAccountValidatorImplTest { private static String eventGridId = "eventgridid"; - private static String invalidJWT = "invalidJWT"; @Mock private AppProperties appProperties; diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java index f567cd985334216cba0ebbed41e04625a904e4f5..e7caf1d3bf93c6e74b665570e48cb94a0d5c7f3d 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java @@ -26,8 +26,6 @@ import org.mockito.junit.MockitoJUnitRunner; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.search.IdToken; -import org.opengroup.osdu.core.common.model.tenant.TenantInfo; -import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; import org.opengroup.osdu.notification.provider.azure.cache.JwtCache; import org.opengroup.osdu.notification.provider.azure.util.AppProperties; import org.opengroup.osdu.notification.provider.azure.util.ServiceAccountJwtAzureClientImpl; @@ -36,8 +34,8 @@ import java.util.concurrent.ExecutorService; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.MockitoAnnotations.initMocks; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; @RunWith(MockitoJUnitRunner.class) public class ServiceAccountClientImplTest { @@ -45,12 +43,6 @@ public class ServiceAccountClientImplTest { final String tenantName = "Test Tenant"; final String validToken = "validToken"; - @Mock - private ITenantFactory tenantInfoServiceProvider; - - @Mock - private TenantInfo tenantInfo; - @Mock private IdToken idToken; @@ -73,29 +65,9 @@ public class ServiceAccountClientImplTest { @Before public void setup() { initMocks(this); - when(tenantInfo.getName()).thenReturn(tenantName); - when(this.tenantInfoServiceProvider.getTenantInfo(tenantName)).thenReturn(tenantInfo); idToken = IdToken.builder().tokenValue(validToken).expirationTimeMillis(System.currentTimeMillis() + 10000000L).build(); } - @Test - public void should_throwAppException_getIdTokenTest() { - // Set up - when(this.tenantInfoServiceProvider.getTenantInfo(tenantName)).thenReturn(null); - try { - // Act - sut.getIdToken(tenantName); - - // Assert - fail("Should throw exception"); - } catch (AppException e) { - Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, e.getError().getCode()); - Assert.assertEquals("Invalid tenant Name from azure", e.getError().getMessage()); - } catch (Exception e) { - fail("Should not throw this exception" + e.getMessage()); - } - } - @Test public void should_getTokenFromCache_getIdTokenTest() { // SetUp