remove unused DocumentDbConverter (#133)
* remove unused DocumentDbConverter * remove gson
This commit is contained in:
Родитель
f362a133fa
Коммит
40717d7cff
7
pom.xml
7
pom.xml
|
@ -47,7 +47,6 @@
|
|||
|
||||
<spring.springframework.version>5.0.5.RELEASE</spring.springframework.version>
|
||||
<spring.data.version>2.0.1.RELEASE</spring.data.version>
|
||||
<google.gson.version>2.8.2</google.gson.version>
|
||||
|
||||
<mockito.core.version>2.8.9</mockito.core.version>
|
||||
<powermock.version>1.7.1</powermock.version>
|
||||
|
@ -112,12 +111,6 @@
|
|||
<version>${azure.documentdb.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${google.gson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>applicationinsights-core</artifactId>
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
|
||||
package com.microsoft.azure.spring.data.cosmosdb.core.convert;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.microsoft.azure.documentdb.Document;
|
||||
|
||||
public class DocumentDbConverter {
|
||||
|
||||
private final Gson gson;
|
||||
|
||||
public DocumentDbConverter() {
|
||||
gson = new Gson();
|
||||
}
|
||||
|
||||
public <T> Document convertToDocument(T entity) {
|
||||
final String json = this.gson.toJson(entity);
|
||||
|
||||
return new Document(json);
|
||||
}
|
||||
|
||||
public <T> T convertFromDocument(Document document, Class<T> entityClass) {
|
||||
return this.gson.fromJson(document.toJson(), entityClass);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
|
||||
package com.microsoft.azure.spring.data.cosmosdb.core.converter;
|
||||
|
||||
|
||||
import com.microsoft.azure.documentdb.Document;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.common.TestConstants;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.core.convert.DocumentDbConverter;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.domain.Address;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.domain.Person;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DocumentDbConverterUnitTest {
|
||||
private DocumentDbConverter dbConverter;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
dbConverter = new DocumentDbConverter();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromEntityToDocument() {
|
||||
final Person person = new Person(TestConstants.ID, TestConstants.FIRST_NAME,
|
||||
TestConstants.LAST_NAME, TestConstants.HOBBIES, TestConstants.ADDRESSES);
|
||||
final Document document = dbConverter.convertToDocument(person);
|
||||
|
||||
assertTrue(document.has(TestConstants.PROPERTY_ID));
|
||||
assertTrue(document.has(TestConstants.PROPERTY_FIRST_NAME));
|
||||
assertTrue(document.has(TestConstants.PROPERTY_LAST_NAME));
|
||||
assertTrue(document.has(TestConstants.PROPERTY_HOBBIES));
|
||||
assertTrue(document.has(TestConstants.PROPERTY_SHIPPING_ADDRESSES));
|
||||
assertThat(document.getId()).isEqualTo(TestConstants.ID);
|
||||
assertThat(document.getString(TestConstants.PROPERTY_FIRST_NAME)).isEqualTo(TestConstants.FIRST_NAME);
|
||||
assertThat(document.getString(TestConstants.PROPERTY_LAST_NAME)).isEqualTo(TestConstants.LAST_NAME);
|
||||
|
||||
final Collection<String> gotHobbies = document.getCollection(TestConstants.PROPERTY_HOBBIES, String.class);
|
||||
assertTrue(TestConstants.HOBBIES.equals(gotHobbies));
|
||||
|
||||
final Collection<Address> gotAddresses =
|
||||
document.getCollection(TestConstants.PROPERTY_SHIPPING_ADDRESSES, Address.class);
|
||||
assertTrue(TestConstants.ADDRESSES.equals(gotAddresses));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromDocumentToEntity() {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put(TestConstants.PROPERTY_ID, TestConstants.ID);
|
||||
json.put(TestConstants.PROPERTY_FIRST_NAME, TestConstants.FIRST_NAME);
|
||||
json.put(TestConstants.PROPERTY_LAST_NAME, TestConstants.LAST_NAME);
|
||||
json.put(TestConstants.PROPERTY_HOBBIES, TestConstants.HOBBIES);
|
||||
json.put(TestConstants.PROPERTY_SHIPPING_ADDRESSES, TestConstants.ADDRESSES);
|
||||
|
||||
final Document document = new Document(JSONObject.valueToString(json));
|
||||
final Person person = dbConverter.convertFromDocument(document, Person.class);
|
||||
assertThat(person.getId()).isEqualTo(TestConstants.ID);
|
||||
assertThat(person.getFirstName()).isEqualTo(TestConstants.FIRST_NAME);
|
||||
assertThat(person.getLastName()).isEqualTo(TestConstants.LAST_NAME);
|
||||
assertThat(person.getHobbies()).isEqualTo(TestConstants.HOBBIES);
|
||||
assertThat(person.getShippingAddresses()).isEqualTo(TestConstants.ADDRESSES);
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче