Skip to content
Snippets Groups Projects
Commit 7d175db3 authored by Zhibin Mai's avatar Zhibin Mai Committed by David Diederich
Browse files

Add unit tests

(cherry picked from commit faf19bec)
parent b630d301
Branches
Tags
6 merge requests!604Merge Delta changes from M16 master to M18 master,!600Merge Delta changes from M16 master to M18 master,!599Merge Delta changes from M16 to M18 master,!598Merged from M16,!522M14 cherrypick to m16 master,!405Cherry-pick 'Geoshape decimation' into release/0.17
/*
* Copyright © Schlumberger
*
* 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
*
* https://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.indexer.util.geo.decimator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
public class DecimationSettingCacheTest {
private static final String VALID_KEY = "Tenant1-indexer-decimation-enabled";
private static final String INVALID_KEY = "Tenant2-indexer-decimation-enabled";
DecimationSettingCache cache;
@Before
public void setup() {
cache = new DecimationSettingCache();
cache.put(VALID_KEY, true);
}
@Test
public void getValidKey() {
Assert.assertTrue(cache.containsKey(VALID_KEY));
}
@Test
public void getInvalidKey() {
Assert.assertFalse(cache.containsKey(INVALID_KEY));
}
}
/*
* Copyright © Schlumberger
*
* 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
*
* https://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.indexer.util.geo.decimator;
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.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.partition.*;
import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(SpringRunner.class)
public class GeoShapeDecimationSettingTest {
private static final String PROPERTY_NAME = "indexer-decimation-enabled";
@InjectMocks
private GeoShapeDecimationSetting sut;
@Mock
private DecimationSettingCache cache;
@Mock
private JaxRsDpsLog logger;
@Mock
private DpsHeaders headers;
@Mock
private IPartitionFactory factory;
@Mock
private IServiceAccountJwtClient tokenService;
@Mock
IPartitionProvider partitionProvider;
@Before
public void setup() {
when(this.headers.getPartitionId()).thenReturn("dataPartitionId");
when(this.headers.getHeaders()).thenReturn(new HashMap());
when(this.factory.create(any())).thenReturn(partitionProvider);
when(this.tokenService.getIdToken(anyString())).thenReturn("token");
}
@Test
public void isDecimationEnabled_return_true() throws PartitionException {
PartitionInfo partitionInfo = new PartitionInfo();
Property property = new Property();
property.setSensitive(false);
property.setValue("true");
partitionInfo.getProperties().put(PROPERTY_NAME, property);
when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo);
boolean enabled = sut.isDecimationEnabled();
Assert.assertTrue(enabled);
}
@Test
public void isDecimationEnabled_return_false_when_property_set_to_false() throws PartitionException {
PartitionInfo partitionInfo = new PartitionInfo();
Property property = new Property();
property.setSensitive(false);
property.setValue("false");
partitionInfo.getProperties().put(PROPERTY_NAME, property);
when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo);
boolean enabled = sut.isDecimationEnabled();
Assert.assertFalse(enabled);
}
@Test
public void isDecimationEnabled_return_false_when_property_does_not_exist() throws PartitionException {
PartitionInfo partitionInfo = new PartitionInfo();
when(this.partitionProvider.get(anyString())).thenReturn(partitionInfo);
boolean enabled = sut.isDecimationEnabled();
Assert.assertFalse(enabled);
}
@Test
public void isDecimationEnabled_return_false_when_partitionProvider_throws_exception() throws PartitionException {
when(this.partitionProvider.get(anyString())).thenThrow(PartitionException.class);
boolean enabled = sut.isDecimationEnabled();
Assert.assertFalse(enabled);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment