diff --git a/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/cache/SearchAfterSettingsCacheImplTest.java b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/cache/SearchAfterSettingsCacheImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7b337d9ec8d0f5bf18f6f3c57a5510e4c0936e5a --- /dev/null +++ b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/cache/SearchAfterSettingsCacheImplTest.java @@ -0,0 +1,115 @@ +// Copyright © Amazon Web Services +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.search.provider.aws.cache; + +import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.mockito.MockedConstruction; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.opengroup.osdu.search.model.SearchAfterSettings; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +@RunWith(MockitoJUnitRunner.class) +public class SearchAfterSettingsCacheImplTest { + + + private final String s = "s"; + private final SearchAfterSettings o = new SearchAfterSettings("pitId", "userId", new ArrayList<String>(), new ArrayList<String>(), false, 0); + private final String password = "password"; + private final String endpoint = "CACHE_CLUSTER_ENDPOINT"; + private final String port = "6369"; + + @Test + public void local_VmCache_test() throws Exception{ + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(true); + })) { + SearchAfterSettingsCacheImpl cacheImpl = new SearchAfterSettingsCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + assertNull(cacheImpl.get(s)); + cacheImpl.clearAll(); + } + } + + @Test + public void non_local_Null_Credential_RedisCache_test() throws Exception{ + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(false); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_ENDPOINT"), any())).thenReturn(endpoint); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_PORT"), any())).thenReturn(port); + when(mockProvider.getCredentialsAsMap("CACHE_CLUSTER_KEY")).thenReturn(null); + })) { + try (MockedConstruction<RedisCache> cache = Mockito.mockConstruction(RedisCache.class, (mockCache, context) -> { + doNothing().when(mockCache).put(s,o); + when(mockCache.get(s)).thenReturn(o); + doNothing().when(mockCache).delete(s); + doNothing().when(mockCache).clearAll(); + doNothing().when(mockCache).close(); + })) { + SearchAfterSettingsCacheImpl cacheImpl = new SearchAfterSettingsCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + cacheImpl.clearAll(); + cacheImpl.close(); + } + } + } + + @Test + public void non_Local_notNull_Credential_RedisCache_test() throws Exception{ + + Map<String, String> map = new HashMap<String, String>(); + map.put("token", password); + + try (MockedConstruction<K8sLocalParameterProvider> provider = Mockito.mockConstruction(K8sLocalParameterProvider.class, (mockProvider, context) -> { + when(mockProvider.getLocalMode()).thenReturn(false); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_ENDPOINT"), any())).thenReturn(endpoint); + when(mockProvider.getParameterAsStringOrDefault(eq("CACHE_CLUSTER_PORT"), any())).thenReturn(port); + when(mockProvider.getCredentialsAsMap("CACHE_CLUSTER_KEY")).thenReturn(map); + })) { + try (MockedConstruction<RedisCache> cache = Mockito.mockConstruction(RedisCache.class, (mockCache, context) -> { + doNothing().when(mockCache).put(s,o); + when(mockCache.get(s)).thenReturn(o); + doNothing().when(mockCache).delete(s); + doNothing().when(mockCache).clearAll(); + doNothing().when(mockCache).close(); + })) { + SearchAfterSettingsCacheImpl cacheImpl = new SearchAfterSettingsCacheImpl(); + cacheImpl.put(s, o); + assertEquals(o, cacheImpl.get(s)); + cacheImpl.delete(s); + cacheImpl.clearAll(); + cacheImpl.close(); + } + } + } + +} diff --git a/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/di/EntitlementsFactoryAwsTest.java b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/di/EntitlementsFactoryAwsTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5f873363dbea5158983defc6f5950d72272e5ad3 --- /dev/null +++ b/provider/search-aws/src/test/java/org/opengroup/osdu/search/provider/aws/di/EntitlementsFactoryAwsTest.java @@ -0,0 +1,39 @@ +/** + * Copyright 2020 IBM Corp. All Rights Reserved. + * Copyright 2020 © Amazon Web Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.osdu.search.provider.aws.di; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.entitlements.EntitlementsFactory; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; + +import static org.junit.Assert.assertEquals; + +@RunWith(MockitoJUnitRunner.class) +public class EntitlementsFactoryAwsTest { + + @Test + public void entitlementsFactory_test(){ + EntitlementsFactoryAws entitlementFactory = new EntitlementsFactoryAws(); + + assertEquals(entitlementFactory.createInstance().getClass(), EntitlementsFactory.class); + assertEquals(entitlementFactory.getObjectType(), IEntitlementsFactory.class); + + } +}