Commit 36f300d3 authored by neelesh thakur's avatar neelesh thakur
Browse files

clean-up

parent 0243115c
Pipeline #10435 passed with stages
in 13 minutes and 46 seconds
// Copyright 2017-2020, 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
//
// 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.partition.model;
import lombok.AllArgsConstructor;
......
......@@ -26,9 +26,7 @@ import org.opengroup.osdu.partition.provider.interfaces.IPartitionService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
......
// Copyright 2017-2020, 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
//
// 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.partition.provider.azure.di;
import lombok.Getter;
......
// Copyright 2017-2020, 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
//
// 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.partition.provider.azure.di;
import com.microsoft.azure.storage.CloudStorageAccount;
......@@ -18,7 +32,7 @@ import java.security.InvalidKeyException;
@Component
public class TableStorageClient {
private final String CONNECTION_STRING = "DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;EndpointSuffix=core.windows.net";
private final static String CONNECTION_STRING = "DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s;EndpointSuffix=core.windows.net";
@Bean
@Lazy
......
// Copyright 2017-2020, 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
//
// 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.partition.provider.azure.persistence;
import com.microsoft.azure.storage.StorageException;
......@@ -42,7 +56,6 @@ public class CloudTableStore {
public Iterable<? extends TableEntity> queryByCompoundKey(final Class<? extends TableEntity> clazzType,
final String rowKey, final String rowValue,
final String valueKey, final String value) {
String rowFilter = TableQuery.generateFilterCondition(
rowKey,
TableQuery.QueryComparisons.EQUAL,
......@@ -66,7 +79,7 @@ public class CloudTableStore {
try {
this.cloudTableClient.execute(batchOperation);
} catch (StorageException e) {
new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "error creating partition", e.getMessage(), e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "error creating partition", e.getMessage(), e);
}
}
}
// Copyright 2017-2020, 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
//
// 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.partition.provider.azure.persistence;
import com.microsoft.azure.storage.table.DynamicTableEntity;
......
// Copyright 2017-2020, 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
//
// 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.partition.provider.azure.persistence;
import com.microsoft.azure.storage.table.EntityProperty;
......@@ -19,8 +33,8 @@ public class PartitionTableStore {
private final static String VALUE = "value";
private final static String SENSITIVE = "sensitive";
private final String PARTITION_KEY = "PartitionKey";
private final String ROW_KEY = "RowKey";
private final static String PARTITION_KEY = "PartitionKey";
private final static String ROW_KEY = "RowKey";
@Autowired
private CloudTableStore cloudTableStore;
......@@ -76,17 +90,21 @@ public class PartitionTableStore {
return out;
}
@SuppressWarnings("unchecked")
public void deletePartition(String partitionId) {
Iterable<PartitionEntity> results = (Iterable<PartitionEntity>) this.cloudTableStore.queryByKey(PartitionEntity.class,
Iterable<PartitionEntity> results = (Iterable<PartitionEntity>)
this.cloudTableStore.queryByKey(PartitionEntity.class,
PARTITION_KEY, partitionId);
for (PartitionEntity tableEntity : results) {
this.cloudTableStore.deleteCloudTableEntity(PartitionEntity.class, tableEntity.getPartitionKey(), tableEntity.getRowKey());
}
}
@SuppressWarnings("unchecked")
private List<PartitionEntity> queryById(String partitionId) {
List<PartitionEntity> out = new ArrayList<>();
Iterable<PartitionEntity> results = (Iterable<PartitionEntity>) this.cloudTableStore.queryByCompoundKey(PartitionEntity.class,
Iterable<PartitionEntity> results = (Iterable<PartitionEntity>)
this.cloudTableStore.queryByCompoundKey(PartitionEntity.class,
ROW_KEY, ID,
VALUE, partitionId);
for (PartitionEntity tableEntity : results) {
......@@ -95,9 +113,11 @@ public class PartitionTableStore {
return out;
}
@SuppressWarnings("unchecked")
private List<PartitionEntity> getAllByPartitionId(String partitionId) {
List<PartitionEntity> out = new ArrayList<>();
Iterable<PartitionEntity> results = (Iterable<PartitionEntity>) this.cloudTableStore.queryByKey(PartitionEntity.class,
Iterable<PartitionEntity> results = (Iterable<PartitionEntity>)
this.cloudTableStore.queryByKey(PartitionEntity.class,
PARTITION_KEY, partitionId);
for (PartitionEntity tableEntity : results) {
tableEntity.setPartitionId(tableEntity.getPartitionKey());
......
......@@ -51,7 +51,7 @@ public class AuthorizationService implements IAuthorizationService {
*
* @return user principal
*/
private final Object getUserPrincipal() {
private Object getUserPrincipal() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
return auth.getPrincipal();
}
......
......@@ -16,13 +16,12 @@ package org.opengroup.osdu.partition.provider.azure;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import javax.inject.Inject;
import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
@RunWith(SpringRunner.class)
public class PartitionApplicationTest {
......
......@@ -24,9 +24,9 @@ import static org.mockito.Mockito.mock;
public class AzureBootstrapConfigTest {
private AzureBootstrapConfig bootstrapConfig = new AzureBootstrapConfig();
private final AzureBootstrapConfig bootstrapConfig = new AzureBootstrapConfig();
private SecretClient kv = mock(SecretClient.class);
private final SecretClient kv = mock(SecretClient.class);
@Test
public void config_returnsCorrectSecret_tblStorage() {
......
......@@ -40,10 +40,10 @@ public class PartitionServiceImplTest {
@InjectMocks
private PartitionServiceImpl sut;
private PartitionInfo partitionInfo = new PartitionInfo();
private final PartitionInfo partitionInfo = new PartitionInfo();
private final static String PARTITION_ID = "my-tenant";
private Map<String, Property> properties = new HashMap<>();
private final Map<String, Property> properties = new HashMap<>();
@Before
public void setup() {
......@@ -60,7 +60,7 @@ public class PartitionServiceImplTest {
try {
sut.createPartition(PARTITION_ID, this.partitionInfo);
} catch (AppException e) {
assertTrue(e.getError().getCode() == 409);
assertEquals(409, e.getError().getCode());
assertTrue(e.getError().getReason().equalsIgnoreCase("partition exist"));
assertTrue(e.getError().getMessage().equalsIgnoreCase("Partition with same id exist"));
}
......@@ -71,7 +71,7 @@ public class PartitionServiceImplTest {
when(this.tableStore.partitionExists(PARTITION_ID)).thenReturn(false);
PartitionInfo partInfo = sut.createPartition(PARTITION_ID, this.partitionInfo);
assertTrue(partInfo.getProperties().size() == 3);
assertEquals(3, partInfo.getProperties().size());
assertTrue(partInfo.getProperties().containsKey("id"));
assertTrue(partInfo.getProperties().containsKey("complianceRuleSet"));
assertTrue(partInfo.getProperties().containsKey("storageAccount"));
......@@ -94,7 +94,7 @@ public class PartitionServiceImplTest {
try {
sut.getPartition(PARTITION_ID);
} catch (AppException e) {
assertTrue(e.getError().getCode() == 404);
assertEquals(404, e.getError().getCode());
assertTrue(e.getError().getReason().equalsIgnoreCase("partition not found"));
assertTrue(e.getError().getMessage().equalsIgnoreCase("my-tenant partition not found"));
}
......@@ -114,7 +114,7 @@ public class PartitionServiceImplTest {
try {
this.sut.deletePartition("test-partition");
} catch (AppException ae) {
assertTrue(ae.getError().getCode() == 404);
assertEquals(404, ae.getError().getCode());
assertEquals("test-partition partition not found", ae.getError().getMessage());
}
}
......
......@@ -25,7 +25,6 @@ import io.jsonwebtoken.Jws;
import io.jsonwebtoken.impl.DefaultClaims;
import io.jsonwebtoken.impl.DefaultJws;
import lombok.Getter;
import net.minidev.json.JSONArray;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -63,7 +62,6 @@ public class AuthorizationServiceTest {
}
private UserPrincipal createAADUserPrincipal(String claimName, String claimValue, String issuer) {
final JSONArray claims = new JSONArray();
final JWTClaimsSet jwtClaimsSet = new JWTClaimsSet.Builder()
//.subject("subject")
.claim(claimName, claimValue)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment